import{ButtonWithLoading as e,Button_default as t,Chip_default as n,FormControl_default as r,Fragment as i,Grid_default as a,InputLabel_default as o,Input_default as s,L as c,MenuItem_default as l,Select_default as u,__toESM as d,heatsRepository as f,jsx as p,jsxs as m,modal_default as h,n as g,require_react as _,useAppSelector as v}from"./index-BSpgqPAY.js";import{RootTypeEnum as y}from"./root-type.enum-Bd2G-woW.js";var b=d(_());const x=e=>e===`Empty`?`secondary`:`primary`,S=({openModal:d,heatId:_,heatName:S,initialLadleId:C,onClose:w})=>{let[T,E]=(0,b.useState)(null),[D,O]=(0,b.useState)(0),k=C?D?`Change`:`Empty`:`Assign new`,A=v(e=>{var t;return(t=e.common.lookupTables)?.roots}),j=(0,b.useMemo)(()=>{let e=Object.values(A||{}).filter(e=>e.rootTypeId===y.LADLE);return e.reduce((e,t)=>(e[t.rootId]=t,e),{})},[A]),[M,N]=(0,b.useState)(!1),P=(0,b.useCallback)(async()=>{N(!0);try{let e=await f.changeLadleForHeat(_,D);e.success?(g(`Success`,{icon:p(c,{})}),O(0),w(!0)):E(e.result)}catch(e){E(e.toString())}finally{N(!1)}},[_,D,w]),F=(0,b.useCallback)(e=>{O(parseInt(e))},[_,D]);return m(i,{children:[m(h,{open:d,handleClose:()=>{w(!1),O(0)},maxWidth:`sm`,title:`Change Ladle for Heat ${S}`,id:`change-ladle-modal`,children:[p(h.Content,{children:m(a,{container:!0,spacing:3,children:[p(a,{item:!0,xs:12,md:6,children:m(r,{style:{minWidth:`170px`,width:`100%`},children:[p(o,{children:`Old Ladle`}),m(u,{onChange:e=>{F(e.target.value)},displayEmpty:!0,disabled:!0,value:C,input:p(s,{}),renderValue:e=>e?p(n,{label:j[e].rootName}):p(`div`,{}),inputProps:{"aria-label":`Without label`},children:[p(l,{disabled:!0,value:``,children:p(`div`,{})}),Object.values(A||{}).filter(e=>e.rootTypeId===y.LADLE).map(e=>p(l,{value:e.rootId,children:e.rootName},`ladle-${e.rootId}`))]})]})}),p(a,{item:!0,xs:12,md:6,children:m(r,{style:{minWidth:`170px`,width:`100%`},children:[p(o,{children:`New Ladle`}),m(u,{onChange:e=>F(e.target.value),displayEmpty:!0,value:D,input:p(s,{}),renderValue:e=>e?p(n,{label:j[e].rootName}):p(`div`,{}),inputProps:{"aria-label":`Without label`},children:[p(l,{value:``,children:p(`div`,{children:`Empty Ladle`})}),Object.values(A||{}).filter(e=>e.rootTypeId===y.LADLE).map(e=>p(l,{value:e.rootId,children:e.rootName},`ladle-${e.rootId}`))]})]})})]})}),p(h.Actions,{children:p(a,{container:!0,justifyContent:`flex-end`,children:p(a,{item:!0,xs:12,children:m(e,{variant:`contained`,isLoading:M,color:x(k),fullWidth:!0,onClick:P,children:[k,` Ladle`]})})})})]}),m(h,{title:`Ups!`,open:!!T,handleClose:()=>E(null),maxWidth:`md`,children:[p(h.Content,{children:p(a,{container:!0,spacing:3,children:p(a,{item:!0,xs:12,children:p(`p`,{children:T})})})}),p(h.Actions,{children:p(t,{onClick:()=>E(null),children:`OK`})})]})]})};export{S as ChangeLadleModal};
//# sourceMappingURL=change-ladle.modal-5bBroKBd.js.map