(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[416],{19746:(e,s,t)=>{Promise.resolve().then(t.t.bind(t,52619,23)),Promise.resolve().then(t.bind(t,68295))},68295:(e,s,t)=>{"use strict";t.d(s,{StressTestRunner:()=>m});var a=t(95155),n=t(12115),l=t(56502),i=t(95088),r=t(84820),c=t(89678),d=t(76445);function m(e){var s,t;let{regions:m}=e,{t:o,locale:x,n:u}=(0,l.s)(),h="ar"===x,[j,p]=(0,n.useState)(""),[b,g]=(0,n.useState)(null),[f,N]=(0,n.useState)(null),[k,v]=(0,n.useState)(!1),P=async()=>{v(!0),N(null);try{g(await c.FH.post("/api/stress-test",{regionCode:j||null,maxDeltaPct:45,stepPct:5}))}catch(e){N(e instanceof c.E6?h?e.failure.messageAr:e.failure.message:String(e))}finally{v(!1)}};return(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsxs)(r.Zk,{children:[(0,a.jsx)(r.aO,{title:o("stressTest.title"),subtitle:o("stressTest.subtitle")}),(0,a.jsxs)(r.l_,{className:"pt-0",children:[(0,a.jsxs)("div",{className:"flex flex-wrap items-end gap-3",children:[(0,a.jsx)(i.D0,{label:o("stressTest.scope"),htmlFor:"stress-region",className:"w-56",children:(0,a.jsxs)(i.l6,{id:"stress-region",value:j,onChange:e=>p(e.target.value),children:[(0,a.jsx)("option",{value:"",children:o("stressTest.national")}),m.map(e=>(0,a.jsx)("option",{value:e.code,children:h?e.nameAr:e.name},e.code))]})}),(0,a.jsx)(i.$n,{onClick:P,loading:k,children:k?o("stressTest.running"):o("stressTest.run")})]}),f?(0,a.jsx)(i.Notice,{tone:"danger",className:"mt-3",children:f}):null]})]}),b?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"grid gap-3 sm:grid-cols-2 lg:grid-cols-4",children:[(0,a.jsx)(r.hI,{label:o("stressTest.breakingPoint"),value:null===b.breakingPointPct?"—":"+".concat(u(b.breakingPointPct),"%"),state:null===b.breakingPointPct?"normal":b.breakingPointPct<=15?"critical":"warning",hint:null===b.breakingPointPct?o("stressTest.noBreakingPoint"):void 0}),(0,a.jsx)(r.hI,{label:o("stressTest.maxSafeLoad"),value:u(b.maximumSafeLoadMw),unit:"MW"}),(0,a.jsx)(r.hI,{label:o("stressTest.weakestAsset"),value:null!=(s=b.weakestAssetCode)?s:"—",hint:h?b.weakestAssetNameAr:b.weakestAssetName}),(0,a.jsx)(r.hI,{label:o("cascade.affectedAssets"),value:u(b.failureSequence.filter(e=>"failed"===e.outcome).length)})]}),(0,a.jsxs)(r.Zk,{children:[(0,a.jsx)(r.aO,{title:o("stressTest.step"),action:(0,a.jsx)(r.Ex,{tone:"accent",children:o("common.simulated")})}),(0,a.jsx)(r.l_,{className:"pt-0",children:(0,a.jsx)("div",{className:"overflow-x-auto",children:(0,a.jsxs)("table",{className:"w-full min-w-[32rem] text-xs",children:[(0,a.jsx)("thead",{children:(0,a.jsxs)("tr",{className:"border-b border-border text-[10px] uppercase tracking-wide text-text-faint",children:[(0,a.jsx)("th",{className:"py-2 text-start font-medium",children:o("stressTest.step")}),(0,a.jsx)("th",{className:"py-2 text-end font-medium",children:o("commandCenter.cards.totalLoad")}),(0,a.jsx)("th",{className:"py-2 text-end font-medium",children:o("common.riskScore")}),(0,a.jsx)("th",{className:"py-2 text-end font-medium",children:o("commandCenter.cards.gridStability")}),(0,a.jsx)("th",{className:"py-2 text-end font-medium",children:o("stressTest.assetsOverLimit")})]})}),(0,a.jsx)("tbody",{children:b.steps.map(e=>(0,a.jsxs)("tr",{className:(0,d.cn)("border-b border-border/50 last:border-0",b.breakingPointPct===e.loadDeltaPct&&"bg-critical/8"),children:[(0,a.jsxs)("td",{className:"tnum py-2 text-text",children:["+",u(e.loadDeltaPct),"%"]}),(0,a.jsx)("td",{className:"tnum py-2 text-end text-text-muted",children:u(e.totalLoadMw)}),(0,a.jsxs)("td",{className:"tnum py-2 text-end text-text-muted",children:[u(e.peakRisk,{maximumFractionDigits:0}),"%"]}),(0,a.jsx)("td",{className:"tnum py-2 text-end text-text-muted",children:u(e.stabilityIndex,{maximumFractionDigits:1})}),(0,a.jsx)("td",{className:(0,d.cn)("tnum py-2 text-end font-medium",e.assetsOverLimit>0?"text-critical":"text-text-faint"),children:u(e.assetsOverLimit)})]},e.loadDeltaPct))})]})})})]}),b.failureSequence.length>0?(0,a.jsxs)(r.Zk,{children:[(0,a.jsx)(r.aO,{title:o("stressTest.sequence"),subtitle:null!=(t=b.weakestAssetCode)?t:""}),(0,a.jsx)(r.l_,{className:"pt-0",children:(0,a.jsx)("ol",{className:"space-y-2",children:b.failureSequence.map((e,s)=>(0,a.jsxs)("li",{className:"flex items-baseline gap-3 text-xs",children:[(0,a.jsxs)("span",{className:"tnum w-12 shrink-0 text-end text-text-faint",children:["+",u(e.offsetMin)]}),(0,a.jsx)("span",{className:"font-mono text-text",children:e.assetCode}),(0,a.jsx)("span",{className:"text-text-muted",children:o("cascade.outcome.".concat(e.outcome))}),(0,a.jsxs)("span",{className:"tnum ms-auto text-text-faint",children:[u(100*e.probability,{maximumFractionDigits:0}),"%"]})]},"".concat(e.assetCode,"-").concat(s)))})})]}):null]}):null]})}}},e=>{e.O(0,[2619,4909,4820,4672,8441,1255,7358],()=>e(e.s=19746)),_N_E=e.O()}]);