import{r as a,b as w,x as F,z as M,j as t,_ as N,a as r,F as O,G as l,S as n,W as I,X as S,Y as E,Z as c,aM as W,bi as j,y as B,B as D}from"./index-BMKwTcAk.js";import{R as y}from"./root-type.enum-Cp1EXS66.js";const R=u=>u==="Empty"?"secondary":"primary",H=({openModal:u,heatId:h,heatName:A,initialLadleId:b,onClose:p})=>{const[g,i]=a.useState(null),[o,m]=a.useState(0),L=b?o?"Change":"Empty":"Assign new",s=w(e=>e.common.lookupTables?.roots),f=a.useMemo(()=>Object.values(s||{}).filter(d=>d.rootTypeId===y.LADLE).reduce((d,x)=>(d[x.rootId]=x,d),{}),[s]),[T,C]=a.useState(!1),k=a.useCallback(async()=>{C(!0);try{const e=await F.changeLadleForHeat(h,o);e.success?(M("Success",{icon:t(N,{})}),m(0),p(!0)):i(e.result)}catch(e){i(e.toString())}finally{C(!1)}},[h,o,p]),v=a.useCallback(e=>{m(parseInt(e))},[h,o]);return r(O,{children:[r(l,{open:u,handleClose:()=>{p(!1),m(0)},maxWidth:"sm",title:`Change Ladle for Heat ${A}`,id:"change-ladle-modal",children:[t(l.Content,{children:r(n,{container:!0,spacing:3,children:[t(n,{item:!0,xs:12,md:6,children:r(I,{style:{minWidth:"170px",width:"100%"},children:[t(S,{children:"Old Ladle"}),r(E,{onChange:e=>{v(e.target.value)},displayEmpty:!0,disabled:!0,value:b,input:t(j,{}),renderValue:e=>e?t(W,{label:f[e].rootName}):t("div",{}),inputProps:{"aria-label":"Without label"},children:[t(c,{disabled:!0,value:"",children:t("div",{})}),Object.values(s||{}).filter(e=>e.rootTypeId===y.LADLE).map(e=>t(c,{value:e.rootId,children:e.rootName},`ladle-${e.rootId}`))]})]})}),t(n,{item:!0,xs:12,md:6,children:r(I,{style:{minWidth:"170px",width:"100%"},children:[t(S,{children:"New Ladle"}),r(E,{onChange:e=>v(e.target.value),displayEmpty:!0,value:o,input:t(j,{}),renderValue:e=>e?t(W,{label:f[e].rootName}):t("div",{}),inputProps:{"aria-label":"Without label"},children:[t(c,{value:"",children:t("div",{children:"Empty Ladle"})}),Object.values(s||{}).filter(e=>e.rootTypeId===y.LADLE).map(e=>t(c,{value:e.rootId,children:e.rootName},`ladle-${e.rootId}`))]})]})})]})}),t(l.Actions,{children:t(n,{container:!0,justifyContent:"flex-end",children:t(n,{item:!0,xs:12,children:r(B,{variant:"contained",isLoading:T,color:R(L),fullWidth:!0,onClick:k,children:[L," Ladle"]})})})})]}),r(l,{title:"Ups!",open:!!g,handleClose:()=>i(null),maxWidth:"md",children:[t(l.Content,{children:t(n,{container:!0,spacing:3,children:t(n,{item:!0,xs:12,children:t("p",{children:g})})})}),t(l.Actions,{children:t(D,{onClick:()=>i(null),children:"OK"})})]})]})};export{H as C};
//# sourceMappingURL=change-ladle.modal-Uvj0fTFl.js.map
