@seedtactics/insight-client 16.8.4-beta.6 → 16.8.4-beta.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -346,7 +346,7 @@ a=extmap-allow-mixed`)!==-1){let n=t.sdp.split(`
346
346
  <tbody>
347
347
  `;for(let r of t){n+=`<tr>`;for(let t of e)if(!t.ignoreDuringExport){let e=t.getForExport?t.getForExport(r):t.getDisplay(r);n+=`<td>`+e+`</td>`}n+=`</tr>
348
348
  `}return n+=`</tbody>
349
- </table>`,n}function J1(e,t){oA(q1(e,t))}var Y1=[{id:0,numeric:!1,label:`Date`,getDisplay:e=>e.time.toLocaleString(),getForSort:e=>e.time.getTime()},{id:1,numeric:!1,label:`Serial`,getDisplay:e=>e.serial||``},{id:2,numeric:!1,label:`Workorder`,getDisplay:e=>e.workorder||``},{id:3,numeric:!1,label:`Inspected`,getDisplay:e=>e.toInspect?`inspected`:``},{id:4,numeric:!1,label:`Failed`,getDisplay:e=>e.failed?`failed`:``}];function X1(e,t,n){let[r,i]=(0,I.useState)(void 0),a;return e&&e===`Last30Days`?a={type:`Last30Days`,set_days_back:e=>{if(e){let t=new Date;i({start:tE(t,-e),end:iE(t,1)})}else i(void 0)}}:e&&e===`ZoomIntoRange`?a={type:`ZoomIntoRange`,default_date_range:n,current_date_zoom:r,set_date_zoom_range:i}:e&&t&&e===`ExtendDays`&&(a={type:`ExtendDays`,curStart:n[0],curEnd:n[1],extend:t}),{zoom:a,zoomRange:r}}var Z1=(0,I.memo)(function(e){let t=R(bI),n=K1(0,Y1),[r,i]=(0,I.useState)(gO.empty()),[a,o]=(0,I.useState)(10),[s,c]=(0,I.useState)(void 0),l=X1(e.zoomType,e.extendDateRange,e.default_date_range),u=JX(e.points,l.zoomRange,n.sortOn);return(0,H.jsx)(`div`,{style:{width:`100%`,marginTop:`1em`},children:Q.of(u).toSortedArray(([e])=>e).map(([u,d])=>{let f=Math.min(r.get(u)??0,Math.ceil(d.material.length/a));return(0,H.jsxs)(ree,{expanded:u===s,onChange:(e,t)=>c(t?u:void 0),children:[(0,H.jsxs)(Sm,{expandIcon:(0,H.jsx)(CT,{}),children:[(0,H.jsx)(q,{variant:`h6`,style:{flexBasis:`33.33%`,flexShrink:0},children:u}),(0,H.jsxs)(q,{variant:`caption`,children:[d.material.length,` total parts, `,d.failedCnt,` failed`]})]}),(0,H.jsx)(see,{children:(0,H.jsxs)(`div`,{style:{width:`100%`},children:[(0,H.jsxs)(AC,{children:[(0,H.jsx)(L1,{columns:Y1,sort:n,showDetailsCol:!0}),(0,H.jsx)(U1,{columns:Y1,pageData:Q.of(d.material).drop(f*a).take(a),rowsPerPage:a,onClickDetails:e.hideOpenDetailColumn?void 0:(e,n)=>t({type:`MatSummary`,summary:{materialID:n.materialID,partName:n.partName,serial:n.serial,workorderId:n.workorder}})})]}),(0,H.jsx)(H1,{tpage:{page:f,rowsPerPage:a,setPage:e=>i(r.set(u,e)),setRowsPerPage:o},count:d.material.length,zoom:l.zoom})]})})]},u)})})}),Q1=20,$1=20,e0=120,t0=20;function n0({link:e,path:t,strokeWidth:n,setTooltip:r}){let[i,a]=(0,I.useState)(!1);if(t===null)return null;function o(t){let n=NA(t);n!==null&&(r({left:n.x,top:n.y,data:e}),a(!0))}function s(){a(!1),r(null)}return(0,H.jsx)(`path`,{d:t,stroke:i?Nr[600]:Nr[300],strokeWidth:n,opacity:.2,fill:`none`,onMouseMove:o,onMouseLeave:s})}function r0({node:e}){return e.x1===void 0||e.x0===void 0||e.y1===void 0||e.y0===void 0?null:(0,H.jsxs)(`g`,{transform:`translate(${e.x0}, ${e.y0})`,children:[(0,H.jsx)(`rect`,{width:e.x1-e.x0,height:e.y1-e.y0,fill:Nr[800],opacity:.8,stroke:`none`}),(0,H.jsx)(`text`,{x:18,y:(e.y1-e.y0)/2,children:e.name})]})}var i0=(0,I.memo)(function({data:e,setTooltip:t,parentHeight:n,parentWidth:r}){let{nodes:i,links:a}=(0,I.useMemo)(()=>{let t=LZ(e);if(t.nodes.length===0)return{nodes:[],links:[]};let i=hZ().nodeWidth(10).nodePadding(10).nodeAlign(iZ).extent([[Q1,$1],[r-e0,n-t0-$1]])({nodes:t.nodes,links:t.links});return{nodes:i.nodes,links:i.links.flatMap(e=>typeof e.source==`object`&&typeof e.target==`object`&&e.width!==void 0?[{...e,source:e.source,target:e.target,width:e.width}]:[])}},[e,r,n]),o=NZ();return(0,H.jsxs)(`svg`,{width:r,height:n,children:[(0,H.jsx)(`g`,{children:i.map((e,t)=>(0,H.jsx)(r0,{node:e},t))}),(0,H.jsx)(`g`,{children:a.map((e,n)=>(0,H.jsx)(n0,{link:e,path:o(e),strokeWidth:Math.max(e.width??1,1),setTooltip:t},n))})]})});function a0({tooltip:e}){return e===null?null:(0,H.jsxs)(`div`,{children:[e.data.source.name,` ➞ `,e.data.target.name,`: `,e.data.value,` parts`]})}var o0=(0,I.memo)(function({data:e}){let t=(0,I.useMemo)(()=>P(null),[]),n=R(t);return(0,H.jsx)(`div`,{style:{position:`relative`},children:(0,H.jsx)(KA,{sx:{height:{xs:`calc(100vh - 230px)`,md:`calc(100vh - 182px)`,xl:`calc(100vh - 130px)`},width:`100%`},chart:({height:t,width:r})=>(0,H.jsx)(i0,{data:e,setTooltip:n,parentHeight:t,parentWidth:r}),tooltipAtom:t,TooltipContent:a0})})}),s0=AO(e=>e(HI)?`aaa`:void 0),c0=AO(e=>e(HI)?`CMM`:void 0),l0=P(!1);function u0(e){let[t,n]=z(s0),[r,i]=z(c0),[a,o]=z(l0),s,c=e.restrictToPart||t;c&&r&&(s=e.inspectionlogs.get(new rL(c,r))?.valuesToLazySeq()??[]);let l=e.inspectionlogs.keysToLazySeq().map(e=>e.part).distinct().toSortedArray(e=>e),u=e.inspectionlogs.keysToLazySeq().map(e=>e.inspType).distinct().toSortedArray(e=>e);return(0,H.jsxs)(J,{sx:{paddingLeft:`24px`,paddingRight:`24px`,paddingTop:`10px`},children:[(0,H.jsxs)(J,{component:`nav`,sx:{display:`flex`,minHeight:`2.5em`,alignItems:`center`,maxWidth:`calc(100vw - 24px - 24px)`},children:[e.subtitle?(0,H.jsx)(q,{variant:`subtitle1`,children:e.subtitle}):void 0,(0,H.jsx)(J,{sx:{flexGrow:1}}),e.onlyTable?void 0:(0,H.jsx)(Ry,{size:`small`,children:(0,H.jsxs)(oS,{autoWidth:!0,value:a?`table`:`sankey`,onChange:e=>o(e.target.value===`table`),children:[(0,H.jsx)(wx,{value:`sankey`,children:`Sankey`},`sankey`),(0,H.jsx)(wx,{value:`table`,children:`Table`},`table`)]})}),(0,H.jsx)(Ry,{size:`small`,children:(0,H.jsxs)(oS,{name:`inspection-sankey-select-type`,autoWidth:!0,displayEmpty:!0,style:{marginRight:`1em`,marginLeft:`1em`},value:r||``,onChange:e=>i(e.target.value),children:[r?void 0:(0,H.jsx)(wx,{value:``,children:(0,H.jsx)(`em`,{children:`Select Inspection Type`})},0),u.map(e=>(0,H.jsx)(wx,{value:e,children:e},e))]})}),e.restrictToPart===void 0?(0,H.jsx)(Ry,{size:`small`,children:(0,H.jsxs)(oS,{name:`inspection-sankey-select-part`,autoWidth:!0,displayEmpty:!0,value:c||``,onChange:e=>n(e.target.value),children:[c?void 0:(0,H.jsx)(wx,{value:``,children:(0,H.jsx)(`em`,{children:`Select Part`})},0),l.map(e=>(0,H.jsx)(wx,{value:e,children:(0,H.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`},children:[(0,H.jsx)(LU,{part:e,size:30}),(0,H.jsx)(`span`,{style:{marginRight:`1em`},children:e})]})},e))]})}):void 0,s?(0,H.jsx)(X,{title:`Copy to Clipboard`,children:(0,H.jsx)(Gm,{onClick:()=>s?QX(c||``,r||``,s):void 0,style:{height:`25px`,paddingTop:0,paddingBottom:0},size:`large`,children:(0,H.jsx)(jT,{})})}):void 0]}),(0,H.jsx)(`main`,{children:s?a||e.onlyTable?(0,H.jsx)(Z1,{zoomType:e.zoomType,points:s,default_date_range:e.default_date_range,extendDateRange:e.extendDateRange,hideOpenDetailColumn:e.hideOpenDetailColumn}):(0,H.jsx)(o0,{data:s}):void 0})]})}var d0=P(null),f0=BO(P(async(e,{signal:t})=>{let n=e(d0);if(n==null||Ut===void 0)return gO.empty();let r=await Ut.get(n.curStart,n.curEnd,t);return Q.of(r).flatMap(sL).filter(e=>e.key.part===n.part).toLookupMap(e=>e.key,e=>e.entry.cntr,e=>e.entry)}),e=>e??gO.empty()),p0=BO(P(async e=>{let t=e(d0);if(t==null)return gO.empty();let n=[];for(let e of Kt)n.push(await e.get(t.curStart,t.curEnd));return Q.of(n).flatMap(e=>e).flatMap(sL).filter(e=>e.key.part===t.part).toLookupMap(e=>e.key,e=>e.entry.cntr,e=>e.entry)}),e=>e??gO.empty()),m0=P(e=>gO.union((e,t)=>e.union(t),e(f0),e(p0)));function h0(e){return t=>t===null?null:e<0?{curStart:tE(t.curStart,e),curEnd:t.curEnd,part:t.part}:{curStart:t.curStart,curEnd:tE(t.curEnd,e),part:t.part}}var g0=[{id:0,numeric:!1,label:`Date`,getDisplay:e=>e.time.toLocaleString(),getForSort:e=>e.time.getTime()},{id:1,numeric:!1,label:`Part`,getDisplay:e=>e.part},{id:2,numeric:!1,label:`Inspection`,getDisplay:e=>e.inspType},{id:3,numeric:!1,label:`Serial`,getDisplay:e=>e.serial||``},{id:4,numeric:!1,label:`Workorder`,getDisplay:e=>e.workorder||``}];function _0(e){let t=WI(),n=K1(0,g0),r=G1(),i=R(bI),a=Math.min(r.page,Math.ceil(e.failed.length/r.rowsPerPage)),o=Q.of(e.failed).sortBy(n.sortOn);return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(AC,{children:[(0,H.jsx)(L1,{columns:g0,sort:n,showDetailsCol:!t}),(0,H.jsx)(U1,{columns:g0,pageData:o.drop(a*r.rowsPerPage).take(r.rowsPerPage),rowsPerPage:r.rowsPerPage,onClickDetails:t?void 0:(e,t)=>{i({type:`MatSummary`,summary:{materialID:t.materialID,partName:t.part,serial:t.serial,workorderId:t.workorder}})}})]}),(0,H.jsx)(H1,{tpage:{...r,page:a},count:e.failed.length})]})}function v0(){let e=L(aL),t=(0,I.useMemo)(()=>{let t=bE();return YX(Q.of(e).flatMap(([e,t])=>t.valuesToLazySeq()),tE(t,-4),tE(t,1))},[e]);return(0,H.jsxs)(`div`,{children:[(0,H.jsxs)(J,{component:`nav`,sx:{display:`flex`,minHeight:`2.5em`,alignItems:`center`,maxWidth:`calc(100vw - 24px - 24px)`},children:[(0,H.jsx)(q,{variant:`subtitle1`,children:`Inspections marked as failed in the last 5 days`}),(0,H.jsx)(J,{sx:{flexGrow:1}}),(0,H.jsx)(X,{title:`Copy to Clipboard`,children:(0,H.jsx)(Gm,{style:{height:`25px`,paddingTop:0,paddingBottom:0},onClick:()=>eZ(t),size:`large`,children:(0,H.jsx)(jT,{})})})]}),(0,H.jsx)(_0,{failed:t})]})}function y0(){let e=WI(),t=R(bI),[n,r]=(0,I.useState)(e?`00000000i9`:``),[i,a]=(0,I.useState)(!1),[o,s]=(0,I.useState)(null);function c(){n&&n!==``&&(a(!0),s(null),Ut.materialForSerial(n).then(e=>{let i=Q.of(e).maxBy(e=>e.materialID);i?(t({type:`MatDetails`,details:i}),r(``),s(null)):s(`No material found with serial `+n)}).catch(e=>{zt.isApiException(e)?s(e.response):e instanceof Error?s(e.message):s(e)}).finally(()=>a(!1)))}return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(MS,{direction:`row`,spacing:2,sx:{alignItems:`center`,marginLeft:`auto`,marginRight:`auto`},children:[(0,H.jsx)(`div`,{children:(0,H.jsx)(Hw,{label:n===``?`Serial`:`Serial (press enter)`,value:n,onChange:e=>r(e.target.value),onKeyPress:e=>{e.key===`Enter`&&n!==``&&(e.preventDefault(),c())}})}),(0,H.jsx)(`div`,{children:(0,H.jsx)(Y,{variant:`contained`,color:`secondary`,disabled:n===``||i,onClick:c,children:i?(0,H.jsxs)(MS,{direction:`row`,spacing:2,children:[(0,H.jsx)(zm,{}),` Searching`]}):(0,H.jsx)(H.Fragment,{children:`Lookup`})})})]}),o&&o!==``?(0,H.jsx)(`div`,{children:o}):void 0]})}function b0(e){let t=e[0];if(t===void 0)return bE();let n=t.endUTC;for(let t of e)t.type===B.MachineCycle&&(n=t.endUTC);return n}function x0(){let e=L(wI),t=L(AI);return e?(0,H.jsx)(nW,{partName:e.partName,serial:e.serial,subtitle:`Path `+qX(XX(t))+` at `+b0(t).toLocaleString()}):(0,H.jsx)(`div`,{children:`Serial Details`})}function S0({setStep:e}){let t=L(wI),n=L(AI),r=R(d0),i=R(bI);return(0,H.jsxs)(MS,{direction:`row`,spacing:2,sx:{mt:`2em`},children:[t?(0,H.jsx)(Y,{variant:`contained`,color:`secondary`,onClick:()=>{let i=b0(n);r({part:t?.partName??``,curStart:cE(tE(i,-5)),curEnd:Sre(tE(i,5))}),e(2)},children:`Lookup Similar Paths`}):void 0,(0,H.jsx)(Y,{variant:`contained`,style:{marginLeft:`2em`},onClick:()=>{i(null),r(null),e(0)},children:`Reset`})]})}function C0(e){let t=L(CI),n=L(AI),[r,i]=z(d0),a=L(m0),o=R(bI);if(t===null)return null;function s(e){i(h0(e))}return(0,H.jsxs)(`div`,{children:[(0,H.jsx)(u0,{inspectionlogs:a,restrictToPart:t.partName,subtitle:`Paths for `+t.partName+` around `+b0(n).toLocaleString(),default_date_range:r?[r.curStart,r.curEnd]:[],zoomType:r?`ExtendDays`:void 0,extendDateRange:s,hideOpenDetailColumn:!0,onlyTable:!0}),(0,H.jsx)(Y,{variant:`contained`,style:{marginTop:`2em`},onClick:()=>{o(null),i(null),e.setStep(0)},children:`Reset`})]})}function w0(){let[e,t]=(0,I.useState)(0),n=L(bI),r=e;return r===0&&n&&(r=1),(0,H.jsxs)(MS,{direction:`column`,spacing:2,children:[(0,H.jsxs)(yC,{activeStep:r,orientation:`horizontal`,children:[(0,H.jsx)(zS,{children:(0,H.jsx)(nC,{children:`Select Material`})}),(0,H.jsx)(zS,{children:(0,H.jsx)(nC,{children:(0,H.jsx)(x0,{})})}),(0,H.jsx)(zS,{children:(0,H.jsx)(nC,{children:`Lookup similar paths`})})]}),r===0?(0,H.jsxs)(MS,{direction:`column`,spacing:4,children:[(0,H.jsx)(q,{children:`Enter a serial number, scan a barcode, or click on a material in the table below to see details.`}),(0,H.jsx)(y0,{}),(0,H.jsx)(v0,{})]}):r===1?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(IU,{fallback:(0,H.jsx)(lW,{}),children:(0,H.jsx)(sW,{})}),(0,H.jsx)(S0,{setStep:t})]}):r===2?(0,H.jsx)(IU,{children:(0,H.jsx)(C0,{setStep:t})}):void 0]})}function T0(){return GI(`Quality Material`),(0,H.jsx)(`main`,{style:{padding:`24px`},children:(0,H.jsx)(w0,{})})}var E0=(0,I.memo)(function(){GI(`Paths`);let e=L(aL);return(0,H.jsx)(u0,{inspectionlogs:(0,I.useMemo)(()=>{let t=bE(),n=tE(t,-6),r=tE(t,1);return e.collectValues(e=>{let t=e.filter(e=>e.time>=n&&e.time<=r);return t.size===0?null:t})},[e]),default_date_range:[tE(bE(),-6),tE(bE(),1)],subtitle:`Paths from the last 7 days`})}),D0=P(!1);function O0(e){let t=``;return e.comments&&e.comments.length>0&&(t=`; `+e.comments[e.comments.length-1].comment),`Due ${e.dueDate.toLocaleDateString()}; Completed ${e.completedQuantity} of ${e.plannedQuantity}${t}`}function k0({work:e}){return e.plannedQuantity<=e.completedQuantity?(0,H.jsx)(lT,{}):(0,H.jsx)(WT,{})}function A0(){let[e,t]=(0,I.useState)(null),n=L(CI),[r]=FI(),i=R(D0);return(0,H.jsx)(Hw,{sx:{mt:`5px`},label:e===null||e===``?`Workorder`:`Workorder (press enter)`,value:e??``,onChange:e=>t(e.target.value),onKeyPress:t=>{t.key===`Enter`&&n&&e&&e!==``&&(t.preventDefault(),r(n,e),i(!1))}})}function j0(){let e=L(CI),t=L(Tie),n=R(D0),[r]=FI();return(0,H.jsx)(sb,{children:(t??[]).map(t=>(0,H.jsx)(hb,{children:(0,H.jsxs)(cb,{onClick:()=>{e&&r(e,t.workorderId),n(!1)},children:[(0,H.jsx)(bb,{children:(0,H.jsx)(k0,{work:t})}),(0,H.jsx)(Tb,{primary:t.workorderId,secondary:O0(t)})]})},t.workorderId))})}var M0=(0,I.memo)(function(){let[e,t]=z(D0),n;return n=e?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(My,{children:`Select Workorder`}),(0,H.jsx)(jy,{children:(0,H.jsxs)(IU,{children:[(0,H.jsx)(A0,{}),(0,H.jsx)(j0,{})]})}),(0,H.jsx)(Ay,{children:(0,H.jsx)(Y,{onClick:()=>t(!1),color:`primary`,children:`Cancel`})})]}):(0,H.jsx)(`p`,{children:`None`}),(0,H.jsx)(ky,{open:e,onClose:()=>t(!1),maxWidth:`md`,children:n})}),N0=P(!1);function P0(){let[e,t]=(0,I.useState)(null),n=L(CI),[r]=NI(),i=R(N0);return(0,H.jsx)(Hw,{sx:{mt:`5px`},label:e===``||e===null?`Inspection Type`:`Inspection Type (press enter)`,value:e??``,onChange:e=>t(e.target.value),onKeyPress:t=>{t.key===`Enter`&&n&&e&&e!==``&&(t.preventDefault(),r({mat:n,inspType:e,inspect:!0}),i(!1))}})}function F0(){let e=L(CI),[t]=NI(),n=L(EL),r=Q.of(n).sortBy(e=>e),i=R(N0);return e===null?null:(0,H.jsx)(sb,{children:r.map(n=>(0,H.jsx)(hb,{children:(0,H.jsxs)(cb,{onClick:()=>{t({mat:e,inspType:n,inspect:!0}),i(!1)},children:[(0,H.jsx)(bb,{children:(0,H.jsx)(UT,{})}),(0,H.jsx)(Tb,{primary:n})]})},n))})}function I0(){let e=R(N0),t=L(EI);return t===null||t.materialID<0?null:(0,H.jsx)(Y,{color:`primary`,onClick:()=>e(!0),children:`Signal Inspection`})}var L0=(0,I.memo)(function(){let[e,t]=z(N0),n;return n=e?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(My,{children:`Select Inspection Type`}),(0,H.jsx)(jy,{children:(0,H.jsxs)(IU,{children:[(0,H.jsx)(P0,{}),(0,H.jsx)(F0,{})]})}),(0,H.jsx)(Ay,{children:(0,H.jsx)(Y,{onClick:()=>t(!1),color:`primary`,children:`Cancel`})})]}):(0,H.jsx)(`p`,{children:`None`}),(0,H.jsx)(ky,{open:e,onClose:()=>t(!1),maxWidth:`md`,children:n})}),R0=function(e){return e[e.Material=0]=`Material`,e[e.FreeMaterialZone=1]=`FreeMaterialZone`,e[e.CompletedCollapsedMaterialZone=2]=`CompletedCollapsedMaterialZone`,e[e.CompletedExpandedMaterialZone=3]=`CompletedExpandedMaterialZone`,e[e.PalletFaceZone=4]=`PalletFaceZone`,e[e.QueueZone=5]=`QueueZone`,e[e.BasketZone=6]=`BasketZone`,e}({});function z0(e){switch(e.type){case 0:return`Material-`+(e.identifier??(e.material?.materialID??-1).toString());case 1:return`FreeMaterialZone`;case 2:return`CompletedCollapsedMaterialZone`;case 3:return`CompletedExpandedMaterialZone`;case 4:return`PalletFaceZone-`+e.face.toString();case 5:return`QueueZone-`+e.queue;case 6:return`BasketZone-`+e.basketId.toString()}}function B0(e){switch(e.type){case 0:return[e.type,e.material,e.identifier];case 1:case 2:case 3:return[e.type,null];case 4:return[e.type,e.face];case 5:return[e.type,e.queue];case 6:return[e.type,e.basketId]}}function V0(e){let t,n,r=new Map,i=new Map,a=new Map,o=[];for(let s of e.values())switch(s.type){case 1:t=s.elem;break;case 2:case 3:n=s.elem;break;case 4:r.set(s.face,s.elem);break;case 5:i.set(s.queue,s.elem);break;case 6:a.set(s.basketId,s.elem);break;case 0:s.material&&o.push([s.elem,s.material]);break}return{freeMaterial:t,completedMaterial:n,faces:r,queues:i,baskets:a,material:o}}function H0(e,t){if(!e)return[];let n=V0(t);if(!n.completedMaterial)return[];let r=[],i=new Map,a=new Map,o=new Map,s=0;for(let[t,c]of Q.of(n.material).sortBy(([e])=>e.left,([e])=>e.top))switch(c.action.type){case V.UnloadToCompletedMaterial:case V.UnloadToInProcess:if(c.action.unloadToBasketId){let i=n.baskets.get(c.action.unloadToBasketId),a=o.get(c.action.unloadToBasketId)??0;o.set(c.action.unloadToBasketId,a+1),r.push({fromX:t.left,fromY:t.top+t.height/2,toX:i===void 0?e.left+2:i.right-5,toY:i===void 0?t.top+t.height/2:i.top+20*(a+1),curveDirection:1})}else if(c.action.type===V.UnloadToCompletedMaterial&&(!c.action.unloadIntoQueue||c.action.unloadIntoQueue===``))r.push({fromX:t.right,fromY:t.top+t.height/2,toY:t.top+t.height/2,toX:n.completedMaterial?n.completedMaterial.left+2:e.right-10,curveDirection:1});else{let i,o;c.action.unloadIntoQueue?(i=n.queues.get(c.action.unloadIntoQueue),o=a.get(c.action.unloadIntoQueue)??0,a.set(c.action.unloadIntoQueue,o+1)):(i=n.freeMaterial,o=s,s+=1),r.push({fromX:t.left,fromY:t.top+t.height/2,toX:i===void 0?e.left+2:i.right-5,toY:i===void 0?t.top+t.height/2:i.top+20*(o+1),curveDirection:1})}break;case V.Loading:if(c.action.loadFromBasketId&&c.action.loadOntoFace){let e=n.faces.get(c.action.loadOntoFace);if(e!==void 0){let n=i.get(c.action.loadOntoFace)??0;i.set(c.action.loadOntoFace,n+1),r.push({fromX:t.right,fromY:t.top+t.height/2,toX:e.left+20,toY:e.top+50+20*n,curveDirection:-1})}}else if(c.action.loadFromBasketId){let i=n.baskets.get(c.action.loadFromBasketId),a=o.get(c.action.loadFromBasketId)??0;o.set(c.action.loadFromBasketId,a+1),r.push({fromX:t.right,fromY:t.top+t.height/2,toX:i===void 0?e.right-10:i.left+20,toY:i===void 0?t.top+t.height/2:i.top+50+20*a,curveDirection:-1})}else if(c.action.loadOntoFace)if(c.location.type===ot.OnPallet)if(c.location.palletNum===c.action.loadOntoPalletNum&&c.location.face===c.action.loadOntoFace)r.push({fromX:t.right,fromY:t.top+t.height*3/4,toX:t.left+t.width*7/8,toY:t.bottom,curveDirection:-1});else{let e=n.faces.get(c.action.loadOntoFace);e&&(c.action.loadOntoFace<(c.location.face??0)?r.push({fromX:t.left,fromY:t.top+t.height/2,toX:t.left,toY:e.bottom+20,curveDirection:-1}):r.push({fromX:t.left,fromY:t.top+t.height/2,toX:t.left,toY:e.top-20,curveDirection:1}))}else{let e=n.faces.get(c.action.loadOntoFace);if(e!==void 0){let n=i.get(c.action.loadOntoFace)??0;i.set(c.action.loadOntoFace,n+1),r.push({fromX:t.right,fromY:t.top+t.height/2,toX:e.left+20,toY:e.top+50+20*n,curveDirection:-1})}}break;case V.LoadingToBasket:{let i=c.action.loadToBasketId;if(i===void 0)break;let a=n.baskets.get(i),s=o.get(i)??0;o.set(i,s+1),r.push({fromX:t.right,fromY:t.top+t.height/2,toX:a===void 0?e.right-10:a.left+20,toY:a===void 0?t.top+t.height/2:a.top+50+20*s,curveDirection:-1});break}}return r.map(t=>({fromX:t.fromX-e.left,fromY:t.fromY-e.top,toX:t.toX-e.left,toY:t.toY-e.top,curveDirection:t.curveDirection}))}function U0(e){let t=e.getBoundingClientRect();return{left:t.left+window.scrollX,top:t.top+window.scrollY,width:t.width,height:t.height,bottom:t.bottom+window.scrollY,right:t.right+window.scrollX}}function W0(e){let t=(e.fromX+e.toX)/2,n=(e.fromY+e.toY)/2,r=Math.atan2(e.toY-e.fromY,e.toX-e.fromX)+Math.PI*e.curveDirection/2,i=t+50*Math.cos(r),a=n+50*Math.sin(r);return`M${e.fromX},${e.fromY} Q ${i} ${a} ${e.toX} ${e.toY}`}var G0=(0,I.memo)(function({container:e,arrowsWithRefs:t}){let[,n]=(0,I.useState)({height:window.innerHeight,width:window.innerWidth});return(0,I.useEffect)(()=>{function e(){n({height:window.innerHeight,width:window.innerWidth})}return window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[n]),(0,H.jsx)(`g`,{children:H0(e.current?U0(e.current):null,t.collectValues(e=>e.elem.current?{...e,elem:U0(e.elem.current)}:null)).map((e,t)=>(0,H.jsx)(`path`,{style:{fill:`none`,stroke:`rgba(0,0,0,0.15)`,strokeWidth:2},d:W0(e),markerEnd:`url(#arrow)`},t))})}),K0=(0,I.createContext)(void 0),q0=(0,I.memo)(function({children:e,hideArrows:t,whiteBackground:n}){let r=(0,I.useRef)(null),[i,a]=(0,I.useState)(gO.empty()),o=(0,I.useMemo)(()=>({registerNode(e,t,n){a(t&&n?r=>r.set(e,{...t,elem:n}):t=>t.delete(e))}}),[a]);return(0,H.jsxs)(`div`,{style:{position:`relative`},children:[(0,H.jsxs)(`svg`,{style:{position:`absolute`,pointerEvents:`none`,width:`100%`,height:`100%`,top:0,right:0,zIndex:-1,backgroundColor:n?`white`:`#F8F8F8`},children:[(0,H.jsx)(`defs`,{children:(0,H.jsx)(`marker`,{id:`arrow`,markerWidth:6,markerHeight:10,refX:`0`,refY:`3`,orient:`auto`,markerUnits:`strokeWidth`,children:(0,H.jsx)(`path`,{d:`M0,0 L0,6 L5,3 z`,fill:`rgba(0,0,0,0.15)`})})}),t?void 0:(0,H.jsx)(G0,{container:r,arrowsWithRefs:i})]}),(0,H.jsx)(`div`,{ref:r,children:(0,H.jsx)(K0.Provider,{value:o,children:e})})]})});function J0(e){let t=(0,I.useContext)(K0);if(!t)throw Error(`useMoveMaterialArrowRef must be used within a MoveMaterialArrowContainer`);let n=(0,I.useRef)(null);return(0,I.useEffect)(()=>{let r=z0(e);return t.registerNode(r,e,n),()=>{t.registerNode(r,null,null)}},[t,...B0(e)]),n}function Y0({kind:e,children:t}){return(0,H.jsx)(`div`,{ref:J0(e),"data-move-material-identifier":z0(e),children:t})}var X0=45,Z0=55;function Q0(){let e=L(GO),t=L(yO),n=L(yr),r=Q.of(e.material).filter(e=>e.location.type===ot.OnPallet||e.action.type===V.Loading).toRLookup(e=>e.location.palletNum??e.action.loadOntoPalletNum??0),i=Q.of(e.material).filter(e=>e.location.type===ot.InBasket&&e.location.basketId!==null&&e.location.basketId!==void 0||e.action.type===V.LoadingToBasket&&e.action.loadToBasketId!==null&&e.action.loadToBasketId!==void 0).toRLookup(e=>e.location.basketId??e.action.loadToBasketId??0),a=Q.ofObject(e.pallets).filter(([e,t])=>t.currentPalletLocation.loc===rt.LoadUnload).toOrderedMap(([e,t])=>[t.currentPalletLocation.num,{lulNum:t.currentPalletLocation.num,pal:{pallet:t,mats:r.get(t.palletNum)??[]},basket:null,staging:[],sources:[]}]),o=Q.ofObject(e.pallets).filter(([,e])=>e.currentPalletLocation.loc===rt.Machine||e.currentPalletLocation.loc===rt.MachineQueue).map(([e,t])=>t).groupBy(e=>e.currentPalletLocation.group,e=>e.currentPalletLocation.num).toLookupOrderedMap(([[e,t],n])=>e,([[e,t],n])=>t,([[t,n],i])=>{let a=i.find(e=>e.currentPalletLocation.loc===rt.Machine),o=a?r.get(a.palletNum)??[]:null,s=i.find(e=>e.currentPalletLocation.loc===rt.MachineQueue),c=s?r.get(s.palletNum)??[]:null,l=!0,u=c?.[0];if(u&&u.lastCompletedMachiningRouteStopIndex!==null&&u.lastCompletedMachiningRouteStopIndex!==void 0){let r=e.jobs[u.jobUnique]?.procsAndPaths?.[u.process-1]?.paths?.[u.path-1]?.stops?.[u.lastCompletedMachiningRouteStopIndex];r.stationGroup===t&&r.stationNums.includes(n)&&(l=!1)}return l?{name:t+` `+n.toString(),inbound:s?{pallet:s,mats:c??[]}:null,worktable:a?{pallet:a,mats:o??[]}:null,outbound:null}:{name:t+` `+n.toString(),inbound:null,worktable:a?{pallet:a,mats:o??[]}:null,outbound:s?{pallet:s,mats:c??[]}:null}}),s=Q.ofObject(e.pallets).filter(([e,t])=>t.currentPalletLocation.loc===rt.Buffer||t.currentPalletLocation.loc===rt.Cart).collect(([e,t])=>{let n=r.get(t.palletNum);return!n||n.length===0?null:{pallet:t,mats:n}}).toOrderedMap(e=>[e.pallet.palletNum,e]),c=1,l=1,u=tE(new Date,-7),d=t.valuesToLazySeq().filter(e=>e.routeEndUTC>u).concat(Q.ofObject(e.jobs).map(([e,t])=>t)).flatMap(e=>e.procsAndPaths).toRArray();for(let e of d)for(let t of(e.basketLoadStations??[]).concat(e.basketUnloadStations??[]))c=Math.max(c,t);let f=Q.of(d).flatMap(e=>e.paths);for(let e of f){for(let t of e.load.concat(e.unload))c=Math.max(c,t);e.face&&(l=Math.max(l,e.face));for(let t of e.stops)o=o.alter(t.stationGroup,e=>{e??=fO.empty();for(let n of t.stationNums)e=e.alter(n,e=>e||{name:t.stationGroup+` `+n.toString(),inbound:null,worktable:null,outbound:null});return e})}for(let e=1;e<=c;e++)a=a.alter(e,t=>t||{lulNum:e,pal:null,basket:null,staging:[],sources:[]});for(let t of Object.values(e.pallets))l=Math.max(l,t.numFaces);for(let t of e.material)t.location.face!==null&&t.location.face!==void 0&&(l=Math.max(l,t.location.face));let p=fO.empty();if(e.machineLocations&&e.machineLocations.length>0)for(let t of e.machineLocations){o=o.alter(t.machineGroup,e=>{if(!e||t.machineNum===void 0)return e;let n=e.delete(t.machineNum);if(n.size!==0)return n});for(let n of t.possibleLoadStations){let r;a=a.alter(n,e=>{r=e});let i=Q.of(r?.pal?.mats??[]).toLookup(n=>{if(n.action.type===V.Machining)return`Machining`;if(n.action.type!==V.Waiting)return`Loading`;if(n.lastCompletedMachiningRouteStopIndex!==null&&n.lastCompletedMachiningRouteStopIndex!==void 0){let r=e.jobs[n.jobUnique]?.procsAndPaths?.[n.process-1]?.paths?.[n.path-1]?.stops?.[n.lastCompletedMachiningRouteStopIndex];if(!r||r.stationGroup===t.machineGroup&&r.stationNums.includes(t.machineNum))return`Loading`}return`Ready`}),o={lulNum:n,machineMoving:t.moving,machineCurrentlyAtLoad:n===t.currentLoadStation?{group:t.machineGroup,num:t.machineNum}:null,readyMats:i.get(`Ready`)??[],machiningMats:i.get(`Machining`)??[],loadingMats:i.get(`Loading`)??[]};p=p.set(n,o)}}let m=new Map,h=new Map,g=new Map,_=0,v=0;for(let t of Q.ofObject(e.baskets??{}).map(([e,t])=>t).sortBy(e=>e.basketId)){let e={basket:t,mats:i.get(t.basketId)??[]};switch(t.position.location){case _t.Storage:e.mats.length>0?v+=1:_+=1;break;case _t.LoadUnload:case _t.LoadStationStaging:{let n=t.position.locationNum;if(n===null){g.set(t.basketId,e);break}let r=t.position.location===_t.LoadUnload?h:m,i=r.get(n)??[];i.push(e),r.set(n,i);break}case _t.InTransit:g.set(t.basketId,e);break}}let y=0,b=0;return a=a.mapValues(e=>{let t=new Map,r=Q.of(e.pal?.mats??e.basket?.mats??[]).filter(e=>e.location.type!==ot.OnPallet).toRArray();for(let e of r){if(e.location.type===ot.Free){let n=`free`,r=t.get(n)??{label:`To Load`,mats:[]};r.mats.push(e),t.set(n,r);continue}if(e.action.loadFromBasketId!==null&&e.action.loadFromBasketId!==void 0){let r=`basket:${e.action.loadFromBasketId}`,i=t.get(r)??{label:`From ${Dk(n.basketName)} ${e.action.loadFromBasketId}`,mats:[]};i.mats.push(e),t.set(r,i);continue}if(e.location.type===ot.InQueue&&e.location.currentQueue){let n=`queue:${e.location.currentQueue}`,r=t.get(n)??{label:`From ${e.location.currentQueue}`,mats:[]};r.mats.push(e),t.set(n,r)}}let i=Q.of(h.get(e.lulNum)??[]).sortBy(e=>e.basket.position.locationNum).toRArray();for(let e of i.slice(1))g.set(e.basket.basketId,e);let a=new Set(Q.of(e.pal?.mats??[]).collect(e=>e.action.loadFromBasketId??null).toRArray()),o=Q.of(m.get(e.lulNum)??[]).filter(e=>!a.has(e.basket.basketId)).sortBy(e=>e.basket.position.locationNum).toRArray();y=Math.max(y,o.length);let s=Q.of(t).map(([e,t])=>({key:e,label:t.label,mats:t.mats})).sortBy(e=>e.label).toRArray();return b=Math.max(b,s.length),{...e,basket:i[0]??null,staging:o,sources:s}}),{machines:o.mapValues(e=>e.valuesToAscLazySeq().toRArray()),loads:a.valuesToAscLazySeq().toRArray(),stockerPals:s.valuesToAscLazySeq().toRArray(),floatingBaskets:Q.of(g.values()).toRArray(),storageBaskets:_+v>0?{empty:_,filled:v}:null,machineAtLoad:p.valuesToAscLazySeq().toRArray(),maxNumFacesOnPallet:l,maxNumStagingRows:y,maxNumSourceRows:b}}function $0({mats:e}){let[t,n]=(0,I.useState)(!1),r=(0,I.useRef)(null),i=(0,I.useRef)(null),[a,o]=(0,I.useState)(!1),s=R(bI),c=L(GO);function l(){r.current!==null&&(clearTimeout(r.current),r.current=null),n(!0)}function u(){r.current=setTimeout(()=>{n(!1),r.current=null},200)}function d(){e.length===1?s({type:`MatDetails`,details:e[0]}):o(!0)}function f(e,t){return t==null?null:(e!=null&&e!=null?c.pallets[e]?.faceNames?.[t-1]:null)??`Face: `+t.toString()}return(0,H.jsxs)(J,{sx:{width:X0,height:X0,overflow:`visible`},children:[(0,H.jsx)(Hp,{elevation:4,onPointerEnter:l,onPointerLeave:u,sx:{position:`relative`,zIndex:t?10:0,width:`max-content`,height:`max-content`},children:(0,H.jsx)(mv,{badgeContent:e.length>1?e.length:0,color:`secondary`,children:(0,H.jsx)(gm,{focusRipple:!0,onClick:d,ref:i,children:(0,H.jsx)(Rp,{orientation:`horizontal`,in:t,collapsedSize:X0,children:(0,H.jsxs)(J,{sx:{display:`flex`},children:[(0,H.jsx)(LU,{part:e[0].partName,size:X0}),(0,H.jsx)(J,{sx:{marginLeft:`10px`,marginRight:`10px`,whiteSpace:`nowrap`,textAlign:`left`},children:(0,H.jsx)(Rp,{in:t,collapsedSize:X0,children:(0,H.jsxs)(MS,{direction:`column`,sx:{marginBottom:`0.2em`},children:[(0,H.jsxs)(q,{variant:`h6`,children:[e[0].partName,`-`,e[0].process]}),(0,H.jsx)(`div`,{children:(0,H.jsx)(`small`,{children:f(e[0].location.palletNum,e[0].location.face)??f(e[0].action.loadOntoPalletNum,e[0].action.loadOntoFace)})}),Q.of(e).collect(e=>e.serial?(0,H.jsx)(`div`,{children:(0,H.jsxs)(`small`,{children:[`Serial: `,e.serial]})},e.materialID):void 0),(0,H.jsx)(`div`,{children:(0,H.jsx)(GU,{mat:e[0]})})]})})})]})})})})}),(0,H.jsx)(bx,{anchorEl:i.current,open:a,onClose:()=>o(!1),anchorOrigin:{vertical:`top`,horizontal:`left`},children:Q.of(e).map((e,t)=>(0,H.jsx)(wx,{onClick:()=>{o(!1),s({type:`MatDetails`,details:e})},children:e.serial&&e.serial!==``?e.serial:(t+1).toString()},e.materialID))})]})}function e2({maxNumFaces:e,mats:t,loadingOntoPallet:n,noFilter:r,showExpanded:i}){if(i&&e===1)return(0,H.jsx)(J,{sx:{display:`flex`,flexDirection:`column`,flexWrap:`wrap`},children:t.map(e=>(0,H.jsx)(QU,{mat:e},e.materialID))});{let i=n?Q.of(t).filter(e=>r||e.location.type!==ot.OnPallet).orderedGroupBy(e=>e.action.loadOntoFace??1):Q.of(t).filter(e=>r||e.location.type===ot.OnPallet).orderedGroupBy(e=>e.action.type===V.Loading?e.action.loadOntoFace??1:e.location.face??1);return(0,H.jsx)(J,{sx:{display:`grid`,gridTemplateRows:`${X0}px`,gridTemplateColumns:`repeat(${e}, ${X0}px)`,columnGap:`5px`,height:`100%`,alignContent:`center`,justifyContent:`center`},children:i.map(([e,t])=>(0,H.jsx)(J,{sx:{gridColumn:e,gridRow:1},children:(0,H.jsx)($0,{mats:t})},e))})}}function t2({mats:e}){let t=Q.of(e).orderedGroupBy(e=>e.location.basketSlot??0);return(0,H.jsx)(J,{sx:{display:`flex`,flexWrap:`wrap`,justifyContent:`flex-start`,alignItems:`flex-start`,gap:`5px`,minHeight:`${X0}px`,paddingLeft:`5px`,paddingRight:`5px`,height:`100%`,alignContent:`center`},children:t.map(([e,t])=>(0,H.jsx)(J,{children:(0,H.jsx)($0,{mats:t})},e))})}function n2({mats:e,maxNumFaces:t}){return(0,H.jsx)(J,{sx:{minHeight:`${Z0}px`,display:`flex`,alignItems:`center`,justifyContent:`flex-start`,paddingLeft:`5px`,gap:`5px`,paddingRight:`5px`},children:(0,H.jsx)(e2,{mats:e,maxNumFaces:t,loadingOntoPallet:!0})})}function r2(e,t){let n=X0*e+5*(e+1);return t?`60px ${Math.max(n,100)}px`:`${Math.max(n,100)}px`}function i2(e){e=Math.round(e);let t=Math.abs(e)%60,n=Math.floor(Math.abs(e)/60),r=n%60,i=Math.floor(n/60);return i>0?`${e<0?`-`:``}${i}:${r.toString().padStart(2,`0`)}:${t.toString().padStart(2,`0`)}`:`${e<0?`-`:``}${r}:${t.toString().padStart(2,`0`)}`}function a2(e){let t=e?.find(e=>e.action.type===V.Machining),n=t?.action?.elapsedMachiningTime,r=t?.action.expectedRemainingMachiningTime,i=L(GO).timeOfCurrentStatusUTC,a=L(KO),o=null;r&&(o=tk(r)-(a-Math.floor(i.getTime()/1e3)));let s=null;return n&&(s=tk(n)+(a-Math.floor(i.getTime()/1e3))),o!==null&&s!==null?[!0,`${i2(s)} / ${i2(o)}`,o<0?-1:s/(s+o)*100]:o===null?s===null?[!!t,`Idle`,null]:[!0,i2(s),null]:[!0,` / `+i2(o),o<0?-1:null]}function o2({machine:e}){let[t,n,r]=a2(e.worktable?.mats);return(0,H.jsxs)(`div`,{children:[(0,H.jsx)(q,{variant:`h5`,children:e.name}),(0,H.jsx)(q,{variant:`subtitle1`,children:n}),t?r===null?(0,H.jsx)(tb,{}):r<0?(0,H.jsx)(tb,{color:`error`}):(0,H.jsx)(tb,{variant:`determinate`,value:r}):void 0]})}function s2({maxNumFaces:e,machine:t}){return(0,H.jsxs)(J,{sx:{display:`grid`,border:`1px solid black`,margin:`5px`,gridTemplateRows:`auto ${Z0}px ${Z0}px ${Z0}px`,gridTemplateColumns:r2(e,!0),gridTemplateAreas:`"machname machname" "inboundpal inboundmat" "worktablepal worktablemat" "outboundpal outboundmat"`},children:[(0,H.jsx)(J,{sx:{gridArea:`machname`,padding:`0.2em`,borderBottom:`1px solid black`},children:(0,H.jsx)(o2,{machine:t})}),(0,H.jsx)(J,{sx:{gridArea:`inboundpal`,borderRight:`1px solid black`,borderBottom:`1px solid black`,padding:`2px`},children:(0,H.jsxs)(MS,{children:[(0,H.jsx)(q,{variant:`body1`,sx:{textAlign:`center`},children:`In`}),t.inbound?(0,H.jsx)(q,{variant:`h6`,sx:{textAlign:`center`},children:t.inbound.pallet.palletNum}):void 0]})}),(0,H.jsx)(J,{sx:{gridArea:`inboundmat`,borderBottom:`1px solid black`},children:t.inbound?(0,H.jsx)(e2,{mats:t.inbound.mats,maxNumFaces:e}):void 0}),(0,H.jsx)(J,{sx:{gridArea:`worktablepal`,borderRight:`1px solid black`,borderBottom:`1px solid black`,padding:`2px`},children:(0,H.jsxs)(MS,{children:[(0,H.jsx)(q,{variant:`body1`,sx:{textAlign:`center`},children:`Work`}),t.worktable?(0,H.jsx)(q,{variant:`h6`,sx:{textAlign:`center`},children:t.worktable.pallet.palletNum}):void 0]})}),(0,H.jsx)(J,{sx:{gridArea:`worktablemat`,borderBottom:`1px solid black`},children:t.worktable?(0,H.jsx)(e2,{mats:t.worktable.mats,maxNumFaces:e}):void 0}),(0,H.jsx)(J,{sx:{gridArea:`outboundpal`,borderRight:`1px solid black`,padding:`2px`},children:(0,H.jsxs)(MS,{children:[(0,H.jsx)(q,{variant:`body1`,sx:{textAlign:`center`},children:`Out`}),t.outbound?(0,H.jsx)(q,{variant:`h6`,sx:{textAlign:`center`},children:t.outbound.pallet.palletNum}):void 0]})}),(0,H.jsx)(J,{sx:{gridArea:`outboundmat`},children:t.outbound?(0,H.jsx)(e2,{mats:t.outbound.mats,maxNumFaces:e}):void 0})]})}function c2(e){let t=(e?.find(e=>e.action.type===V.Loading||e.action.type===V.LoadingToBasket||e.action.type===V.UnloadToCompletedMaterial||e.action.type===V.UnloadToInProcess))?.action?.elapsedLoadUnloadTime,n=L(GO).timeOfCurrentStatusUTC,r=L(KO),i=null;return t&&(i=tk(t)+(r-Math.floor(n.getTime()/1e3))),i===null?`Idle`:i2(i)}function l2({load:e}){let t=c2(e.pal?.mats??e.basket?.mats),n=L(yr);return(0,H.jsxs)(J,{sx:{display:`flex`,justifyContent:`space-between`,alignItems:`baseline`},children:[(0,H.jsx)(q,{variant:`h5`,children:Tk(e.lulNum,n.loadStationNames)}),(0,H.jsx)(q,{variant:`body1`,children:t})]})}function u2({maxNumFaces:e,maxNumStagingRows:t,maxNumSourceRows:n,load:r}){let i=Dk(L(yr).basketName),a=r.pal?`Pallet`:r.basket?i:null,o=r.pal?r.pal.pallet.palletNum.toString():r.basket?r.basket.basket.basketId.toString():null,s=Math.max(1,n),c=Math.max(1,t),l=Array.from({length:s},(e,t)=>`"source${t} sourcemat${t}"`),u=Array.from({length:c},(e,t)=>`"stage${t} stagemat${t}"`),d=[`"lulname lulname"`,...l,`"current currentmat"`,...u].join(` `);return(0,H.jsxs)(J,{sx:{display:`grid`,border:`1px solid black`,margin:`5px`,gridTemplateRows:`auto repeat(${s+1+c}, ${Z0}px)`,gridTemplateColumns:r2(e,!0),gridTemplateAreas:d},children:[(0,H.jsx)(J,{sx:{gridArea:`lulname`,padding:`0.2em`,borderBottom:`1px solid black`},children:(0,H.jsx)(l2,{load:r})}),Array.from({length:s},(t,n)=>{let i=r.sources[n]??null;return(0,H.jsxs)(I.Fragment,{children:[(0,H.jsx)(J,{sx:{gridArea:`source${n}`,borderRight:`1px solid black`,borderBottom:`1px solid black`,padding:`2px`,display:`flex`,alignItems:`center`,justifyContent:`center`},children:i?(0,H.jsx)(q,{variant:`body2`,sx:{textAlign:`center`},children:i.label}):void 0}),(0,H.jsx)(J,{sx:{gridArea:`sourcemat${n}`,borderBottom:`1px solid black`,display:`flex`,flexDirection:`column`,justifyContent:`center`},children:i?(0,H.jsx)(n2,{mats:i.mats,maxNumFaces:e}):void 0})]},`source-${n}`)}),(0,H.jsx)(J,{sx:{gridArea:`current`,borderRight:`1px solid black`,borderBottom:`1px solid black`,padding:`2px`,display:`flex`,alignItems:`center`,justifyContent:`center`},children:(0,H.jsxs)(MS,{children:[a?(0,H.jsx)(q,{variant:`body1`,sx:{textAlign:`center`},children:a}):void 0,o?(0,H.jsx)(q,{variant:`h6`,sx:{textAlign:`center`},children:o}):void 0]})}),(0,H.jsxs)(J,{sx:{gridArea:`currentmat`,display:`flex`,flexDirection:`column`,justifyContent:`center`,borderBottom:`1px solid black`},children:[r.pal?(0,H.jsx)(e2,{mats:r.pal.mats,maxNumFaces:e}):void 0,!r.pal&&r.basket?(0,H.jsx)(t2,{mats:r.basket.mats}):void 0]}),Array.from({length:c},(e,t)=>{let n=r.staging[t]??null,a=t===c-1;return(0,H.jsxs)(I.Fragment,{children:[(0,H.jsx)(J,{sx:{gridArea:`stage${t}`,borderRight:`1px solid black`,...a?{}:{borderBottom:`1px solid black`},padding:`2px`,display:`flex`,alignItems:`center`,justifyContent:`center`},children:n?(0,H.jsxs)(q,{variant:`body2`,sx:{textAlign:`center`},children:[`Staging `,i,` `,n.basket.basketId]}):void 0}),(0,H.jsx)(J,{sx:{gridArea:`stagemat${t}`,...a?{}:{borderBottom:`1px solid black`},display:`flex`,flexDirection:`column`,justifyContent:`center`},children:n?(0,H.jsx)(t2,{mats:n.mats}):void 0})]},`stage-${t}`)})]})}function d2({status:e}){let t=c2(e.loadingMats),[n,r,i]=a2(e.machiningMats);return(0,H.jsxs)(`div`,{children:[(0,H.jsxs)(q,{variant:`h5`,children:[`Station `,e.lulNum]}),e.machineCurrentlyAtLoad?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(q,{variant:`h5`,children:[e.machineCurrentlyAtLoad.group,` `,e.machineCurrentlyAtLoad.num]}),(0,H.jsx)(q,{variant:`subtitle1`,children:r===`Idle`?t:r}),n?i===null?(0,H.jsx)(tb,{}):i<0?(0,H.jsx)(tb,{color:`error`}):(0,H.jsx)(tb,{variant:`determinate`,value:i}):void 0]}):(0,H.jsxs)(H.Fragment,{children:[e.machineMoving?(0,H.jsx)(q,{variant:`subtitle2`,children:`Machine Moving`}):void 0,(0,H.jsxs)(q,{variant:`subtitle1`,children:[`Loading `,t]})]})]})}function f2({maxNumFaces:e,status:t}){return(0,H.jsxs)(J,{sx:{display:`grid`,border:`1px solid black`,margin:`5px`,gridTemplateRows:`minmax(104px, max-content) repeat(3, ${e>1?Z0.toString()+`px`:`minmax(110px, max-content)`})`,gridTemplateColumns:e===1?`60px minmax(230px, max-content)`:r2(e,!0),gridTemplateAreas:`"name name" "ready readymat" "machining machiningmat" "loadstation loadstationmat"`},children:[(0,H.jsx)(J,{sx:{gridArea:`name`,padding:`0.2em`,borderBottom:`1px solid black`},children:(0,H.jsx)(d2,{status:t})}),(0,H.jsx)(J,{sx:{gridArea:`ready`,borderRight:`1px solid black`,borderBottom:`1px solid black`,padding:`2px`},children:(0,H.jsx)(q,{variant:`body1`,sx:{textAlign:`center`},children:`Ready`})}),(0,H.jsx)(J,{sx:{gridArea:`readymat`,borderBottom:`1px solid black`,display:`flex`,flexDirection:`column`,justifyContent:`center`},children:(0,H.jsx)(e2,{mats:t.readyMats,maxNumFaces:e,showExpanded:!0})}),(0,H.jsx)(J,{sx:{gridArea:`machining`,borderRight:`1px solid black`,borderBottom:`1px solid black`,padding:`2px`},children:(0,H.jsx)(q,{variant:`body1`,sx:{textAlign:`center`},children:`Work`})}),(0,H.jsx)(J,{sx:{gridArea:`machiningmat`,borderBottom:`1px solid black`,display:`flex`,flexDirection:`column`,justifyContent:`center`},children:(0,H.jsx)(e2,{mats:t.machiningMats,maxNumFaces:e,showExpanded:!0})}),(0,H.jsx)(J,{sx:{gridArea:`loadstation`,borderRight:`1px solid black`,padding:`2px`},children:(0,H.jsxs)(MS,{children:[(0,H.jsx)(q,{variant:`body1`,sx:{textAlign:`center`},children:`Load`}),(0,H.jsx)(q,{variant:`body1`,sx:{textAlign:`center`},children:`Station`})]})}),(0,H.jsx)(J,{sx:{gridArea:`loadstationmat`,display:`flex`,flexDirection:`column`,justifyContent:`center`},children:(0,H.jsx)(e2,{mats:t.loadingMats,maxNumFaces:e,showExpanded:!0,noFilter:!0})})]})}function p2({maxNumFaces:e,pallet:t}){return(0,H.jsxs)(J,{sx:{display:`grid`,border:`1px solid black`,margin:`5px`,gridTemplateRows:`auto ${Z0}px`,gridTemplateColumns:r2(e,!1),gridTemplateAreas:`"palname" "palmat"`},children:[(0,H.jsxs)(q,{variant:`h5`,sx:{gridArea:`palname`,padding:`0.2em`,borderBottom:`1px solid black`},children:[`Pallet `,t.pallet.palletNum]}),(0,H.jsx)(J,{sx:{gridArea:`palmat`},children:(0,H.jsx)(e2,{mats:t.mats,maxNumFaces:e})})]})}function m2({basket:e}){let t=Dk(L(yr).basketName);return(0,H.jsxs)(J,{sx:{display:`grid`,border:`1px solid black`,margin:`5px`,gridTemplateRows:`auto ${Z0}px`,gridTemplateColumns:`minmax(120px, max-content)`,gridTemplateAreas:`"basketname" "basketmat"`},children:[(0,H.jsxs)(q,{variant:`h5`,sx:{gridArea:`basketname`,padding:`0.2em`,borderBottom:`1px solid black`},children:[t,` `,e.basket.basketId]}),(0,H.jsx)(J,{sx:{gridArea:`basketmat`},children:(0,H.jsx)(t2,{mats:e.mats})})]})}function h2({empty:e,filled:t}){return(0,H.jsxs)(J,{sx:{display:`grid`,border:`1px solid black`,margin:`5px`,padding:`0.5em 1em`,alignContent:`center`,minWidth:`170px`},children:[(0,H.jsxs)(q,{variant:`h5`,children:[Dk(L(yr).basketName),` Storage`]}),(0,H.jsxs)(q,{variant:`body1`,children:[`Empty: `,e]}),(0,H.jsxs)(q,{variant:`body1`,children:[`Filled: `,t]})]})}var g2=(0,I.memo)(function({overview:e}){return(0,H.jsxs)(`div`,{children:[e.machines.toAscLazySeq().map(([t,n])=>(0,H.jsx)(J,{sx:{display:`flex`,flexWrap:`wrap`,justifyContent:`space-evenly`},children:n.map(t=>(0,H.jsx)(s2,{machine:t,maxNumFaces:e.maxNumFacesOnPallet},t.name))},t)),e.loads.length>0?(0,H.jsx)(J,{sx:{display:`flex`,flexWrap:`wrap`,justifyContent:`space-evenly`},children:e.loads.map(t=>(0,H.jsx)(u2,{load:t,maxNumFaces:e.maxNumFacesOnPallet,maxNumStagingRows:e.maxNumStagingRows,maxNumSourceRows:e.maxNumSourceRows},t.lulNum))}):void 0,e.machineAtLoad.length>0?(0,H.jsx)(J,{sx:{display:`flex`,flexWrap:`wrap`,justifyContent:`space-evenly`},children:e.machineAtLoad.map(t=>(0,H.jsx)(f2,{status:t,maxNumFaces:e.maxNumFacesOnPallet},t.lulNum))}):void 0,e.stockerPals.length>0||e.floatingBaskets.length>0||e.storageBaskets?(0,H.jsxs)(J,{sx:{display:`flex`,flexWrap:`wrap`,justifyContent:`space-evenly`},children:[e.stockerPals.map(t=>(0,H.jsx)(p2,{pallet:t,maxNumFaces:e.maxNumFacesOnPallet},t.pallet.palletNum)),e.floatingBaskets.map(e=>(0,H.jsx)(m2,{basket:e},e.basket.basketId)),e.storageBaskets?(0,H.jsx)(h2,{empty:e.storageBaskets.empty,filled:e.storageBaskets.filled}):void 0]}):void 0]})}),_2=(0,I.memo)(function({ignoreOperator:e}){let[t,n]=(0,I.useState)(null),[r,i]=(0,I.useState)(null);function a(){n(null),i(null)}return(0,H.jsx)(dW,{onClose:a,allowNote:!0,highlightProcsGreaterOrEqualTo:r?.process??void 0,extraDialogElements:(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(JY,{st:t,setState:n}),r===null?null:(0,H.jsx)(WY,{st:r,setState:i})]}),buttons:(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(HY,{ignoreOperator:e}),(0,H.jsx)(I0,{}),(0,H.jsx)(YY,{st:t,setState:n,onClose:a,ignoreOperator:e}),(0,H.jsx)(GY,{st:r,setState:i,onClose:a,ignoreOperator:e})]})})});function v2({ignoreOperator:e,whiteBackground:t}){GI(`System Overview`);let n=Q0();return(0,H.jsxs)(`main`,{style:{padding:`10px`,minHeight:`calc(100vh - 64px)`,backgroundColor:t?`white`:`#F8F8F8`},children:[(0,H.jsx)(g2,{overview:n}),(0,H.jsx)(_2,{ignoreOperator:e}),(0,H.jsx)(L0,{})]})}var y2=30;function b2({machine:e}){let t=Dd(),[,,n]=a2(e.worktable?.mats);return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`rect`,{x:3,y:3,width:24,height:24,stroke:`black`}),`;`,(0,H.jsx)(`rect`,{x:3,y:3,width:24,height:8,fill:e.inbound===null?`white`:t.palette.secondary.main}),(0,H.jsx)(`rect`,{x:3,y:11,width:24,height:8,fill:e.worktable===null?`white`:n!=null&&n<0?t.palette.error.main:t.palette.secondary.main}),(0,H.jsx)(`rect`,{x:3,y:19,width:24,height:8,fill:e.outbound===null?`white`:t.palette.secondary.main})]})}function x2({load:e}){let t=Dd();return(0,H.jsx)(`polygon`,{points:`3,27 27,27 15,3`,fill:e.pal===null&&e.basket===null&&e.staging.length===0?`white`:t.palette.secondary.main,stroke:`black`})}function S2({status:e}){let t=Dd(),[,,n]=a2(e.machiningMats);return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`rect`,{x:3,y:3,width:24,height:24,stroke:`black`}),`;`,(0,H.jsx)(`rect`,{x:3,y:3,width:24,height:8,fill:e.readyMats.length===0?`white`:t.palette.secondary.main}),(0,H.jsx)(`rect`,{x:3,y:11,width:24,height:8,fill:e.machiningMats.length===0?`white`:n!=null&&n<0?t.palette.error.main:t.palette.secondary.main}),(0,H.jsx)(`rect`,{x:3,y:19,width:24,height:8,fill:e.loadingMats.length===0?`white`:t.palette.secondary.main})]})}var C2=(0,I.memo)(function({overview:e}){let t=e.machines.toAscLazySeq().sumBy(([,e])=>e.length);return(0,H.jsx)(J,{sx:{height:`1.5em`,"&:hover":{backgroundColor:`primary.light`}},children:(0,H.jsxs)(`svg`,{viewBox:`0 0 ${(t+e.loads.length+e.machineAtLoad.length)*y2} ${y2}`,preserveAspectRatio:`none`,width:`140px`,height:`1.5em`,children:[(0,H.jsx)(`g`,{children:e.machines.toAscLazySeq().flatMap(([,e])=>e).map((e,t)=>(0,H.jsx)(`g`,{transform:`translate(${t*y2})`,children:(0,H.jsx)(b2,{machine:e})},e.name))}),(0,H.jsx)(`g`,{transform:`translate(${t*y2})`,children:e.loads.map((e,t)=>(0,H.jsx)(`g`,{transform:`translate(${t*y2})`,children:(0,H.jsx)(x2,{load:e})},e.lulNum))}),(0,H.jsx)(`g`,{transform:`translate(${(t+e.loads.length)*y2})`,children:e.machineAtLoad.map((e,t)=>(0,H.jsx)(`g`,{transform:`translate(${t*y2})`,children:(0,H.jsx)(S2,{status:e})},e.lulNum))})]})})}),w2=(0,I.memo)(function({full:e}){let[t,n]=(0,I.useState)(!1),r=Q0();return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(Y,{onClick:()=>n(!0),children:(0,H.jsx)(C2,{overview:r})}),(0,H.jsxs)(ky,{open:t,onClose:()=>n(!1),maxWidth:`xl`,fullScreen:e,children:[e?(0,H.jsx)(ph,{sx:{position:`relative`},children:(0,H.jsxs)(rw,{children:[(0,H.jsx)(Gm,{edge:`start`,color:`inherit`,onClick:()=>n(!1),"aria-label":`close`,children:(0,H.jsx)(pT,{})}),(0,H.jsx)(q,{sx:{ml:2,flex:1},variant:`h6`,component:`div`,children:`System Overview`})]})}):void 0,(0,H.jsx)(jy,{children:(0,H.jsx)(J,{sx:{paddingBottom:`2em`,paddingLeft:`5em`,paddingRight:`5em`},children:(0,H.jsx)(g2,{overview:r})})})]})]})});function T2(e){return Number.isInteger(e)&&(e??0)>0}function E2(e){return typeof e==`string`&&e.trim()!==``}function D2(e,t){if(e.location.type===ot.InBasket&&e.location.basketId===t&&(e.action.type===V.UnloadToInProcess||e.action.type===V.UnloadToCompletedMaterial))return T2(e.location.basketSlot)?`unload`:`invalid`;if(e.action.type===V.LoadingToBasket)return T2(e.action.loadToBasketId)?e.action.loadToBasketId===t?!T2(e.action.loadToBasketSlot)||e.location.type!==ot.Free&&(e.location.type!==ot.InQueue||!E2(e.location.currentQueue))?`invalid`:`load`:void 0:`invalid`}function O2(e,t){let n=Q.of(e).collect(e=>{let n=D2(e,t);return n===void 0?void 0:{phase:n,workId:e.action.workId}}).toRArray();if(n.some(({phase:e})=>e===`invalid`))return{type:`inconsistent`};let r=n.filter(e=>e.phase!==`invalid`);if(r.length===0)return{type:`none`};let i=r.filter(e=>E2(e.workId)),a=Q.of(i).toHashSet(({workId:e})=>e),o=Q.of(i).toHashSet(({phase:e})=>e);return i.length!==r.length||a.size!==1||o.size!==1?{type:`inconsistent`}:{type:`confirmable`,work:{workId:i[0].workId,phase:i[0].phase}}}function k2(e){return e.location.type===ot.InQueue&&e.location.currentQueue?e.location.currentQueue:`raw material`}function A2({material:e,fsize:t}){return e.map(e=>(0,H.jsx)(Y0,{kind:{type:R0.Material,material:e},children:(0,H.jsx)(QU,{mat:e,fsize:t})},e.materialID))}function j2({stationNumber:e,basket:t,material:n,fsize:r,submitCommand:i}){let[a,o]=(0,I.useState)(`idle`),s=(0,I.useMemo)(()=>O2(n,t.basketId),[t.basketId,n]),c=s.type===`confirmable`?s.work:void 0;(0,I.useEffect)(()=>o(`idle`),[c?.workId]);let l=(0,I.useMemo)(()=>Q.of(n).filter(e=>e.location.type===ot.InBasket&&e.location.basketId===t.basketId&&e.location.basketSlot!==void 0).groupBy(e=>e.location.basketSlot??0).toHashMap(e=>e),[t.basketId,n]),u=(0,I.useMemo)(()=>Q.of(n).filter(e=>e.action.type===V.LoadingToBasket&&e.action.loadToBasketId===t.basketId&&e.action.loadToBasketSlot!==void 0).groupBy(e=>e.action.loadToBasketSlot??0).toHashMap(e=>e),[t.basketId,n]),d=(0,I.useMemo)(()=>Q.of(t.emptySlots??[]).concat(t.unknownSlots??[]).concat(l.keysToLazySeq()).concat(u.keysToLazySeq()).distinctBy(e=>e).toSortedArray(e=>e),[t.emptySlots,t.unknownSlots,l,u]);async function f(){if(!(c===void 0||i===void 0)){o(`submitting`);try{o(await i(e,{workId:c.workId}))}catch{o(`error`)}}}let p=a===`submitting`||a===`accepted`||a===`conflict`,m=c?.phase===`unload`?`Unload Complete`:`Load Complete`;return(0,H.jsxs)(MS,{spacing:2,sx:{mt:2},children:[(0,H.jsx)(q,{variant:`h6`,children:`Basket slots`}),(0,H.jsx)(J,{sx:{display:`grid`,gridTemplateColumns:`repeat(auto-fit, minmax(15em, 1fr))`,gap:2},children:d.map(e=>{let n=l.get(e)??[],i=u.get(e)??[],a=t.unknownSlots?.includes(e)===!0;return(0,H.jsx)(Av,{"data-testid":`basket-load-station-slot-${e}`,variant:`outlined`,children:(0,H.jsxs)(Pv,{children:[(0,H.jsxs)(q,{variant:`h6`,children:[`Slot `,e]}),n.length>0?(0,H.jsx)(A2,{material:n,fsize:r}):(0,H.jsx)(q,{color:a?`warning.main`:`text.secondary`,children:a?`Unknown`:`Empty`}),i.map((e,t)=>(0,H.jsxs)(J,{sx:{mt:1},children:[(0,H.jsxs)(q,{children:[`Load from `,k2(e)]}),(0,H.jsxs)(q,{variant:`body2`,color:`text.secondary`,children:[e.partName,` · Process `,e.action.processAfterLoad??e.process]})]},`${e.jobUnique}-${e.process}-${t}`))]})},e)})}),c&&i?(0,H.jsx)(J,{sx:{display:`flex`,justifyContent:`flex-end`},children:(0,H.jsx)(Y,{variant:`contained`,disabled:p,onClick:()=>void f(),children:m})}):c?(0,H.jsx)(rh,{severity:`warning`,children:`Basket work confirmation is not configured.`}):s.type===`inconsistent`?(0,H.jsx)(rh,{severity:`warning`,children:`Basket work is inconsistent. Wait for refreshed material actions before confirming.`}):null,a===`accepted`?(0,H.jsx)(rh,{severity:`success`,children:`Confirmation accepted. Waiting for refreshed work.`}):a===`conflict`?(0,H.jsx)(rh,{severity:`warning`,children:`Basket work changed before confirmation. Review the refreshed slots and try again.`}):a===`error`?(0,H.jsx)(rh,{severity:`error`,children:`Unable to confirm basket work. No work was assumed complete.`}):null]})}function M2(e){return encodeURIComponent(e.toString())}function N2(e){switch(e.kind){case`queue`:return`load-station-queue-${M2(e.label)}`;case`baskets`:return`load-station-baskets`;case`free`:return`load-station-material`}}function P2(e,t,n){switch(e.action.type){case V.Loading:return t!==void 0&&e.action.loadOntoPalletNum===t.palletNum||n!==void 0&&e.action.loadFromBasketId===n.basketId;case V.LoadingToBasket:return n!==void 0&&e.action.loadToBasketId===n.basketId;default:return!1}}function F2(e,t,n,r){let i,a,o=new Set;if(e>=0){for(let t of Object.values(n.pallets))if(t.currentPalletLocation.loc===rt.LoadUnload&&t.currentPalletLocation.num===e){i=t;break}for(let t of Object.values(n.baskets??{}))t.position.locationNum===e&&(t.position.location===_t.LoadUnload?a=t:t.position.location===_t.LoadStationStaging&&o.add(t.basketId))}let s=new Set(t);if(i!==void 0)for(let e of n.material)e.action.type===V.Loading&&e.action.loadOntoPalletNum===i.palletNum&&e.location.type===ot.InQueue&&e.location.currentQueue&&s.add(e.location.currentQueue),e.action.type===V.Loading&&e.action.loadOntoPalletNum===i.palletNum&&e.action.loadFromBasketId&&o.add(e.action.loadFromBasketId),(e.action.type===V.UnloadToInProcess||e.action.type===V.UnloadToCompletedMaterial)&&e.action.unloadToBasketId&&e.location.type===ot.OnPallet&&e.location.palletNum===i.palletNum&&o.add(e.action.unloadToBasketId),(e.action.type===V.UnloadToInProcess||e.action.type===V.UnloadToCompletedMaterial)&&e.action.unloadIntoQueue&&e.location.type===ot.OnPallet&&e.location.palletNum===i.palletNum&&s.add(e.action.unloadIntoQueue);else if(a!==void 0)for(let e of n.material)e.location.type===ot.InBasket&&e.location.basketId===a.basketId&&(e.action.type===V.UnloadToInProcess||e.action.type===V.UnloadToCompletedMaterial)&&e.action.unloadIntoQueue&&s.add(e.action.unloadIntoQueue),e.location.type===ot.InQueue&&e.location.currentQueue&&P2(e,void 0,a)&&s.add(e.location.currentQueue);let c=new Map(Q.of(s).map(e=>[e,{mats:[],hiddenCnt:0}])),l=new Map(Q.of(o).map(e=>[e,{mats:[],hiddenCnt:0}])),u=[],d=fO.empty(),f=null;if(i)for(let e=1;e<=i.numFaces;e++)d=d.set(e,[]);else a&&(d=d.set(1,[]));for(let e of n.material){if(i?(e.action.type===V.Loading&&e.action.loadOntoPalletNum===i.palletNum&&(e.action.elapsedLoadUnloadTime&&(f=e.action.elapsedLoadUnloadTime),e.action.loadOntoFace&&!d.has(e.action.loadOntoFace)&&(d=d.set(e.action.loadOntoFace,[])),e.location.type===ot.Free&&u.push(e)),e.location.type===ot.OnPallet&&e.location.palletNum===i.palletNum&&((e.action.type===V.UnloadToCompletedMaterial||e.action.type===V.UnloadToInProcess)&&e.action.elapsedLoadUnloadTime&&(f=e.action.elapsedLoadUnloadTime),d=d.alter(e.location.face??1,t=>t?(t.push(e),t):[e]))):a&&(P2(e,i,a)&&e.action.elapsedLoadUnloadTime&&(f=e.action.elapsedLoadUnloadTime),e.action.type===V.LoadingToBasket&&e.action.loadToBasketId===a.basketId&&e.location.type===ot.Free&&u.push(e),e.location.type===ot.InBasket&&e.location.basketId===a.basketId&&((e.action.type===V.UnloadToCompletedMaterial||e.action.type===V.UnloadToInProcess)&&e.action.elapsedLoadUnloadTime&&(f=e.action.elapsedLoadUnloadTime),d=d.alter(1,t=>t?(t.push(e),t):[e]))),e.location.type===ot.InQueue&&e.location.currentQueue&&c.has(e.location.currentQueue)){let t=c.get(e.location.currentQueue);r&&!P2(e,i,a)?t===void 0?c.set(e.location.currentQueue,{mats:[],hiddenCnt:1}):t.hiddenCnt+=1:t===void 0?c.set(e.location.currentQueue,{mats:[e],hiddenCnt:0}):t.mats.push(e)}if(e.location.type===ot.InBasket&&e.location.basketId&&l.has(e.location.basketId)){let t=l.get(e.location.basketId);r&&!P2(e,i,a)?t===void 0?l.set(e.location.basketId,{mats:[],hiddenCnt:1}):t.hiddenCnt+=1:t===void 0?l.set(e.location.basketId,{mats:[e],hiddenCnt:0}):t.mats.push(e)}}c.forEach(e=>e.mats.sort(WE(e=>e.location.queuePosition??0))),l.forEach(e=>e.mats.sort(WE(e=>e.location.basketSlot??0)));let p=u.length+d.valuesToAscLazySeq().sumBy(e=>e.length);return{pallet:i,activeBasket:a,allMaterial:n.material,face:d,freeLoadingMaterial:u,queues:c,baskets:l,elapsedLoadingTime:f,fsize:p<=2?`x-large`:p<=6?`large`:`normal`}}function I2({loadData:e}){let t=WI(),n=L(UO),r=(0,I.useMemo)(()=>{let t=e.pallet;return t?Q.of(e.face.values()).append(e.freeLoadingMaterial).concat(Q.of(e.queues).collect(([e,t])=>t.mats)).flatMap(e=>e).collect(e=>e.action.type===V.Loading&&e.action.loadOntoPalletNum===t.palletNum&&e.location.type===ot.OnPallet&&e.location.palletNum===t.palletNum?Qt(e.partName,`unload`,e.materialID,t.palletNum,e.process,n):e.action.type===V.Loading&&e.action.loadOntoPalletNum===t.palletNum?Qt(e.partName,`load`,e.materialID,t.palletNum,e.action.processAfterLoad??e.process,n):e.location.type===ot.OnPallet&&e.location.palletNum===t.palletNum&&(e.action.type===V.UnloadToCompletedMaterial||e.action.type===V.UnloadToInProcess)?Qt(e.partName,`unload`,e.materialID,t.palletNum,e.process,n):null).toRArray():[]},[e,n]);if(r.length===0||t)return(0,H.jsx)(`div`,{});function i(){for(let e of r)window.open(e,`_blank`)}return(0,H.jsx)(J,{sx:{position:`fixed`,bottom:`5px`,right:`5px`},children:(0,H.jsx)(X,{title:`Open All Instructions`,children:(0,H.jsx)(Iy,{onClick:i,color:`secondary`,children:(0,H.jsx)(DT,{})})})})}function L2({elapsedLoadTime:e}){let t=L(GO).timeOfCurrentStatusUTC,n=L(KO);return e?(0,H.jsx)(`span`,{children:i2(tk(e)+(n-Math.floor(t.getTime()/1e3)))}):null}function R2({data:e,faceNum:t,loadNum:n,submitBasketLoadStationCommand:r}){let i=e.face.get(t),a=Dk(L(yr).basketName);return i?e.activeBasket&&!e.pallet?(0,H.jsxs)(`div`,{"data-testid":`load-station-active-basket`,children:[t===1?(0,H.jsxs)(J,{sx:{display:`grid`,gridTemplateColumns:`1fr auto`},children:[(0,H.jsxs)(q,{variant:`h4`,children:[a,` `,e.activeBasket.basketId]}),(0,H.jsx)(J,{sx:{justifySelf:`flex-end`},children:(0,H.jsx)(L2,{elapsedLoadTime:e.elapsedLoadingTime})})]}):null,(0,H.jsx)(J,{sx:{ml:`4em`,mr:`4em`},children:(0,H.jsx)(Y0,{kind:{type:R0.BasketZone,basketId:e.activeBasket.basketId},children:(0,H.jsx)(j2,{stationNumber:n,basket:e.activeBasket,material:e.allMaterial,fsize:e.fsize,submitCommand:r})})})]}):e.pallet?(0,H.jsxs)(`div`,{"data-testid":`load-station-pallet-face-${t}`,children:[t===1?(0,H.jsxs)(J,{sx:{display:`grid`,gridTemplateColumns:e.pallet.numFaces>1?`1fr 1fr 1fr`:`1fr 1fr`},children:[(0,H.jsxs)(q,{variant:`h4`,children:[`Pallet `,e.pallet.palletNum]}),e.pallet.numFaces>1?(0,H.jsx)(q,{variant:`h6`,sx:{justifySelf:`center`},children:e.pallet.faceNames?.[t-1]??`Face 1`}):void 0,(0,H.jsx)(J,{sx:{justifySelf:`flex-end`},children:(0,H.jsx)(L2,{elapsedLoadTime:e.elapsedLoadingTime})})]}):e.pallet.numFaces>1?(0,H.jsx)(J,{sx:{display:`flex`,justifyContent:`center`},children:(0,H.jsx)(q,{variant:`h6`,children:e.pallet.faceNames?.[t-1]??`Face ${t}`})}):void 0,(0,H.jsx)(J,{sx:{ml:`4em`,mr:`4em`},children:(0,H.jsx)(Y0,{kind:{type:R0.PalletFaceZone,face:t},children:(0,H.jsx)(J,{sx:{display:`flex`,flexWrap:`wrap`,justifyContent:`space-around`},children:i.map((t,n)=>(0,H.jsx)(Y0,{kind:{type:R0.Material,material:t},children:(0,H.jsx)(QU,{mat:t,fsize:e.fsize})},n))})})})]}):null:null}function z2({data:e,mat:t}){return(0,H.jsxs)(`div`,{children:[t.label===``?null:(0,H.jsx)(q,{variant:`h4`,children:t.label}),t.material.mats.map((n,r)=>(0,H.jsx)(Y0,{kind:{type:R0.Material,material:n,identifier:n.materialID<0?`raw-${t.isFree?`free`:`queue`}-${t.label}-${r}`:void 0},children:t.isFree||t.sortable===!1?(0,H.jsx)(QU,{mat:n,displayActionForSinglePallet:e.pallet?e.pallet.palletNum:0,fsize:e.fsize,showRawMaterial:!0,showJobComment:!0}):(0,H.jsx)($U,{mat:n,displayActionForSinglePallet:e.pallet?e.pallet.palletNum:0,shake:n.action.type===V.Loading&&n.action.loadOntoPalletNum===e.pallet?.palletNum,fsize:n.action.type===V.Loading&&n.action.loadOntoPalletNum===e.pallet?.palletNum?e.fsize:void 0,showRawMaterial:!0,showJobComment:!0})},r)),t.material.hiddenCnt>0?(0,H.jsxs)(q,{variant:`body2`,color:`textSecondary`,sx:{textAlign:`center`,mt:`0.5em`},children:[`+`,t.material.hiddenCnt,` hidden`]}):null]})}function B2({data:e,label:t,baskets:n}){return(0,H.jsxs)(`div`,{children:[(0,H.jsx)(q,{variant:`h4`,children:t}),n.map((t,n)=>(0,H.jsxs)(J,{"data-testid":`load-station-basket-${M2(t.basketId)}`,sx:{mt:n===0?`0.5em`:`1.5em`,pt:n===0?void 0:`1em`},children:[(0,H.jsx)(q,{variant:`h6`,sx:{mb:`0.5em`},children:t.label}),(0,H.jsx)(Y0,{kind:{type:R0.BasketZone,basketId:t.basketId},children:(0,H.jsx)(z2,{data:e,mat:{label:``,material:t.material,isFree:!1,sortable:!1}})})]},t.basketId))]})}function V2({data:e,region:t}){switch(t.kind){case`free`:return(0,H.jsx)(Y0,{kind:{type:R0.FreeMaterialZone},children:(0,H.jsx)(z2,{data:e,mat:{label:t.label,material:t.material,isFree:!0,sortable:!1}})});case`queue`:return(0,H.jsx)(Y0,{kind:{type:R0.QueueZone,queue:t.label},children:(0,H.jsx)($q,{matIds:t.material.mats.map(e=>e.materialID),direction:`vertical`,queueName:t.label,renderDragOverlay:t=>(0,H.jsx)(eW,{mat:t,displayActionForSinglePallet:e.pallet?e.pallet.palletNum:0,fsize:t.action.type===V.Loading&&t.action.loadOntoPalletNum===e.pallet?.palletNum?e.fsize:void 0}),children:(0,H.jsx)(z2,{data:e,mat:{label:t.label,material:t.material,isFree:!1,sortable:!0}})})});case`baskets`:return(0,H.jsx)(B2,{data:e,label:t.label,baskets:t.baskets})}}function H2(){let e=L(lL);return(0,H.jsx)(`div`,{children:(0,I.useMemo)(()=>{let t=iE(new Date,-5);return e.matsById.valuesToLazySeq().filter(e=>e.completed_last_proc_machining===!0&&e.last_unload_time!==void 0&&e.last_unload_time>=t).toSortedArray({desc:e=>e.last_unload_time?.getTime()??0})},[e]).map((e,t)=>(0,H.jsx)(ZU,{mat:e},t))})}var U2=(0,I.memo)(function({fillViewPort:e,showMaterial:t}){let n=J0({type:t?R0.CompletedExpandedMaterialZone:R0.CompletedCollapsedMaterialZone});return t&&e?(0,H.jsxs)(J,{ref:n,sx:{padding:`8px`,display:`flex`,flexDirection:`column`,height:`100%`},children:[(0,H.jsx)(q,{variant:`h4`,children:`Completed`}),(0,H.jsx)(J,{sx:{position:`relative`,flexGrow:1},children:(0,H.jsx)(J,{sx:{position:`absolute`,top:`0`,left:`0`,right:`0`,bottom:`0`,overflow:`auto`},children:(0,H.jsx)(H2,{})})})]}):t?(0,H.jsxs)(J,{ref:n,sx:{padding:`8px`},children:[(0,H.jsx)(q,{variant:`h4`,children:`Completed`}),(0,H.jsx)(H2,{})]}):(0,H.jsx)(J,{ref:n,sx:{display:`flex`,justifyContent:e?`flex-end`:void 0,padding:`8px`},children:(0,H.jsx)(q,{variant:`h4`,sx:{margin:`4px`,...e?{textOrientation:`mixed`,writingMode:`vertical-rl`}:{}},children:`Completed`})})});function W2({pallet:e}){let t=L(EI),n=L(UO),r=WI();if(t===null)return null;let i;if(t.action.type===V.Loading&&t.action.loadOntoPalletNum===e?i=`load`:(t.action.type===V.UnloadToInProcess||t.action.type===V.UnloadToCompletedMaterial)&&t.location.type===ot.OnPallet&&t.location.palletNum===e&&(i=`unload`),i===void 0)return null;let a=Qt(t.partName,i,t.materialID,e,t.action.type===V.Loading?t.action.processAfterLoad??t.process:t.process,n);return r?(0,H.jsx)(Y,{color:`primary`,children:`Instructions`}):(0,H.jsx)(Y,{href:a,target:`bms-instructions`,color:`primary`,children:`Instructions`})}function G2({queues:e,onClose:t,toQueue:n,showAddToQueue:r,setShowAddToQueue:i}){let a=R(bI),o=L(jI),s=L(CI),c=L(EI),l=L(UO),[u,d]=LI();return!s||c?.location.type===ot.OnPallet||c?.action.type===V.Loading||c?.action.type===V.LoadingToBasket||e.length===0||c?.location.type===ot.InQueue&&c?.location.currentQueue&&e.includes(c?.location.currentQueue)?null:r?(0,H.jsxs)(Y,{color:`primary`,disabled:n===null||d,onClick:()=>{u({materialId:s.materialID,queue:n??``,queuePosition:-1,operator:l}),a(null),t()},children:[`Add To `,n??`Queue`,` `,o?` To Run Process ${o.process+1}`:``]}):(0,H.jsx)(Y,{color:`primary`,onClick:()=>i(!0),children:`Add To Queue`})}function K2(){let e=L(yr),t=R(D0),n=L(CI);return!e.allowChangeWorkorderAtLoadStation||n===null||n.materialID<0?null:(0,H.jsx)(Y,{color:`primary`,onClick:()=>t(!0),children:`Assign Workorder`})}var q2=(0,I.memo)(function(e){let[t,n]=(0,I.useState)(null),[r,i]=(0,I.useState)(null),[a,o]=(0,I.useState)(!1),[s,c]=(0,I.useState)(null),l=(0,I.useCallback)(function(){n(null),i(null),o(!1),c(null)},[n,i]);return(0,H.jsx)(dW,{onClose:l,allowNote:!0,highlightProcsGreaterOrEqualTo:r?.process??void 0,extraDialogElements:(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(JY,{st:t,setState:n}),r===null?null:(0,H.jsx)(WY,{st:r,setState:i}),a?(0,H.jsx)(LY,{selectedQueue:s,setSelectedQueue:c,queueNames:e.queues}):void 0]}),buttons:(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(W2,{pallet:e.pallet}),(0,H.jsx)(xY,{}),(0,H.jsx)(HY,{}),(0,H.jsx)(I0,{}),(0,H.jsx)(G2,{toQueue:s,queues:e.queues,onClose:l,showAddToQueue:a,setShowAddToQueue:o}),(0,H.jsx)(YY,{st:t,setState:n,onClose:l}),(0,H.jsx)(GY,{st:r,setState:i,onClose:l,loadStation:!0}),(0,H.jsx)(K2,{})]})})});function J2({numMatCols:e,maxNumFaces:t,horizontal:n,showMatInCompleted:r}){let i=``,a=``;if(t<=0&&(t=1),n){let n=``;for(let t=0;t<e;t++)a+=`minmax(16em, max-content) `,n+=`mat${t} `;a+=`1fr `,r?a+=`minmax(16em, max-content)`:a+=` 4.5em`;let o=`minmax(calc((100vh - 64px) / ${t}), max-content)`;for(let e=0;e<t;e++){let r=e===t-1?`1fr`:o;i+=`"${n} palface${e} completed" ${r}\n`}}else{a=`1fr`;for(let e=0;e<t;e++)i+=`"palface${e}" minmax(134px, max-content)\n`;for(let t=0;t<e;t++)i+=`"mat${t}" minmax(134px, max-content)\n`;i+=`"completed" minmax(134px, max-content)
349
+ </table>`,n}function J1(e,t){oA(q1(e,t))}var Y1=[{id:0,numeric:!1,label:`Date`,getDisplay:e=>e.time.toLocaleString(),getForSort:e=>e.time.getTime()},{id:1,numeric:!1,label:`Serial`,getDisplay:e=>e.serial||``},{id:2,numeric:!1,label:`Workorder`,getDisplay:e=>e.workorder||``},{id:3,numeric:!1,label:`Inspected`,getDisplay:e=>e.toInspect?`inspected`:``},{id:4,numeric:!1,label:`Failed`,getDisplay:e=>e.failed?`failed`:``}];function X1(e,t,n){let[r,i]=(0,I.useState)(void 0),a;return e&&e===`Last30Days`?a={type:`Last30Days`,set_days_back:e=>{if(e){let t=new Date;i({start:tE(t,-e),end:iE(t,1)})}else i(void 0)}}:e&&e===`ZoomIntoRange`?a={type:`ZoomIntoRange`,default_date_range:n,current_date_zoom:r,set_date_zoom_range:i}:e&&t&&e===`ExtendDays`&&(a={type:`ExtendDays`,curStart:n[0],curEnd:n[1],extend:t}),{zoom:a,zoomRange:r}}var Z1=(0,I.memo)(function(e){let t=R(bI),n=K1(0,Y1),[r,i]=(0,I.useState)(gO.empty()),[a,o]=(0,I.useState)(10),[s,c]=(0,I.useState)(void 0),l=X1(e.zoomType,e.extendDateRange,e.default_date_range),u=JX(e.points,l.zoomRange,n.sortOn);return(0,H.jsx)(`div`,{style:{width:`100%`,marginTop:`1em`},children:Q.of(u).toSortedArray(([e])=>e).map(([u,d])=>{let f=Math.min(r.get(u)??0,Math.ceil(d.material.length/a));return(0,H.jsxs)(ree,{expanded:u===s,onChange:(e,t)=>c(t?u:void 0),children:[(0,H.jsxs)(Sm,{expandIcon:(0,H.jsx)(CT,{}),children:[(0,H.jsx)(q,{variant:`h6`,style:{flexBasis:`33.33%`,flexShrink:0},children:u}),(0,H.jsxs)(q,{variant:`caption`,children:[d.material.length,` total parts, `,d.failedCnt,` failed`]})]}),(0,H.jsx)(see,{children:(0,H.jsxs)(`div`,{style:{width:`100%`},children:[(0,H.jsxs)(AC,{children:[(0,H.jsx)(L1,{columns:Y1,sort:n,showDetailsCol:!0}),(0,H.jsx)(U1,{columns:Y1,pageData:Q.of(d.material).drop(f*a).take(a),rowsPerPage:a,onClickDetails:e.hideOpenDetailColumn?void 0:(e,n)=>t({type:`MatSummary`,summary:{materialID:n.materialID,partName:n.partName,serial:n.serial,workorderId:n.workorder}})})]}),(0,H.jsx)(H1,{tpage:{page:f,rowsPerPage:a,setPage:e=>i(r.set(u,e)),setRowsPerPage:o},count:d.material.length,zoom:l.zoom})]})})]},u)})})}),Q1=20,$1=20,e0=120,t0=20;function n0({link:e,path:t,strokeWidth:n,setTooltip:r}){let[i,a]=(0,I.useState)(!1);if(t===null)return null;function o(t){let n=NA(t);n!==null&&(r({left:n.x,top:n.y,data:e}),a(!0))}function s(){a(!1),r(null)}return(0,H.jsx)(`path`,{d:t,stroke:i?Nr[600]:Nr[300],strokeWidth:n,opacity:.2,fill:`none`,onMouseMove:o,onMouseLeave:s})}function r0({node:e}){return e.x1===void 0||e.x0===void 0||e.y1===void 0||e.y0===void 0?null:(0,H.jsxs)(`g`,{transform:`translate(${e.x0}, ${e.y0})`,children:[(0,H.jsx)(`rect`,{width:e.x1-e.x0,height:e.y1-e.y0,fill:Nr[800],opacity:.8,stroke:`none`}),(0,H.jsx)(`text`,{x:18,y:(e.y1-e.y0)/2,children:e.name})]})}var i0=(0,I.memo)(function({data:e,setTooltip:t,parentHeight:n,parentWidth:r}){let{nodes:i,links:a}=(0,I.useMemo)(()=>{let t=LZ(e);if(t.nodes.length===0)return{nodes:[],links:[]};let i=hZ().nodeWidth(10).nodePadding(10).nodeAlign(iZ).extent([[Q1,$1],[r-e0,n-t0-$1]])({nodes:t.nodes,links:t.links});return{nodes:i.nodes,links:i.links.flatMap(e=>typeof e.source==`object`&&typeof e.target==`object`&&e.width!==void 0?[{...e,source:e.source,target:e.target,width:e.width}]:[])}},[e,r,n]),o=NZ();return(0,H.jsxs)(`svg`,{width:r,height:n,children:[(0,H.jsx)(`g`,{children:i.map((e,t)=>(0,H.jsx)(r0,{node:e},t))}),(0,H.jsx)(`g`,{children:a.map((e,n)=>(0,H.jsx)(n0,{link:e,path:o(e),strokeWidth:Math.max(e.width??1,1),setTooltip:t},n))})]})});function a0({tooltip:e}){return e===null?null:(0,H.jsxs)(`div`,{children:[e.data.source.name,` ➞ `,e.data.target.name,`: `,e.data.value,` parts`]})}var o0=(0,I.memo)(function({data:e}){let t=(0,I.useMemo)(()=>P(null),[]),n=R(t);return(0,H.jsx)(`div`,{style:{position:`relative`},children:(0,H.jsx)(KA,{sx:{height:{xs:`calc(100vh - 230px)`,md:`calc(100vh - 182px)`,xl:`calc(100vh - 130px)`},width:`100%`},chart:({height:t,width:r})=>(0,H.jsx)(i0,{data:e,setTooltip:n,parentHeight:t,parentWidth:r}),tooltipAtom:t,TooltipContent:a0})})}),s0=AO(e=>e(HI)?`aaa`:void 0),c0=AO(e=>e(HI)?`CMM`:void 0),l0=P(!1);function u0(e){let[t,n]=z(s0),[r,i]=z(c0),[a,o]=z(l0),s,c=e.restrictToPart||t;c&&r&&(s=e.inspectionlogs.get(new rL(c,r))?.valuesToLazySeq()??[]);let l=e.inspectionlogs.keysToLazySeq().map(e=>e.part).distinct().toSortedArray(e=>e),u=e.inspectionlogs.keysToLazySeq().map(e=>e.inspType).distinct().toSortedArray(e=>e);return(0,H.jsxs)(J,{sx:{paddingLeft:`24px`,paddingRight:`24px`,paddingTop:`10px`},children:[(0,H.jsxs)(J,{component:`nav`,sx:{display:`flex`,minHeight:`2.5em`,alignItems:`center`,maxWidth:`calc(100vw - 24px - 24px)`},children:[e.subtitle?(0,H.jsx)(q,{variant:`subtitle1`,children:e.subtitle}):void 0,(0,H.jsx)(J,{sx:{flexGrow:1}}),e.onlyTable?void 0:(0,H.jsx)(Ry,{size:`small`,children:(0,H.jsxs)(oS,{autoWidth:!0,value:a?`table`:`sankey`,onChange:e=>o(e.target.value===`table`),children:[(0,H.jsx)(wx,{value:`sankey`,children:`Sankey`},`sankey`),(0,H.jsx)(wx,{value:`table`,children:`Table`},`table`)]})}),(0,H.jsx)(Ry,{size:`small`,children:(0,H.jsxs)(oS,{name:`inspection-sankey-select-type`,autoWidth:!0,displayEmpty:!0,style:{marginRight:`1em`,marginLeft:`1em`},value:r||``,onChange:e=>i(e.target.value),children:[r?void 0:(0,H.jsx)(wx,{value:``,children:(0,H.jsx)(`em`,{children:`Select Inspection Type`})},0),u.map(e=>(0,H.jsx)(wx,{value:e,children:e},e))]})}),e.restrictToPart===void 0?(0,H.jsx)(Ry,{size:`small`,children:(0,H.jsxs)(oS,{name:`inspection-sankey-select-part`,autoWidth:!0,displayEmpty:!0,value:c||``,onChange:e=>n(e.target.value),children:[c?void 0:(0,H.jsx)(wx,{value:``,children:(0,H.jsx)(`em`,{children:`Select Part`})},0),l.map(e=>(0,H.jsx)(wx,{value:e,children:(0,H.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`},children:[(0,H.jsx)(LU,{part:e,size:30}),(0,H.jsx)(`span`,{style:{marginRight:`1em`},children:e})]})},e))]})}):void 0,s?(0,H.jsx)(X,{title:`Copy to Clipboard`,children:(0,H.jsx)(Gm,{onClick:()=>s?QX(c||``,r||``,s):void 0,style:{height:`25px`,paddingTop:0,paddingBottom:0},size:`large`,children:(0,H.jsx)(jT,{})})}):void 0]}),(0,H.jsx)(`main`,{children:s?a||e.onlyTable?(0,H.jsx)(Z1,{zoomType:e.zoomType,points:s,default_date_range:e.default_date_range,extendDateRange:e.extendDateRange,hideOpenDetailColumn:e.hideOpenDetailColumn}):(0,H.jsx)(o0,{data:s}):void 0})]})}var d0=P(null),f0=BO(P(async(e,{signal:t})=>{let n=e(d0);if(n==null||Ut===void 0)return gO.empty();let r=await Ut.get(n.curStart,n.curEnd,t);return Q.of(r).flatMap(sL).filter(e=>e.key.part===n.part).toLookupMap(e=>e.key,e=>e.entry.cntr,e=>e.entry)}),e=>e??gO.empty()),p0=BO(P(async e=>{let t=e(d0);if(t==null)return gO.empty();let n=[];for(let e of Kt)n.push(await e.get(t.curStart,t.curEnd));return Q.of(n).flatMap(e=>e).flatMap(sL).filter(e=>e.key.part===t.part).toLookupMap(e=>e.key,e=>e.entry.cntr,e=>e.entry)}),e=>e??gO.empty()),m0=P(e=>gO.union((e,t)=>e.union(t),e(f0),e(p0)));function h0(e){return t=>t===null?null:e<0?{curStart:tE(t.curStart,e),curEnd:t.curEnd,part:t.part}:{curStart:t.curStart,curEnd:tE(t.curEnd,e),part:t.part}}var g0=[{id:0,numeric:!1,label:`Date`,getDisplay:e=>e.time.toLocaleString(),getForSort:e=>e.time.getTime()},{id:1,numeric:!1,label:`Part`,getDisplay:e=>e.part},{id:2,numeric:!1,label:`Inspection`,getDisplay:e=>e.inspType},{id:3,numeric:!1,label:`Serial`,getDisplay:e=>e.serial||``},{id:4,numeric:!1,label:`Workorder`,getDisplay:e=>e.workorder||``}];function _0(e){let t=WI(),n=K1(0,g0),r=G1(),i=R(bI),a=Math.min(r.page,Math.ceil(e.failed.length/r.rowsPerPage)),o=Q.of(e.failed).sortBy(n.sortOn);return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(AC,{children:[(0,H.jsx)(L1,{columns:g0,sort:n,showDetailsCol:!t}),(0,H.jsx)(U1,{columns:g0,pageData:o.drop(a*r.rowsPerPage).take(r.rowsPerPage),rowsPerPage:r.rowsPerPage,onClickDetails:t?void 0:(e,t)=>{i({type:`MatSummary`,summary:{materialID:t.materialID,partName:t.part,serial:t.serial,workorderId:t.workorder}})}})]}),(0,H.jsx)(H1,{tpage:{...r,page:a},count:e.failed.length})]})}function v0(){let e=L(aL),t=(0,I.useMemo)(()=>{let t=bE();return YX(Q.of(e).flatMap(([e,t])=>t.valuesToLazySeq()),tE(t,-4),tE(t,1))},[e]);return(0,H.jsxs)(`div`,{children:[(0,H.jsxs)(J,{component:`nav`,sx:{display:`flex`,minHeight:`2.5em`,alignItems:`center`,maxWidth:`calc(100vw - 24px - 24px)`},children:[(0,H.jsx)(q,{variant:`subtitle1`,children:`Inspections marked as failed in the last 5 days`}),(0,H.jsx)(J,{sx:{flexGrow:1}}),(0,H.jsx)(X,{title:`Copy to Clipboard`,children:(0,H.jsx)(Gm,{style:{height:`25px`,paddingTop:0,paddingBottom:0},onClick:()=>eZ(t),size:`large`,children:(0,H.jsx)(jT,{})})})]}),(0,H.jsx)(_0,{failed:t})]})}function y0(){let e=WI(),t=R(bI),[n,r]=(0,I.useState)(e?`00000000i9`:``),[i,a]=(0,I.useState)(!1),[o,s]=(0,I.useState)(null);function c(){n&&n!==``&&(a(!0),s(null),Ut.materialForSerial(n).then(e=>{let i=Q.of(e).maxBy(e=>e.materialID);i?(t({type:`MatDetails`,details:i}),r(``),s(null)):s(`No material found with serial `+n)}).catch(e=>{zt.isApiException(e)?s(e.response):e instanceof Error?s(e.message):s(e)}).finally(()=>a(!1)))}return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(MS,{direction:`row`,spacing:2,sx:{alignItems:`center`,marginLeft:`auto`,marginRight:`auto`},children:[(0,H.jsx)(`div`,{children:(0,H.jsx)(Hw,{label:n===``?`Serial`:`Serial (press enter)`,value:n,onChange:e=>r(e.target.value),onKeyPress:e=>{e.key===`Enter`&&n!==``&&(e.preventDefault(),c())}})}),(0,H.jsx)(`div`,{children:(0,H.jsx)(Y,{variant:`contained`,color:`secondary`,disabled:n===``||i,onClick:c,children:i?(0,H.jsxs)(MS,{direction:`row`,spacing:2,children:[(0,H.jsx)(zm,{}),` Searching`]}):(0,H.jsx)(H.Fragment,{children:`Lookup`})})})]}),o&&o!==``?(0,H.jsx)(`div`,{children:o}):void 0]})}function b0(e){let t=e[0];if(t===void 0)return bE();let n=t.endUTC;for(let t of e)t.type===B.MachineCycle&&(n=t.endUTC);return n}function x0(){let e=L(wI),t=L(AI);return e?(0,H.jsx)(nW,{partName:e.partName,serial:e.serial,subtitle:`Path `+qX(XX(t))+` at `+b0(t).toLocaleString()}):(0,H.jsx)(`div`,{children:`Serial Details`})}function S0({setStep:e}){let t=L(wI),n=L(AI),r=R(d0),i=R(bI);return(0,H.jsxs)(MS,{direction:`row`,spacing:2,sx:{mt:`2em`},children:[t?(0,H.jsx)(Y,{variant:`contained`,color:`secondary`,onClick:()=>{let i=b0(n);r({part:t?.partName??``,curStart:cE(tE(i,-5)),curEnd:Sre(tE(i,5))}),e(2)},children:`Lookup Similar Paths`}):void 0,(0,H.jsx)(Y,{variant:`contained`,style:{marginLeft:`2em`},onClick:()=>{i(null),r(null),e(0)},children:`Reset`})]})}function C0(e){let t=L(CI),n=L(AI),[r,i]=z(d0),a=L(m0),o=R(bI);if(t===null)return null;function s(e){i(h0(e))}return(0,H.jsxs)(`div`,{children:[(0,H.jsx)(u0,{inspectionlogs:a,restrictToPart:t.partName,subtitle:`Paths for `+t.partName+` around `+b0(n).toLocaleString(),default_date_range:r?[r.curStart,r.curEnd]:[],zoomType:r?`ExtendDays`:void 0,extendDateRange:s,hideOpenDetailColumn:!0,onlyTable:!0}),(0,H.jsx)(Y,{variant:`contained`,style:{marginTop:`2em`},onClick:()=>{o(null),i(null),e.setStep(0)},children:`Reset`})]})}function w0(){let[e,t]=(0,I.useState)(0),n=L(bI),r=e;return r===0&&n&&(r=1),(0,H.jsxs)(MS,{direction:`column`,spacing:2,children:[(0,H.jsxs)(yC,{activeStep:r,orientation:`horizontal`,children:[(0,H.jsx)(zS,{children:(0,H.jsx)(nC,{children:`Select Material`})}),(0,H.jsx)(zS,{children:(0,H.jsx)(nC,{children:(0,H.jsx)(x0,{})})}),(0,H.jsx)(zS,{children:(0,H.jsx)(nC,{children:`Lookup similar paths`})})]}),r===0?(0,H.jsxs)(MS,{direction:`column`,spacing:4,children:[(0,H.jsx)(q,{children:`Enter a serial number, scan a barcode, or click on a material in the table below to see details.`}),(0,H.jsx)(y0,{}),(0,H.jsx)(v0,{})]}):r===1?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(IU,{fallback:(0,H.jsx)(lW,{}),children:(0,H.jsx)(sW,{})}),(0,H.jsx)(S0,{setStep:t})]}):r===2?(0,H.jsx)(IU,{children:(0,H.jsx)(C0,{setStep:t})}):void 0]})}function T0(){return GI(`Quality Material`),(0,H.jsx)(`main`,{style:{padding:`24px`},children:(0,H.jsx)(w0,{})})}var E0=(0,I.memo)(function(){GI(`Paths`);let e=L(aL);return(0,H.jsx)(u0,{inspectionlogs:(0,I.useMemo)(()=>{let t=bE(),n=tE(t,-6),r=tE(t,1);return e.collectValues(e=>{let t=e.filter(e=>e.time>=n&&e.time<=r);return t.size===0?null:t})},[e]),default_date_range:[tE(bE(),-6),tE(bE(),1)],subtitle:`Paths from the last 7 days`})}),D0=P(!1);function O0(e){let t=``;return e.comments&&e.comments.length>0&&(t=`; `+e.comments[e.comments.length-1].comment),`Due ${e.dueDate.toLocaleDateString()}; Completed ${e.completedQuantity} of ${e.plannedQuantity}${t}`}function k0({work:e}){return e.plannedQuantity<=e.completedQuantity?(0,H.jsx)(lT,{}):(0,H.jsx)(WT,{})}function A0(){let[e,t]=(0,I.useState)(null),n=L(CI),[r]=FI(),i=R(D0);return(0,H.jsx)(Hw,{sx:{mt:`5px`},label:e===null||e===``?`Workorder`:`Workorder (press enter)`,value:e??``,onChange:e=>t(e.target.value),onKeyPress:t=>{t.key===`Enter`&&n&&e&&e!==``&&(t.preventDefault(),r(n,e),i(!1))}})}function j0(){let e=L(CI),t=L(Tie),n=R(D0),[r]=FI();return(0,H.jsx)(sb,{children:(t??[]).map(t=>(0,H.jsx)(hb,{children:(0,H.jsxs)(cb,{onClick:()=>{e&&r(e,t.workorderId),n(!1)},children:[(0,H.jsx)(bb,{children:(0,H.jsx)(k0,{work:t})}),(0,H.jsx)(Tb,{primary:t.workorderId,secondary:O0(t)})]})},t.workorderId))})}var M0=(0,I.memo)(function(){let[e,t]=z(D0),n;return n=e?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(My,{children:`Select Workorder`}),(0,H.jsx)(jy,{children:(0,H.jsxs)(IU,{children:[(0,H.jsx)(A0,{}),(0,H.jsx)(j0,{})]})}),(0,H.jsx)(Ay,{children:(0,H.jsx)(Y,{onClick:()=>t(!1),color:`primary`,children:`Cancel`})})]}):(0,H.jsx)(`p`,{children:`None`}),(0,H.jsx)(ky,{open:e,onClose:()=>t(!1),maxWidth:`md`,children:n})}),N0=P(!1);function P0(){let[e,t]=(0,I.useState)(null),n=L(CI),[r]=NI(),i=R(N0);return(0,H.jsx)(Hw,{sx:{mt:`5px`},label:e===``||e===null?`Inspection Type`:`Inspection Type (press enter)`,value:e??``,onChange:e=>t(e.target.value),onKeyPress:t=>{t.key===`Enter`&&n&&e&&e!==``&&(t.preventDefault(),r({mat:n,inspType:e,inspect:!0}),i(!1))}})}function F0(){let e=L(CI),[t]=NI(),n=L(EL),r=Q.of(n).sortBy(e=>e),i=R(N0);return e===null?null:(0,H.jsx)(sb,{children:r.map(n=>(0,H.jsx)(hb,{children:(0,H.jsxs)(cb,{onClick:()=>{t({mat:e,inspType:n,inspect:!0}),i(!1)},children:[(0,H.jsx)(bb,{children:(0,H.jsx)(UT,{})}),(0,H.jsx)(Tb,{primary:n})]})},n))})}function I0(){let e=R(N0),t=L(EI);return t===null||t.materialID<0?null:(0,H.jsx)(Y,{color:`primary`,onClick:()=>e(!0),children:`Signal Inspection`})}var L0=(0,I.memo)(function(){let[e,t]=z(N0),n;return n=e?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(My,{children:`Select Inspection Type`}),(0,H.jsx)(jy,{children:(0,H.jsxs)(IU,{children:[(0,H.jsx)(P0,{}),(0,H.jsx)(F0,{})]})}),(0,H.jsx)(Ay,{children:(0,H.jsx)(Y,{onClick:()=>t(!1),color:`primary`,children:`Cancel`})})]}):(0,H.jsx)(`p`,{children:`None`}),(0,H.jsx)(ky,{open:e,onClose:()=>t(!1),maxWidth:`md`,children:n})}),R0=function(e){return e[e.Material=0]=`Material`,e[e.FreeMaterialZone=1]=`FreeMaterialZone`,e[e.CompletedCollapsedMaterialZone=2]=`CompletedCollapsedMaterialZone`,e[e.CompletedExpandedMaterialZone=3]=`CompletedExpandedMaterialZone`,e[e.PalletFaceZone=4]=`PalletFaceZone`,e[e.QueueZone=5]=`QueueZone`,e[e.BasketZone=6]=`BasketZone`,e}({});function z0(e){switch(e.type){case 0:return`Material-`+(e.identifier??(e.material?.materialID??-1).toString());case 1:return`FreeMaterialZone`;case 2:return`CompletedCollapsedMaterialZone`;case 3:return`CompletedExpandedMaterialZone`;case 4:return`PalletFaceZone-`+e.face.toString();case 5:return`QueueZone-`+e.queue;case 6:return`BasketZone-`+e.basketId.toString()}}function B0(e){switch(e.type){case 0:return[e.type,e.material,e.identifier];case 1:case 2:case 3:return[e.type,null];case 4:return[e.type,e.face];case 5:return[e.type,e.queue];case 6:return[e.type,e.basketId]}}function V0(e){let t,n,r=new Map,i=new Map,a=new Map,o=[];for(let s of e.values())switch(s.type){case 1:t=s.elem;break;case 2:case 3:n=s.elem;break;case 4:r.set(s.face,s.elem);break;case 5:i.set(s.queue,s.elem);break;case 6:a.set(s.basketId,s.elem);break;case 0:s.material&&o.push([s.elem,s.material]);break}return{freeMaterial:t,completedMaterial:n,faces:r,queues:i,baskets:a,material:o}}function H0(e,t){if(!e)return[];let n=V0(t);if(!n.completedMaterial)return[];let r=[],i=new Map,a=new Map,o=new Map,s=0;for(let[t,c]of Q.of(n.material).sortBy(([e])=>e.left,([e])=>e.top))switch(c.action.type){case V.UnloadToCompletedMaterial:case V.UnloadToInProcess:if(c.action.unloadToBasketId){let i=n.baskets.get(c.action.unloadToBasketId),a=o.get(c.action.unloadToBasketId)??0;o.set(c.action.unloadToBasketId,a+1),r.push({fromX:t.left,fromY:t.top+t.height/2,toX:i===void 0?e.left+2:i.right-5,toY:i===void 0?t.top+t.height/2:i.top+20*(a+1),curveDirection:1})}else if(c.action.type===V.UnloadToCompletedMaterial&&(!c.action.unloadIntoQueue||c.action.unloadIntoQueue===``))r.push({fromX:t.right,fromY:t.top+t.height/2,toY:t.top+t.height/2,toX:n.completedMaterial?n.completedMaterial.left+2:e.right-10,curveDirection:1});else{let i,o;c.action.unloadIntoQueue?(i=n.queues.get(c.action.unloadIntoQueue),o=a.get(c.action.unloadIntoQueue)??0,a.set(c.action.unloadIntoQueue,o+1)):(i=n.freeMaterial,o=s,s+=1),r.push({fromX:t.left,fromY:t.top+t.height/2,toX:i===void 0?e.left+2:i.right-5,toY:i===void 0?t.top+t.height/2:i.top+20*(o+1),curveDirection:1})}break;case V.Loading:if(c.action.loadFromBasketId&&c.action.loadOntoFace){let e=n.faces.get(c.action.loadOntoFace);if(e!==void 0){let n=i.get(c.action.loadOntoFace)??0;i.set(c.action.loadOntoFace,n+1),r.push({fromX:t.right,fromY:t.top+t.height/2,toX:e.left+20,toY:e.top+50+20*n,curveDirection:-1})}}else if(c.action.loadFromBasketId){let i=n.baskets.get(c.action.loadFromBasketId),a=o.get(c.action.loadFromBasketId)??0;o.set(c.action.loadFromBasketId,a+1),r.push({fromX:t.right,fromY:t.top+t.height/2,toX:i===void 0?e.right-10:i.left+20,toY:i===void 0?t.top+t.height/2:i.top+50+20*a,curveDirection:-1})}else if(c.action.loadOntoFace)if(c.location.type===ot.OnPallet)if(c.location.palletNum===c.action.loadOntoPalletNum&&c.location.face===c.action.loadOntoFace)r.push({fromX:t.right,fromY:t.top+t.height*3/4,toX:t.left+t.width*7/8,toY:t.bottom,curveDirection:-1});else{let e=n.faces.get(c.action.loadOntoFace);e&&(c.action.loadOntoFace<(c.location.face??0)?r.push({fromX:t.left,fromY:t.top+t.height/2,toX:t.left,toY:e.bottom+20,curveDirection:-1}):r.push({fromX:t.left,fromY:t.top+t.height/2,toX:t.left,toY:e.top-20,curveDirection:1}))}else{let e=n.faces.get(c.action.loadOntoFace);if(e!==void 0){let n=i.get(c.action.loadOntoFace)??0;i.set(c.action.loadOntoFace,n+1),r.push({fromX:t.right,fromY:t.top+t.height/2,toX:e.left+20,toY:e.top+50+20*n,curveDirection:-1})}}break;case V.LoadingToBasket:{let i=c.action.loadToBasketId;if(i===void 0)break;let a=n.baskets.get(i),s=o.get(i)??0;o.set(i,s+1),r.push({fromX:t.right,fromY:t.top+t.height/2,toX:a===void 0?e.right-10:a.left+20,toY:a===void 0?t.top+t.height/2:a.top+50+20*s,curveDirection:-1});break}}return r.map(t=>({fromX:t.fromX-e.left,fromY:t.fromY-e.top,toX:t.toX-e.left,toY:t.toY-e.top,curveDirection:t.curveDirection}))}function U0(e){let t=e.getBoundingClientRect();return{left:t.left+window.scrollX,top:t.top+window.scrollY,width:t.width,height:t.height,bottom:t.bottom+window.scrollY,right:t.right+window.scrollX}}function W0(e){let t=(e.fromX+e.toX)/2,n=(e.fromY+e.toY)/2,r=Math.atan2(e.toY-e.fromY,e.toX-e.fromX)+Math.PI*e.curveDirection/2,i=t+50*Math.cos(r),a=n+50*Math.sin(r);return`M${e.fromX},${e.fromY} Q ${i} ${a} ${e.toX} ${e.toY}`}var G0=(0,I.memo)(function({container:e,arrowsWithRefs:t}){let[,n]=(0,I.useState)({height:window.innerHeight,width:window.innerWidth});return(0,I.useEffect)(()=>{function e(){n({height:window.innerHeight,width:window.innerWidth})}return window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[n]),(0,H.jsx)(`g`,{children:H0(e.current?U0(e.current):null,t.collectValues(e=>e.elem.current?{...e,elem:U0(e.elem.current)}:null)).map((e,t)=>(0,H.jsx)(`path`,{style:{fill:`none`,stroke:`rgba(0,0,0,0.15)`,strokeWidth:2},d:W0(e),markerEnd:`url(#arrow)`},t))})}),K0=(0,I.createContext)(void 0),q0=(0,I.memo)(function({children:e,hideArrows:t,whiteBackground:n}){let r=(0,I.useRef)(null),[i,a]=(0,I.useState)(gO.empty()),o=(0,I.useMemo)(()=>({registerNode(e,t,n){a(t&&n?r=>r.set(e,{...t,elem:n}):t=>t.delete(e))}}),[a]);return(0,H.jsxs)(`div`,{style:{position:`relative`},children:[(0,H.jsxs)(`svg`,{style:{position:`absolute`,pointerEvents:`none`,width:`100%`,height:`100%`,top:0,right:0,zIndex:-1,backgroundColor:n?`white`:`#F8F8F8`},children:[(0,H.jsx)(`defs`,{children:(0,H.jsx)(`marker`,{id:`arrow`,markerWidth:6,markerHeight:10,refX:`0`,refY:`3`,orient:`auto`,markerUnits:`strokeWidth`,children:(0,H.jsx)(`path`,{d:`M0,0 L0,6 L5,3 z`,fill:`rgba(0,0,0,0.15)`})})}),t?void 0:(0,H.jsx)(G0,{container:r,arrowsWithRefs:i})]}),(0,H.jsx)(`div`,{ref:r,children:(0,H.jsx)(K0.Provider,{value:o,children:e})})]})});function J0(e){let t=(0,I.useContext)(K0);if(!t)throw Error(`useMoveMaterialArrowRef must be used within a MoveMaterialArrowContainer`);let n=(0,I.useRef)(null);return(0,I.useEffect)(()=>{let r=z0(e);return t.registerNode(r,e,n),()=>{t.registerNode(r,null,null)}},[t,...B0(e)]),n}function Y0({kind:e,children:t}){return(0,H.jsx)(`div`,{ref:J0(e),"data-move-material-identifier":z0(e),children:t})}var X0=45,Z0=55;function Q0(){let e=L(GO),t=L(yO),n=L(yr),r=Q.of(e.material).filter(e=>e.location.type===ot.OnPallet||e.action.type===V.Loading).toRLookup(e=>e.location.palletNum??e.action.loadOntoPalletNum??0),i=Q.of(e.material).filter(e=>e.location.type===ot.InBasket&&e.location.basketId!==null&&e.location.basketId!==void 0||e.action.type===V.LoadingToBasket&&e.action.loadToBasketId!==null&&e.action.loadToBasketId!==void 0).toRLookup(e=>e.location.basketId??e.action.loadToBasketId??0),a=Q.ofObject(e.pallets).filter(([e,t])=>t.currentPalletLocation.loc===rt.LoadUnload).toOrderedMap(([e,t])=>[t.currentPalletLocation.num,{lulNum:t.currentPalletLocation.num,pal:{pallet:t,mats:r.get(t.palletNum)??[]},basket:null,staging:[],sources:[]}]),o=Q.ofObject(e.pallets).filter(([,e])=>e.currentPalletLocation.loc===rt.Machine||e.currentPalletLocation.loc===rt.MachineQueue).map(([e,t])=>t).groupBy(e=>e.currentPalletLocation.group,e=>e.currentPalletLocation.num).toLookupOrderedMap(([[e,t],n])=>e,([[e,t],n])=>t,([[t,n],i])=>{let a=i.find(e=>e.currentPalletLocation.loc===rt.Machine),o=a?r.get(a.palletNum)??[]:null,s=i.find(e=>e.currentPalletLocation.loc===rt.MachineQueue),c=s?r.get(s.palletNum)??[]:null,l=!0,u=c?.[0];if(u&&u.lastCompletedMachiningRouteStopIndex!==null&&u.lastCompletedMachiningRouteStopIndex!==void 0){let r=e.jobs[u.jobUnique]?.procsAndPaths?.[u.process-1]?.paths?.[u.path-1]?.stops?.[u.lastCompletedMachiningRouteStopIndex];r.stationGroup===t&&r.stationNums.includes(n)&&(l=!1)}return l?{name:t+` `+n.toString(),inbound:s?{pallet:s,mats:c??[]}:null,worktable:a?{pallet:a,mats:o??[]}:null,outbound:null}:{name:t+` `+n.toString(),inbound:null,worktable:a?{pallet:a,mats:o??[]}:null,outbound:s?{pallet:s,mats:c??[]}:null}}),s=Q.ofObject(e.pallets).filter(([e,t])=>t.currentPalletLocation.loc===rt.Buffer||t.currentPalletLocation.loc===rt.Cart).collect(([e,t])=>{let n=r.get(t.palletNum);return!n||n.length===0?null:{pallet:t,mats:n}}).toOrderedMap(e=>[e.pallet.palletNum,e]),c=1,l=1,u=tE(new Date,-7),d=t.valuesToLazySeq().filter(e=>e.routeEndUTC>u).concat(Q.ofObject(e.jobs).map(([e,t])=>t)).flatMap(e=>e.procsAndPaths).toRArray();for(let e of d)for(let t of(e.basketLoadStations??[]).concat(e.basketUnloadStations??[]))c=Math.max(c,t);let f=Q.of(d).flatMap(e=>e.paths);for(let e of f){for(let t of e.load.concat(e.unload))c=Math.max(c,t);e.face&&(l=Math.max(l,e.face));for(let t of e.stops)o=o.alter(t.stationGroup,e=>{e??=fO.empty();for(let n of t.stationNums)e=e.alter(n,e=>e||{name:t.stationGroup+` `+n.toString(),inbound:null,worktable:null,outbound:null});return e})}for(let e=1;e<=c;e++)a=a.alter(e,t=>t||{lulNum:e,pal:null,basket:null,staging:[],sources:[]});for(let t of Object.values(e.pallets))l=Math.max(l,t.numFaces);for(let t of e.material)t.location.face!==null&&t.location.face!==void 0&&(l=Math.max(l,t.location.face));let p=fO.empty();if(e.machineLocations&&e.machineLocations.length>0)for(let t of e.machineLocations){o=o.alter(t.machineGroup,e=>{if(!e||t.machineNum===void 0)return e;let n=e.delete(t.machineNum);if(n.size!==0)return n});for(let n of t.possibleLoadStations){let r;a=a.alter(n,e=>{r=e});let i=Q.of(r?.pal?.mats??[]).toLookup(n=>{if(n.action.type===V.Machining)return`Machining`;if(n.action.type!==V.Waiting)return`Loading`;if(n.lastCompletedMachiningRouteStopIndex!==null&&n.lastCompletedMachiningRouteStopIndex!==void 0){let r=e.jobs[n.jobUnique]?.procsAndPaths?.[n.process-1]?.paths?.[n.path-1]?.stops?.[n.lastCompletedMachiningRouteStopIndex];if(!r||r.stationGroup===t.machineGroup&&r.stationNums.includes(t.machineNum))return`Loading`}return`Ready`}),o={lulNum:n,machineMoving:t.moving,machineCurrentlyAtLoad:n===t.currentLoadStation?{group:t.machineGroup,num:t.machineNum}:null,readyMats:i.get(`Ready`)??[],machiningMats:i.get(`Machining`)??[],loadingMats:i.get(`Loading`)??[]};p=p.set(n,o)}}let m=new Map,h=new Map,g=new Map,_=0,v=0;for(let t of Q.ofObject(e.baskets??{}).map(([e,t])=>t).sortBy(e=>e.basketId)){let e={basket:t,mats:i.get(t.basketId)??[]};switch(t.position.location){case _t.Storage:e.mats.length>0?v+=1:_+=1;break;case _t.LoadUnload:case _t.LoadStationStaging:{let n=t.position.locationNum;if(n===null){g.set(t.basketId,e);break}let r=t.position.location===_t.LoadUnload?h:m,i=r.get(n)??[];i.push(e),r.set(n,i);break}case _t.InTransit:g.set(t.basketId,e);break}}let y=0,b=0;return a=a.mapValues(e=>{let t=new Map,r=Q.of(e.pal?.mats??e.basket?.mats??[]).filter(e=>e.location.type!==ot.OnPallet).toRArray();for(let e of r){if(e.location.type===ot.Free){let n=`free`,r=t.get(n)??{label:`To Load`,mats:[]};r.mats.push(e),t.set(n,r);continue}if(e.action.loadFromBasketId!==null&&e.action.loadFromBasketId!==void 0){let r=`basket:${e.action.loadFromBasketId}`,i=t.get(r)??{label:`From ${Dk(n.basketName)} ${e.action.loadFromBasketId}`,mats:[]};i.mats.push(e),t.set(r,i);continue}if(e.location.type===ot.InQueue&&e.location.currentQueue){let n=`queue:${e.location.currentQueue}`,r=t.get(n)??{label:`From ${e.location.currentQueue}`,mats:[]};r.mats.push(e),t.set(n,r)}}let i=Q.of(h.get(e.lulNum)??[]).sortBy(e=>e.basket.position.locationNum).toRArray();for(let e of i.slice(1))g.set(e.basket.basketId,e);let a=new Set(Q.of(e.pal?.mats??[]).collect(e=>e.action.loadFromBasketId??null).toRArray()),o=Q.of(m.get(e.lulNum)??[]).filter(e=>!a.has(e.basket.basketId)).sortBy(e=>e.basket.position.locationNum).toRArray();y=Math.max(y,o.length);let s=Q.of(t).map(([e,t])=>({key:e,label:t.label,mats:t.mats})).sortBy(e=>e.label).toRArray();return b=Math.max(b,s.length),{...e,basket:i[0]??null,staging:o,sources:s}}),{machines:o.mapValues(e=>e.valuesToAscLazySeq().toRArray()),loads:a.valuesToAscLazySeq().toRArray(),stockerPals:s.valuesToAscLazySeq().toRArray(),floatingBaskets:Q.of(g.values()).toRArray(),storageBaskets:_+v>0?{empty:_,filled:v}:null,machineAtLoad:p.valuesToAscLazySeq().toRArray(),maxNumFacesOnPallet:l,maxNumStagingRows:y,maxNumSourceRows:b}}function $0({mats:e}){let[t,n]=(0,I.useState)(!1),r=(0,I.useRef)(null),i=(0,I.useRef)(null),[a,o]=(0,I.useState)(!1),s=R(bI),c=L(GO);function l(){r.current!==null&&(clearTimeout(r.current),r.current=null),n(!0)}function u(){r.current=setTimeout(()=>{n(!1),r.current=null},200)}function d(){e.length===1?s({type:`MatDetails`,details:e[0]}):o(!0)}function f(e,t){return t==null?null:(e!=null&&e!=null?c.pallets[e]?.faceNames?.[t-1]:null)??`Face: `+t.toString()}return(0,H.jsxs)(J,{sx:{width:X0,height:X0,overflow:`visible`},children:[(0,H.jsx)(Hp,{elevation:4,onPointerEnter:l,onPointerLeave:u,sx:{position:`relative`,zIndex:t?10:0,width:`max-content`,height:`max-content`},children:(0,H.jsx)(mv,{badgeContent:e.length>1?e.length:0,color:`secondary`,children:(0,H.jsx)(gm,{focusRipple:!0,onClick:d,ref:i,children:(0,H.jsx)(Rp,{orientation:`horizontal`,in:t,collapsedSize:X0,children:(0,H.jsxs)(J,{sx:{display:`flex`},children:[(0,H.jsx)(LU,{part:e[0].partName,size:X0}),(0,H.jsx)(J,{sx:{marginLeft:`10px`,marginRight:`10px`,whiteSpace:`nowrap`,textAlign:`left`},children:(0,H.jsx)(Rp,{in:t,collapsedSize:X0,children:(0,H.jsxs)(MS,{direction:`column`,sx:{marginBottom:`0.2em`},children:[(0,H.jsxs)(q,{variant:`h6`,children:[e[0].partName,`-`,e[0].process]}),(0,H.jsx)(`div`,{children:(0,H.jsx)(`small`,{children:f(e[0].location.palletNum,e[0].location.face)??f(e[0].action.loadOntoPalletNum,e[0].action.loadOntoFace)})}),Q.of(e).collect(e=>e.serial?(0,H.jsx)(`div`,{children:(0,H.jsxs)(`small`,{children:[`Serial: `,e.serial]})},e.materialID):void 0),(0,H.jsx)(`div`,{children:(0,H.jsx)(GU,{mat:e[0]})})]})})})]})})})})}),(0,H.jsx)(bx,{anchorEl:i.current,open:a,onClose:()=>o(!1),anchorOrigin:{vertical:`top`,horizontal:`left`},children:Q.of(e).map((e,t)=>(0,H.jsx)(wx,{onClick:()=>{o(!1),s({type:`MatDetails`,details:e})},children:e.serial&&e.serial!==``?e.serial:(t+1).toString()},e.materialID))})]})}function e2({maxNumFaces:e,mats:t,loadingOntoPallet:n,noFilter:r,showExpanded:i}){if(i&&e===1)return(0,H.jsx)(J,{sx:{display:`flex`,flexDirection:`column`,flexWrap:`wrap`},children:t.map(e=>(0,H.jsx)(QU,{mat:e},e.materialID))});{let i=n?Q.of(t).filter(e=>r||e.location.type!==ot.OnPallet).orderedGroupBy(e=>e.action.loadOntoFace??1):Q.of(t).filter(e=>r||e.location.type===ot.OnPallet).orderedGroupBy(e=>e.action.type===V.Loading?e.action.loadOntoFace??1:e.location.face??1);return(0,H.jsx)(J,{sx:{display:`grid`,gridTemplateRows:`${X0}px`,gridTemplateColumns:`repeat(${e}, ${X0}px)`,columnGap:`5px`,height:`100%`,alignContent:`center`,justifyContent:`center`},children:i.map(([e,t])=>(0,H.jsx)(J,{sx:{gridColumn:e,gridRow:1},children:(0,H.jsx)($0,{mats:t})},e))})}}function t2({mats:e}){let t=Q.of(e).orderedGroupBy(e=>e.location.basketSlot??0);return(0,H.jsx)(J,{sx:{display:`flex`,flexWrap:`wrap`,justifyContent:`flex-start`,alignItems:`flex-start`,gap:`5px`,minHeight:`${X0}px`,paddingLeft:`5px`,paddingRight:`5px`,height:`100%`,alignContent:`center`},children:t.map(([e,t])=>(0,H.jsx)(J,{children:(0,H.jsx)($0,{mats:t})},e))})}function n2({mats:e,maxNumFaces:t}){return(0,H.jsx)(J,{sx:{minHeight:`${Z0}px`,display:`flex`,alignItems:`center`,justifyContent:`flex-start`,paddingLeft:`5px`,gap:`5px`,paddingRight:`5px`},children:(0,H.jsx)(e2,{mats:e,maxNumFaces:t,loadingOntoPallet:!0})})}function r2(e,t){let n=X0*e+5*(e+1);return t?`60px ${Math.max(n,100)}px`:`${Math.max(n,100)}px`}function i2(e){e=Math.round(e);let t=Math.abs(e)%60,n=Math.floor(Math.abs(e)/60),r=n%60,i=Math.floor(n/60);return i>0?`${e<0?`-`:``}${i}:${r.toString().padStart(2,`0`)}:${t.toString().padStart(2,`0`)}`:`${e<0?`-`:``}${r}:${t.toString().padStart(2,`0`)}`}function a2(e){let t=e?.find(e=>e.action.type===V.Machining),n=t?.action?.elapsedMachiningTime,r=t?.action.expectedRemainingMachiningTime,i=L(GO).timeOfCurrentStatusUTC,a=L(KO),o=null;r&&(o=tk(r)-(a-Math.floor(i.getTime()/1e3)));let s=null;return n&&(s=tk(n)+(a-Math.floor(i.getTime()/1e3))),o!==null&&s!==null?[!0,`${i2(s)} / ${i2(o)}`,o<0?-1:s/(s+o)*100]:o===null?s===null?[!!t,`Idle`,null]:[!0,i2(s),null]:[!0,` / `+i2(o),o<0?-1:null]}function o2({machine:e}){let[t,n,r]=a2(e.worktable?.mats);return(0,H.jsxs)(`div`,{children:[(0,H.jsx)(q,{variant:`h5`,children:e.name}),(0,H.jsx)(q,{variant:`subtitle1`,children:n}),t?r===null?(0,H.jsx)(tb,{}):r<0?(0,H.jsx)(tb,{color:`error`}):(0,H.jsx)(tb,{variant:`determinate`,value:r}):void 0]})}function s2({maxNumFaces:e,machine:t}){return(0,H.jsxs)(J,{sx:{display:`grid`,border:`1px solid black`,margin:`5px`,gridTemplateRows:`auto ${Z0}px ${Z0}px ${Z0}px`,gridTemplateColumns:r2(e,!0),gridTemplateAreas:`"machname machname" "inboundpal inboundmat" "worktablepal worktablemat" "outboundpal outboundmat"`},children:[(0,H.jsx)(J,{sx:{gridArea:`machname`,padding:`0.2em`,borderBottom:`1px solid black`},children:(0,H.jsx)(o2,{machine:t})}),(0,H.jsx)(J,{sx:{gridArea:`inboundpal`,borderRight:`1px solid black`,borderBottom:`1px solid black`,padding:`2px`},children:(0,H.jsxs)(MS,{children:[(0,H.jsx)(q,{variant:`body1`,sx:{textAlign:`center`},children:`In`}),t.inbound?(0,H.jsx)(q,{variant:`h6`,sx:{textAlign:`center`},children:t.inbound.pallet.palletNum}):void 0]})}),(0,H.jsx)(J,{sx:{gridArea:`inboundmat`,borderBottom:`1px solid black`},children:t.inbound?(0,H.jsx)(e2,{mats:t.inbound.mats,maxNumFaces:e}):void 0}),(0,H.jsx)(J,{sx:{gridArea:`worktablepal`,borderRight:`1px solid black`,borderBottom:`1px solid black`,padding:`2px`},children:(0,H.jsxs)(MS,{children:[(0,H.jsx)(q,{variant:`body1`,sx:{textAlign:`center`},children:`Work`}),t.worktable?(0,H.jsx)(q,{variant:`h6`,sx:{textAlign:`center`},children:t.worktable.pallet.palletNum}):void 0]})}),(0,H.jsx)(J,{sx:{gridArea:`worktablemat`,borderBottom:`1px solid black`},children:t.worktable?(0,H.jsx)(e2,{mats:t.worktable.mats,maxNumFaces:e}):void 0}),(0,H.jsx)(J,{sx:{gridArea:`outboundpal`,borderRight:`1px solid black`,padding:`2px`},children:(0,H.jsxs)(MS,{children:[(0,H.jsx)(q,{variant:`body1`,sx:{textAlign:`center`},children:`Out`}),t.outbound?(0,H.jsx)(q,{variant:`h6`,sx:{textAlign:`center`},children:t.outbound.pallet.palletNum}):void 0]})}),(0,H.jsx)(J,{sx:{gridArea:`outboundmat`},children:t.outbound?(0,H.jsx)(e2,{mats:t.outbound.mats,maxNumFaces:e}):void 0})]})}function c2(e){let t=(e?.find(e=>e.action.type===V.Loading||e.action.type===V.LoadingToBasket||e.action.type===V.UnloadToCompletedMaterial||e.action.type===V.UnloadToInProcess))?.action?.elapsedLoadUnloadTime,n=L(GO).timeOfCurrentStatusUTC,r=L(KO),i=null;return t&&(i=tk(t)+(r-Math.floor(n.getTime()/1e3))),i===null?`Idle`:i2(i)}function l2({load:e}){let t=c2(e.pal?.mats??e.basket?.mats),n=L(yr);return(0,H.jsxs)(J,{sx:{display:`flex`,justifyContent:`space-between`,alignItems:`baseline`},children:[(0,H.jsx)(q,{variant:`h5`,children:Tk(e.lulNum,n.loadStationNames)}),(0,H.jsx)(q,{variant:`body1`,children:t})]})}function u2({maxNumFaces:e,maxNumStagingRows:t,maxNumSourceRows:n,load:r}){let i=Dk(L(yr).basketName),a=r.pal?`Pallet`:r.basket?i:null,o=r.pal?r.pal.pallet.palletNum.toString():r.basket?r.basket.basket.basketId.toString():null,s=Math.max(1,n),c=Math.max(1,t),l=Array.from({length:s},(e,t)=>`"source${t} sourcemat${t}"`),u=Array.from({length:c},(e,t)=>`"stage${t} stagemat${t}"`),d=[`"lulname lulname"`,...l,`"current currentmat"`,...u].join(` `);return(0,H.jsxs)(J,{sx:{display:`grid`,border:`1px solid black`,margin:`5px`,gridTemplateRows:`auto repeat(${s+1+c}, ${Z0}px)`,gridTemplateColumns:r2(e,!0),gridTemplateAreas:d},children:[(0,H.jsx)(J,{sx:{gridArea:`lulname`,padding:`0.2em`,borderBottom:`1px solid black`},children:(0,H.jsx)(l2,{load:r})}),Array.from({length:s},(t,n)=>{let i=r.sources[n]??null;return(0,H.jsxs)(I.Fragment,{children:[(0,H.jsx)(J,{sx:{gridArea:`source${n}`,borderRight:`1px solid black`,borderBottom:`1px solid black`,padding:`2px`,display:`flex`,alignItems:`center`,justifyContent:`center`},children:i?(0,H.jsx)(q,{variant:`body2`,sx:{textAlign:`center`},children:i.label}):void 0}),(0,H.jsx)(J,{sx:{gridArea:`sourcemat${n}`,borderBottom:`1px solid black`,display:`flex`,flexDirection:`column`,justifyContent:`center`},children:i?(0,H.jsx)(n2,{mats:i.mats,maxNumFaces:e}):void 0})]},`source-${n}`)}),(0,H.jsx)(J,{sx:{gridArea:`current`,borderRight:`1px solid black`,borderBottom:`1px solid black`,padding:`2px`,display:`flex`,alignItems:`center`,justifyContent:`center`},children:(0,H.jsxs)(MS,{children:[a?(0,H.jsx)(q,{variant:`body1`,sx:{textAlign:`center`},children:a}):void 0,o?(0,H.jsx)(q,{variant:`h6`,sx:{textAlign:`center`},children:o}):void 0]})}),(0,H.jsxs)(J,{sx:{gridArea:`currentmat`,display:`flex`,flexDirection:`column`,justifyContent:`center`,borderBottom:`1px solid black`},children:[r.pal?(0,H.jsx)(e2,{mats:r.pal.mats,maxNumFaces:e}):void 0,!r.pal&&r.basket?(0,H.jsx)(t2,{mats:r.basket.mats}):void 0]}),Array.from({length:c},(e,t)=>{let n=r.staging[t]??null,a=t===c-1;return(0,H.jsxs)(I.Fragment,{children:[(0,H.jsx)(J,{sx:{gridArea:`stage${t}`,borderRight:`1px solid black`,...a?{}:{borderBottom:`1px solid black`},padding:`2px`,display:`flex`,alignItems:`center`,justifyContent:`center`},children:n?(0,H.jsxs)(q,{variant:`body2`,sx:{textAlign:`center`},children:[`Staging `,i,` `,n.basket.basketId]}):void 0}),(0,H.jsx)(J,{sx:{gridArea:`stagemat${t}`,...a?{}:{borderBottom:`1px solid black`},display:`flex`,flexDirection:`column`,justifyContent:`center`},children:n?(0,H.jsx)(t2,{mats:n.mats}):void 0})]},`stage-${t}`)})]})}function d2({status:e}){let t=c2(e.loadingMats),[n,r,i]=a2(e.machiningMats);return(0,H.jsxs)(`div`,{children:[(0,H.jsxs)(q,{variant:`h5`,children:[`Station `,e.lulNum]}),e.machineCurrentlyAtLoad?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(q,{variant:`h5`,children:[e.machineCurrentlyAtLoad.group,` `,e.machineCurrentlyAtLoad.num]}),(0,H.jsx)(q,{variant:`subtitle1`,children:r===`Idle`?t:r}),n?i===null?(0,H.jsx)(tb,{}):i<0?(0,H.jsx)(tb,{color:`error`}):(0,H.jsx)(tb,{variant:`determinate`,value:i}):void 0]}):(0,H.jsxs)(H.Fragment,{children:[e.machineMoving?(0,H.jsx)(q,{variant:`subtitle2`,children:`Machine Moving`}):void 0,(0,H.jsxs)(q,{variant:`subtitle1`,children:[`Loading `,t]})]})]})}function f2({maxNumFaces:e,status:t}){return(0,H.jsxs)(J,{sx:{display:`grid`,border:`1px solid black`,margin:`5px`,gridTemplateRows:`minmax(104px, max-content) repeat(3, ${e>1?Z0.toString()+`px`:`minmax(110px, max-content)`})`,gridTemplateColumns:e===1?`60px minmax(230px, max-content)`:r2(e,!0),gridTemplateAreas:`"name name" "ready readymat" "machining machiningmat" "loadstation loadstationmat"`},children:[(0,H.jsx)(J,{sx:{gridArea:`name`,padding:`0.2em`,borderBottom:`1px solid black`},children:(0,H.jsx)(d2,{status:t})}),(0,H.jsx)(J,{sx:{gridArea:`ready`,borderRight:`1px solid black`,borderBottom:`1px solid black`,padding:`2px`},children:(0,H.jsx)(q,{variant:`body1`,sx:{textAlign:`center`},children:`Ready`})}),(0,H.jsx)(J,{sx:{gridArea:`readymat`,borderBottom:`1px solid black`,display:`flex`,flexDirection:`column`,justifyContent:`center`},children:(0,H.jsx)(e2,{mats:t.readyMats,maxNumFaces:e,showExpanded:!0})}),(0,H.jsx)(J,{sx:{gridArea:`machining`,borderRight:`1px solid black`,borderBottom:`1px solid black`,padding:`2px`},children:(0,H.jsx)(q,{variant:`body1`,sx:{textAlign:`center`},children:`Work`})}),(0,H.jsx)(J,{sx:{gridArea:`machiningmat`,borderBottom:`1px solid black`,display:`flex`,flexDirection:`column`,justifyContent:`center`},children:(0,H.jsx)(e2,{mats:t.machiningMats,maxNumFaces:e,showExpanded:!0})}),(0,H.jsx)(J,{sx:{gridArea:`loadstation`,borderRight:`1px solid black`,padding:`2px`},children:(0,H.jsxs)(MS,{children:[(0,H.jsx)(q,{variant:`body1`,sx:{textAlign:`center`},children:`Load`}),(0,H.jsx)(q,{variant:`body1`,sx:{textAlign:`center`},children:`Station`})]})}),(0,H.jsx)(J,{sx:{gridArea:`loadstationmat`,display:`flex`,flexDirection:`column`,justifyContent:`center`},children:(0,H.jsx)(e2,{mats:t.loadingMats,maxNumFaces:e,showExpanded:!0,noFilter:!0})})]})}function p2({maxNumFaces:e,pallet:t}){return(0,H.jsxs)(J,{sx:{display:`grid`,border:`1px solid black`,margin:`5px`,gridTemplateRows:`auto ${Z0}px`,gridTemplateColumns:r2(e,!1),gridTemplateAreas:`"palname" "palmat"`},children:[(0,H.jsxs)(q,{variant:`h5`,sx:{gridArea:`palname`,padding:`0.2em`,borderBottom:`1px solid black`},children:[`Pallet `,t.pallet.palletNum]}),(0,H.jsx)(J,{sx:{gridArea:`palmat`},children:(0,H.jsx)(e2,{mats:t.mats,maxNumFaces:e})})]})}function m2({basket:e}){let t=Dk(L(yr).basketName);return(0,H.jsxs)(J,{sx:{display:`grid`,border:`1px solid black`,margin:`5px`,gridTemplateRows:`auto ${Z0}px`,gridTemplateColumns:`minmax(120px, max-content)`,gridTemplateAreas:`"basketname" "basketmat"`},children:[(0,H.jsxs)(q,{variant:`h5`,sx:{gridArea:`basketname`,padding:`0.2em`,borderBottom:`1px solid black`},children:[t,` `,e.basket.basketId]}),(0,H.jsx)(J,{sx:{gridArea:`basketmat`},children:(0,H.jsx)(t2,{mats:e.mats})})]})}function h2({empty:e,filled:t}){return(0,H.jsxs)(J,{sx:{display:`grid`,border:`1px solid black`,margin:`5px`,padding:`0.5em 1em`,alignContent:`center`,minWidth:`170px`},children:[(0,H.jsxs)(q,{variant:`h5`,children:[Dk(L(yr).basketName),` Storage`]}),(0,H.jsxs)(q,{variant:`body1`,children:[`Empty: `,e]}),(0,H.jsxs)(q,{variant:`body1`,children:[`Filled: `,t]})]})}var g2=(0,I.memo)(function({overview:e}){return(0,H.jsxs)(`div`,{children:[e.machines.toAscLazySeq().map(([t,n])=>(0,H.jsx)(J,{sx:{display:`flex`,flexWrap:`wrap`,justifyContent:`space-evenly`},children:n.map(t=>(0,H.jsx)(s2,{machine:t,maxNumFaces:e.maxNumFacesOnPallet},t.name))},t)),e.loads.length>0?(0,H.jsx)(J,{sx:{display:`flex`,flexWrap:`wrap`,justifyContent:`space-evenly`},children:e.loads.map(t=>(0,H.jsx)(u2,{load:t,maxNumFaces:e.maxNumFacesOnPallet,maxNumStagingRows:e.maxNumStagingRows,maxNumSourceRows:e.maxNumSourceRows},t.lulNum))}):void 0,e.machineAtLoad.length>0?(0,H.jsx)(J,{sx:{display:`flex`,flexWrap:`wrap`,justifyContent:`space-evenly`},children:e.machineAtLoad.map(t=>(0,H.jsx)(f2,{status:t,maxNumFaces:e.maxNumFacesOnPallet},t.lulNum))}):void 0,e.stockerPals.length>0||e.floatingBaskets.length>0||e.storageBaskets?(0,H.jsxs)(J,{sx:{display:`flex`,flexWrap:`wrap`,justifyContent:`space-evenly`},children:[e.stockerPals.map(t=>(0,H.jsx)(p2,{pallet:t,maxNumFaces:e.maxNumFacesOnPallet},t.pallet.palletNum)),e.floatingBaskets.map(e=>(0,H.jsx)(m2,{basket:e},e.basket.basketId)),e.storageBaskets?(0,H.jsx)(h2,{empty:e.storageBaskets.empty,filled:e.storageBaskets.filled}):void 0]}):void 0]})}),_2=(0,I.memo)(function({ignoreOperator:e}){let[t,n]=(0,I.useState)(null),[r,i]=(0,I.useState)(null);function a(){n(null),i(null)}return(0,H.jsx)(dW,{onClose:a,allowNote:!0,highlightProcsGreaterOrEqualTo:r?.process??void 0,extraDialogElements:(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(JY,{st:t,setState:n}),r===null?null:(0,H.jsx)(WY,{st:r,setState:i})]}),buttons:(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(HY,{ignoreOperator:e}),(0,H.jsx)(I0,{}),(0,H.jsx)(YY,{st:t,setState:n,onClose:a,ignoreOperator:e}),(0,H.jsx)(GY,{st:r,setState:i,onClose:a,ignoreOperator:e})]})})});function v2({ignoreOperator:e,whiteBackground:t}){GI(`System Overview`);let n=Q0();return(0,H.jsxs)(`main`,{style:{padding:`10px`,minHeight:`calc(100vh - 64px)`,backgroundColor:t?`white`:`#F8F8F8`},children:[(0,H.jsx)(g2,{overview:n}),(0,H.jsx)(_2,{ignoreOperator:e}),(0,H.jsx)(L0,{})]})}var y2=30;function b2({machine:e}){let t=Dd(),[,,n]=a2(e.worktable?.mats);return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`rect`,{x:3,y:3,width:24,height:24,stroke:`black`}),`;`,(0,H.jsx)(`rect`,{x:3,y:3,width:24,height:8,fill:e.inbound===null?`white`:t.palette.secondary.main}),(0,H.jsx)(`rect`,{x:3,y:11,width:24,height:8,fill:e.worktable===null?`white`:n!=null&&n<0?t.palette.error.main:t.palette.secondary.main}),(0,H.jsx)(`rect`,{x:3,y:19,width:24,height:8,fill:e.outbound===null?`white`:t.palette.secondary.main})]})}function x2({load:e}){let t=Dd();return(0,H.jsx)(`polygon`,{points:`3,27 27,27 15,3`,fill:e.pal===null&&e.basket===null&&e.staging.length===0?`white`:t.palette.secondary.main,stroke:`black`})}function S2({status:e}){let t=Dd(),[,,n]=a2(e.machiningMats);return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`rect`,{x:3,y:3,width:24,height:24,stroke:`black`}),`;`,(0,H.jsx)(`rect`,{x:3,y:3,width:24,height:8,fill:e.readyMats.length===0?`white`:t.palette.secondary.main}),(0,H.jsx)(`rect`,{x:3,y:11,width:24,height:8,fill:e.machiningMats.length===0?`white`:n!=null&&n<0?t.palette.error.main:t.palette.secondary.main}),(0,H.jsx)(`rect`,{x:3,y:19,width:24,height:8,fill:e.loadingMats.length===0?`white`:t.palette.secondary.main})]})}var C2=(0,I.memo)(function({overview:e}){let t=e.machines.toAscLazySeq().sumBy(([,e])=>e.length);return(0,H.jsx)(J,{sx:{height:`1.5em`,"&:hover":{backgroundColor:`primary.light`}},children:(0,H.jsxs)(`svg`,{viewBox:`0 0 ${(t+e.loads.length+e.machineAtLoad.length)*y2} ${y2}`,preserveAspectRatio:`none`,width:`140px`,height:`1.5em`,children:[(0,H.jsx)(`g`,{children:e.machines.toAscLazySeq().flatMap(([,e])=>e).map((e,t)=>(0,H.jsx)(`g`,{transform:`translate(${t*y2})`,children:(0,H.jsx)(b2,{machine:e})},e.name))}),(0,H.jsx)(`g`,{transform:`translate(${t*y2})`,children:e.loads.map((e,t)=>(0,H.jsx)(`g`,{transform:`translate(${t*y2})`,children:(0,H.jsx)(x2,{load:e})},e.lulNum))}),(0,H.jsx)(`g`,{transform:`translate(${(t+e.loads.length)*y2})`,children:e.machineAtLoad.map((e,t)=>(0,H.jsx)(`g`,{transform:`translate(${t*y2})`,children:(0,H.jsx)(S2,{status:e})},e.lulNum))})]})})}),w2=(0,I.memo)(function({full:e}){let[t,n]=(0,I.useState)(!1),r=Q0();return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(Y,{onClick:()=>n(!0),children:(0,H.jsx)(C2,{overview:r})}),(0,H.jsxs)(ky,{open:t,onClose:()=>n(!1),maxWidth:`xl`,fullScreen:e,children:[e?(0,H.jsx)(ph,{sx:{position:`relative`},children:(0,H.jsxs)(rw,{children:[(0,H.jsx)(Gm,{edge:`start`,color:`inherit`,onClick:()=>n(!1),"aria-label":`close`,children:(0,H.jsx)(pT,{})}),(0,H.jsx)(q,{sx:{ml:2,flex:1},variant:`h6`,component:`div`,children:`System Overview`})]})}):void 0,(0,H.jsx)(jy,{children:(0,H.jsx)(J,{sx:{paddingBottom:`2em`,paddingLeft:`5em`,paddingRight:`5em`},children:(0,H.jsx)(g2,{overview:r})})})]})]})});function T2(e){return Number.isInteger(e)&&(e??0)>0}function E2(e){return typeof e==`string`&&e.trim()!==``}function D2(e,t){if(e.location.type===ot.InBasket&&e.location.basketId===t&&(e.action.type===V.UnloadToInProcess||e.action.type===V.UnloadToCompletedMaterial))return T2(e.location.basketSlot)?{type:`valid`,workId:e.action.workId}:{type:`invalid`};if(e.action.type===V.LoadingToBasket){if(!T2(e.action.loadToBasketId))return{type:`invalid`};if(e.action.loadToBasketId!==t)return;let n=e.location.type===ot.InBasket&&e.location.basketId===t&&e.location.basketSlot===e.action.loadToBasketSlot;return!T2(e.action.loadToBasketSlot)||!n&&e.location.type!==ot.Free&&(e.location.type!==ot.InQueue||!E2(e.location.currentQueue))?{type:`invalid`}:{type:`valid`,workId:e.action.workId}}}function O2(e,t){let n=Q.of(e).collect(e=>D2(e,t)).toRArray();if(n.some(e=>e.type===`invalid`))return{type:`inconsistent`};let r=n.filter(e=>e.type===`valid`);if(r.length===0)return{type:`none`};let i=r.filter(e=>E2(e.workId)),a=Q.of(i).toHashSet(({workId:e})=>e);return i.length!==r.length||a.size!==1?{type:`inconsistent`}:{type:`confirmable`,work:{workId:i[0].workId}}}function k2(e){return e.location.type===ot.InBasket&&e.location.basketId===e.action.loadToBasketId&&e.location.basketSlot===e.action.loadToBasketSlot?`Unload, re-plate, and reload this slot`:e.location.type===ot.InQueue&&e.location.currentQueue?`Load from ${e.location.currentQueue}`:`Load from raw material`}function A2({material:e,fsize:t}){return e.map(e=>(0,H.jsx)(Y0,{kind:{type:R0.Material,material:e},children:(0,H.jsx)(QU,{mat:e,fsize:t})},e.materialID))}function j2({stationNumber:e,basket:t,material:n,fsize:r,submitCommand:i}){let[a,o]=(0,I.useState)(`idle`),s=(0,I.useMemo)(()=>O2(n,t.basketId),[t.basketId,n]),c=s.type===`confirmable`?s.work:void 0;(0,I.useEffect)(()=>o(`idle`),[c?.workId]);let l=(0,I.useMemo)(()=>Q.of(n).filter(e=>e.location.type===ot.InBasket&&e.location.basketId===t.basketId&&e.location.basketSlot!==void 0).groupBy(e=>e.location.basketSlot??0).toHashMap(e=>e),[t.basketId,n]),u=(0,I.useMemo)(()=>Q.of(n).filter(e=>e.action.type===V.LoadingToBasket&&e.action.loadToBasketId===t.basketId&&e.action.loadToBasketSlot!==void 0).groupBy(e=>e.action.loadToBasketSlot??0).toHashMap(e=>e),[t.basketId,n]),d=(0,I.useMemo)(()=>Q.of(t.emptySlots??[]).concat(t.unknownSlots??[]).concat(l.keysToLazySeq()).concat(u.keysToLazySeq()).distinctBy(e=>e).toSortedArray(e=>e),[t.emptySlots,t.unknownSlots,l,u]);async function f(){if(!(c===void 0||i===void 0)){o(`submitting`);try{o(await i(e,{workId:c.workId}))}catch{o(`error`)}}}let p=a===`submitting`||a===`accepted`||a===`conflict`;return(0,H.jsxs)(MS,{spacing:2,sx:{mt:2},children:[(0,H.jsx)(q,{variant:`h6`,children:`Basket slots`}),(0,H.jsx)(J,{sx:{display:`grid`,gridTemplateColumns:`repeat(auto-fit, minmax(15em, 1fr))`,gap:2},children:d.map(e=>{let n=l.get(e)??[],i=u.get(e)??[],a=t.unknownSlots?.includes(e)===!0;return(0,H.jsx)(Av,{"data-testid":`basket-load-station-slot-${e}`,variant:`outlined`,children:(0,H.jsxs)(Pv,{children:[(0,H.jsxs)(q,{variant:`h6`,children:[`Slot `,e]}),n.length>0?(0,H.jsx)(A2,{material:n,fsize:r}):(0,H.jsx)(q,{color:a?`warning.main`:`text.secondary`,children:a?`Unknown`:`Empty`}),i.map((e,t)=>(0,H.jsxs)(J,{sx:{mt:1},children:[(0,H.jsx)(q,{children:k2(e)}),(0,H.jsxs)(q,{variant:`body2`,color:`text.secondary`,children:[e.partName,` · Process `,e.action.processAfterLoad??e.process]})]},`${e.jobUnique}-${e.process}-${t}`))]})},e)})}),c&&i?(0,H.jsx)(J,{sx:{display:`flex`,justifyContent:`flex-end`},children:(0,H.jsx)(Y,{variant:`contained`,disabled:p,onClick:()=>void f(),children:`Confirm`})}):c?(0,H.jsx)(rh,{severity:`warning`,children:`Basket work confirmation is not configured.`}):s.type===`inconsistent`?(0,H.jsx)(rh,{severity:`warning`,children:`Basket work is inconsistent. Wait for refreshed material actions before confirming.`}):null,a===`accepted`?(0,H.jsx)(rh,{severity:`success`,children:`Confirmation accepted. Waiting for refreshed work.`}):a===`conflict`?(0,H.jsx)(rh,{severity:`warning`,children:`Basket work changed before confirmation. Review the refreshed slots and try again.`}):a===`error`?(0,H.jsx)(rh,{severity:`error`,children:`Unable to confirm basket work. No work was assumed complete.`}):null]})}function M2(e){return encodeURIComponent(e.toString())}function N2(e){switch(e.kind){case`queue`:return`load-station-queue-${M2(e.label)}`;case`baskets`:return`load-station-baskets`;case`free`:return`load-station-material`}}function P2(e,t,n){switch(e.action.type){case V.Loading:return t!==void 0&&e.action.loadOntoPalletNum===t.palletNum||n!==void 0&&e.action.loadFromBasketId===n.basketId;case V.LoadingToBasket:return n!==void 0&&e.action.loadToBasketId===n.basketId;default:return!1}}function F2(e,t,n,r){let i,a,o=new Set;if(e>=0){for(let t of Object.values(n.pallets))if(t.currentPalletLocation.loc===rt.LoadUnload&&t.currentPalletLocation.num===e){i=t;break}for(let t of Object.values(n.baskets??{}))t.position.locationNum===e&&(t.position.location===_t.LoadUnload?a=t:t.position.location===_t.LoadStationStaging&&o.add(t.basketId))}let s=new Set(t);if(i!==void 0)for(let e of n.material)e.action.type===V.Loading&&e.action.loadOntoPalletNum===i.palletNum&&e.location.type===ot.InQueue&&e.location.currentQueue&&s.add(e.location.currentQueue),e.action.type===V.Loading&&e.action.loadOntoPalletNum===i.palletNum&&e.action.loadFromBasketId&&o.add(e.action.loadFromBasketId),(e.action.type===V.UnloadToInProcess||e.action.type===V.UnloadToCompletedMaterial)&&e.action.unloadToBasketId&&e.location.type===ot.OnPallet&&e.location.palletNum===i.palletNum&&o.add(e.action.unloadToBasketId),(e.action.type===V.UnloadToInProcess||e.action.type===V.UnloadToCompletedMaterial)&&e.action.unloadIntoQueue&&e.location.type===ot.OnPallet&&e.location.palletNum===i.palletNum&&s.add(e.action.unloadIntoQueue);else if(a!==void 0)for(let e of n.material)e.location.type===ot.InBasket&&e.location.basketId===a.basketId&&(e.action.type===V.UnloadToInProcess||e.action.type===V.UnloadToCompletedMaterial)&&e.action.unloadIntoQueue&&s.add(e.action.unloadIntoQueue),e.location.type===ot.InQueue&&e.location.currentQueue&&P2(e,void 0,a)&&s.add(e.location.currentQueue);let c=new Map(Q.of(s).map(e=>[e,{mats:[],hiddenCnt:0}])),l=new Map(Q.of(o).map(e=>[e,{mats:[],hiddenCnt:0}])),u=[],d=fO.empty(),f=null;if(i)for(let e=1;e<=i.numFaces;e++)d=d.set(e,[]);else a&&(d=d.set(1,[]));for(let e of n.material){if(i?(e.action.type===V.Loading&&e.action.loadOntoPalletNum===i.palletNum&&(e.action.elapsedLoadUnloadTime&&(f=e.action.elapsedLoadUnloadTime),e.action.loadOntoFace&&!d.has(e.action.loadOntoFace)&&(d=d.set(e.action.loadOntoFace,[])),e.location.type===ot.Free&&u.push(e)),e.location.type===ot.OnPallet&&e.location.palletNum===i.palletNum&&((e.action.type===V.UnloadToCompletedMaterial||e.action.type===V.UnloadToInProcess)&&e.action.elapsedLoadUnloadTime&&(f=e.action.elapsedLoadUnloadTime),d=d.alter(e.location.face??1,t=>t?(t.push(e),t):[e]))):a&&(P2(e,i,a)&&e.action.elapsedLoadUnloadTime&&(f=e.action.elapsedLoadUnloadTime),e.action.type===V.LoadingToBasket&&e.action.loadToBasketId===a.basketId&&e.location.type===ot.Free&&u.push(e),e.location.type===ot.InBasket&&e.location.basketId===a.basketId&&((e.action.type===V.UnloadToCompletedMaterial||e.action.type===V.UnloadToInProcess)&&e.action.elapsedLoadUnloadTime&&(f=e.action.elapsedLoadUnloadTime),d=d.alter(1,t=>t?(t.push(e),t):[e]))),e.location.type===ot.InQueue&&e.location.currentQueue&&c.has(e.location.currentQueue)){let t=c.get(e.location.currentQueue);r&&!P2(e,i,a)?t===void 0?c.set(e.location.currentQueue,{mats:[],hiddenCnt:1}):t.hiddenCnt+=1:t===void 0?c.set(e.location.currentQueue,{mats:[e],hiddenCnt:0}):t.mats.push(e)}if(e.location.type===ot.InBasket&&e.location.basketId&&l.has(e.location.basketId)){let t=l.get(e.location.basketId);r&&!P2(e,i,a)?t===void 0?l.set(e.location.basketId,{mats:[],hiddenCnt:1}):t.hiddenCnt+=1:t===void 0?l.set(e.location.basketId,{mats:[e],hiddenCnt:0}):t.mats.push(e)}}c.forEach(e=>e.mats.sort(WE(e=>e.location.queuePosition??0))),l.forEach(e=>e.mats.sort(WE(e=>e.location.basketSlot??0)));let p=u.length+d.valuesToAscLazySeq().sumBy(e=>e.length);return{pallet:i,activeBasket:a,allMaterial:n.material,face:d,freeLoadingMaterial:u,queues:c,baskets:l,elapsedLoadingTime:f,fsize:p<=2?`x-large`:p<=6?`large`:`normal`}}function I2({loadData:e}){let t=WI(),n=L(UO),r=(0,I.useMemo)(()=>{let t=e.pallet;return t?Q.of(e.face.values()).append(e.freeLoadingMaterial).concat(Q.of(e.queues).collect(([e,t])=>t.mats)).flatMap(e=>e).collect(e=>e.action.type===V.Loading&&e.action.loadOntoPalletNum===t.palletNum&&e.location.type===ot.OnPallet&&e.location.palletNum===t.palletNum?Qt(e.partName,`unload`,e.materialID,t.palletNum,e.process,n):e.action.type===V.Loading&&e.action.loadOntoPalletNum===t.palletNum?Qt(e.partName,`load`,e.materialID,t.palletNum,e.action.processAfterLoad??e.process,n):e.location.type===ot.OnPallet&&e.location.palletNum===t.palletNum&&(e.action.type===V.UnloadToCompletedMaterial||e.action.type===V.UnloadToInProcess)?Qt(e.partName,`unload`,e.materialID,t.palletNum,e.process,n):null).toRArray():[]},[e,n]);if(r.length===0||t)return(0,H.jsx)(`div`,{});function i(){for(let e of r)window.open(e,`_blank`)}return(0,H.jsx)(J,{sx:{position:`fixed`,bottom:`5px`,right:`5px`},children:(0,H.jsx)(X,{title:`Open All Instructions`,children:(0,H.jsx)(Iy,{onClick:i,color:`secondary`,children:(0,H.jsx)(DT,{})})})})}function L2({elapsedLoadTime:e}){let t=L(GO).timeOfCurrentStatusUTC,n=L(KO);return e?(0,H.jsx)(`span`,{children:i2(tk(e)+(n-Math.floor(t.getTime()/1e3)))}):null}function R2({data:e,faceNum:t,loadNum:n,submitBasketLoadStationCommand:r}){let i=e.face.get(t),a=Dk(L(yr).basketName);return i?e.activeBasket&&!e.pallet?(0,H.jsxs)(`div`,{"data-testid":`load-station-active-basket`,children:[t===1?(0,H.jsxs)(J,{sx:{display:`grid`,gridTemplateColumns:`1fr auto`},children:[(0,H.jsxs)(q,{variant:`h4`,children:[a,` `,e.activeBasket.basketId]}),(0,H.jsx)(J,{sx:{justifySelf:`flex-end`},children:(0,H.jsx)(L2,{elapsedLoadTime:e.elapsedLoadingTime})})]}):null,(0,H.jsx)(J,{sx:{ml:`4em`,mr:`4em`},children:(0,H.jsx)(Y0,{kind:{type:R0.BasketZone,basketId:e.activeBasket.basketId},children:(0,H.jsx)(j2,{stationNumber:n,basket:e.activeBasket,material:e.allMaterial,fsize:e.fsize,submitCommand:r})})})]}):e.pallet?(0,H.jsxs)(`div`,{"data-testid":`load-station-pallet-face-${t}`,children:[t===1?(0,H.jsxs)(J,{sx:{display:`grid`,gridTemplateColumns:e.pallet.numFaces>1?`1fr 1fr 1fr`:`1fr 1fr`},children:[(0,H.jsxs)(q,{variant:`h4`,children:[`Pallet `,e.pallet.palletNum]}),e.pallet.numFaces>1?(0,H.jsx)(q,{variant:`h6`,sx:{justifySelf:`center`},children:e.pallet.faceNames?.[t-1]??`Face 1`}):void 0,(0,H.jsx)(J,{sx:{justifySelf:`flex-end`},children:(0,H.jsx)(L2,{elapsedLoadTime:e.elapsedLoadingTime})})]}):e.pallet.numFaces>1?(0,H.jsx)(J,{sx:{display:`flex`,justifyContent:`center`},children:(0,H.jsx)(q,{variant:`h6`,children:e.pallet.faceNames?.[t-1]??`Face ${t}`})}):void 0,(0,H.jsx)(J,{sx:{ml:`4em`,mr:`4em`},children:(0,H.jsx)(Y0,{kind:{type:R0.PalletFaceZone,face:t},children:(0,H.jsx)(J,{sx:{display:`flex`,flexWrap:`wrap`,justifyContent:`space-around`},children:i.map((t,n)=>(0,H.jsx)(Y0,{kind:{type:R0.Material,material:t},children:(0,H.jsx)(QU,{mat:t,fsize:e.fsize})},n))})})})]}):null:null}function z2({data:e,mat:t}){return(0,H.jsxs)(`div`,{children:[t.label===``?null:(0,H.jsx)(q,{variant:`h4`,children:t.label}),t.material.mats.map((n,r)=>(0,H.jsx)(Y0,{kind:{type:R0.Material,material:n,identifier:n.materialID<0?`raw-${t.isFree?`free`:`queue`}-${t.label}-${r}`:void 0},children:t.isFree||t.sortable===!1?(0,H.jsx)(QU,{mat:n,displayActionForSinglePallet:e.pallet?e.pallet.palletNum:0,fsize:e.fsize,showRawMaterial:!0,showJobComment:!0}):(0,H.jsx)($U,{mat:n,displayActionForSinglePallet:e.pallet?e.pallet.palletNum:0,shake:n.action.type===V.Loading&&n.action.loadOntoPalletNum===e.pallet?.palletNum,fsize:n.action.type===V.Loading&&n.action.loadOntoPalletNum===e.pallet?.palletNum?e.fsize:void 0,showRawMaterial:!0,showJobComment:!0})},r)),t.material.hiddenCnt>0?(0,H.jsxs)(q,{variant:`body2`,color:`textSecondary`,sx:{textAlign:`center`,mt:`0.5em`},children:[`+`,t.material.hiddenCnt,` hidden`]}):null]})}function B2({data:e,label:t,baskets:n}){return(0,H.jsxs)(`div`,{children:[(0,H.jsx)(q,{variant:`h4`,children:t}),n.map((t,n)=>(0,H.jsxs)(J,{"data-testid":`load-station-basket-${M2(t.basketId)}`,sx:{mt:n===0?`0.5em`:`1.5em`,pt:n===0?void 0:`1em`},children:[(0,H.jsx)(q,{variant:`h6`,sx:{mb:`0.5em`},children:t.label}),(0,H.jsx)(Y0,{kind:{type:R0.BasketZone,basketId:t.basketId},children:(0,H.jsx)(z2,{data:e,mat:{label:``,material:t.material,isFree:!1,sortable:!1}})})]},t.basketId))]})}function V2({data:e,region:t}){switch(t.kind){case`free`:return(0,H.jsx)(Y0,{kind:{type:R0.FreeMaterialZone},children:(0,H.jsx)(z2,{data:e,mat:{label:t.label,material:t.material,isFree:!0,sortable:!1}})});case`queue`:return(0,H.jsx)(Y0,{kind:{type:R0.QueueZone,queue:t.label},children:(0,H.jsx)($q,{matIds:t.material.mats.map(e=>e.materialID),direction:`vertical`,queueName:t.label,renderDragOverlay:t=>(0,H.jsx)(eW,{mat:t,displayActionForSinglePallet:e.pallet?e.pallet.palletNum:0,fsize:t.action.type===V.Loading&&t.action.loadOntoPalletNum===e.pallet?.palletNum?e.fsize:void 0}),children:(0,H.jsx)(z2,{data:e,mat:{label:t.label,material:t.material,isFree:!1,sortable:!0}})})});case`baskets`:return(0,H.jsx)(B2,{data:e,label:t.label,baskets:t.baskets})}}function H2(){let e=L(lL);return(0,H.jsx)(`div`,{children:(0,I.useMemo)(()=>{let t=iE(new Date,-5);return e.matsById.valuesToLazySeq().filter(e=>e.completed_last_proc_machining===!0&&e.last_unload_time!==void 0&&e.last_unload_time>=t).toSortedArray({desc:e=>e.last_unload_time?.getTime()??0})},[e]).map((e,t)=>(0,H.jsx)(ZU,{mat:e},t))})}var U2=(0,I.memo)(function({fillViewPort:e,showMaterial:t}){let n=J0({type:t?R0.CompletedExpandedMaterialZone:R0.CompletedCollapsedMaterialZone});return t&&e?(0,H.jsxs)(J,{ref:n,sx:{padding:`8px`,display:`flex`,flexDirection:`column`,height:`100%`},children:[(0,H.jsx)(q,{variant:`h4`,children:`Completed`}),(0,H.jsx)(J,{sx:{position:`relative`,flexGrow:1},children:(0,H.jsx)(J,{sx:{position:`absolute`,top:`0`,left:`0`,right:`0`,bottom:`0`,overflow:`auto`},children:(0,H.jsx)(H2,{})})})]}):t?(0,H.jsxs)(J,{ref:n,sx:{padding:`8px`},children:[(0,H.jsx)(q,{variant:`h4`,children:`Completed`}),(0,H.jsx)(H2,{})]}):(0,H.jsx)(J,{ref:n,sx:{display:`flex`,justifyContent:e?`flex-end`:void 0,padding:`8px`},children:(0,H.jsx)(q,{variant:`h4`,sx:{margin:`4px`,...e?{textOrientation:`mixed`,writingMode:`vertical-rl`}:{}},children:`Completed`})})});function W2({pallet:e}){let t=L(EI),n=L(UO),r=WI();if(t===null)return null;let i;if(t.action.type===V.Loading&&t.action.loadOntoPalletNum===e?i=`load`:(t.action.type===V.UnloadToInProcess||t.action.type===V.UnloadToCompletedMaterial)&&t.location.type===ot.OnPallet&&t.location.palletNum===e&&(i=`unload`),i===void 0)return null;let a=Qt(t.partName,i,t.materialID,e,t.action.type===V.Loading?t.action.processAfterLoad??t.process:t.process,n);return r?(0,H.jsx)(Y,{color:`primary`,children:`Instructions`}):(0,H.jsx)(Y,{href:a,target:`bms-instructions`,color:`primary`,children:`Instructions`})}function G2({queues:e,onClose:t,toQueue:n,showAddToQueue:r,setShowAddToQueue:i}){let a=R(bI),o=L(jI),s=L(CI),c=L(EI),l=L(UO),[u,d]=LI();return!s||c?.location.type===ot.OnPallet||c?.action.type===V.Loading||c?.action.type===V.LoadingToBasket||e.length===0||c?.location.type===ot.InQueue&&c?.location.currentQueue&&e.includes(c?.location.currentQueue)?null:r?(0,H.jsxs)(Y,{color:`primary`,disabled:n===null||d,onClick:()=>{u({materialId:s.materialID,queue:n??``,queuePosition:-1,operator:l}),a(null),t()},children:[`Add To `,n??`Queue`,` `,o?` To Run Process ${o.process+1}`:``]}):(0,H.jsx)(Y,{color:`primary`,onClick:()=>i(!0),children:`Add To Queue`})}function K2(){let e=L(yr),t=R(D0),n=L(CI);return!e.allowChangeWorkorderAtLoadStation||n===null||n.materialID<0?null:(0,H.jsx)(Y,{color:`primary`,onClick:()=>t(!0),children:`Assign Workorder`})}var q2=(0,I.memo)(function(e){let[t,n]=(0,I.useState)(null),[r,i]=(0,I.useState)(null),[a,o]=(0,I.useState)(!1),[s,c]=(0,I.useState)(null),l=(0,I.useCallback)(function(){n(null),i(null),o(!1),c(null)},[n,i]);return(0,H.jsx)(dW,{onClose:l,allowNote:!0,highlightProcsGreaterOrEqualTo:r?.process??void 0,extraDialogElements:(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(JY,{st:t,setState:n}),r===null?null:(0,H.jsx)(WY,{st:r,setState:i}),a?(0,H.jsx)(LY,{selectedQueue:s,setSelectedQueue:c,queueNames:e.queues}):void 0]}),buttons:(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(W2,{pallet:e.pallet}),(0,H.jsx)(xY,{}),(0,H.jsx)(HY,{}),(0,H.jsx)(I0,{}),(0,H.jsx)(G2,{toQueue:s,queues:e.queues,onClose:l,showAddToQueue:a,setShowAddToQueue:o}),(0,H.jsx)(YY,{st:t,setState:n,onClose:l}),(0,H.jsx)(GY,{st:r,setState:i,onClose:l,loadStation:!0}),(0,H.jsx)(K2,{})]})})});function J2({numMatCols:e,maxNumFaces:t,horizontal:n,showMatInCompleted:r}){let i=``,a=``;if(t<=0&&(t=1),n){let n=``;for(let t=0;t<e;t++)a+=`minmax(16em, max-content) `,n+=`mat${t} `;a+=`1fr `,r?a+=`minmax(16em, max-content)`:a+=` 4.5em`;let o=`minmax(calc((100vh - 64px) / ${t}), max-content)`;for(let e=0;e<t;e++){let r=e===t-1?`1fr`:o;i+=`"${n} palface${e} completed" ${r}\n`}}else{a=`1fr`;for(let e=0;e<t;e++)i+=`"palface${e}" minmax(134px, max-content)\n`;for(let t=0;t<e;t++)i+=`"mat${t}" minmax(134px, max-content)\n`;i+=`"completed" minmax(134px, max-content)
350
350
  `}return`${i} / ${a}`}function Y2(e){let t=Dk(L(yr).basketName),n=t.endsWith(`s`)?t:`${t}s`,r=L(GO),i=L(Pq),a=(0,I.useMemo)(()=>F2(e.loadNum,e.queues,r,i),[r,e.loadNum,e.queues,i]),o=[...Q.of(a.queues).sortBy(([e,t])=>e).map(([e,t])=>({kind:`queue`,label:e,material:t})).toRArray()];if(a.baskets.size>0){let e=Q.of(a.baskets).filter(([e,t])=>e!==a.activeBasket?.basketId).sortBy(([e,t])=>e).map(([e,n])=>({basketId:e,label:`${t} ${e}`,material:n})).toRArray();e.length>0&&o.push({kind:`baskets`,label:n,baskets:e})}(a.queues.size===0&&a.baskets.size===0||a.freeLoadingMaterial.length>0)&&o.push({kind:`free`,label:`Material`,material:{mats:a.freeLoadingMaterial,hiddenCnt:0}});let s=o.length+ +!!e.completed,c=Yw(s<=1?`(min-width: 720px)`:s===2?`(min-width: 1030px)`:`(min-width: 1320px)`),l=J2({numMatCols:o.length,maxNumFaces:a.face.size,horizontal:c,showMatInCompleted:e.completed});return(0,H.jsx)(q0,{hideArrows:!c,whiteBackground:e.whiteBackground,children:(0,H.jsxs)(J,{component:`main`,sx:{width:`100%`,display:`grid`,gridTemplate:l,minHeight:{xs:`calc(100vh - 64px - 32px)`,sm:`calc(100vh - 64px - 40px)`,md:`calc(100vh - 64px)`},padding:c?void 0:`8px`},children:[o.map((e,t)=>(0,H.jsx)(J,{"data-testid":N2(e),sx:{gridArea:`mat${t}`,padding:`8px`,borderRight:c?`1px solid black`:void 0,borderBottom:c?void 0:`1px solid black`},children:(0,H.jsx)(V2,{data:a,region:e})},t)),a.face.keysToAscLazySeq().map((t,n)=>(0,H.jsx)(J,{sx:{marginLeft:`15px`,gridArea:`palface${n}`,padding:`8px`,borderTop:a.pallet&&n!==0?`1px solid black`:void 0},children:(0,H.jsx)(R2,{data:a,faceNum:t,loadNum:e.loadNum,submitBasketLoadStationCommand:e.submitBasketLoadStationCommand})},t)),(0,H.jsx)(J,{"data-testid":`load-station-completed`,sx:{borderLeft:c?`1px solid black`:void 0,borderTop:c?void 0:`1px solid black`,gridArea:`completed`},children:(0,H.jsx)(U2,{fillViewPort:c,showMaterial:e.completed})}),(0,H.jsx)(I2,{loadData:a}),(0,H.jsx)(M0,{}),(0,H.jsx)(L0,{}),(0,H.jsx)(q2,{pallet:a.pallet?.palletNum??null,queues:e.queues})]})})}function X2(e){let t=L(yr);return GI(Tk(e.loadNum,t.loadStationNames)),(0,H.jsx)(Y2,{...e})}function Z2(e){let t=WI(),n=L(UO),r=L(CI),i=L(jI)?.process,[a,o]=Eie(),s=R(bI);if(r===null)return null;function c(t){r&&(a({mat:r,inspType:e.inspection_type,success:t,operator:n}),s(null))}let l=Qt(r.partName,e.inspection_type,r.materialID,null,i,n);return(0,H.jsxs)(H.Fragment,{children:[r.partName===``?void 0:t?(0,H.jsx)(Y,{color:`primary`,children:`Instructions`}):(0,H.jsx)(Y,{href:l,target:`bms-instructions`,color:`primary`,children:`Instructions`}),(0,H.jsx)(HY,{}),(0,H.jsxs)(Y,{color:`primary`,disabled:o,onClick:()=>c(!0),children:[`Mark `,e.inspection_type,` Success`]}),(0,H.jsxs)(Y,{color:`primary`,disabled:o,onClick:()=>c(!1),children:[`Mark `,e.inspection_type,` Failed`]})]})}function Q2({focusInspectionType:e}){let t=L(MI);return t===null||e||t.signaledInspections.length===1?null:(0,H.jsx)(H.Fragment,{children:t.signaledInspections.map(e=>(0,H.jsx)(Ay,{children:(0,H.jsx)(Z2,{inspection_type:e})},e))})}function $2({focusInspectionType:e}){let t=L(MI),n;if(e)n=e;else if(t&&t.signaledInspections.length===1)n=t.signaledInspections[0];else return null;return(0,H.jsx)(Z2,{inspection_type:n})}var e4=(0,I.memo)(function(e){return(0,H.jsx)(dW,{allowNote:!0,extraDialogElements:(0,H.jsx)(Q2,{focusInspectionType:e.focusInspectionType}),buttons:(0,H.jsx)($2,{focusInspectionType:e.focusInspectionType})})});function t4({focusInspectionType:e,forceSingleColumn:t}){let n=L(lL),r=(0,I.useMemo)(()=>r4(n.matsById,e),[n,e]);return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(J,{sx:{display:t?void 0:{md:`flex`}},children:[(0,H.jsxs)(J,{sx:{padding:`8px`,minHeight:t?void 0:{md:`calc(100vh - 64px)`},width:t?`100%`:{md:`50vw`},borderRight:t?void 0:{md:`1px solid black`},borderBottom:t?`1px solid black`:{sm:`1px solid black`,md:`none`}},children:[(0,H.jsx)(q,{variant:`h4`,children:`Parts to Inspect`}),(0,H.jsx)(J,{sx:{display:`flex`,justifyContent:`flex-start`,flexWrap:`wrap`},children:r.waiting_to_inspect.map((t,n)=>(0,H.jsx)(ZU,{mat:t,focusInspectionType:e,hideWarningIcon:!0},n))})]}),(0,H.jsxs)(J,{sx:{padding:`8px`,width:t?`100%`:{md:`50vw`}},children:[(0,H.jsx)(q,{variant:`h4`,children:`Recently Inspected`}),(0,H.jsx)(J,{sx:{display:`flex`,justifyContent:`flex-start`,flexWrap:`wrap`},children:r.inspect_completed.map((t,n)=>(0,H.jsx)(ZU,{mat:t,focusInspectionType:e,hideWarningIcon:!0},n))})]})]}),(0,H.jsx)(e4,{focusInspectionType:e})]})}function n4(e){let t=e.completedInspections;return t===void 0?e.signaledInspections.length===0:Q.of(e.signaledInspections).every(e=>e in t)}function r4(e,t){let n=tE(new Date,-7),r=tE(new Date,-1),i=Array.from(t===null?e.valuesToLazySeq().filter(e=>e.last_unload_time!==void 0&&e.last_unload_time>=n&&e.signaledInspections.length>0&&!n4(e)):e.valuesToLazySeq().filter(e=>e.last_unload_time!==void 0&&e.last_unload_time>=n&&e.signaledInspections.includes(t)&&(e.completedInspections||{})[t]===void 0));i.sort((e,t)=>e.last_unload_time&&t.last_unload_time?t.last_unload_time.getTime()-e.last_unload_time.getTime():0);let a=Array.from(t===null?e.valuesToLazySeq().filter(e=>e.completed_inspect_time!==void 0&&e.completed_inspect_time>=r&&e.signaledInspections.length>0&&n4(e)):e.valuesToLazySeq().filter(e=>e.completed_inspect_time!==void 0&&e.completed_inspect_time>=r&&e.signaledInspections.includes(t)&&(e.completedInspections||{})[t]!==void 0));return a.sort((e,t)=>e.completed_inspect_time&&t.completed_inspect_time?t.completed_inspect_time.getTime()-e.completed_inspect_time.getTime():0),{waiting_to_inspect:i,inspect_completed:a}}function i4(e){return GI(e.focusInspectionType&&e.focusInspectionType!==``?`Inspection ${e.focusInspectionType}`:`Inspection`),(0,H.jsx)(J,{component:`main`,sx:{backgroundColor:`#F8F8F8`,minHeight:{sm:`calc(100vh - 64px - 40px)`,md:`calc(100vh - 64px)`}},children:(0,H.jsx)(t4,{...e})})}function a4(){let e=L(yr),t=L(CI),[n,r]=PI(),i=L(UO),[a,o]=z(bI);if(t===null)return null;let s=e.requireScanAtCloseout,c=e.requireWorkorderBeforeAllowCloseoutComplete,l;s?a!==null&&(a.type===`Barcode`||a.type===`ManuallyEnteredSerial`)||(l=`Scan Required`):c&&(t.workorderId===void 0||t.workorderId===``)&&(l=`No workorder assigned`);function u(e){t!==null&&(n({mat:t,operator:i,failed:e}),o(null))}return l?(0,H.jsx)(X,{title:l,placement:`top`,children:(0,H.jsx)(`div`,{children:(0,H.jsx)(Y,{color:`primary`,disabled:!0,children:`Close Out`})})}):(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(Y,{color:`primary`,disabled:r,onClick:()=>u(!0),children:`Fail Close Out`}),(0,H.jsx)(Y,{color:`primary`,disabled:r,onClick:()=>u(!1),children:`Pass Close Out`})]})}function o4(){let e=WI(),t=L(CI),n=L(UO),r=L(jI)?.process;if(t===null||t.partName===``)return null;let i=Qt(t.partName,`closeout`,t.materialID,null,r,n);return e?(0,H.jsx)(Y,{color:`primary`,children:`Instructions`}):(0,H.jsx)(Y,{href:i,target:`bms-instructions`,color:`primary`,children:`Instructions`})}function s4(){let e=R(D0);return L(CI)===null?null:(0,H.jsx)(Y,{color:`primary`,onClick:()=>e(!0),children:`Assign Workorder`})}var c4=(0,I.memo)(function(){return(0,H.jsx)(dW,{allowNote:!0,buttons:(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(o4,{}),(0,H.jsx)(HY,{}),(0,H.jsx)(s4,{}),(0,H.jsx)(a4,{})]})})}),l4=P(new Date);l4.onMount=e=>{e(new Date);let t=setInterval(()=>{e(new Date)},1e3*60);return()=>clearInterval(t)};function u4({forceSingleColumn:e}){let t=L(lL),n=L(l4),r=(0,I.useMemo)(()=>{let e=iE(n,-48),r=iE(n,-2),i=[],a=[];for(let n of t.matsById.values())n.completed_last_proc_machining===!0&&n.last_unload_time&&n.last_unload_time>=e&&(n.closeout_completed===void 0?i.push(n):n.closeout_completed>=r&&a.push(n));return i.sort((e,t)=>e.last_unload_time&&t.last_unload_time?e.last_unload_time.getTime()-t.last_unload_time.getTime():0),a.sort((e,t)=>e.last_unload_time&&t.last_unload_time?t.last_unload_time.getTime()-e.last_unload_time.getTime():0),{uncompleted:i,closed:a}},[t,n]);return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(J,{sx:{display:e?void 0:{md:`flex`}},children:[(0,H.jsxs)(J,{sx:{padding:`8px`,minHeight:e?void 0:{md:`calc(100vh - 64px)`},width:e?`100%`:{md:`50vw`},borderRight:e?void 0:{md:`1px solid black`},borderBottom:e?`1px solid black`:{sm:`1px solid black`,md:`none`}},children:[(0,H.jsx)(q,{variant:`h4`,children:`Recently Completed`}),(0,H.jsx)(J,{sx:{display:`flex`,justifyContent:`flex-start`,flexWrap:`wrap`},children:r.uncompleted.map((e,t)=>(0,H.jsx)(ZU,{mat:e},t))})]}),(0,H.jsxs)(J,{sx:{padding:`8px`,width:e?`100%`:{md:`50vw`}},children:[(0,H.jsx)(q,{variant:`h4`,children:`Recently Closed Out`}),(0,H.jsx)(J,{sx:{display:`flex`,justifyContent:`flex-start`,flexWrap:`wrap`},children:r.closed.map((e,t)=>(0,H.jsx)(ZU,{mat:e},t))})]})]}),(0,H.jsx)(M0,{}),(0,H.jsx)(c4,{})]})}function d4(){return GI(`Close Out`),(0,H.jsx)(J,{component:`main`,sx:{backgroundColor:`#F8F8F8`,minHeight:{sm:`calc(100vh - 64px - 40px)`,md:`calc(100vh - 64px)`}},children:(0,H.jsx)(u4,{})})}function f4(e,t){return e.mapValues(e=>{let n=Q.of(e.recentCycles).flatMap(e=>e.tools).filter(e=>!e.toolChangedDuringMiddleOfCycle).groupBy(e=>e.toolName).map(([e,t])=>({toolName:e,cycleUsageMinutes:Q.of(t).sumBy(e=>e.cycleUsageMinutes)/t.length,cycleUsageCnt:Q.of(t).sumBy(e=>e.cycleUsageCnt)/t.length,toolChangedDuringMiddleOfCycle:!1})).toMutableArray();return t&&n.sort((e,t)=>e.toolName.localeCompare(t.toolName)),{tools:n}})}var p4=class{constructor(e,t){this.statGroup=e,this.operation=t}compare(e){let t=this.statGroup.localeCompare(e.statGroup);return t===0?this.operation.localeCompare(e.operation):t}hash(){return jD(this.statGroup,this.operation)}toString(){return`{statGroup: ${this.statGroup}, operation: ${this.operation}}`}};function m4(e,t){let n=0,r=0;for(let i of Q.of(e).filter(e=>e.machines.has(t)??!1))n+=i.quantity*(i.scheduledUseMinutes/i.scheduledUseCnt),r+=i.quantity;return r===0?0:n/r}function h4(e,t,n){let r=gO.empty();for(let[t,n]of Q.ofObject(e.jobs)){let i=n.cycles??0;for(let a=0;a<n.procsAndPaths.length;a++){let o=0,s=gO.empty();for(let r=0;r<n.procsAndPaths[a].paths.length;r++){o+=n.completed?.[a]?.[r]??0;let i=n.procsAndPaths[a].paths[r];for(let n=0;n<i.stops.length;n+=1){let o=i.stops[n],c=Q.of(e.material).filter(e=>e.jobUnique===t&&e.process==a+1&&e.path===r+1&&(e.action.type===V.UnloadToCompletedMaterial||e.action.type===V.UnloadToInProcess||e.lastCompletedMachiningRouteStopIndex!==void 0&&e.lastCompletedMachiningRouteStopIndex>n)).length();o.program!==void 0&&o.program!==``&&(s=s.modify(new p4(o.stationGroup,o.program),e=>(e??0)+c))}}for(let[e,t]of s)r=r.modify(new rk(n.partName,e.statGroup,e.operation),e=>(e??0)+i-o-t)}}let i=Q.of(f4(n,!1)).flatMap(([e,t])=>{let i=window.bmsToolReportOverridePartQuantity??r.get(e);return i!==void 0&&i>0?t.tools.map(t=>({toolName:t.toolName,part:{partAndProg:e,quantity:i,scheduledUseMinutes:t.cycleUsageMinutes,scheduledUseCnt:t.cycleUsageCnt===0?1:t.cycleUsageCnt,machines:n.get(e)?.machines??uO.empty()}})):[]}).sortBy(e=>e.part.partAndProg.part,e=>e.part.partAndProg.operation).toLookup(e=>e.toolName,e=>e.part);return Q.of(t).orderedGroupBy(e=>e.toolName).map(([e,t])=>{let n=!1;return{toolName:e,machines:Q.of(t).sortBy(e=>e.machineGroupName,e=>e.machineNum,e=>e.pocket).map(t=>{let r=t.currentUse!==null&&t.currentUse!==void 0&&t.currentUse!==``?nk(t.currentUse):null,a=t.totalLifeTime!==null&&t.totalLifeTime!==void 0&&t.totalLifeTime!==``?nk(t.totalLifeTime):null,o=wk(t.machineGroupName,t.machineNum),s=t.currentUseCount??null,c=t.totalLifeCount??null;if(s===null&&c===null){let t=m4(i.get(e)??[],o);t>0&&(n=!0,s=r===null?null:r/t,c=a===null?null:a/t)}return{machineName:o,pocket:t.pocket,serial:t.serial,currentUseMinutes:r,lifetimeMinutes:a,remainingMinutes:r!==null&&a!==null?Math.max(0,a-r):null,currentUseCnt:s??null,lifetimeCnt:c??null,remainingCnt:s!==null&&c!==null?Math.max(0,c-s):null}}).toRArray(),parts:i.get(e)??[],estimatedToolCounts:n}}).toRArray()}var g4=P(null),_4=P(e=>e(g4)?.time??null,async(e,t,n)=>{t(g4,{tools:await Wt.getToolsInMachines(),time:n})}),v4=P(e=>{let t=e(g4);return t===null?[]:Q.of(t.tools).toOrderedSet(e=>wk(e.machineGroupName,e.machineNum)).toAscLazySeq().toRArray()}),y4=P(e=>{let t=e(g4);if(t===null)return null;let n=e(GO),r=e(FL);return h4(n,t.tools,r)}),b4=P(e=>{let t=e(y4);return t?Q.of(t).flatMap(e=>e.machines).some(e=>e.serial!=null&&e.serial!==``):!1}),x4=P(e=>{let t=e(y4);return t?Q.of(t).some(e=>e.estimatedToolCounts):!1});function S4(e){let t=Q.of(e).flatMap(e=>e.machines).some(e=>e.currentUseMinutes!=null),n=Q.of(e).flatMap(e=>e.machines).some(e=>e.currentUseCnt!=null),r=`<table>
351
351
  <thead><tr>`;r+=`<th>Tool</th><th>Machine</th><th>Pocket</th>`,t&&(r+=`<th>Scheduled Use (min)</th><th>Current Use (min)</th><th>Lifetime (min)</th><th>Remaining Life (min)</th>`),n&&(r+=`<th>Scheduled Use (cnt)</th><th>Current Use (cnt)</th><th>Lifetime (cnt)</th><th>Remaining Life (cnt)</th>`),r+=`</tr></thead>
352
352
  <tbody>
@@ -41,59 +41,64 @@ function isPositiveInteger(value) {
41
41
  function isNonBlank(value) {
42
42
  return typeof value === "string" && value.trim() !== "";
43
43
  }
44
- function actionPhase(mat, basketId) {
44
+ function basketAction(mat, basketId) {
45
45
  if (mat.location.type === api.LocType.InBasket &&
46
46
  mat.location.basketId === basketId &&
47
47
  (mat.action.type === api.ActionType.UnloadToInProcess ||
48
48
  mat.action.type === api.ActionType.UnloadToCompletedMaterial)) {
49
49
  if (!isPositiveInteger(mat.location.basketSlot)) {
50
- return "invalid";
50
+ return { type: "invalid" };
51
51
  }
52
- return "unload";
52
+ return { type: "valid", workId: mat.action.workId };
53
53
  }
54
54
  if (mat.action.type === api.ActionType.LoadingToBasket) {
55
55
  if (!isPositiveInteger(mat.action.loadToBasketId))
56
- return "invalid";
56
+ return { type: "invalid" };
57
57
  if (mat.action.loadToBasketId !== basketId)
58
58
  return undefined;
59
+ const reloadsSameSlot = mat.location.type === api.LocType.InBasket &&
60
+ mat.location.basketId === basketId &&
61
+ mat.location.basketSlot === mat.action.loadToBasketSlot;
59
62
  if (!isPositiveInteger(mat.action.loadToBasketSlot) ||
60
- (mat.location.type !== api.LocType.Free &&
63
+ (!reloadsSameSlot &&
64
+ mat.location.type !== api.LocType.Free &&
61
65
  (mat.location.type !== api.LocType.InQueue || !isNonBlank(mat.location.currentQueue)))) {
62
- return "invalid";
66
+ return { type: "invalid" };
63
67
  }
64
- return "load";
68
+ return { type: "valid", workId: mat.action.workId };
65
69
  }
66
70
  return undefined;
67
71
  }
68
72
  function confirmableWork(material, basketId) {
69
73
  const classifiedActions = LazySeq.of(material)
70
- .collect((mat) => {
71
- const phase = actionPhase(mat, basketId);
72
- return phase === undefined ? undefined : { phase, workId: mat.action.workId };
73
- })
74
+ .collect((mat) => basketAction(mat, basketId))
74
75
  .toRArray();
75
- if (classifiedActions.some(({ phase }) => phase === "invalid")) {
76
+ if (classifiedActions.some((action) => action.type === "invalid")) {
76
77
  return { type: "inconsistent" };
77
78
  }
78
- const phaseActions = classifiedActions.filter((action) => action.phase !== "invalid");
79
- if (phaseActions.length === 0)
79
+ const validActions = classifiedActions.filter((action) => action.type === "valid");
80
+ if (validActions.length === 0)
80
81
  return { type: "none" };
81
- const tagged = phaseActions.filter((action) => isNonBlank(action.workId));
82
+ const tagged = validActions.filter((action) => isNonBlank(action.workId));
82
83
  const workIds = LazySeq.of(tagged).toHashSet(({ workId }) => workId);
83
- const phases = LazySeq.of(tagged).toHashSet(({ phase }) => phase);
84
- if (tagged.length !== phaseActions.length || workIds.size !== 1 || phases.size !== 1) {
84
+ if (tagged.length !== validActions.length || workIds.size !== 1) {
85
85
  return { type: "inconsistent" };
86
86
  }
87
87
  return {
88
88
  type: "confirmable",
89
- work: { workId: tagged[0].workId, phase: tagged[0].phase },
89
+ work: { workId: tagged[0].workId },
90
90
  };
91
91
  }
92
- function loadingSource(mat) {
92
+ function loadingInstruction(mat) {
93
+ if (mat.location.type === api.LocType.InBasket &&
94
+ mat.location.basketId === mat.action.loadToBasketId &&
95
+ mat.location.basketSlot === mat.action.loadToBasketSlot) {
96
+ return "Unload, re-plate, and reload this slot";
97
+ }
93
98
  if (mat.location.type === api.LocType.InQueue && mat.location.currentQueue) {
94
- return mat.location.currentQueue;
99
+ return `Load from ${mat.location.currentQueue}`;
95
100
  }
96
- return "raw material";
101
+ return "Load from raw material";
97
102
  }
98
103
  function SlotMaterial({ material, fsize, }) {
99
104
  return material.map((mat) => (_jsx(MoveMaterialArrowNode, { kind: { type: MoveMaterialNodeKindType.Material, material: mat }, children: _jsx(InProcMaterial, { mat: mat, fsize: fsize }) }, mat.materialID)));
@@ -133,7 +138,6 @@ export function BasketLoadStationWorkflow({ stationNumber, basket, material, fsi
133
138
  }
134
139
  }
135
140
  const submissionDisabled = submission === "submitting" || submission === "accepted" || submission === "conflict";
136
- const buttonLabel = work?.phase === "unload" ? "Unload Complete" : "Load Complete";
137
141
  return (_jsxs(Stack, { spacing: 2, sx: { mt: 2 }, children: [_jsx(Typography, { variant: "h6", children: "Basket slots" }), _jsx(Box, { sx: {
138
142
  display: "grid",
139
143
  gridTemplateColumns: "repeat(auto-fit, minmax(15em, 1fr))",
@@ -142,6 +146,6 @@ export function BasketLoadStationWorkflow({ stationNumber, basket, material, fsi
142
146
  const slotMaterial = materialBySlot.get(slot) ?? [];
143
147
  const loads = loadsBySlot.get(slot) ?? [];
144
148
  const isUnknown = basket.unknownSlots?.includes(slot) === true;
145
- return (_jsx(Card, { "data-testid": `basket-load-station-slot-${slot}`, variant: "outlined", children: _jsxs(CardContent, { children: [_jsxs(Typography, { variant: "h6", children: ["Slot ", slot] }), slotMaterial.length > 0 ? (_jsx(SlotMaterial, { material: slotMaterial, fsize: fsize })) : (_jsx(Typography, { color: isUnknown ? "warning.main" : "text.secondary", children: isUnknown ? "Unknown" : "Empty" })), loads.map((mat, index) => (_jsxs(Box, { sx: { mt: 1 }, children: [_jsxs(Typography, { children: ["Load from ", loadingSource(mat)] }), _jsxs(Typography, { variant: "body2", color: "text.secondary", children: [mat.partName, " \u00B7 Process ", mat.action.processAfterLoad ?? mat.process] })] }, `${mat.jobUnique}-${mat.process}-${index}`)))] }) }, slot));
146
- }) }), work && submitCommand ? (_jsx(Box, { sx: { display: "flex", justifyContent: "flex-end" }, children: _jsx(Button, { variant: "contained", disabled: submissionDisabled, onClick: () => void submit(), children: buttonLabel }) })) : work ? (_jsx(Alert, { severity: "warning", children: "Basket work confirmation is not configured." })) : workState.type === "inconsistent" ? (_jsx(Alert, { severity: "warning", children: "Basket work is inconsistent. Wait for refreshed material actions before confirming." })) : null, submission === "accepted" ? (_jsx(Alert, { severity: "success", children: "Confirmation accepted. Waiting for refreshed work." })) : submission === "conflict" ? (_jsx(Alert, { severity: "warning", children: "Basket work changed before confirmation. Review the refreshed slots and try again." })) : submission === "error" ? (_jsx(Alert, { severity: "error", children: "Unable to confirm basket work. No work was assumed complete." })) : null] }));
149
+ return (_jsx(Card, { "data-testid": `basket-load-station-slot-${slot}`, variant: "outlined", children: _jsxs(CardContent, { children: [_jsxs(Typography, { variant: "h6", children: ["Slot ", slot] }), slotMaterial.length > 0 ? (_jsx(SlotMaterial, { material: slotMaterial, fsize: fsize })) : (_jsx(Typography, { color: isUnknown ? "warning.main" : "text.secondary", children: isUnknown ? "Unknown" : "Empty" })), loads.map((mat, index) => (_jsxs(Box, { sx: { mt: 1 }, children: [_jsx(Typography, { children: loadingInstruction(mat) }), _jsxs(Typography, { variant: "body2", color: "text.secondary", children: [mat.partName, " \u00B7 Process ", mat.action.processAfterLoad ?? mat.process] })] }, `${mat.jobUnique}-${mat.process}-${index}`)))] }) }, slot));
150
+ }) }), work && submitCommand ? (_jsx(Box, { sx: { display: "flex", justifyContent: "flex-end" }, children: _jsx(Button, { variant: "contained", disabled: submissionDisabled, onClick: () => void submit(), children: "Confirm" }) })) : work ? (_jsx(Alert, { severity: "warning", children: "Basket work confirmation is not configured." })) : workState.type === "inconsistent" ? (_jsx(Alert, { severity: "warning", children: "Basket work is inconsistent. Wait for refreshed material actions before confirming." })) : null, submission === "accepted" ? (_jsx(Alert, { severity: "success", children: "Confirmation accepted. Waiting for refreshed work." })) : submission === "conflict" ? (_jsx(Alert, { severity: "warning", children: "Basket work changed before confirmation. Review the refreshed slots and try again." })) : submission === "error" ? (_jsx(Alert, { severity: "error", children: "Unable to confirm basket work. No work was assumed complete." })) : null] }));
147
151
  }
package/dist/index.html CHANGED
@@ -44,7 +44,7 @@
44
44
  }
45
45
  }
46
46
  </style>
47
- <script type="module" crossorigin src="/assets/index-BLYS5tHD.js"></script>
47
+ <script type="module" crossorigin src="/assets/index-DHusyIyb.js"></script>
48
48
  <link rel="stylesheet" crossorigin href="/assets/index-DXfAwuj-.css">
49
49
  </head>
50
50
  <body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seedtactics/insight-client",
3
- "version": "16.8.4-beta.6",
3
+ "version": "16.8.4-beta.8",
4
4
  "license": "BSD-3-Clause",
5
5
  "repository": {
6
6
  "url": "https://github.com/SeedTactics/fms-insight"