1import{j as e}from"./ui-Cu1gnBpE.js";import{f as H,r as t}from"./vendor-C2oe7B4d.js";import{c as K,bJ as U,bK as W,s as z,p,au as j,q as P,b as u,A as G}from"./index-B9Jcbg0q.js";import{A as J,aq as V,w as N,S as Q,m as X,bP as Y}from"./charts-DxSaJjZU.js";import"./supabase-VOZc-uDy.js";import"./utils-BB_LO4AF.js";import"./admin-DWSwWI9J.js";import"./forms-CRAqh77y.js";const Z=new Set(["Produce","Vegetables","Dairy","Dairy & Eggs","Meat","Poultry","Seafood","Protein","Proteins","Bakery"]),f=a=>Z.has(a),A=a=>(a??0)===0,y=a=>(a??0)>0&&(a??0)<10,E=a=>(a??0)>=10&&(a??0)<25,ie=()=>{const a=H(),{toast:v}=K(),[d,L]=t.useState([]),[T,F]=t.useState([]),[l,M]=t.useState(""),[r,k]=t.useState(""),[O,w]=t.useState(!0),[n,R]=t.useState(null),{supplierId:x}=U(),[B,I]=t.useState([]),S=new Map;T.filter(s=>s.is_active).forEach(s=>{(s.target_products||[]).forEach(i=>{S.set(i,{discount:Math.min(100,Math.max(0,s.discount_percentage)),title:s.title})})});const _=t.useCallback(async()=>{try{const s={supplier_id:x};l&&(s.search=l),r&&(s.category=r);const o=(await W("list-products",s)).data||[];L(o),!l&&!r&&I([...new Set(o.map(c=>c.category).filter(Boolean))].sort())}catch(s){console.error("Error loading products:",s),v({title:"Couldn't load products",description:"Please check your connection and try again.",variant:"destructive"})}},[l,r,x,v]),q=t.useCallback(async()=>{const{data:s}=await z.from("supplier_promotions").select("*").eq("supplier_id",x).order("created_at",{ascending:!1});F(s||[])},[x]);t.useEffect(()=>{w(!0),Promise.all([_(),q()]).finally(()=>w(!1))},[x]);const C=t.useRef(!0);t.useEffect(()=>{if(C.current){C.current=!1;return}const s=setTimeout(()=>{_()},300);return()=>clearTimeout(s)},[l,r]);const h=d.filter(s=>y(s.stock_level)||A(s.stock_level)).length,g=d.filter(s=>f(s.category)&&(y(s.stock_level)||E(s.stock_level))).length;return e.jsxs("div",{className:"flex flex-col min-h-full bg-muted/30",children:[e.jsxs("div",{className:"bg-background border-b px-4 py-3 flex items-center gap-3 sticky top-0 z-10",children:[e.jsx("button",{onClick:()=>a(-1),className:"p-1 -ml-1 active:scale-90 transition-transform",children:e.jsx(J,{className:"h-5 w-5 text-foreground"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h1",{className:"text-lg font-bold text-foreground",children:"Product Catalog"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[d.length," products"]})]})]}),e.jsxs("div",{className:"flex-1 px-4 py-4 pb-28 space-y-4",children:[(h>0||g>0)&&e.jsxs("div",{className:"flex items-center gap-3 rounded-2xl border border-amber-200 dark:border-amber-800 bg-amber-50 dark:bg-amber-900/20 px-4 py-3",children:[e.jsx(V,{className:"h-4 w-4 text-amber-500 shrink-0"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3 text-xs",children:[h>0&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"font-semibold text-red-500",children:h}),e.jsx("span",{className:"text-foreground",children:"low/out of stock"})]}),g>0&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(N,{className:"h-3 w-3 text-amber-500"}),e.jsx("span",{className:"font-semibold text-amber-600",children:g}),e.jsx("span",{className:"text-foreground",children:"perishable items need attention"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"relative",children:[e.jsx(Q,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx("input",{type:"text",placeholder:"Search products...",value:l,onChange:s=>M(s.target.value),className:"w-full pl-9 pr-4 py-2.5 border rounded-xl text-sm bg-background text-foreground placeholder:text-muted-foreground outline-none focus:ring-2 focus:ring-primary/30"})]}),e.jsxs("div",{className:"flex gap-2 overflow-x-auto pb-1 -mx-4 px-4",children:[e.jsx("button",{onClick:()=>k(""),className:p("flex-shrink-0 px-3 py-1.5 rounded-full text-xs font-semibold border transition-all active:scale-95",r?"bg-card text-muted-foreground border-border":"bg-primary text-primary-foreground border-primary"),children:"All"}),B.map(s=>e.jsxs("button",{onClick:()=>k(s===r?"":s),className:p("flex-shrink-0 px-3 py-1.5 rounded-full text-xs font-semibold border transition-all active:scale-95",r===s?"bg-primary text-primary-foreground border-primary":"bg-card text-muted-foreground border-border"),children:[f(s)&&e.jsx(N,{className:"h-3 w-3 inline mr-1"}),s]},s))]})]}),O?e.jsx("div",{className:"space-y-3",children:Array.from({length:5}).map((s,i)=>e.jsxs("div",{className:"rounded-2xl border bg-card p-4 space-y-2",children:[e.jsx(j,{className:"h-5 w-40"}),e.jsx(j,{className:"h-4 w-24"}),e.jsx(j,{className:"h-4 w-32"})]},i))}):d.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-16",children:[e.jsx(X,{className:"h-12 w-12 text-muted-foreground
1/40 mb-4"}),e.jsx("p",{className:"text-base font-semibold text-foreground mb-1",children:"No products found"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Try adjusting your search or filters."})]}):e.jsx("div",{className:"space-y-2",children:d.map((s,i)=>{const o=S.get(s.id),c=!!o,D=c?s.price*(1-o.discount/100):s.price,m=A(s.stock_level),b=y(s.stock_level),$=f(s.category)&&E(s.stock_level);return e.jsxs(P.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},transition:{delay:i*.02},onClick:()=>R((n==null?void 0:n.id)===s.id?null:s),className:p("rounded-2xl border bg-card p-4 active:scale-[0.98] transition-all cursor-pointer",m&&"opacity-60"),children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap mb-1",children:[e.jsx("p",{className:"text-sm font-bold text-foreground",children:s.name}),f(s.category)&&e.jsx(N,{className:"h-3 w-3 text-emerald-500 shrink-0"})]}),e.jsxs("p",{className:"text-xs text-muted-foreground mb-1.5",children:[s.category," · SKU: ",s.sku]}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[m&&e.jsx(u,{variant:"destructive",className:"text-[10px] px-1.5 py-0",children:"OUT"}),b&&!m&&e.jsxs(u,{className:"text-[10px] px-1.5 py-0 bg-red-500/15 text-red-600 border-red-500/30",children:["LOW (",s.stock_level,")"]}),$&&!b&&!m&&e.jsxs(u,{className:"text-[10px] px-1.5 py-0 bg-amber-500/15 text-amber-600 border-amber-500/30",children:["WATCH (",s.stock_level,")"]}),c&&e.jsxs(u,{className:"text-[10px] px-1.5 py-0 bg-gradient-to-r from-purple-500 to-orange-500 text-white border-0 gap-0.5",children:[e.jsx(Y,{className:"h-2.5 w-2.5"})," ",o.discount,"% OFF"]})]})]}),e.jsxs("div",{className:"text-right shrink-0",children:[c?e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"text-xs text-muted-foreground line-through",children:["$",s.price.toFixed(2)]}),e.jsxs("p",{className:"text-base font-bold text-emerald-600",children:["$",D.toFixed(2)]})]}):e.jsxs("p",{className:"text-base font-bold text-foreground",children:["$",s.price.toFixed(2)]}),e.jsxs("p",{className:"text-[10px] text-muted-foreground",children:["/ ",s.unit]})]})]}),e.jsx(G,{children:(n==null?void 0:n.id)===s.id&&e.jsx(P.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},className:"overflow-hidden",children:e.jsxs("div",{className:"mt-3 pt-3 border-t space-y-2",children:[e.jsxs("div",{className:"flex justify-between text-xs",children:[e.jsx("span",{className:"text-muted-foreground",children:"Stock Level"}),e.jsxs("span",{className:p("font-semibold",m?"text-red-500":b?"text-amber-500":"text-foreground"),children:[s.stock_level??"N/A"," units"]})]}),e.jsxs("div",{className:"flex justify-between text-xs",children:[e.jsx("span",{className:"text-muted-foreground",children:"Category"}),e.jsx("span",{className:"text-foreground",children:s.category})]}),c&&e.jsxs("div",{className:"flex justify-between text-xs",children:[e.jsx("span",{className:"text-muted-foreground",children:"Promotion"}),e.jsx("span",{className:"text-primary font-semibold",children:o.title})]})]})})})]},s.id)})})]})]})};export{ie 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.