(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[7627],{20063:(e,s,t)=>{"use strict";var a=t(47260);t.o(a,"usePathname")&&t.d(s,{usePathname:function(){return a.usePathname}}),t.o(a,"useRouter")&&t.d(s,{useRouter:function(){return a.useRouter}}),t.o(a,"useSearchParams")&&t.d(s,{useSearchParams:function(){return a.useSearchParams}})},21576:(e,s,t)=>{"use strict";t.d(s,{SettingsForm:()=>x});var a,i=t(95155),r=t(12115),l=t(20063),n=t(56502),o=t(95088),m=t(84820),u=t(89678);a=0;let c={anomaly:.22,dna:.24,load:.26,thermal:.19,weather:.09,healthAmplifier:.35,networkAmplifier:.15,gamma:1.15},d={anomaly:"risk.weight.anomaly",dna:"risk.weight.dna",load:"risk.weight.load",thermal:"risk.weight.thermal",weather:"risk.weight.weather",healthAmplifier:"risk.amplifier.health",networkAmplifier:"risk.amplifier.network",gamma:"risk.gamma"},h=["risk","escalation","prediction","runtime"];function x(e){let{settings:s,canManage:t,preview:a}=e,{t:x,locale:k,n:g}=(0,n.s)(),p=(0,l.useRouter)(),[f,y]=(0,r.useState)(()=>Object.fromEntries(s.map(e=>[e.key,e.value]))),[j,v]=(0,r.useState)(!1),[b,w]=(0,r.useState)(null),[N,S]=(0,r.useState)(null),[O,P]=(0,r.useState)({}),_=(0,r.useMemo)(()=>s.some(e=>f[e.key]!==e.value),[s,f]),C=[d.anomaly,d.dna,d.load,d.thermal,d.weather].reduce((e,s)=>e+(Number(f[s])||0),0),E=h.map(e=>({group:e,items:s.filter(s=>s.groupKey===e)})).filter(e=>e.items.length>0),A=async()=>{if(!_||j)return;v(!0),S(null),w(null),P({});let e=Object.fromEntries(s.filter(e=>f[e.key]!==e.value).map(e=>[e.key,f[e.key]]));try{await u.FH.patch("/api/settings",{values:e}),w(x("common.saved")),p.refresh()}catch(e){e instanceof u.E6?(S((0,u.oh)(e.failure,k)),e.failure.details&&P(e.failure.details)):S(x("common.serverError"))}finally{v(!1)}},D=()=>{let e={};for(let[s,t]of Object.entries(d))e[t]=String(c[s]);y(s=>({...s,...e}))};return(0,i.jsxs)("div",{className:"space-y-6",children:[N?(0,i.jsx)(o.Notice,{tone:"danger",children:N}):null,b?(0,i.jsx)(o.Notice,{tone:"success",children:b}):null,E.map(e=>{let{group:s,items:a}=e;return(0,i.jsxs)(m.Zk,{children:[(0,i.jsx)(m.aO,{title:x("settings.groups.".concat(s)),subtitle:"risk"===s?x("settings.riskNote"):void 0,action:"risk"===s&&t?(0,i.jsx)(o.$n,{size:"sm",variant:"ghost",onClick:D,children:x("settings.restoreDefaults")}):null}),(0,i.jsxs)(m.l_,{className:"space-y-4",children:["risk"===s?(0,i.jsxs)("div",{className:"rounded-lg border border-border bg-surface-2/40 px-4 py-3",children:[(0,i.jsxs)("div",{className:"flex flex-wrap items-baseline justify-between gap-2",children:[(0,i.jsx)("span",{className:"text-xs text-text-muted",children:x("settings.weightSum",{value:g(C,{maximumFractionDigits:2})})}),(0,i.jsx)("span",{className:"text-[11px] text-text-faint",children:x("settings.weightSumNote")})]}),(0,i.jsx)(m.kI,{value:Math.min(100,100*C),className:"mt-2"})]}):null,(0,i.jsx)("div",{className:"grid gap-4 sm:grid-cols-2",children:a.map(e=>{var s,a;return(0,i.jsx)(o.D0,{label:"ar"===k?e.labelAr:e.label,htmlFor:e.key,hint:"ar"===k?e.descriptionAr:e.description,error:(0,u.qd)(O[e.key],x),children:"boolean"===e.valueType?(0,i.jsx)(o.dO,{id:e.key,checked:"true"===f[e.key],disabled:!t,onChange:s=>y(t=>({...t,[e.key]:String(s)})),label:"true"===f[e.key]?x("common.yes"):x("common.no")}):(0,i.jsx)(o.pd,{id:e.key,type:"number",dir:"ltr",step:null!==e.maxValue&&e.maxValue<=2?.01:1,min:null!=(s=e.minValue)?s:void 0,max:null!=(a=e.maxValue)?a:void 0,value:f[e.key],disabled:!t,invalid:!!O[e.key],onChange:s=>y(t=>({...t,[e.key]:s.target.value}))})},e.key)})})]})]},s)}),a?(0,i.jsxs)(m.Zk,{children:[(0,i.jsx)(m.aO,{title:x("settings.preview"),subtitle:x("settings.previewNote")}),(0,i.jsxs)(m.l_,{children:[(0,i.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[(0,i.jsx)("span",{className:"font-mono text-sm text-brand",children:a.assetCode}),(0,i.jsxs)("span",{className:"tnum text-2xl font-semibold text-text",children:[g(a.riskScore,{maximumFractionDigits:1}),"%"]})]}),(0,i.jsx)(m.kI,{value:a.riskScore,className:"mt-3"})]})]}):null,t?(0,i.jsx)("div",{className:"sticky bottom-4 flex justify-end",children:(0,i.jsx)(o.$n,{onClick:A,loading:j,disabled:!_,size:"lg",children:j?x("common.saving"):x("common.save")})}):(0,i.jsx)(o.Notice,{tone:"info",children:x("common.permissionDeniedBody")})]})}},88947:(e,s,t)=>{Promise.resolve().then(t.t.bind(t,52619,23)),Promise.resolve().then(t.bind(t,21576))}},e=>{e.O(0,[2619,4909,4820,4672,8441,1255,7358],()=>e(e.s=88947)),_N_E=e.O()}]);