PageSourceSearch

https://custanova.com/assets/WarehouseDashboard-Bbfbw11H.js

js custanova.com collected 2026-10-03 20:09:53 UTC 74,643 bytes, 2 lines download raw bytes

1import{r as a,j as e}from"./vendor-react-BbG-g1cJ.js";import{B as Ce,C as ze,b as Ie,c as Be,f as De,d as Ee,e as Te,p as Le,g as Me,h as Fe,i as Re}from"./vendor-charts-C5hqWxMZ.js";import{GuidedTour as Ue}from"./GuidedTour-C0lcwB6G.js";import{u as me,b as ke,g as oe,o as $e}from"./main-Crx5jUUR.js";import{i as re}from"./inventoryService-oQ1qYhqW.js";import{J as H,bw as Q,ah as ve,b5 as J,cf as ce,ax as se,c9 as Ae,bn as be,E as ge,r as X,X as O,k as Ne,aA as he,aZ as xe,bM as Z,I as Pe,aL as ue,a1 as pe,aF as we,V as Ke,bf as ye,aY as Se,bg as We,R as Oe,Z as qe,l as Ve,ao as fe,aD as je,g as Ge,aj as He,c4 as Qe,bi as Ze}from"./vendor-lucide-CIXusJgP.js";import{P as Je}from"./PickListModal-IYviF3jK.js";import{_ as Xe}from"./vendor-pdf-cBcxTF1a.js";import{H as Ye,a as ie}from"./html5-qrcode-scanner-DGVCs8Fg.js";import{O as et}from"./OpsIntelligenceHub-COOsan8z.js";import"./vendor-monaco-DAVwsOto.js";import"./vendor-cmdk-BgeUCl9K.js";import"./vendor-framer-BF-Ey5gk.js";import"./vendor-zod-qMAaBktq.js";import"./vendor-date-Cnu4SYO9.js";
1import"./UpgradePlaceholder-4oBKFWgJ.js";const tt=()=>{const{tenantId:s,region:n}=me(),{addToast:o}=ke(),d=oe(n),c=re(d),[g,m]=a.useState(!0),[x,w]=a.useState([]),[y,D]=a.useState([]),[E,B]=a.useState([]),[f,S]=a.useState("skus"),[u,j]=a.useState(""),[M,$]=a.useState(!1),[_,F]=a.useState(!1),[T,A]=a.useState(null),[h,R]=a.useState(null),[p,N]=a.useState({title:"",sku:"",barcode:"",unit_of_measure:"units",reorder_point:0,tracking_type:"none",fulfillment_strategy:"fifo",category:"General"}),[b,I]=a.useState({name:"",zone:"",warehouse_id:"",capacity_volume:100,capacity_weight:1e3,is_active:!0}),L=async()=>{if(s){m(!0);try{const[t,i,k]=await Promise.all([c.getItems(s),c.getWarehouses(s),c.getBins(s)]);w(t),D(i),B(k),i.length>0&&!b.warehouse_id&&I(U=>({...U,warehouse_id:i[0].id}))}catch(t){console.error("Failed to fetch inventory data:",t)}finally{m(!1)}}};a.useEffect(()=>{L()},[s]);const q=a.useMemo(()=>x.filter(t=>t.title.toLowerCase().includes(u.toLowerCase())||t.sku.toLowerCase().includes(u.toLowerCase())),[x,u]),K=async t=>{if(t.preventDefault(),!!s){m(!0);try{T?(await c.updateItem(T.id,p),o({message:"SKU Updated Successfully",type:"success"})):(await c.createItem({...p,tenant_id:s}),o({message:"New SKU Created",type:"success"})),$(!1),A(null),N({title:"",sku:"",barcode:"",unit_of_measure:"units",reorder_point:0,tracking_type:"none",fulfillment_strategy:"fifo",category:"General"}),L()}catch{o({message:"Error saving SKU",type:"error"})}finally{m(!1)}}},Y=async t=>{if(confirm("Are you sure you want to delete this SKU? This will remove all associated stock records."))try{await c.deleteItem(t),o({message:"SKU Deleted",type:"success"}),L()}catch{o({message:"Error deleting SKU",type:"error"})}};return g&&x.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center p-20 space-y-4",children:[e.jsx(H,{className:"animate-spin text-brand-primary",size:32}),e.jsx("p",{className:"text-sm font-black uppercase tracking-widest text-gray-400",children:"Loading SKU Catalog..."})]}):e.jsxs("div",{className:"flex-1 flex flex-col h-full bg-white dark:bg-gray-800 rounded-[2.5rem] border border-gray-200 dark:border-gray-700 shadow-xl overflow-hidden",children:[e.jsxs("div",{className:"p-6 border-b border-gray-100 dark:border-gray-700 flex items-center justify-between bg-white/50 dark:bg-gray-800/50 backdrop-blur-md",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"text-xl font-black text-gray-900 dark:text-white uppercase tracking-tight flex items-center gap-3",children:[e.jsx(Q,{className:"text-indigo-600"})," Stock Catalog"]}),e.jsx("p",{className:"text-[10px] font-bold text-gray-400 uppercase tracking-widest mt-1",children:"Industrial Asset Configuration"})]}),e.jsxs("div",{className:"flex bg-gray-100 dark:bg-gray-900 p-1 rounded-xl",children:[e.jsx("button",{onClick:()=>S("skus"),className:`px-4 py-1.5 text-[10px] font-black uppercase tracking-widest rounded-lg transition-all ${f==="skus"?"bg-white dark:bg-gray-800 text-indigo-600 shadow-sm":"text-gray-400"}`,children:"SKU Catalog"}),e.jsx("button",{onClick:()=>S("bins"),className:`px-4 py-1.5 text-[10px] font-black uppercase tracking-widest rounded-lg transition-all ${f==="bins"?"bg-white dark:bg-gray-800 text-indigo-600 shadow-sm":"text-gray-400"}`,children:"Bin Registry"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx(ve,{size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-gray-400"}),e.jsx("input",{value:u,onChange:t=>j(t.target.value),placeholder:`Search ${f==="skus"?"SKUs":"Bins"}...`,className:"pl-10 pr-4 py-2 bg-gray-50 dark:bg-gray-900 border-0 rounded-xl text-sm w-64 outline-none focus:ring-2 focus:ring-indigo-500 transition-all font-medium"})]}),e.jsxs("button",{onClick:()=>f==="skus"?$(!0):F(!0),className:"bg-black dark:bg-white text-white dark:text-black px-4 py-2 rounded-xl text-xs font-black uppercase tracking-widest flex items-center gap-2 hover:scale-105 active:scale-95 transition-all shadow-lg",children:[e.jsx(J,{size:16})," ",f==="skus"?"Add SKU":"Add Bin"]})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-6 custom-scrollbar",children:f==="skus"?e.jsx("div",{className:"space-y-3",children:q.map(t=>e.jsxs("div",{className:"grid grid-cols-5 items-center p-4 bg-gray-50 dark:bg-gray-900/40 rounded-2xl border border-transparent hover:border-indigo-500/20 hover:bg-white dark:hover:bg-gray-800 transition-all group shadow-sm",children:[e.jsxs("div",{className:"col-span-2 flex items-center gap-4",children:[e.jsx("div",{className:"w-12 h-12 rounded-xl bg-white dark:bg-gray-900 border border-gray-100 dark:border-gray-700 flex items-center justify-center text-indigo-600 shadow-sm group-hover:scale-110 transition-transform",children:e.jsx(Q,{size:24})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-black text-gray-900 dark:text-white truncate",children:t.title}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsx("span",{className:"text-[10px] font-mono font-bold text-gray-400 uppercase bg-white dark:bg-gray-700 px-1.5 py-0.5 rounded border border-gray-100 dark:border-gray-600",children:t.sku}),e.jsx("span",{className:"text-[10px] font-bold text-indigo-500 uppercase",children:t.category})]})]})]}),e.jsx("div",{children:e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("span",{className:`inline-flex items-center gap-1.5 px-2 py-0.5 rounded-full text-[9px] font-black uppercase tracking-wider w-fit ${t.tracking_type==="serial"?"bg-amber-100 text-amber-700":t.tracking_type==="batch"?"bg-indigo-100 text-indigo-700":"bg-gray-100 text-gray-600"}`,children:[t.tracking_type==="serial"?e.jsx(ce,{size:10}):e.jsx(se,{size:10})," ",t.tracking_type]}),e.jsxs("span",{className:"text-[10px] font-bold text-gray-400 uppercase flex items-center gap-1",children:[e.jsx(Ae,{size:10})," ",t.fulfillment_strategy]})]})}),e.jsxs("div",{children:[e.jsxs("p",{className:`text-sm font-black ${t.current_stock<=t.reorder_point?"text-red-500":"text-gray-900 dark:text-white"}
1`,children:[t.current_stock.toLocaleString()," ",e.jsx("span",{className:"text-[10px] font-bold text-gray-400",children:t.unit_of_measure})]}),e.jsx("div",{className:"w-24 h-1 bg-gray-200 dark:bg-gray-700 rounded-full mt-2 overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full ${t.current_stock<=t.reorder_point?"bg-red-500":"bg-emerald-500"}`,style:{width:`${Math.min(100,t.current_stock/(t.reorder_point*2||1)*100)}%`}})})]}),e.jsxs("div",{className:"text-right flex justify-end gap-2",children:[e.jsx("button",{onClick:()=>{A(t),N(t),$(!0)},className:"p-2 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-xl text-gray-400 hover:text-indigo-600 transition-all",children:e.jsx(be,{size:16})}),e.jsx("button",{onClick:()=>Y(t.id),className:"p-2 hover:bg-red-50 dark:hover:bg-red-900/20 rounded-xl text-gray-400 hover:text-red-600 transition-all",children:e.jsx(ge,{size:16})})]})]},t.id))}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-5 px-4 text-[10px] font-black uppercase tracking-widest text-gray-400 mb-2",children:[e.jsx("div",{className:"col-span-2",children:"Bin / Warehouse"}),e.jsx("div",{children:"Zone"}),e.jsx("div",{children:"Current Load"}),e.jsx("div",{className:"text-right",children:"Actions"})]}),E.filter(t=>t.name.toLowerCase().includes(u.toLowerCase())||y.find(i=>i.id===t.warehouse_id)?.name.toLowerCase().includes(u.toLowerCase())).map(t=>e.jsxs("div",{className:"grid grid-cols-5 items-center p-4 bg-gray-50 dark:bg-gray-900/40 rounded-2xl border border-transparent hover:border-indigo-500/20 hover:bg-white dark:hover:bg-gray-800 transition-all group shadow-sm",children:[e.jsxs("div",{className:"col-span-2 flex items-center gap-4",children:[e.jsx("div",{className:"w-12 h-12 rounded-xl bg-white dark:bg-gray-900 border border-gray-100 dark:border-gray-700 flex items-center justify-center text-emerald-600 shadow-sm",children:e.jsx(X,{size:24})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-black text-gray-900 dark:text-white truncate",children:t.name}),e.jsx("p",{className:"text-[10px] font-bold text-gray-400 uppercase tracking-widest",children:y.find(i=>i.id===t.warehouse_id)?.name||"Unknown Warehouse"})]})]}),e.jsx("div",{children:e.jsx("span",{className:"text-[10px] font-black uppercase text-gray-500 bg-gray-100 dark:bg-gray-800 px-2 py-0.5 rounded-lg border border-gray-200 dark:border-gray-700",children:t.zone||"No Zone"})}),e.jsx("div",{children:e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("div",{className:"flex justify-between items-end w-24",children:e.jsxs("span",{className:"text-[9px] font-black text-gray-400 uppercase",children:["Vol: ",Math.round(t.current_occupancy_volume/(t.capacity_volume||1)*100),"%"]})}),e.jsx("div",{className:"w-24 h-1 bg-gray-200 dark:bg-gray-700 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-indigo-500 rounded-full",style:{width:`${Math.min(100,t.current_occupancy_volume/(t.capacity_volume||1)*100)}%`}})})]})}),e.jsxs("div",{className:"text-right flex justify-end gap-2",children:[e.jsx("button",{onClick:()=>{R(t),I(t),F(!0)},className:"p-2 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-xl text-gray-400 hover:text-indigo-600 transition-all",children:e.jsx(be,{size:16})}),e.jsx("button",{onClick:()=>{},className:"p-2 hover:bg-red-50 dark:hover:bg-red-900/20 rounded-xl text-gray-400 hover:text-red-600 transition-all",children:e.jsx(ge,{size:16})})]})]},t.id))]})}),M&&e.jsx("div",{className:"fixed inset-0 z-[110] flex items-center justify-center p-4 bg-black/60 backdrop-blur-sm animate-in fade-in duration-200",children:e.jsxs("div",{className:"bg-white dark:bg-gray-900 rounded-[2.5rem] shadow-2xl w-full max-w-2xl overflow-hidden border border-white/10 flex flex-col",children:[e.jsxs("div",{className:"p-6 border-b border-gray-100 dark:border-gray-800 flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-xl font-black text-gray-900 dark:text-white uppercase tracking-tight",children:T?"Edit SKU":"New SKU Configuration"}),e.jsx("p",{className:"text-[10px] font-bold text-gray-400 uppercase tracking-widest mt-1",children:"Master Inventory Record"})]}),e.jsx("button",{onClick:()=>{$(!1),A(null)},className:"p-2 hover:bg-gray-100 dark:hover:bg-gray-800 rounded-full text-gray-500",children:e.jsx(O,{size:20})})]}),e.jsxs("form",{onSubmit:K,className:"p-8 space-y-6 overflow-y-auto max-h-[70vh] custom-scrollbar",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-[10px] font-black uppercase tracking-widest text-indigo-500 ml-1",children:"Basic Info"}),e.jsx("input",{placeholder:"Item Title",required:!0,value:p.title,onChange:t=>N({...p,title:t.target.value}),className:"w-full px-4 py-3 bg-gray-50 dark:bg-gray-800 border-0 rounded-2xl text-sm font-bold outline-none ring-1 ring-gray-100 dark:ring-gray-700 focus:ring-2 focus:ring-indigo-500 transition-all"}),e.jsx("input",{placeholder:"SKU Code",required:!0,value:p.sku,onChange:t=>N({...p,sku:t.target.value}),className:"w-full px-4 py-3 bg-gray-50 dark:bg-gray-800 border-0 rounded-2xl text-sm font-mono font-bold outline-none ring-1 ring-gray-100 dark:ring-gray-700 focus:ring-2 focus:ring-indigo-500 transition-all uppercase"}),e.jsxs("div",{className:"relative group",children:[e.jsx(ce,{className:"absolute left-3 top-1/2 -translate-y-1/2 text-gray-400 group-focus-within:text-indigo-500",size:16}),e.jsx("input",{placeholder:"Global Barcode (GTIN/EAN)",value:p.barcode,onChange:t=>N({...p,barcode:t.target.value}),className:"w-full pl-10 pr-4 py-3 bg-gray-50 dark:bg-gray-800 border-0 rounded-2xl text-sm font-bold outline-none ring-1 ring-gray-100 dark:ring-gray-700 focus:ring-2 focus:ring-indigo-500 transition-all"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-[10px] font-black uppercase tracking-widest text-indigo-500 ml-1",children:"Logistics Parameters"}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx("input",{placeholder:"UoM (e.g. Kg)",value:p.unit_of_measure,onChange:t=>N({...p,unit_of_measure:t.target.value}),className:"w-1/2 px-4 py-3 bg-gray-50 dark:bg-gray-800 border-0 rounded-2xl text-sm font-bold outline-none ring-1 ring-gray-100 dark:ring-gray-700 focus:ring-2 focus:ring-indigo-500 transition-all"}),e.jsx("input",{type:"number",placeholder:"Reorder Point",value:p.reorder_point,onChange:t=>N({...p,reorder_point:parseInt(t.target.value)}),className:"w-1/2 px-4 py-3 bg-gray-50 dark:bg-gray-800 border-0 rounded-2xl text-sm font-bold outline-none ring-1 ring-gray-100 dark:ring-gray-700 focus:ring-2 focus:ring-indigo-500 transition-all"})]})]})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"text-[10px] font-black uppercase tracking-widest text-indigo-500 ml-1",children:"Fulfillment Mode"}),e.jsxs("div",{className:"grid grid-cols-1 gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>N({...p,tracking_type:"none"}),className:`p-4 rounded-2xl border text-left flex items-center gap-3 transition-all ${p.tracking_type==="none"?"bg-indigo-50 border-indigo-200 dark:bg-indigo-900/20 dark:border-indigo-800":"bg-gray-50 dark:bg-gray-800 border-transparent text-gray-500"}`,children:[e.jsx(se,{size:18}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-black uppercase tracking-tight",children:"Standard Quantity"}),e.jsx("p",{className:"text-[9px] font-bold opacity-60",children:"Bulk tracking (no batches)"})]})]}),e.jsxs("button",{type:"button",onClick:()=>N({...p,tracking_type:"batch"}),className:`p-4 rounded-2xl border text-left flex items-center gap-3 transition-all ${p.tracking_type==="batch"?"bg-indigo-50 border-indigo-200 dark:bg-indigo-900/20 dark:border-indigo-800":"bg-gray-50 dark:bg-gray-800 border-transparent text-gray-500"}`,children:[e.jsx(Ne,{size:18}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-black uppercase tracking-tight",children:"Batch Tracking"}),e.jsx("p",{className:"text-[9px] font-bold opacity-60",children:"Support for Expiry/Lots"})]})]}),e.jsxs("button",{type:"button",onClick:()=>N({...p,tracking_type:"serial"}),className:`p-4 rounded-2xl border text-left flex items-center gap-3 transition-all ${p.tracking_type==="serial"?"bg-indigo-50 border-indigo-200 dark:bg-indigo-900/20 dark:border-indigo-800":"bg-gray-50 dark:bg-gray-800 border-transparent text-gray-500"}`,children:[e.jsx(he,{size:18}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-black uppercase tracking-tight",children:"Unit Serial Tracking"}),e.jsx("p",{className:"text-[9px] font-bold opacity-60",children:"Individual lifecycle tracing"})]})]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"text-[10px] font-black uppercase tracking-widest text-indigo-500 ml-1",children:"Inventory Strategy"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:()=>N({...p,fulfillment_strategy:"fifo"}),className:`flex-1 py-3 rounded-xl border text-[10px] font-black uppercase tracking-widest transition-all ${p.fulfillment_strategy==="fifo"?"bg-black dark:bg-white text-white dark:text-black border-black dark:border-white shadow-lg":"bg-gray-50 dark:bg-gray-800 border-transparent text-gray-400"}`,children:"FIFO (Oldest First)"}),e.jsx("button",{type:"button",onClick:()=>N({...p,fulfillment_strategy:"lifo"}),className:`flex-1 py-3 rounded-xl border text-[10px] font-black uppercase tracking-widest transition-all ${p.fulfillment_strategy==="lifo"?"bg-black dark:bg-white text-white dark:text-black border-black dark:border-white shadow-lg":"bg-gray-50 dark:bg-gray-800 border-transparent text-gray-400"}`,children:"LIFO (Newest First)"})]})]})]})]}),e.jsxs("div",{className:"pt-6 border-t border-gray-100 dark:border-gray-800 flex justify-end gap-3",children:[e.jsx("button",{type:"button",onClick:()=>{$(!1),A(null)},className:"px-6 py-3 text-xs font-black uppercase tracking-widest text-gray-400 hover:text-gray-900 dark:hover:text-white transition-colors",children:"Cancel"}),e.jsx("button",{type:"submit",disabled:g,className:"bg-indigo-600 text-white px-10 py-3 rounded-2xl text-xs font-black uppercase tracking-widest hover:scale-105 active:scale-95 transition-all shadow-xl shadow-indigo-500/20 flex items-center gap-2",children:g?e.jsx(H,{size:16,className:"animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsx(xe,{size:16})," Save Configuration"]})})]})]})]})}),_&&e.jsx("div",{className:"fixed inset-0 z-[110] flex items-center justify-center p-4 bg-black/60 backdrop-blur-sm animate-in fade-in duration-200",children:e.jsxs("form",{onSubmit:async t=>{t.preventDefault(),m(!0);try{h?(await c.updateBin(h.id,b),o({message:"Bin Updated",type:"success"})):(await c.createBin({...b,tenant_id:s}),o({message:"Bin Created",type:"success"})),F(!1),R(null),I({name:"",zone:"",warehouse_id:y[0]?.id||"",capacity_volume:100,capacity_weight:1e3,is_active:!0}),L()}catch{o({message:"Error saving bin",type:"error"})}finally{m(!1)}},className:"bg-white dark:bg-gray-900 rounded-[2.5rem] shadow-2xl w-full max-w-lg overflow-hidden border border-white/10 flex flex-col",children:[e.jsxs("div",{className:"p-6 border-b border-gray-100 dark:border-gray-800 flex items-center justify-between",children:[e.jsx("h3",{className:"text-xl font-black text-gray-900 dark:text-white uppercase tracking-tight",children:h?"Edit Bin":"Add Physical Bin"}),e.jsx("button",{type:"button",onClick:()=>{F(!1),R(null)},className:"p-2 text-gray-500",children:e.jsx(O,{size:20})})]}),e.jsxs("div",{className:"p-8 space-y-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-[10px] font-black uppercase tracking-widest text-indigo-500",children:"Target Warehouse"}),e.jsxs("select",{required:!0,value:b.warehouse_id,onChange:t=>I({...b,warehouse_id:t.target.value}),className:"w-full px-4 py-3 bg-gray-50 dark:bg-gray-900 border-0 rounded-2xl text-sm font-bold outline-none ring-1 ring-gray-200 dark:ring-gray-700 transition-all",children:[e.jsx("option",{value:"",children:"-- Select Site --"}),y.map(t=>e.jsx("option",{value:t.id,children:t.name},t.id))]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-[10px] font-black uppercase tracking-widest text-indigo-500",children:"Bin Identifier"}),e.jsx("input",{required:!0,placeholder:"e.g. A-101",value:b.name,onChange:t=>I({...b,name:t.target.value}),className:"w-full px-4 py-3 bg-gray-50 dark:bg-gray-800 border-0 rounded-2xl text-sm font-bold outline-none ring-1 ring-gray-200 dark:ring-gray-700 transition-all"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-[10px] font-black uppercase tracking-widest text-indigo-500",children:"Rack / Zone"}),e.jsx("input",{placeholder:"e.g. North Rack",value:b.zone,onChange:t=>I({...b,zone:t.target.value}),className:"w-full px-4 py-3 bg-gray-50 dark:bg-gray-800 border-0 rounded-2xl text-sm font-bold outline-none ring-1 ring-gray-200 dark:ring-gray-700 transition-all"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-[10px] font-black uppercase tracking-widest text-indigo-500",children:"Volume (m³)"}),e.jsx("input",{type:"number",value:b.capacity_volume,onChange:t=>I({...b,capacity_volume:parseFloat(t.target.value)}),className:"w-full px-4 py-3 bg-gray-50 dark:bg-gray-800 border-0 rounded-2xl text-sm font-bold outline-none ring-1 ring-gray-200 dark:ring-gray-700 transition-all"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-[10px] font-black uppercase tracking-widest text-indigo-500",children:"Weight (kg)"}),e.jsx("input",{type:"number",value:b.capacity_weight,onChange:t=>I({...b,capacity_weight:parseFloat(t.target.value)}),className:"w-full px-4 py-3 bg-gray-50 dark:bg-gray-800 border-0 rounded-2xl text-sm font-bold outline-none ring-1 ring-gray-200 dark:ring-gray-700 transition-all"})]})]})]}),e.jsx("button",{type:"submit",disabled:g,className:"w-full bg-indigo-600 text-white py-4 rounded-2xl text-xs font-black uppercase tracking-widest shadow-xl shadow-indigo-500/20 active:scale-95 transition-all flex items-center justify-center gap-2",children:g?e.jsx(H,{className:"animate-spin",size:16}):"Finalize Physical Bin"})]})]})})]})},at=({isOpen:s,onClose:n,supabase:o,tenantId:d,userId:c,sourceBin:g,onSuccess:m})=>{const{addToast:x}
1=ke(),w=re(o),[y,D]=a.useState(!1),[E,B]=a.useState(!1),[f,S]=a.useState([]),[u,j]=a.useState([]),[M,$]=a.useState([]),[_,F]=a.useState(""),[T,A]=a.useState(),[h,R]=a.useState(1),[p,N]=a.useState(""),[b,I]=a.useState(""),L=async()=>{if(!(!d||!g)){B(!0);try{const[i,k]=await Promise.all([w.getWarehouses(d),w.getBinItems(g.id)]);S(i),$(k),N(g.warehouse_id),k.length>0&&(F(k[0].item_id),A(k[0].batch_id),R(k[0].quantity))}catch(i){console.error("Failed to load transfer data:",i)}finally{B(!1)}}},q=async i=>{if(d)try{const U=(await w.getBins(d)).filter(ee=>ee.warehouse_id===i&&ee.id!==g?.id);j(U),U.length>0?I(U[0].id):I("")}catch(k){console.error("Failed to load destination bins:",k)}};a.useEffect(()=>{s&&L()},[s,g]),a.useEffect(()=>{p&&q(p)},[p]);const K=async i=>{if(i.preventDefault(),!_||!b||h<=0){x({message:"Please complete all fields",type:"error"});return}D(!0);try{await w.transferStock(d,g.id,b,_,h,c,T),x({message:"Stock Transfer Successful",type:"success"}),m(),n()}catch(k){x({message:$e(k)||"Transfer failed",type:"error"})}finally{D(!1)}};if(!s||!g)return null;const t=M.find(i=>i.item_id===_&&i.batch_id===T)?.quantity||0;return e.jsx("div",{className:"fixed inset-0 z-[130] flex items-center justify-center p-4 bg-black/60 backdrop-blur-sm animate-in fade-in duration-200",children:e.jsxs("div",{className:"bg-white dark:bg-gray-900 rounded-[2.5rem] shadow-2xl w-full max-w-xl overflow-hidden border border-white/10 flex flex-col",children:[e.jsxs("div",{className:"p-6 border-b border-gray-100 dark:border-gray-800 flex items-center justify-between bg-gray-50/50 dark:bg-gray-900/50",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-xl font-black text-gray-900 dark:text-white uppercase tracking-tight flex items-center gap-2",children:[e.jsx(Z,{className:"text-indigo-600",size:24})," Stock Relocation"]}),e.jsxs("p",{className:"text-[10px] font-bold text-gray-400 uppercase tracking-widest mt-1",children:["Movement from ",g.name]})]}),e.jsx("button",{onClick:n,className:"p-2 hover:bg-gray-200 dark:hover:bg-gray-800 rounded-full text-gray-500 transition-colors",children:e.jsx(O,{size:20})})]}),e.jsxs("form",{onSubmit:K,className:"p-8 space-y-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-[10px] font-black uppercase tracking-widest text-indigo-500 ml-1",children:"Select Item to Move"}),e.jsxs("select",{value:`${_}|${T||""}`,onChange:i=>{const[k,U]=i.target.value.split("|");F(k),A(U||void 0)},className:"w-full px-4 py-4 bg-gray-50 dark:bg-gray-800 border-0 rounded-2xl text-sm font-bold outline-none ring-1 ring-gray-100 dark:ring-gray-700 focus:ring-2 focus:ring-indigo-500 transition-all",children:[M.map((i,k)=>e.jsxs("option",{value:`${i.item_id}|${i.batch_id||""}`,children:[i.inventory_items?.title," (",i.quantity," in bin) ",i.inventory_batches?`- Batch: ${i.inventory_batches.batch_number}`:""]},k)),M.length===0&&e.jsx("option",{value:"",children:"No items available in this bin"})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("label",{className:"text-[10px] font-black uppercase tracking-widest text-indigo-500 ml-1",children:["Transfer Quantity (Max: ",t,")"]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("input",{type:"number",min:1,max:t,value:h,onChange:i=>R(Math.min(t,parseInt(i.target.value)||0)),className:"flex-1 px-4 py-4 bg-gray-50 dark:bg-gray-800 border-0 rounded-2xl text-xl font-black outline-none ring-1 ring-gray-100 dark:ring-gray-700 focus:ring-2 focus:ring-indigo-500 transition-all text-center"}),e.jsx("button",{type:"button",onClick:()=>R(t),className:"px-4 py-4 bg-gray-100 dark:bg-gray-800 text-[10px] font-black text-indigo-600 rounded-2xl hover:bg-indigo-50 transition-all uppercase tracking-widest",children:"Max"})]})]})]}),e.jsxs("div",{className:"flex items-center justify-center py-2 opacity-20",children:[e.jsx("div",{className:"h-px flex-1 bg-gray-300"}),e.jsx(Z,{className:"mx-4",size:20}),e.jsx("div",{className:"h-px flex-1 bg-gray-300"})]}),e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-[10px] font-black uppercase tracking-widest text-indigo-500 ml-1",children:"Target Site"}),e.jsx("select",{value:p,onChange:i=>N(i.target.value),className:"w-full px-4 py-4 bg-gray-50 dark:bg-gray-800 border-0 rounded-2xl text-sm font-bold outline-none ring-1 ring-gray-100 dark:ring-gray-700 focus:ring-2 focus:ring-indigo-500 transition-all",children:f.map(i=>e.jsx("option",{value:i.id,children:i.name},i.id))})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-[10px] font-black uppercase tracking-widest text-indigo-500 ml-1",children:"Target Bin"}),e.jsxs("select",{value:b,onChange:i=>I(i.target.value),className:"w-full px-4 py-4 bg-gray-50 dark:bg-gray-800 border-0 rounded-2xl text-sm font-bold outline-none ring-1 ring-gray-100 dark:ring-gray-700 focus:ring-2 focus:ring-indigo-500 transition-all",children:[e.jsx("option",{value:"",children:"-- Choose Bin --"}),u.map(i=>
1e.jsxs("option",{value:i.id,children:[i.name," (",i.zone||"No Zone",")"]},i.id)),u.length===0&&e.jsx("option",{value:"",children:"No other bins at this site"})]})]})]})}),e.jsx("button",{type:"submit",disabled:y||M.length===0||!b,className:"w-full bg-indigo-600 text-white py-4 rounded-[2rem] text-sm font-black uppercase tracking-widest shadow-xl shadow-indigo-500/20 hover:scale-[1.02] active:scale-95 disabled:grayscale disabled:opacity-50 transition-all flex items-center justify-center gap-3",children:y?e.jsx(H,{className:"animate-spin",size:20}):e.jsxs(e.Fragment,{children:[e.jsx(Z,{size:20})," Authorize Relocation"]})})]})]})})},st=({isOpen:s,onClose:n,bin:o,supabase:d})=>{const c=re(d),{tenantId:g,user:m}=me(),[x,w]=a.useState(!0),[y,D]=a.useState([]),[E,B]=a.useState(!1);if(a.useEffect(()=>{s&&o&&(async()=>{w(!0);try{const u=await c.getBinItems(o.id);D(u)}catch(u){console.error("Failed to load bin items:",u)}finally{w(!1)}})()},[s,o]),!s||!o)return null;const f=o.capacity_volume>0?o.current_occupancy_volume/o.capacity_volume*100:0;return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[120] flex items-center justify-center p-4 bg-black/60 backdrop-blur-sm animate-in fade-in duration-200",children:e.jsxs("div",{className:"bg-white dark:bg-gray-900 rounded-[2.5rem] shadow-2xl w-full max-w-xl overflow-hidden border border-white/10 flex flex-col max-h-[85vh]",children:[e.jsxs("div",{className:"p-6 border-b border-gray-100 dark:border-gray-800 flex items-center justify-between bg-gray-50/50 dark:bg-gray-900/50",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-xl font-black text-gray-900 dark:text-white uppercase tracking-tight",children:[o.name," Details"]}),e.jsxs("p",{className:"text-[10px] font-bold text-gray-400 uppercase tracking-widest mt-1",children:["Zone: ",o.zone||"General"]})]}),e.jsx("button",{onClick:n,className:"p-2 hover:bg-gray-100 dark:hover:bg-gray-800 rounded-full text-gray-500 transition-colors",children:e.jsx(O,{size:20})})]}),e.jsxs("div",{className:"p-6 flex-1 overflow-y-auto custom-scrollbar space-y-6",children:[e.jsxs("div",{className:"p-4 bg-gray-50 dark:bg-gray-800/40 rounded-2xl border border-gray-100 dark:border-gray-800 flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[10px] font-black text-gray-400 uppercase tracking-widest",children:"Occupancy Level"}),e.jsxs("p",{className:"text-2xl font-black text-gray-900 dark:text-white",children:[Math.round(f),"%"]}),e.jsxs("p",{className:"text-[10px] font-bold text-gray-400",children:["Volume: ",o.current_occupancy_volume,"/",o.capacity_volume," m³"]})]}),e.jsxs("div",{className:"w-16 h-16 rounded-full border-4 border-gray-100 dark:border-gray-700 flex items-center justify-center relative",children:[e.jsx("div",{className:"absolute inset-0 rounded-full border-4 border-transparent border-t-indigo-600 transition-all",style:{transform:`rotate(${f/100*360}deg)`}}),e.jsx(se,{size:20,className:"text-indigo-600"})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h4",{className:"text-[10px] font-black uppercase tracking-widest text-indigo-500 ml-1",children:"Current Inventory"}),x?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 opacity-40 animate-pulse",children:[e.jsx(H,{className:"animate-spin mb-2",size:20}),e.jsx("p",{className:"text-[10px] font-bold uppercase tracking-[0.2em]",children:"Auditing Bin..."})]}):y.length>0?e.jsx("div",{className:"space-y-2",children:y.map((S,u)=>e.jsxs("div",{className:"p-4 bg-gray-50 dark:bg-gray-800 rounded-2xl border border-transparent hover:border-indigo-500/20 transition-all flex items-center gap-4 relative overflow-hidden group",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-white dark:bg-gray-900 border border-gray-100 dark:border-gray-700 flex items-center justify-center text-indigo-600 shadow-sm shrink-0",children:e.jsx(Q,{size:20})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-black text-gray-900 dark:text-white uppercase tracking-tight truncate",children:S.inventory_items?.title}),e.jsxs("div",{className:"flex items-center gap-3 mt-1",children:[e.jsx("span",{className:"text-[10px] font-mono font-bold text-gray-400",children:S.inventory_items?.sku}),S.inventory_batches&&e.jsxs("span",{className:"flex items-center gap-1 text-[9px] font-black uppercase text-amber-600 bg-amber-50 dark:bg-amber-900/20 px-1.5 py-0.5 rounded border border-amber-100 dar
1k:border-amber-800",children:[e.jsx(Ne,{size:8})," ",S.inventory_batches.batch_number]})]})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("p",{className:"text-lg font-black text-gray-900 dark:text-white leading-none",children:S.quantity}),e.jsx("p",{className:"text-[9px] font-bold text-gray-400 uppercase tracking-widest mt-1",children:S.inventory_items?.unit_of_measure})]})]},u))}):e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 opacity-30 border-2 border-dashed border-gray-100 dark:border-gray-800 rounded-2xl",children:[e.jsx(Pe,{size:32,className:"mb-2"}),e.jsx("p",{className:"text-xs font-black uppercase tracking-widest",children:"Bin is currently vacant"})]})]})]}),e.jsxs("div",{className:"p-6 bg-gray-50/50 dark:bg-gray-900/50 border-t border-gray-100 dark:border-gray-800 flex gap-3",children:[e.jsx("button",{onClick:n,className:"flex-1 py-3 text-[10px] font-black uppercase tracking-widest text-gray-500 hover:text-gray-900 dark:hover:text-white transition-colors",children:"Close View"}),e.jsxs("button",{onClick:()=>B(!0),className:"flex-1 bg-black dark:bg-white text-white dark:text-black py-3 rounded-xl text-[10px] font-black uppercase tracking-widest flex items-center justify-center gap-2 hover:scale-[1.02] transition-transform",children:[e.jsx(Z,{size:14})," Internal Transfer"]})]})]})}),e.jsx(at,{isOpen:E,onClose:()=>B(!1),supabase:d,tenantId:g||"",userId:m?.id||"",sourceBin:o,onSuccess:()=>{(async()=>{w(!0);try{const u=await c.getBinItems(o.id);D(u)}catch(u){console.error("Failed to load bin items:",u)}finally{w(!1)}})()}})]})},rt=({isOpen:s,onClose:n,onScan:o,title:d="Scan Barcode"})=>{const c=a.useRef(null);return a.useEffect(()=>{if(s){const g=setTimeout(()=>{const m=new Ye("qr-reader",{fps:10,qrbox:{width:250,height:150},aspectRatio:1,formatsToSupport:[ie.QR_CODE,ie.EAN_13,ie.CODE_128,ie.UPC_A,ie.UPC_E],showTorchButtonIfSupported:!0},!1);m.render(x=>{o(x),m.clear(),n()},x=>{}),c.current=m},300);return()=>{clearTimeout(g),c.current&&c.current.clear().catch(m=>console.warn("Scanner cleanup failed",m))}}},[s]),s?e.jsx("div",{className:"fixed inset-0 z-[200] flex flex-col items-center justify-center bg-black/90 backdrop-blur-xl animate-in fade-in duration-300",children:e.jsxs("div",{className:"w-full max-w-md p-6 flex flex-col items-center gap-8 h-full",children:[e.jsxs("div",{className:"w-full flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3 text-white",children:[e.jsx(ue,{className:"text-indigo-500"}),e.jsx("h3",{className:"font-black uppercase tracking-widest text-sm",children:d})]}),e.jsx("button",{onClick:n,className:"p-3 bg-white/10 hover:bg-white/20 rounded-full text-white transition-colors",children:e.jsx(O,{size:24})})]}),e.jsxs("div",{className:"w-full aspect-square relative rounded-[2rem] overflow-hidden border-2 border-indigo-500/50 shadow-2xl shadow-indigo-500/20",children:[e.jsx("div",{id:"qr-reader",className:"w-full h-full"}),e.jsx("div",{className:"absolute inset-0 pointer-events-none",children:e.jsxs("div",{className:"absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-64 h-32 border-2 border-emerald-500/80 rounded-xl",children:[e.jsx("div",{className:"absolute top-0 left-0 w-4 h-4 border-t-4 border-l-4 border-emerald-500 -ml-1 -mt-1"}),e.jsx("div",{className:"absolute top-0 right-0 w-4 h-4 border-t-4 border-r-4 border-emerald-500 -mr-1 -mt-1"}),e.jsx("div",{className:"absolute bottom-0 left-0 w-4 h-4 border-b-4 border-l-4 border-emerald-500 -ml-1 -mt-1"}),e.jsx("div",{className:"absolute bottom-0 right-0 w-4 h-4 border-b-4 border-r-4 border-emerald-500 -mr-1 -mt-1"}),e.jsx("div",{className:"w-full h-0.5 bg-emerald-500/40 absolute top-1/2 -translate-y-1/2 animate-pulse"})]})})]}),e.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center text-center space-y-4",children:[e.jsx("p",{className:"text-indigo-300/80 text-xs font-bold uppercase tracking-widest animate-pulse",children:"Align Barcode within the frame"}),e.jsx("p",{className:"text-white/40 text-[10px] font-medium max-w-xs uppercase leading-relaxed",children:"Supports Industrial Standards: EAN-13, CODE-128, UPC, and QR"})]})]})}):null},it=({isOpen:s,onClose:n,supabase:o,tenantId:d,userId:c,onSuccess:g})=>
1{const m=re(o),[x,w]=a.useState(1),[y,D]=a.useState(!1),[E,B]=a.useState([]),[f,S]=a.useState([]),[u,j]=a.useState([]),[M,$]=a.useState([]),[_,F]=a.useState(""),[T,A]=a.useState(""),[h,R]=a.useState(null),[p,N]=a.useState("1"),[b,I]=a.useState(""),[L,q]=a.useState(""),[K,Y]=a.useState(""),[t,i]=a.useState([]),[k,U]=a.useState(""),[ee,te]=a.useState(!1),[ne,ae]=a.useState("item");a.useEffect(()=>{s&&d&&(async()=>{D(!0);try{const[l,v]=await Promise.all([m.getWarehouses(d),m.getItems(d)]);B(l),j(v),l.length>0&&F(l[0].id)}finally{D(!1)}})()},[s,d]),a.useEffect(()=>{_&&m.getBins(d,_).then(S)},[_]),a.useEffect(()=>{h&&h.tracking_type==="batch"&&m.getBatches(d,h.id).then($)},[h]);const W=async()=>{if(!(!T||!h||!p)){D(!0);try{let r=b;L&&(r=(await m.createBatch({tenant_id:d,item_id:h.id,batch_number:L,expiry_date:K||void 0})).id),await m.receiveStock(d,h.id,T,parseInt(p),c,r||void 0,t.length>0?t:void 0);const l=(await Xe(async()=>{const{default:v}=await import("./confetti.module-C94ZD2ww.js");return{default:v}},[])).default;l({particleCount:150,spread:70,origin:{y:.6},colors:["#4f46e5","#10b981","#f59e0b"]}),g(),n()}catch(r){console.error("Receive failed:",r)}finally{D(!1)}}};if(!s)return null;const de=()=>{if(x===1)return!T;if(x===2)return!h;if(x===3){if(h?.tracking_type==="batch")return!b&&!L;if(h?.tracking_type==="serial")return t.length===0}return!1};return e.jsxs("div",{className:"fixed inset-0 z-[100] flex items-center justify-center p-4 bg-black/60 backdrop-blur-sm animate-in fade-in duration-200",children:[e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-[2.5rem] shadow-2xl w-full max-w-xl overflow-hidden border border-white/10 flex flex-col max-h-[90vh]",children:[e.jsxs("div",{className:"p-6 border-b border-gray-100 dark:border-gray-700 flex items-center justify-between bg-gray-50/50 dark:bg-gray-900/50",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-xl font-black text-gray-900 dark:text-white uppercase tracking-tight",children:"Receive Inventory"}),e.jsx("p",{className:"text-[10px] font-bold text-gray-400 uppercase tracking-widest mt-1",children:"Industrial Inbound Protocol"})]}),e.jsx("button",{onClick:n,className:"p-2 hover:bg-gray-200 dark:hover:bg-gray-700 rounded-full transition-colors text-gray-500",children:e.jsx(O,{size:20})})]}),e.jsxs("div",{className:"p-6 flex-1 overflow-y-auto custom-scrollbar",children:[e.jsx("div",{className:"flex justify-center gap-2 mb-8",children:[1,2,3,4].map(r=>e.jsx("div",{className:`h-1.5 rounded-full transition-all ${x===r?"w-8 bg-indigo-500":"w-2 bg-gray-200 dark:bg-gray-700"}`},r))}),x===1&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"text-[10px] font-black uppercase tracking-widest text-indigo-500 ml-1",children:"1. Select Target Site"}),e.jsx("div",{className:"grid grid-cols-1 gap-3",children:E.map(r=>e.jsxs("button",{onClick:()=>F(r.id),className:`p-4 rounded-2xl border transition-all text-left flex items-center justify-between group ${_===r.id?"bg-indigo-50 border-indigo-200 dark:bg-indigo-900/20 dark:border-indigo-800":"bg-gray-50 border-gray-100 dark:bg-gray-900/40 dark:border-gray-800 hover:border-gray-300"}`,children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`p-2 rounded-xl ${_===r.id?"bg-indigo-500 text-white shadow-lg shadow-indigo-500/20":"bg-white dark:bg-gray-800 text-gray-400 group-hover:text-indigo-500"} transition-colors`,children:e.jsx(X,{size:18})}),e.jsx("span",{className:`text-sm font-bold ${_===r.id?"text-indigo-600 dark:text-indigo-400":"text-gray-600 dark:text-gray-300"}`,children:r.name})]}),_===r.id&&e.jsx(pe,{size:18,className:"text-indigo-500"})]},r.id))})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"text-[10px] font-black uppercase tracking-widest text-indigo-500 ml-1",children:"2. Select Target Bin"}),e.jsx("div",{className:"grid grid-cols-2 gap-3",children:f.map(r=>e.jsx("button",{onClick:()=>A(r.id),className:`p-3 rounded-xl border text-xs font-bold transition-all ${T===r.id?"bg-indigo-500 border-indigo-600 text-white shadow-lg":"bg-gray-50 border-gray-100 dark:bg-gray-900/40 dark:border-gray-800 hover:border-indigo-300 text-gray-600 dark:text-gray-300"}`,children:r.name},r.id))})]})]}),x===2&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between ml-1",children:[e.jsx("label",{className:"text-[10px] font-black uppercase tracking-widest text-indigo-500",children:"Select SKU to Receive"}),e.jsxs("button",{onClick:()=>{ae("item"),te(!0)},className:"flex items-center gap-1.5 px-3 py-1 bg-indigo-50 dark:bg-indigo-900/40 text-indigo-600 dark:text-indigo-400 rounded-lg text-[10px] font-black uppercase tracking-wider hover:bg-indigo-100 transition-colors",children:[e.jsx(ue,{size:12})," Scan Barcode"]})]}),e.jsx("div",{className:"space-y-2",children:u.map(r=>e.jsxs("button",{onClick:()=>R(r),className:`w-full p-4 rounded-2xl border transition-all text-left flex items-center justify-between group ${h?.id===r.id?"bg-indigo-50 border-indigo-200 dark:bg-indigo-900/20 dark:border-indigo-800":"bg-gray-50 border-gray-100 dark:bg-gray-900/40 dark:border-gray-800"}`,children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 bg-white dark:bg-gray-800 rounded-xl text-gray-400 group-hover:text-indigo-500 transition-colors border border-gray-100 dark:border-gray-700",children:e.jsx(Q,{size:20})}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"text-sm font-bold text-gray-900 dark:text-white leading-none",children:r.title}),r.tracking_type!=="none"&&e.jsxs("span",{className:"text-[8px] font-black uppercase bg-amber-100 text-amber-700 px-1 rounded flex items-center gap-0.5",children:[r.tracking_type==="batch"?e.jsx(se,{size:8}):e.jsx(ce,{size:8})," ",r.tracking_type]})]}),e.jsx("p",{className:"text-[10px] font-mono font-bold text-gray-400 uppercase tracking-tighter mt-1",children:r.sku})]})]}),h?.id===r.id&&e.jsx(pe,{size:18,className:"text-indigo-500"})]},r.id))})]}),x===3&&h&&e.jsxs("div",{className:"space-y-6",children:[h.tracking_type==="batch"&&e.jsxs("div",{className:"space-y-4",children:[e.jsx("label",{className:"text-[10px] font-black uppercase tracking-widest text-indigo-500 ml-1",children:"Batch / Lot Tracking"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("select",{value:b,onChange:r=>I(r.target.value),className:"w-full px-4 py-3 bg-gray-50 dark:bg-gray-900 border-0 rounded-xl text-sm font-bold outline-none ring-1 ring-gray-200 dark:ring-gray-700 focus:ring-2 focus:ring-indigo-500",children:[e.jsx("option",{value:"",children:"-- Use Existing Batch --"}),M.map(r=>
1e.jsxs("option",{value:r.id,children:[r.batch_number," ",r.expiry_date?`(Exp: ${new Date(r.expiry_date).toLocaleDateString()})`:""]},r.id))]}),e.jsxs("div",{className:"relative flex items-center gap-2",children:[e.jsx("div",{className:"h-px bg-gray-200 dark:bg-gray-700 flex-1"}),e.jsx("span",{className:"text-[9px] font-black text-gray-400 uppercase tracking-widest",children:"OR Create New"}),e.jsx("div",{className:"h-px bg-gray-200 dark:bg-gray-700 flex-1"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx("input",{placeholder:"New Batch #",value:L,onChange:r=>{q(r.target.value),I("")},className:"px-4 py-3 bg-gray-50 dark:bg-gray-900 border-0 rounded-xl text-sm font-bold outline-none ring-1 ring-gray-200 dark:ring-gray-700 focus:ring-2 focus:ring-indigo-500"}),e.jsx("input",{type:"date",value:K,onChange:r=>Y(r.target.value),className:"px-4 py-3 bg-gray-50 dark:bg-gray-900 border-0 rounded-xl text-sm font-bold outline-none ring-1 ring-gray-200 dark:ring-gray-700 focus:ring-2 focus:ring-indigo-500"})]})]})]}),h.tracking_type==="serial"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between ml-1",children:[e.jsx("label",{className:"text-[10px] font-black uppercase tracking-widest text-indigo-500",children:"Serial Registration"}),e.jsxs("button",{onClick:()=>{ae("serial"),te(!0)},className:"flex items-center gap-1.5 px-3 py-1 bg-indigo-50 dark:bg-indigo-900/40 text-indigo-600 dark:text-indigo-400 rounded-lg text-[10px] font-black uppercase tracking-wider hover:bg-indigo-100 transition-colors",children:[e.jsx(ue,{size:12})," Scan Serial"]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{placeholder:"Enter Serial Number",value:k,onChange:r=>U(r.target.value),onKeyDown:r=>{r.key==="Enter"&&k&&(i([...t,k]),U(""))},className:"flex-1 px-4 py-3 bg-gray-50 dark:bg-gray-900 border-0 rounded-xl text-sm font-bold outline-none ring-1 ring-gray-200 dark:ring-gray-700 focus:ring-2 focus:ring-indigo-500"}),e.jsx("button",{onClick:()=>{k&&(i([...t,k]),U(""))},className:"p-3 bg-indigo-600 text-white rounded-xl",children:e.jsx(J,{size:18})})]}),e.jsx("div",{className:"grid grid-cols-2 gap-2 max-h-40 overflow-y-auto pr-2 custom-scrollbar",children:t.map((r,l)=>e.jsxs("div",{className:"flex items-center justify-between p-2 bg-indigo-50 dark:bg-indigo-900/20 rounded-lg border border-indigo-100 dark:border-indigo-800",children:[e.jsx("span",{className:"text-[10px] font-mono font-bold text-indigo-700 dark:text-indigo-400",children:r}),e.jsx("button",{onClick:()=>i(t.filter((v,V)=>V!==l)),children:e.jsx(O,{size:12,className:"text-red-500"})})]},l))}),e.jsxs("p",{className:"text-[10px] font-bold text-gray-400 uppercase text-center",children:[t.length," units registered"]})]}),h.tracking_type==="none"&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-20 opacity-40",children:[e.jsx(he,{size:48,className:"text-indigo-600 mb-4"}),e.jsx("p",{className:"text-xs font-black uppercase tracking-widest",children:"Standard Tracking"}),e.jsx("p",{className:"text-[10px] font-bold mt-1 text-center",children:"No batch or serial registration required for this SKU."})]})]}),x===4&&h&&e.jsxs("div",{className:"space-y-8 py-4",children:[e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx("div",{className:"w-20 h-20 bg-indigo-50 dark:bg-indigo-900/30 rounded-3xl flex items-center justify-center text-indigo-600 dark:text-indigo-400 mb-4 shadow-inner",children:e.jsx(se,{size:32})}),e.jsx("h4",{className:"text-xl font-black text-gray-900 dark:text-white tracking-tight",children:h.title}),e.jsx("p",{className:"text-xs font-bold text-gray-400 uppercase tracking-widest mt-1",children:"Final Verification"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"p-4 bg-gray-50 dark:bg-gray-900/40 rounded-2xl border border-gray-100 dark:border-gray-800",children:[e.jsx("p",{className:"text-[10px] font-black text-gray-400 uppercase tracking-widest mb-1",children:"Target Bin"}),e.jsx("p",{className:"text-sm font-bold text-gray-900 dark:text-white",children:f.find(r=>r.id===T)?.name})]}),e.jsxs("div",{className:"p-4 bg-gray-50 dark:bg-gray-900/40 rounded-2xl border border-gray-100 dark:border-gray-800",children:[e.jsx("p",{className:"text-[10px] font-black text-gray-400 uppercase tracking-widest mb-1",children:"Batch / Info"}),e.jsx("p",{className:"text-sm font-bold text-indigo-600",children:L||M.find(r=>r.id===b)?.batch_number||"Standard"})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"text-[10px] font-black uppercase tracking-widest text-indigo-500 ml-1",children:"Confirm Quantity"}),h.tracking_type==="serial"?e.jsx("div",{className:"w-full text-center text-4xl font-black bg-gray-100 dark:bg-gray-800 border-0 rounded-[1.5rem] py-6 text-indigo-600 shadow-inner",children:t.length}):e.jsx("input",{type:"number",value:p,onChange:r=>N(r.target.value),className:"w-full text-center text-4xl font-black bg-gray-50 dark:bg-gray-900/80 border-0 rounded-[1.5rem] py-6 focus:ring-2 focus:ring-indigo-500 transition-all text-gray-900 dark:text-white shadow-inner"})]})]})]}),e.jsxs("div",{className:"p-6 bg-gray-50/50 dark:bg-gray-900/50 border-t border-gray-100 dark:border-gray-700 flex justify-between gap-3",children:[x>1?e.jsx("button",{onClick:()=>w(x-1),className:"px-6 py-3 font-bold text-xs uppercase tracking-widest text-gray-500 hover:text-gray-900 dark:hover:text-white",children:"Back"}):e.jsx("div",{}),x<4?e.jsxs("button",{disabled:y||de(),onClick:()=>{x===3&&h?.tracking_type==="serial"&&N(t.length.toString()),w(x+1)},className:"bg-black dark:bg-white text-white dark:text-black hover:scale-105 active:scale-95 transition-all px-8 py-3 rounded-2xl text-xs font-black uppercase tracking-[0.2em] shadow-xl disabled:opacity-50 flex items-center gap-2",children:["Next Step ",e.jsx(we,{size:16})]}):e.jsx("button",{disabled:y,onClick:W,className:"bg-indigo-600 text-white hover:scale-105 active:scale-95 transition-all px-12 py-4 rounded-2xl text-sm font-black uppercase tracking-[0.2em] shadow-xl shadow-indigo-500/20 disabled:opacity-50 flex items-center gap-3",children:y?e.jsx(H,{size:20,className:"animate-spin"}):"Finalize Receipt"})]})]}),e.jsx(rt,{isOpen:ee,onClose:()=>te(!1),onScan:r=>{if(ne==="item"){const l=u.find(v=>v.barcode===r||v.sku===r);l&&R(l)}else ne==="serial"&&(t.includes(r)||i([...t,r]))}})]})},nt=({isOpen:s,onClose:n,supabase:o,tenantId:d,onSuccess:c})=>
1{const g=re(o),[m,x]=a.useState(!1),[w,y]=a.useState([]),[D,E]=a.useState(!1),[B,f]=a.useState({name:"",location:"",is_active:!0}),S=async()=>{x(!0);try{const j=await g.getWarehouses(d);y(j)}catch(j){console.error("Fetch warehouses failed:",j)}finally{x(!1)}};a.useEffect(()=>{s&&d&&S()},[s,d]);const u=async j=>{j.preventDefault(),x(!0);try{await g.createWarehouse({...B,tenant_id:d,metadata:{}}),E(!1),f({name:"",location:"",is_active:!0}),S(),c()}catch(M){console.error("Create warehouse failed:",M)}finally{x(!1)}};return s?e.jsx("div",{className:"fixed inset-0 z-[110] flex items-center justify-center p-4 bg-black/60 backdrop-blur-sm animate-in fade-in duration-200",children:e.jsxs("div",{className:"bg-white dark:bg-gray-900 rounded-[2.5rem] shadow-2xl w-full max-w-2xl overflow-hidden border border-white/10 flex flex-col max-h-[85vh]",children:[e.jsxs("div",{className:"p-6 border-b border-gray-100 dark:border-gray-800 flex items-center justify-between bg-gray-50/50 dark:bg-gray-900/50",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-xl font-black text-gray-900 dark:text-white uppercase tracking-tight",children:"Regional Sites"}),e.jsx("p",{className:"text-[10px] font-bold text-gray-400 uppercase tracking-widest mt-1",children:"Multi-Warehouse Network Management"})]}),e.jsx("button",{onClick:n,className:"p-2 hover:bg-gray-200 dark:hover:bg-gray-800 rounded-full transition-colors text-gray-500",children:e.jsx(O,{size:20})})]}),e.jsx("div",{className:"p-8 flex-1 overflow-y-auto custom-scrollbar space-y-8",children:D?e.jsxs("form",{onSubmit:u,className:"space-y-6 animate-in slide-in-from-top-4 duration-300",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-[10px] font-black uppercase tracking-widest text-indigo-500 ml-1",children:"Site Identity"}),e.jsx("input",{required:!0,placeholder:"Site Name (e.g. JHB Central Hub)",value:
1B.name,onChange:j=>f({...B,name:j.target.value}),className:"w-full px-4 py-4 bg-gray-50 dark:bg-gray-800 border-0 rounded-2xl text-sm font-bold outline-none ring-1 ring-gray-100 dark:ring-gray-700 focus:ring-2 focus:ring-indigo-500 transition-all"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-[10px] font-black uppercase tracking-widest text-indigo-500 ml-1",children:"Geographic Location"}),e.jsxs("div",{className:"relative",children:[e.jsx(Ke,{className:"absolute left-4 top-1/2 -translate-y-1/2 text-gray-400",size:18}),e.jsx("input",{placeholder:"Physical Address or Region",value:B.location,onChange:j=>f({...B,location:j.target.value}),className:"w-full pl-12 pr-4 py-4 bg-gray-50 dark:bg-gray-800 border-0 rounded-2xl text-sm font-bold outline-none ring-1 ring-gray-100 dark:ring-gray-700 focus:ring-2 focus:ring-indigo-500 transition-all"})]})]})]}),e.jsxs("div",{className:"flex gap-3 pt-4 border-t border-gray-100 dark:border-gray-800",children:[e.jsx("button",{type:"button",onClick:()=>E(!1),className:"flex-1 py-4 text-xs font-black uppercase tracking-widest text-gray-400 hover:text-gray-900 dark:hover:text-white transition-colors",children:"Cancel"}),e.jsx("button",{type:"submit",disabled:m,className:"flex-1 bg-indigo-600 text-white py-4 rounded-2xl text-xs font-black uppercase tracking-widest shadow-xl shadow-indigo-500/20 hover:scale-[1.02] active:scale-95 transition-all flex items-center justify-center gap-2",children:m?e.jsx(H,{size:16,className:"animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsx(pe,{size:16})," Commission Site"]})})]})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h4",{className:"text-[10px] font-black uppercase tracking-widest text-gray-400",children:[w.length," Sites Active"]}),e.jsxs("button",{onClick:()=>E(!0),className:"text-[10px] font-black uppercase tracking-widest text-indigo-600 hover:text-indigo-700 flex items-center gap-1",children:[e.jsx(J,{size:12})," Add New Site"]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-3",children:[w.map(j=>e.jsxs("div",{className:"p-5 bg-gray-50 dark:bg-gray-800 rounded-2xl border border-transparent shadow-sm flex items-center justify-between group hover:border-indigo-500/20 transition-all",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"w-12 h-12 rounded-xl bg-white dark:bg-gray-900 border border-gray-100 dark:border-gray-700 flex items-center justify-center text-indigo-600 shadow-sm",children:e.jsx(ye,{size:24})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-black text-gray-900 dark:text-white uppercase tracking-tight",children:j.name}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsx(X,{size:10,className:"text-gray-400"}),e.jsx("span",{className:"text-[10px] font-bold text-gray-400",children:j.location||"No location set"})]})]})]}),e.jsx("button",{className:"p-2 text-gray-300 hover:text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20 rounded-lg transition-all opacity-0 group-hover:opacity-100",children:e.jsx(ge,{size:16})})]},j.id)),w.length===0&&!m&&e.jsxs("div",{className:"py-12 border-2 border-dashed border-gray-100 dark:border-gray-800 rounded-2xl flex flex-col items-center justify-center opacity-40",children:[e.jsx(ye,{size:32,className:"mb-2"}),e.jsx("p",{className:"text-xs font-black uppercase tracking-widest",children:"No warehouses configured"})]})]})]})}),e.jsx("div",{className:"p-6 bg-gray-50/50 dark:bg-gray-900/50 border-t border-gray-100 dark:border-gray-800",children:e.jsx("button",{onClick:n,className:"w-full py-4 text-[10px] font-black uppercase tracking-widest text-gray-500 hover:text-gray-900 dark:hover:text-white transition-colors",children:"Close Site Manager"})})]})}):null},le=({label:s,value:n,subtext:o,color:d,icon:c})=>e.jsx("div",{className:"bg-white dark:bg-gray-800 rounded-2xl p-4 border border-gray-100 dark:border-gray-700 shadow-sm hover:shadow-md transition-shadow",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"w-12 h-12 rounded-xl flex items-center justify-center text-white shadow-lg",style:{backgroundColor:d},children:c}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-bold uppercase tracking-wider text-gray-400",children:s}),e.jsx("p",{className:"text-2xl font-black text-gray-900 dark:text-white leading-tight",children:n}),e.jsx("p",{className:"text-[10px] text-gray-400 font-medium mt
1-0.5",children:o})]})]})}),lt=({bin:s,onClick:n})=>{const o=s.capacity_volume>0?s.current_occupancy_volume/s.capacity_volume:0;let d="bg-gray-50 dark:bg-gray-900/40",c="border-gray-200 dark:border-gray-800",g="text-gray-400";return o>.9?(d="bg-red-500",c="border-red-600",g="text-white"):o>.7?(d="bg-orange-500",c="border-orange-600",g="text-white"):o>.4?(d="bg-amber-400",c="border-amber-500",g="text-gray-900"):o>0&&(d="bg-emerald-400",c="border-emerald-500",g="text-gray-900"),e.jsxs("button",{onClick:n,className:`w-full aspect-square rounded-lg border ${d} ${c} flex flex-col items-center justify-center p-1 transition-transform hover:scale-105 active:scale-95 group relative shadow-sm`,title:`${s.name}: ${(o*100).toFixed(0)}% full`,children:[e.jsx("span",{className:`text-[10px] font-black uppercase tracking-tighter ${g}`,children:s.name.split("-").pop()}),e.jsx("div",{className:"absolute inset-0 bg-white/10 opacity-0 group-hover:opacity-100 transition-opacity rounded-lg"})]})},dt=({items:s})=>e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-4 px-4 text-[10px] font-black uppercase tracking-widest text-gray-400 mb-2",children:[e.jsx("div",{className:"col-span-2",children:"Item / SKU"}),e.jsx("div",{children:"Category"}),e.jsx("div",{className:"text-right",children:"Stock Level"})]}),e.jsxs("div",{className:"space-y-2",children:[s.map(n=>e.jsxs("div",{className:"grid grid-cols-4 items-center p-4 bg-gray-50 dark:bg-gray-900/40 rounded-2xl border border-transparent hover:border-brand-primary/20 hover:bg-white dark:hover:bg-gray-800 transition-all group cursor-pointer shadow-sm hover:shadow-md",children:[e.jsxs("div",{className:"col-span-2 flex items-center gap-4",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-white dark:bg-gray-800 border border-gray-100 dark:border-gray-700 flex items-center justify-center text-brand-primary group-hover:scale-110 transition-transform shadow-sm",children:n.image_url?e.jsx("img",{src:n.image_url,className:"w-full h-full object-cover rounded-xl",alt:""}):e.jsx(Se,{size:20})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-bold text-gray-900 dark:text-white line-clamp-1",children:n.title}),e.jsx("p",{className:"text-[10px] font-mono font-bold text-gray-400 uppercase tracking-tighter",children:n.sku})]})]}),e.jsx("div",{children:e.jsx("span",{className:"inline-flex px-2 py-0.5 rounded-full bg-indigo-50 dark:bg-indigo-900/30 text-indigo-600 dark:text-indigo-300 text-[10px] font-black uppercase tracking-wider",children:n.category||"General"})}),e.jsx("div",{className:"text-right",children:e.jsxs("div",{className:"inline-flex items-center gap-3",children:[e.jsxs("div",{className:"text-right",children:[e.jsx("p",{className:`text-sm font-black ${n.current_stock<=n.reorder_point?"text-red-500":"text-gray-900 dark:text-white"}`,children:n.current_stock.toLocaleString()}),e.jsx("p",{className:"text-[9px] font-bold text-gray-400 uppercase",children:n.unit_of_measure})]}),e.jsx(we,{size:16,className:"text-gray-300 group-hover:translate-x-1 transition-transform"})]})})]},n.id)),s.length===0&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-20 opacity-40",children:[e.jsx(se,{size:48,className:"mb-4"}),e.jsx("p",{className:"text-sm font-black uppercase tracking-widest",children:"No matching inventory"})]})]})]}),ot=({bins:s,onBinClick:n})=>{const o=a.useMemo(()=>{const d={};return s.forEach(c=>{const g=c.zone||"Default";d[g]||(d[g]=[]),d[g].push(c)}),d},[s]);return e.jsxs("div",{className:"space-y-8",children:[Object.entries(o).map(([d,c])=>e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h3",{className:"text-xs font-black uppercase tracking-widest text-indigo-600 dark:text-indigo-400 flex items-center gap-2",children:[e.jsx(X,{size:12})," Zone: ",d]}),e.jsxs("span",{className:"text-[10px] font-bold text-gray-400",children:[c.length," Active Bins"]})]}),e.jsxs("div",{className:"grid grid-cols-4 sm:grid-cols-6 md:grid-cols-8 lg:grid-cols-10 xl:grid-cols-12 gap-3",children:[c.map(g=>e.jsx(lt,{bin:g,onClick:()=>n(g)},g.id)),e.jsx("button",{className:"w-full aspect-square rounded-lg border-2 border-dashed border-gray-200 dark:border-gray-700 flex items-center justify-center text-gray-400 hover:border-brand-primary hover:text-brand-primary transition-all",children:e.jsx(J,{size:16})})]})]},d)),Object.keys(o).length===0&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-20 opacity-40",children:[e.jsx(X,{size:48,className:"mb-4"}),e.jsx("p",{className:"text-sm font-black uppercase tracking-widest",children:"No bins configured for this site"})]})]})},ct=({movements:s})=>e.jsxs("div",{className:"space-y-4",children:[s.map(n=>e.jsxs("div",{className:"flex items-center gap-4 p-4 bg-gray-50 dark:bg-gray-900/40 rounded-2xl border border-gray-100 dark:border-gray-700 relative group overflow-hidden",children:[e.jsx("div",{className:`absolute left-0 top-0 bottom-0 w-1 ${n.type==="RECEIVE"?"bg-emerald-500":n.type==="PICK"?"bg-amber-500":"bg-indigo-500"}`}),e.jsx("div",{className:`w-10 h-10 rounded-xl flex items-center justify-center shrink-0 ${n.type==="RECEIVE"?"bg-emerald-100 text-emerald-600":n.type==="PICK"?"bg-amber-100 text-amber-600":"bg-indigo-100 text-indigo-600"}`,children:n.type==="RECEIVE"?e.jsx(J,{size:20}):e.jsx(Z,{size:20})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("p",{className:"text-sm font-black text-gray-900 dark:text-white uppercase tracking-tight",children:[n.type," ",n.quantity," ",n.inventory_items?.unit_of_measure||"units"]}),e.jsx("span",{className:"text-[10px] font-bold text-gray-400",children:"•"}),e.jsx("p",{className:"text-xs font-bold text-gray-600 dark:text-gray-300 truncate font-mono",children:n.inventory_items?.title||"Unknown Item"})]}),e.jsxs("p",{className:"text-[10px] font-bold text-gray-400 mt-1 flex items-center gap-3",children:[e.jsx("span",{children:new Date(n.created_at).toLocaleStr
1ing()}),n.reason&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"w-1 h-1 rounded-full bg-gray-300"})," ",e.jsx("span",{children:n.reason})]})]})]}),e.jsx("div",{className:"text-right",children:e.jsx("button",{className:"p-2 text-gray-400 hover:text-black dark:hover:text-white transition-colors",children:e.jsx(We,{size:16})})})]},n.id)),s.length===0&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-20 opacity-40",children:[e.jsx(Z,{size:48,className:"mb-4"}),e.jsx("p",{className:"text-sm font-black uppercase tracking-widest",children:"No stock movements recorded"})]})]});ze.register(Ie,Be,De,Ee,Te,Le,Me,Fe,Re);const Ct=()=>{const{tenantId:s,region:n,user:o}=me(),d=oe(n),c=re(d),[g,m]=a.useState(!0),[x,w]=a.useState([]),[y,D]=a.useState([]),[E,B]=a.useState([]),[f,S]=a.useState(""),[u,j]=a.useState("inventory"),[M,$]=a.useState([]),[_,F]=a.useState(""),[T,A]=a.useState(!1),[h,R]=a.useState(!1),[p,N]=a.useState(!1),[b,I]=a.useState(null),[L,q]=a.useState([]),[K,Y]=a.useState([]),[t,i]=a.useState([]),[k,U]=a.useState([]),[ee,te]=a.useState(!1),ne=[{target:"warehouse-header",title:"Warehouse Console",content:"The definitive interface for multi-site inventory and logistics consistency."},{target:"warehouse-stats",title:"Operational Pulse",content:"High-level KPIs covering SKU health, floor utilization, and stock alerts."},{target:"warehouse-tabs",title:"Inventory Ledger",content:"View and search your full SKU catalog across all facilities.",onShow:()=>j("inventory")},{target:"warehouse-tabs",title:"Visual Floor Matrix",content:"Switch to the Bin Heatmap to see real-time capacity and occupancy across your physical layout.",onShow:()=>j("bins")},{target:"warehouse-tabs",title:"Immutable Audit Trail",content:"Every movement (Receive, Pick, Transfer) is recorded with a cryptographically verifiable trail.",onShow:()=>j("movements")}];a.useEffect(()=>{if(!s)return;(async()=>{m(!0);try{const v=await c.getWarehouses(s);$(v),v.length>0&&F(v[0].id)}catch(v){console.error("Warehouse load failed:",v)}finally{m(!1)}})()},[s]);const ae=async()=>{if(!s||!_)return;const l=oe(n);try{const[v,V,P,C,z,G,_e]=await Promise.all([c.getBins(s,_),c.getItems(s),c.getMovements(s),l.from("tasks").select("*").eq("tenant_id",s).eq("is_delivery",!0).limit(20),l.from("invoices").select("*").eq("tenant_id",s).order("issued_at",{ascending:!1}).limit(20),l.from("forms").select("*").eq("tenant_id",s),l.from("form_submissions").select("*").eq("tenant_id",s).order("created_at",{ascending:!1}).limit(20)]);w(v),D(V),B(P),q(C.data||[]),Y(z.data||[]),i(G.data||[]),U(_e.data||[])}catch(v){console.error("Data sync failed:",v)}};a.useEffect(()=>{ae()},[s,_]);const W=a.useMemo(()=>{const l=y.filter(z=>z.current_stock<=z.reorder_point).length,v=y.reduce((z,G)=>z+G.current_stock,0),V=x.length>0?Math.round(x.reduce((z,G)=>z+(G.capacity_volume>0?G.current_occupancy_volume/G.capacity_volume:0),0)/x.length*100):0,P=[];l>0&&P.push({type:"low_stock",message:`${l} SKUs are below reorder threshold.`});const C=x.find(z=>z.capacity_volume>0&&z.current_occupancy_volume/z.capacity_volume>.9);return C&&P.push({type:"capacity",message:`Bin ${C.name} is at critical capacity (${Math.round(C.current_occupancy_volume/C.capacity_volume*100)}%).`}),{totalSKUs:y.length,lowStock:l,totalItemsOrdered:v,avgOccupancy:V,alerts:P}},[y,x]),de=a.useMemo(()=>y.filter(l=>l.title?.toLowerCase().includes(f.toLowerCase())||l.sku?.toLowerCase().includes(f.toLowerCase())||l.barcode?.includes(f)),[y,f]),r=a.useMemo(()=>{const l=Array.from({length:7},(P,C)=>{const z=new Date;return z.setDate(z.getDate()-(6-C)),z.toISOString().split("T")[0]}),v=l.map(P=>E.filter(C=>C.created_at.startsWith(P)&&(C.type==="RECEIVE"||C.type==="RETURN")).reduce((C,z)=>C+z.quantity,0)),V=l.map(P=>E.filter(C=>C.created_at.startsWith(P)&&(C.type==="PICK"||C.type==="SHIPPED")).reduce((C,z)=>C+z.quantity,0));return{labels:l.map(P=>new Date(P).toLocaleDateString(void 0,{weekday:"short"})),datasets:[{label:"Inbound",data:v,backgroundColor:"rgba(79, 70, 229, 0.8)",borderRadius:6},{label:"Outbound",data:V,backgroundColor:"rgba(16, 185, 129, 0.8)",borderRadius:6}]}},[E]);return g?e.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center p-12 space-y-4",children:[e.jsx(Oe,{size:32,className:"text-brand-primary animate-spin"}),e.jsx("p",{className:"text-sm font-bold text-gray-500 uppercase tracking-widest animate-pulse",children:"Synchronizing Inventory Ledger..."})]}):e.jsxs("div",{className:"flex-1 flex flex-col h-full bg-gray-50 dark:bg-gray-900/50 overflow-hidden",children:[e.jsxs("div",{className:"p-4 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between","data-tour-id":"warehouse-header",children:[e.jsxs("div",{className:"flex items-center gap-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-black text-gray-900 dark:text-white uppercase tracking-tight",children:"Warehouse Console"}),e.jsxs("p",{className:"text-xs font-bold text-gray-400 flex items-center gap-1.5 uppercase tracking-wider",children:[e.jsx(qe,{size:10,
1className:"text-amber-500"})," Real-time Logistics Consistency"]})]}),e.jsxs("div",{className:"h-10 px-4 bg-white dark:bg-gray-800 rounded-xl border border-gray-100 dark:border-gray-700 flex items-center gap-3 shadow-sm",children:[e.jsx(X,{size:14,className:"text-indigo-500"}),e.jsx("select",{value:_,onChange:l=>F(l.target.value),className:"bg-transparent text-[11px] font-black uppercase tracking-widest text-gray-700 dark:text-gray-200 outline-none cursor-pointer",children:M.map(l=>e.jsx("option",{value:l.id,children:l.name},l.id))}),e.jsx("button",{onClick:()=>N(!0),className:"p-1.5 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-lg text-gray-400 hover:text-indigo-600 transition-colors",children:e.jsx(J,{size:14})})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{onClick:()=>te(!0),className:"flex items-center gap-2 px-4 py-2 bg-white dark:bg-slate-800 text-[10px] font-black uppercase tracking-widest rounded-xl border border-slate-200 dark:border-slate-700 hover:bg-slate-50 transition-all",children:"Take a Tour"}),e.jsxs("button",{onClick:()=>A(!0),className:"flex items-center gap-2 px-4 py-2 bg-black dark:bg-white text-white dark:text-black text-xs font-black uppercase tracking-widest rounded-xl hover:scale-105 transition-all shadow-lg border border-white/10",children:[e.jsx(J,{size:14})," Receive Stock"]}),e.jsxs("button",{onClick:()=>R(!0),className:"flex items-center gap-2 px-4 py-2 bg-indigo-600 text-white text-xs font-black uppercase tracking-widest rounded-xl hover:bg-black transition-all shadow-lg shadow-indigo-500/20",children:[e.jsx(Ve,{size:14})," Plan Pick List"]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4","data-tour-id":"warehouse-stats",children:[e.jsx(le,{label:"Total SKUs",value:W.totalSKUs,subtext:"Managed items",color:"#4f46e5",icon:e.jsx(Q,{size:20})}),e.jsx(le,{label:"Low Stock",value:W.lowStock,subtext:"Requires reorder",color:"#ef4444",icon:e.jsx(fe,{size:20})}),e.jsx(le,{label:"Units on Hand",value:W.totalItemsOrdered.toLocaleString(),subtext:"Full floor count",color:"#10b981",icon:e.jsx(Se,{size:20})}),e.jsx(le,{label:"Floor Utilization",value:`${W.avgOccupancy}%`,subtext:"Capacity heatmap",color:"#f59e0b",icon:e.jsx(je,{size:20})})]}),e.jsx("div",{className:"mt-6 px-4",children:e.jsx(et,{inventoryItems:y,tasks:L,invoices:K,forms:t,formSubmissions:k,region:n})})]}),e.jsxs("div",{className:"flex-1 flex gap-4 p-4 pt-0 min-h-0",children:[e.jsxs("div",{className:"w-64 flex flex-col gap-4 shrink-0",children:[e.jsx("div",{className:"bg-white dark:bg-gray-800 rounded-2xl border border-gray-100 dark:border-gray-700 p-2 space-y-1 overflow-hidden shadow-sm","data-tour-id":"warehouse-tabs",children:[{id:"inventory",icon:Q,label:"SKU Inventory",count:y.length},{id:"bins",icon:je,label:"Bin Heatmap",count:x.length},{id:"movements",icon:Z,label:"Audit Trail",count:E.length},{id:"manage",icon:xe,label:"Manage SKUs"}].map(l=>e.jsxs("button",{onClick:()=>j(l.id),className:`w-full flex items-center justify-between px-3 py-2.5 rounded-xl text-sm font-bold transition-all ${u===l.id?"bg-indigo-50 dark:bg-indigo-900/30 text-indigo-600 dark:text-indigo-400 shadow-sm":"text-gray-500 hover:bg-gray-100 dark:hover:bg-gray-700/50"}`,children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(l.icon,{size:18})," ",l.label]}),l.count!==void 0&&e.jsx("span",{className:"text-[10px] bg-white dark:bg-gray-700 px-1.5 py-0.5 rounded-full border border-gray-100 dark:border-gray-600",children:l.count})]},l.id))}),e.jsxs("div",{className:"bg-indigo-900/90 rounded-2xl p-4 text-white shadow-xl shadow-indigo-500/10 relative overflow-hidden group",children:[e.jsx("div",{className:"absolute top-0 right-0 w-32 h-32 bg-white/10 rounded-full blur-3xl -mr-16 -mt-16 group-hover:scale-150 transition-transform duration-700"}),e.jsx("h4",{className:"text-[10px] font-black uppercase tracking-widest opacity-60 mb-3",children:"Live Fleet Alerts"}),e.jsx("div",{className:"space-y-3 relative z-10",children:W.alerts.length>0?W.alerts.map((l,v)=>e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(fe,{size:14,className:`${l.type==="capacity"?"text-red-400":"text-amber-400"} mt-0.5 shrink-0`}),e.jsx("p",{className:"text-[11px] font-bold leading-tight",children:l.message})]},v)):e.jsxs("div",{className:"flex items-start gap-2 opacity-60",children:[e.jsx(he,{size:14,className:"text-emerald-400 mt-0.5"}),e.jsx("p",{className:"text-[11px] font-bold leading-tight",children:"All systems n
1ominal. No stock deviations detected."})]})})]}),e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-2xl p-5 border border-gray-100 dark:border-gray-700 shadow-sm",children:[e.jsx("div",{className:"flex items-center justify-between mb-4",children:e.jsxs("h4",{className:"text-[10px] font-black uppercase tracking-widest text-indigo-500 flex items-center gap-2",children:[e.jsx(Ge,{size:12})," Velocity Trend"]})}),e.jsx("div",{className:"h-32",children:e.jsx(Ce,{data:r,options:{responsive:!0,maintainAspectRatio:!1,plugins:{legend:{display:!1}},scales:{x:{grid:{display:!1},ticks:{font:{size:8,weight:"bold"}}},y:{grid:{color:"rgba(0,0,0,0.05)"},ticks:{font:{size:8,weight:"bold"}}}}}})})]})]}),e.jsxs("div",{className:"flex-1 bg-white dark:bg-gray-800 rounded-[2.5rem] border border-gray-200 dark:border-gray-700 shadow-xl overflow-hidden flex flex-col",children:[e.jsxs("div",{className:"p-6 border-b border-gray-100 dark:border-gray-700 flex items-center justify-between bg-white/50 dark:bg-gray-800/50 backdrop-blur-md sticky top-0 z-20",children:[e.jsxs("h2",{className:"text-lg font-black text-gray-900 dark:text-white uppercase tracking-wide flex items-center gap-3",children:[u==="inventory"&&e.jsxs(e.Fragment,{children:[e.jsx(Q,{className:"text-brand-primary"})," Global Stock Consistency"]}),u==="bins"&&e.jsxs(e.Fragment,{children:[e.jsx(X,{className:"text-brand-primary"})," Visual Floor Matrix"]}),u==="movements"&&e.jsxs(e.Fragment,{children:[e.jsx(He,{className:"text-brand-primary"})," Immutable Sync Protocol"]}),u==="manage"&&e.jsxs(e.Fragment,{children:[e.jsx(xe,{className:"text-brand-primary"})," Master SKU Config"]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"relative group",children:[e.jsx(ve,{size:16,className:"absolute left-3 top-1/2 -translate-y-1/2 text-gray-400 group-focus-within:text-brand-primary transition-colors"}),e.jsx("input",{value:f,onChange:l=>S(l.target.value),placeholder:"Search warehouse...",className:"pl-10 pr-4 py-2 bg-gray-50 dark:bg-gray-900 border border-transparent focus:border-brand-primary focus:bg-white dark:focus:bg-gray-800 text-sm rounded-xl outline-none transition-all w-64 shadow-inner"})]}),e.jsx("button",{className:"p-2.5 rounded-xl bg-gray-50 dark:bg-gray-900 text-gray-400 hover:text-brand-primary hover:bg-gray-100 transition-all border border-transparent hover:border-brand-primary/20",children:e.jsx(Qe,{size:18})}),e.jsx("button",{className:"p-2.5 rounded-xl bg-gray-50 dark:bg-gray-900 text-gray-400 hover:text-brand-primary hover:bg-gray-100 transition-all border border-transparent hover:border-brand-primary/20",children:e.jsx(Ze,{size:18})})]})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-6 custom-scrollbar",children:[u==="inventory"&&e.jsx(dt,{items:de}),u==="bins"&&e.jsx(ot,{bins:x,onBinClick:I}),u==="movements"&&e.jsx(ct,{movements:E}),u==="manage"&&e.jsx(tt,{})]})]})]}),e.jsx(it,{isOpen:T,onClose:()=>A(!1),supabase:d,tenantId:s||"",userId:o?.id||"",onSuccess:ae}),e.jsx(Je,{isOpen:h,onClose:()=>R(!1),supabase:d,tenantId:s||"",warehouseId:_,userId:o?.id||"",onSuccess:ae}),e.jsx(st,{isOpen:!!b,onClose:()=>I(null),bin:b,supabase:d}),e.jsx(nt,{isOpen:p,onClose:()=>N(!1),supabase:d,tenantId:s||"",onSuccess:async()=>{const l=await c.getWarehouses(s||"");$(l)}}),ee&&e.jsx(Ue,{steps:ne,onClose:()=>te(!1)})]})};export{Ct as default};
2//# sourceMappingURL=WarehouseDashboard-Bbfbw11H.js.map

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.