1import{E as h,dt as p,r as c,j as e,I as j,C as g,t as N,d1 as _,w as m,Z as o,k as f,du as v,bH as y,bI as w,bJ as b,bK as C}from"./index-CaijLYwW.js";import{P as S}from"./PageHeader-CjJy_Ia_.js";import{S as k}from"./search-DqRlkmJy.js";function Q(){const{data:s}=h(p),[r,l]=c.useState(""),[a,i]=c.useState(null),x=c.useMemo(()=>{const t=r.trim().toLowerCase();return t?s.filter(d=>[d.batch_code,d.container_number,d.roasts?.name,d.notes].filter(Boolean).join(" ").toLowerCase().includes(t)):s},[s,r]),u=s.find(t=>t.id===a)??null;return e.jsxs("div",{className:"mx-auto max-w-7xl",children:[e.jsx(S,{eyebrow:"Traceability",title:"Roast batches",description:"Every roasting run â links each bag we sell back to the specific green coffee lot(s) it came from."}),e.jsx("div",{className:"mb-4 flex items-center gap-2",children:e.jsxs("div",{className:"relative flex-1 max-w-md",children:[e.jsx(k,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(j,{placeholder:"Search batch code, roast, containerâ¦",className:"pl-9",value:r,onChange:t=>l(t.target.value)})]})}),x.length===0?e.jsx(g,{className:"border-dashed",children:e.jsxs(N,{className:"flex flex-col items-center gap-3 py-16 text-center",children:[e.jsx(_,{className:"h-10 w-10 text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"No roast batches yet. Batches are created automatically when you receive a roasted-coffee line on a purchase order."})]})}):e.jsx("div",{className:"overflow-hidden rounded-lg border",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-muted/50 text-left text-xs uppercase tracking-wider text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-3",children:"Batch"}),e.jsx("th",{className:"px-4 py-3",children:"Roast"}),e.jsx("th",{className:"px-4 py-3",children:"Roasted on"}),e.jsx("th",{className:"px-4 py-3 text-right",children:"Green in"}),e.jsx("th",{className:"px-4 py-3 text-right",children:"Roasted out"}),e.jsx("th",{className:"px-4 py-3 text-right",children:"Loss"}),e.jsx("th",{className:"px-4 py-3",children:"Container"})]})}),e.jsx("tbody",{children:x.map(t=>e.jsxs("tr",{className:"cursor-pointer border-t hover:bg-muted/30",onClick:()=>i(t.id),children:[e.jsx("td",{className:"px-4 py-3 font-mono text-xs",children:t.batch_code}),e.jsxs("td",{className:"px-4 py-3",children:[t.roasts?.name??"â"," ",t.roasts?.roast&&e.jsx(m,{variant:"secondary",className:"ml-1 capitalize",children:t.roasts.roast.replace("_"," ")})]}),e.jsx("td",{className:"px-4 py-3",children:t.roasted_on}),e.jsx("td",{className:"px-4 py-3 text-right",children:o(t.green_kg_in)}),e.jsx("td",{className:"px-4 py-3 text-right",children:o(t.roasted_kg_out)}),e.jsx("td",{className:"px-4 py-3 text-right",children:t.actual_loss_pct==null?"â":`${t.actual_loss_pct.toFixed(1)}%`}),e.jsx("td",{className:"px-4 py-3 text-xs text-muted-foreground",children:t.container_number??"â"})]},t.id))})]})}),e.jsx(R,{batch:u,onClose:()=>i(null)})]})}function R({batch:s,onClose:r}){const l=f(v(s?.id??""));return e.jsx(y,{open:!!s,onOpenChange:a=>!a&&r(),children:e.jsxs(w,{className:"sm:max-w-lg",children:[e.jsx(b,{children:e.jsx(C,{children:s?.batch_code})}),s&&e.jsxs("div",{className:"mt-4 space-y-4 text-sm",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx(n,{label:"Roast",value:s.roasts?.name??"â"}),e.jsx(n,{label:"Roasted on",value:s.roasted_on}),e.jsx(n,{label:"Green in",value:o(s.green_kg_in)}),e.jsx(n,{label:"Roasted out",value:o(s.roasted_kg_out)}),e.jsx(n,{label:"Loss",value:s.actual_loss_pct==null?"â":`${s.actual_loss_pct.toFixed(1)}%`}),e.jsx(n,{label:"Container",value:s.container_number??"â"})]}),s.notes&&e.jsx("div",{className:"rounded-md bg-muted/40 px-3 py-2 text-xs text-muted-foreground",children:s.notes}),e.jsxs("div",{children:[e.jsx("div",{className:"mb-2 text-xs uppercase tracking-wider text-muted-foreground",children:"Consumed from lots"}),l.data&&l.data.length>0?e.jsx("div",{className:"space-y-2",children:l.data.map(a=>e.jsxs("div",{className:"rounded-md border p-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"font-medium",children:a.raw_bean_lots?.raw_beans?.name??"â"}),e.jsx(m,{variant:"secondary",children:o(Number(a.kg_used))})]}),e.jsxs("div",{className:"mt-1 text-xs text-muted-foreground",children:["Lot ",e.jsx("span",{className:"font-mono",children:a.raw_bean_lots?.lot_code}
1),a.raw_bean_lots?.container_number?` ⢠Container ${a.raw_bean_lots.container_number}`:"",a.raw_bean_lots?.arrival_date?` ⢠Arrived ${a.raw_bean_lots.arrival_date}`:""]})]},a.id))}):e.jsx("p",{className:"text-xs text-muted-foreground",children:"No lot consumption recorded."})]})]})]})})}function n({label:s,value:r}){return e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wider text-muted-foreground",children:s}),e.jsx("div",{className:"mt-0.5 font-medium",children:r})]})}export{Q as component};
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.