1var e=(e,a,l)=>new Promise((s,r)=>{var t=e=>{try{n(l.next(e))}catch(a){r(a)}},i=e=>{try{n(l.throw(e))}catch(a){r(a)}},n=e=>e.done?s(e.value):Promise.resolve(e.value).then(t,i);n((l=l.apply(e,a)).next())});import{j as a,B as l}from"./main-BnzPSaAB.js";import{r as s}from"./redux-vendor-C5HMt75f.js";import{s as r,O as t}from"./OpsPageHeader-ByeknP4s.js";import{D as i}from"./DataTable-Be04SSQn.js";import{M as n}from"./Modal-B0GCE2ju.js";import{o,c,a as d}from"./opsApi-D5d6X89L.js";import{S as p,b as u}from"./StatusChip-DNXNqn1J.js";import{g as m}from"./opsMemberMapper-B35rZJ_W.js";import{d as h,a as v,L as j}from"./router-vendor-CDEUxg0V.js";import"./react-vendor-d2XN-_nt.js";import"./ui-vendor-B78xTfmQ.js";function y(){var y,x,b,f,g,N,k,S,C,D,P,A,w;const{id:L}=h(),E=null==(y=v().state)?void 0:y.submitted,[I,M]=s.useState(null),[R,B]=s.useState([]),[O,T]=s.useState([]),[V,$]=s.useState(E?"approval":"overview"),[G,U]=s.useState(null),[Q,F]=s.useState(null),[H,q]=s.useState(null),[z,J]=s.useState(""),[K,W]=s.useState(!1),X=s.useCallback(()=>e(null,null,function*(){var e;if(L)try{const[a,l]=yield Promise.all([o.batches.get(Number(L)),o.dailyPlans.list({batchId:Number(L)})]);M(a.batch),B(null!=(e=l.plans)?e:[]),U(null)}catch(a){U(c(a))}}),[L]);if(s.useEffect(()=>{X()},[X]),s.useEffect(()=>{o.members.list().then(e=>{var a;return T(null!=(a=e.members)?a:[])}).catch(()=>{})},[]),!I&&!G)return a.jsx("div",{className:r.page,children:"Loadingâ¦"});const Y="SUBMITTED"===(null==I?void 0:I.status);return a.jsxs("div",{className:r.page,children:[a.jsx(t,{title:`Batch ${null!=(x=null==I?void 0:I.batchId)?x:L}`,subtitle:I?`${null!=(b=I.skuCode)?b:"â"} · ${null!=(f=I.productName)?f:"â"}`:"",actions:a.jsxs(a.Fragment,{children:["APPROVED"===(null==I?void 0:I.status)&&a.jsx(j,{to:`/operations/daily-plans/new?batchId=${L}`,children:a.jsx(l,{children:"+ Daily plan"})}),Y&&a.jsxs(a.Fragment,{children:[a.jsx(l,{variant:"secondary",onClick:()=>q("reject"),children:"Reject"}),a.jsx(l,{onClick:()=>q("approve"),children:"Approve"})]}),"APPROVED"===(null==I?void 0:I.status)&&a.jsx(l,{variant:"secondary",onClick:()=>e(null,null,function*(){if(I)try{const e=yield o.batches.hold(I.id);M(e.batch),F(null)}catch(e){F(c(e))}}),children:"Hold batch"})]})}),G&&a.jsx("p",{className:r.error,children:G}),Q&&a.jsx("p",{className:r.error,children:Q}),E&&"SUBMITTED"===(null==I?void 0:I.status)&&a.jsx("p",{style:{color:"#166534",marginBottom:12},children:"Batch submitted for approval. A member with the Batch approver role can approve it here."}),a.jsx("div",{className:r.tabs,children:["overview","daily-plans","approval"].map(e=>a.jsx("button",{type:"button",className:`${r.tab} ${V===e?r.tabActive:""}`,onClick:()=>$(e),children:"daily-plans"===e?"Daily plans":e.charAt(0).toUpperCase()+e.slice(1)},e))}),"overview"===V&&I&&a.jsxs("div",{className:r.metricsGrid,children:[a.jsxs("div",{className:r.metricCard,children:[a.jsx("p",{className:r.metricLabel,children:"Planned qty"}),a.jsx("p",{className:r.metricValue,children:null==(g=I.plannedQty)?void 0:g.toLocaleString()})]}),a.jsxs("div",{className:r.metricCard,children:[a.jsx("p",{className:r.metricLabel,children:"Est. serial buffer"}),a.jsx("p",{className:r.metricValue,children:null!=(k=null==(N=I.serialsToGenerate)?void 0:N.toLocaleString())?k:"â"})]}),a.jsxs("div",{className:r.metricCard,children:[a.jsx("p",{className:r.metricLabel,children:"Overage"}),a.jsxs("p",{className:r.metricValue,children:[null!=(S=I.overagePercent)?S:0,"%"]})]}),a.jsxs("div",{className:r.metricCard,children:[a.jsx("p",{className:r.metricLabel,children:"Generated"}),a.jsx("p",{className:r.metricValue,children:null!=(D=null==(C=I.generatedCount)?void 0:C.toLocaleString())?D:0})]}),a.jsxs("div",{className:r.metricCard,children:[a.jsx("p",{className:r.metricLabel,children:"Status"}),a.jsx(p,{label:d(I.status),tone:u(I.status)})]})]}),"daily-plans"===V&&a.jsx(i,{columns:[{key:"dailyPlanId",header:"Daily plan ID",render:e=>a.jsx(j,{to:`/operations/daily-plans/${e.id}`,children:e.dailyPlanId})},{key:"planDate",header:"Date"},{key:"plannedQty",header:"Qty"},{key:"serialsGenerated",header:"Generated"},{key:"serialsPrinted",header:"Printed"},{key:"status",header:"Status",render:e=>a.jsx(p,{label:e.status,tone:"info"})}],data:R,keyExtractor:e=>e.id,emptyMessage:"APPROVED"===(null==I?void 0:I.status)?"No daily plans for this batch yet":"Daily plans are available after batch approval"}),"approval"===V&&I&&a.jsxs("div",{className:r.card,children:[I.submittedAt&&a.jsxs("p",{children:["Submitted: ",new Date(I.submittedAt).toLocaleStr
1ing()]}),(null!=(A=null==(P=I.approvals)?void 0:P.length)?A:0)>0?a.jsx(i,{columns:[{key:"decision",header:"Decision",render:e=>a.jsx(p,{label:e.decision,tone:"APPROVED"===e.decision?"success":"warning"})},{key:"approverMembershipId",header:"Approver",render:e=>m(O,e.approverMembershipId)},{key:"remarks",header:"Remarks",render:e=>{var a;return null!=(a=e.remarks)?a:"â"}},{key:"decidedAt",header:"Decided at",render:e=>new Date(e.decidedAt).toLocaleString()}],data:null!=(w=I.approvals)?w:[],keyExtractor:e=>e.id,emptyMessage:"No approval history yet"}):a.jsx("p",{children:"No approval history yet."}),Y&&a.jsx("p",{style:{marginTop:16,fontSize:"0.875rem",color:"#64748b"},children:"Use Approve or Reject above while this batch is awaiting approval."})]}),a.jsxs(n,{isOpen:null!==H,onClose:()=>{q(null),J("")},title:"approve"===H?"Approve batch":"Reject batch",children:[a.jsxs("label",{style:{display:"block",marginBottom:12},children:["Remarks (optional)",a.jsx("textarea",{value:z,onChange:e=>J(e.target.value),rows:3,style:{width:"100%",marginTop:4},placeholder:"approve"===H?"Looks good for this production run":"Reason for rejection"})]}),a.jsxs("div",{style:{display:"flex",gap:8,justifyContent:"flex-end"},children:[a.jsx(l,{variant:"secondary",onClick:()=>q(null),children:"Cancel"}),a.jsx(l,{onClick:()=>e(null,null,function*(){if(I&&H){W(!0),F(null);try{const e=z.trim()?{remarks:z.trim()}:void 0,a="approve"===H?yield o.batches.approve(I.id,e):yield o.batches.reject(I.id,e);M(a.batch),q(null),J(""),$("approval")}catch(e){F(c(e))}finally{W(!1)}}}),disabled:K,children:K?"Savingâ¦":"approve"===H?"Confirm approval":"Confirm rejection"})]})]})]})}export{y as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.