PageSourceSearch

https://offers2.lovable.app/assets/FlaggedStock-C2t8VD07.js

js offers2.lovable.app collected 2026-10-03 03:36:46 UTC 43,436 bytes, 6 lines download raw bytes

1import{R as Ze,_ as Oe,r as y,bP as O,b$ as $e,j as e,z as ye,A as _e,F as ve,G as je,B as I,h as S,a6 as Xe,a1 as Je,L as P,g as Pe,l as es,s as g,$ as _,k as Be,n as Qe,I as ge,Y as ss,u as z,aC as ts,e as Re,f as he,K as Ke,bT as as,bQ as ze,C as ns,c as os,P as rs}from"./index-UhpylRvY.js";import{b as is}from"./staffHandover-CxwdfiVT.js";import{u as G}from"./useMutation-DDUPvvZi.js";import{T as cs,a as ls,b as se,c as te}from"./tabs-gHTCexuJ.js";import{D as me,a as pe,b as fe,c as L}from"./dropdown-menu-DgqNukXk.js";import{S as ds}from"./switch-B3dNii4R.js";import{T as us}from"./thumbnail-image-LnekvR4i.js";import{L as Z}from"./label-8WyDtcYj.js";import{R as gs,a as hs}from"./radio-group-gq3hQKq_.js";import{S as ms,a as ps,b as fs,c as xs,d as ys}from"./select-DMiC7NCu.js";import{M as Ge}from"./map-pin-1LLayUj6.js";import{A as _s}from"./arrow-left-BIXO1-F9.js";import{C as re}from"./chevron-down-Dr6pKxk8.js";import{C as vs,a as js,b as ws}from"./collapsible-Cv1IGgSt.js";import{C as bs}from"./chevron-right-DRjDX2gG.js";import{u as ks}from"./useCurrentStaff-C6YHUQ-2.js";import{I as Ns}from"./InvestigationDetailDialog-Dd74M8oR.js";import{P as Ss}from"./package-search-D6riY7it.js";import{E as Ie}from"./eye-off-kxinSfzQ.js";import{R as Me}from"./recycle-kPkA-Nup.js";import"./index-5vnHJd8E.js";import"./check-CmVMxEt6.js";import"./circle-BZrQEsnn.js";import"./index-LrataqBD.js";import"./chevron-up-I27GzVCW.js";import"./index-DElkbwns.js";import"./popover-DR9GCW9A.js";import"./hash-JRlVmU3A.js";import"./circle-check-DACR-5mb.js";import"./file-text-Bu0M4Pk7.js";import"./wrench-BQKQu4-Q.js";import"./formatDistanceToNow-BA31f_eQ.js";import"./constructNow-T1DMWgyJ.js";import"./constructFrom-DWjd9ymD.js";import"./compareAsc-CHfyVEbt.js";import"./constants-BEUXd630.js";import"./differenceInCalendarMonths-C940wegS.js";import"./endOfDay-D_u90-W9.js";import"./endOfMonth-vwEZmsY1.js";import"./getRoundingMethod-D0I6Z7xl.js";import"./differenceInMilliseconds-CY041Hv9.js";import"./en-US-ClfMaaVW.js";import"./getTimezoneOffsetInMilliseconds-8oUTNwRy.js";import"./format-C-8x8zgz.js";import"./differenceInCalendarDays-Bz1OIFRn.js";/**
2 * @license lucide-react v0.462.0 - ISC
3 *
4 * This source code is licensed under the ISC license.
5 * See the LICENSE file in the root directory of this source tree.
6 */const Ae=Ze("FolderSearch",[["path",{d:"M10.7 20H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v4.1",key:"1bw5m7"}],["path",{d:"m21 21-1.9-1.9",key:"1g2n9r"}],["circle",{cx:"17",cy:"17",r:"3",key:"18b49y"}]]),Cs=["Shop floor","Processing","Upstairs","Back stock","Bay 1","Bay 2","Bay 3","Bay 4"];function Ds({open:t,onOpenChange:r,item:a,onComplete:l}){const{user:i}=Oe(),[n,m]=y.useState("found"),[c,v]=y.useState("good"),[b,T]=y.useState(""),[k,j]=y.useState(""),[w,p]=y.useState(null),[f,C]=y.useState(null),[F,M]=y.useState(!1),q=()=>{m("found"),v("good"),T(""),j(""),p(null),C(null),M(!1)},X=h=>{h||q(),r(h)},ie=h=>{var R;const E=(R=h.target.files)==null?void 0:R[0];E&&(p(E),C(URL.createObjectURL(E)))},H=async()=>{if(a){M(!0);try{let h=null;if(w){const R=w.name.split(".").pop(),U=`flagged/${a.shopify_id}/${Date.now()}.${R}`,{error:V}=await g.storage.from("sourcing-images").upload(U,w);if(V)throw V;const{data:J}=g.storage.from("sourcing-images").getPublicUrl(U);h=J.publicUrl}const{error:E}=await g.from("shopify_products").update({last_sourced_at:new Date().toISOString(),location:b||null}).eq("shopify_id",a.shopify_id);if(E)throw E;await g.from("sourcing_logs").insert({sourcing_task_id:null,user_name:(i==null?void 0:i.email)||"Staff",action_type:"found",notes:`Sourced from Flagged Stock. Condition: ${c}. ${k||""}`.trim(),image_url:h,sourced_via:"desktop"}),_.success("Item sourced and verified"),q(),r(!1),l()}catch(h){_.error(h.message||"Failed to complete sourcing")}finally{M(!1)}}},$=async()=>{if(a){M(!0);try{const{data:h}=await g.from("missing_investigations").select("id").eq("shopify_product_id",a.shopify_id).in("status",["active","investigating"]).maybeSingle();if(!h){const{error:E}=await g.from("missing_investigations").insert({shopify_product_id:a.shopify_id,a_code:a.sku||null,status:"active",started_at:new Date().toISOString(),started_by:(i==null?void 0:i.email)||"Staff",investigation_notes:[],search_attempts:[]});if(E)throw E}await g.from("missing_item_searches").insert({shopify_product_id:a.shopify_id,a_code:a.sku||null,searched_by:(i==null?void 0:i.email)||"Staff",searched_at:new Date().toISOString(),found:!1,notes:"Searched from Flagged Stock — item not found",areas_checked:["Flagged Stock review"]}),_.success("Item added to Missing Investigation"),q(),r(!1),l()}catch(h){_.error(h.message||"Failed to create investigation")}finally{M(!1)}}};if(!a)return null;const Q=O(a.images),A=$e(a.vendor);return e.jsx(ye,{open:t,onOpenChange:X,children:e.jsxs(_e,{className:"max-w-lg max-h-[90vh] overflow-y-auto",children:[e.jsx(ve,{children:e.jsx(je,{children:"Mark as Found"})}),e.jsxs("div",{className:"flex gap-3",children:[Q?e.jsx("img",{src:Q,alt:"",className:"w-28 h-28 object-cover rounded-lg flex-shrink-0"}):e.jsx("div",{className:"w-28 h-28 bg-muted rounded-lg flex items-center justify-center text-muted-foreground text-xs flex-shrink-0",children:"No image"}),e.jsxs("div",{className:"space-y-1 text-sm min-w-0",children:[e.jsx("p",{className:"font-mono font-bold",children:a.sku||"—"}),e.jsx("p",{className:"text-muted-foreground line-clamp-2",children:a.title}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Qty: ",a.inventory_quantity??0]}),A&&e.jsx(I,{className:"bg-orange-500 text-white text-xs",children:"🟠 CONSIGNMENT"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Source: Flagged Stock"})]})]}),n==="found"&&e.jsxs("div",{className:"space-y-4 pt-2",children:[e.jsxs("div",{children:[e.jsx(Z,{className:"mb-2 block",children:"Verification Photo (optional)"}),f?e.jsxs("div",{className:"relative w-full max-w-xs",children:[e.jsx("img",{src:f,alt:"Preview",className:"rounded-lg border max-h-48 object-cover w-full"}),e.jsx(S,{variant:"outline",size:"sm",className:"mt-2",onClick:()=>{p(null),C(null)},children:"Remove"})]}):e.jsxs("label",{className:"flex flex-col items-center justify-center h-28 border-2 border-dashed rounded-lg cursor-pointer hover:bg-muted/50 transition-colors",children:[e.jsx(Xe,{className:"h-7 w-7 text-muted-foreground mb-1"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Tap to take photo"}),e.jsx("input",{type:"file",accept:"image/*",className:"hidden",onChange:ie})]})]}),e.jsxs("div",{children:[e.jsxs(Z,{className:"mb-2 block flex items-center gap-1",children:[e.jsx(Ge,{className:"h-4 w-4"})," Where did you find it?"]}
6),e.jsxs(ms,{value:b,onValueChange:T,children:[e.jsx(ps,{children:e.jsx(fs,{placeholder:"Select location"})}),e.jsx(xs,{children:Cs.map(h=>e.jsx(ys,{value:h,children:h},h))})]})]}),e.jsxs("div",{children:[e.jsx(Z,{className:"mb-2 block",children:"Condition"}),e.jsx(gs,{value:c,onValueChange:v,className:"flex gap-4",children:[{value:"good",label:"Good"},{value:"minor_issues",label:"Minor Issues"},{value:"damaged",label:"Damaged"}].map(h=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(hs,{value:h.value,id:`src-cond-${h.value}`}),e.jsx(Z,{htmlFor:`src-cond-${h.value}`,children:h.label})]},h.value))})]}),e.jsxs("div",{children:[e.jsx(Z,{className:"mb-2 block",children:"Notes (optional)"}),e.jsx(Je,{value:k,onChange:h=>j(h.target.value),placeholder:"Any details...",rows:2})]}),e.jsxs(S,{onClick:H,disabled:F,className:"w-full bg-green-600 hover:bg-green-700 text-white",children:[F?e.jsx(P,{className:"h-4 w-4 animate-spin mr-2"}):e.jsx(Pe,{className:"h-4 w-4 mr-2"}),"Mark as Found"]}),e.jsx("div",{className:"text-center pt-1",children:e.jsx("button",{type:"button",className:"text-sm text-muted-foreground underline hover:text-destructive transition-colors",onClick:()=>m("cannot_find"),children:"I cannot find this item →"})})]}),n==="cannot_find"&&e.jsxs("div",{className:"space-y-4 pt-2",children:[e.jsxs(S,{variant:"ghost",size:"sm",onClick:()=>m("found"),className:"gap-1 -ml-2",children:[e.jsx(_s,{className:"h-4 w-4"})," Back"]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"This will create a Missing Investigation for this item. The item will appear in the Missing Investigation queue for further follow-up."}),e.jsxs(S,{onClick:$,disabled:F,variant:"destructive",className:"w-full",children:[F?e.jsx(P,{className:"h-4 w-4 animate-spin mr-2"}):e.jsx(es,{className:"h-4 w-4 mr-2"}),"Mark as Not Found — Start Investigation"]})]})]})})}const le=t=>`R${Math.round(t).toLocaleString("en-ZA")}`;function qs({shopifyId:t,price:r,cost:a,daysOnFloor:l,reason:i}){const n=Be(),[m,c]=y.useState(!1),v=r?Math.max(Math.round(r*.85/50)*50,50):0,[b,T]=y.useState(String(v||"")),k=G({mutationFn:async()=>{const{data:p}=await g.from("sales_reductions").select("id").eq("shopify_product_id",t).eq("status","proposed").limit(1);if(p&&p.length)return"exists";const{error:f}=await g.from("sales_reductions").insert({shopify_product_id:t,current_price:r,suggested_price:v||null,reduction_percent:r?15:null,days_on_floor:l,reason:i||"Sent from Flagged Stock",source:"flagged_stock",status:"proposed"});if(f)throw f;return"added"},onSuccess:p=>{_.success(p==="exists"?"Already in the reduction queue":"Sent to the reduction queue"),n.invalidateQueries({queryKey:["proposed-reductions"]})},onError:p=>_.error(p.message)}),j=G({mutationFn:async()=>{const p=parseFloat(b);if(isNaN(p)||p<=0)throw new Error("Enter a valid price");if(r!=null&&p>=r)throw new Error("New price must be lower than the current price");const{data:f,error:C}=await g.functions.invoke("store-health-update",{body:{shopify_id:t,updates:{price:String(p)}}});if(C)throw C;if(f&&f.success===!1)throw new Error(f.error||"Update failed")},onSuccess:()=>{_.success("Price reduced on Shopify"),c(!1),n.invalidateQueries({queryKey:["flagged-slow-movers"]})},onError:p=>_.error(p.message)}),w=parseFloat(b);return e.jsxs(e.Fragment,{children:[e.jsxs(me,{children:[e.jsx(pe,{asChild:!0,children:e.jsxs(S,{size:"sm",variant:"outline",disabled:k.isPending,children:[e.jsx(Qe,{className:"h-3 w-3 mr-1"})," Reduce ",e.jsx(re,{className:"h-3 w-3 ml-1"})]})}),e.jsxs(fe,{align:"end",children:[e.jsx(L,{onClick:()=>k.mutate(),children:"Send to reduction queue"}),e.jsx(L,{onClick:()=>c(!0),children:"Reduce price now…"})]})]}),e.jsx(ye,{open:m,onOpenChange:c,children:e.jsxs(_e,{children:[e.jsx(ve,{children:e.jsx(je,{children:"Reduce price now"})}),e.jsxs("div",{className:"space-y-2 text-sm",children:[e.jsxs("p",{children:["Current: ",e.jsx("b",{children:r!=null?le(r):"?"})," · Cost: ",e.jsx("b",{children:a!=null?le(a):"?"})]}),e.jsx(ge,{type:"number",inputMode:"numeric",value:b,onChange:p=>T(p.target.value)}),!isNaN(w)&&a!=null&&e.jsxs("p",{className:w<a?"text-destructive":"text-muted-foreground",children:["Margin after reduction: ",le(w-a),w<a?" (below cost)":""]})]}),e.jsxs(ss,{children:[e.jsx(S,{variant:"outline",onClick:()=>c(!1),children:"Cancel"}),e.jsxs(S,{onClick:()=>j.mutate(),disabled:j.isPending,children:[j.isPending&&e.jsx(P,{className:"h-3 w-3 mr-1 animate-spin"})," Apply to Shopify"]})]})]})})]})}const Ee=t=>t?new Date(t).toLocaleDateString("en-ZA",{day:"2-digit",month:"short",year:"2-digit"}):"—";function Ts({shopifyId:t,lastSourcedAt:r}){const[a,l]=y.useState(!1),{data:i=[],isLoading:n,error:m}=z({queryKey:["item-touch-history",t],enabled:a,queryFn:async()=>{const{data:c,error:v}=await g.from("sourcing_tasks").select("id, status, source_type, sourced_by, assigned_to, sourced_at, created_at, location_found, condition, notes").eq("shopify_product_id",t).order("created_at",{ascending:!1}).limit(20);if(v)throw v;return c||[]}});return e.jsxs(vs,{open:a,onOpenChange:l,children:[e.jsxs(js,{className:"flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground",children:[a?e.jsx(re,{className:"h-3 w-3"}):e.jsx(bs,{className:"h-3 w-3"}),"Last sourced: ",r?Ee(r):"Never"," · history"]}),e.jsxs(ws,{className:"mt-1 space-y-1",children:[n&&e.jsx(P,{className:"h-3 w-3 animate-spin"}),m&&e.jsx("p",{className:"text-xs text-destructive",children:"Couldn't load history"}),!n&&!m&&i.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"No physical interactions recorded."}),i.map(c=>e.jsxs("div",{className:"text-xs border-l-2 border-border pl-2",children:[e.jsx("span",{className:"font-medium capitalize",children:(c.status||"pending").replace("_"," ")}),e.jsxs("span",{className:"text-muted-foreground",children:[" · ",(c.source_type||"").replace("_"," ")," · ",Ee(c.sourced_at||c.created_at)]}),(c.sourced_by||c.assigned_to)&&e.jsxs("span",{className:"text-muted-foreground",children:[" · ",c.sourced_by||c.assigned_to]}),c.location_found&&e.jsxs("span",{className:"text-muted-foreground inline-flex items-center gap-0.5",children:[" · ",e.jsx(Ge,{className:"h-2.5 w-2.5"}),c.location_found]}),c.condition&&c.condition!=="good"&&e.jsxs("span",{className:"text-warning",children:[" · ",c.condition]}),c.notes&&e.jsx("div",{className:"text-muted-foreground line-clamp-2",children:c.notes})]},c.id))]})]})}const Fs=[[/fridge|freezer|washing|dryer|dishwasher|stove|oven/i,{days:45,space:1.3}],[/l shape|sleeper|couch|sofa/i,{days:90,space:1.6}],[/bed|mattress|headboard/i,{days:90,space:1.4}],[/wardrobe|cupboard|cabinet|display/i,{days:120,space:1.5}],[/boardroom|dining table|table/i,{days:120,space:1.3}],[/desk/i,{days:150,space:1}]];function Is(t){for(const[r,a]of Fs)if(t&&r.test(t))return a;return{days:120,space:1}}function xe(t){const r=Is(t.product_type),a=t.created_at_shopify?Math.floor((Date.now()-new Date(t.created_at_shopify).getTime())/864e5):null,l=a!=null?a/r.days:1,i=t.price!=null?Number(t.price):null,n=t.cost!=null?Number(t.cost):null,m=i!=null?i-(n??0):null,c=m==null?1:m<300?1.8:m<1e3?1.3:m<3e3?1:.8,v=Math.max(1,Number(t.inventory_quantity)||1),b=Math.round(l*r.space*c*Math.min(v,3)*10),T=l>=2&&(m==null||m<1e3)?"move-now":l>=1.5?"reduce":"watch";return{score:b,band:T,daysOnFloor:a,expectedDays:r.days,overdueRatio:l,margin:m}}const de={"move-now":{label:"Move now",className:"bg-destructive text-destructive-foreground",hint:"Well overdue and little left to recover — auction, recycle or dump"},reduce:{label:"Reduce",className:"bg-warning text-warning-foreground",hint:"Overdue but worth recovering — a price drop should move it"},watch:{label:"Watch",className:"bg-secondary text-secondary-foreground",hint:"Slow but still within a normal range for its category"}},B=["Blessings",is()],Ms=["Fridge","Fridge Freezer","Fridge Double Door","Mini Fridge","1 
6Seater Couch","2 Seater Couch","3 Seater Couch","L Shape Couch","Sleeper Couch","Three Seater Couch","White Three Seater Leather Couch","4 X Bouquet Couch","Dining Table","Glass Dining Table","Glass Top Dining Table","8 Seater Dining Table","Boardroom Table","Coffee Table","Outdoor Table","Round Table","Table","Double Bed","Queen Bed","King Bed","Single Bed Frame","Double Bed Frame","Double Bed Base","Queen Bed and base","Queen Bed Frame","king bed and base","Cot Bed","Bed Frame","Extra Queen Base With Headboard","double bed base","Double Mattress","Queen Mattress","King Mattress","Headboard","Double Headboard","Single Headboard","Queen Headboard","single headboard","king size headboard","Wardrobe","Cupboard","Linen Cupboard","Office Cupboard","Washing Machine","Dishwasher","Tumble Dryer","Dryer","Kelvinator Dishwasher","Oven","3 Plate Stove","Defy Glass Top Induction Stovetop","Desk","DESK","desk","Office Desk","Computer Desk","Small Desk","L Shape Desk","L Shaped Desk","Large Desk","3 drawer desk","2 drawer desk","4 Drawer Desk","Conner Desk","Pc Desk","Laptop Desk","Reception Desk","L Shape Desk With Drawers","Computer Desk Glass And Silver","Office Desk With Metal Cabinet","Bookshelf","3 tier bookshelf","Shelf","Steel Shelf","Display Shelf","Ladder Shelf","Filling Cabinet","2 Draw Steel Cabinet","Converter Battery Cabinet","Small Metal Cupboard With Black Handle","Lounge Cabinet Cream","Sideboard","Dresser","Chest of Drawers"],As=new Set(["sale","origin","book","books","fence","fences","plant","plants","clothing","clothes","accessories","toy","toys","dvd","cd","vinyl","art","print","curtain","curtains","linen","bedding","pillow","cushion","ornament","decor","candle","vase","frame","picture frame","mirror small"]);async function Es(){const{data:t}=await g.from("sourcing_tasks").select("assigned_to").eq("status","pending").in("assigned_to",B),r={};return B.forEach(a=>r[a]=0),(t||[]).forEach(a=>{a.assigned_to&&r[a.assigned_to]!==void 0&&r[a.assigned_to]++}),B.reduce((a,l)=>r[a]<=r[l]?a:l)}async function Ls(t){const{data:r}=await g.from("sourcing_tasks").select("assigned_to").eq("status","pending").in("assigned_to",B),a={};B.forEach(i=>a[i]=0),(r||[]).forEach(i=>{i.assigned_to&&a[i.assigned_to]!==void 0&&a[i.assigned_to]++});const l=[...B].sort((i,n)=>a[i]-a[n]);return Array.from({length:t},(i,n)=>l[n%l.length])}async function ue(){const t=new Date(Date.now()-2592e6).toISOString(),{data:r}=await g.from("sourcing_tasks").select("shopify_product_id").gte("updated_at",t).not("shopify_product_id","is",null);return new Set((r||[]).map(a=>a.shopify_product_id))}async function ae(t){const r=t.filter(i=>!i.last_sourced_at);if(r.length===0)return t;const a=r.map(i=>i.shopify_id),{data:l}=await g.from("sourcing_tasks").select("shopify_product_id, created_at").in("shopify_product_id",a).eq("status","found").order("created_at",{ascending:!1});if(l&&l.length>0){const i=new Map;for(const n of l)n.shopify_product_id&&!i.has(n.shopify_product_id)&&i.set(n.shopify_product_id,n.created_at);for(const n of t)!n.last_sourced_at&&i.has(n.shopify_id)&&(n.last_sourced_at=i.get(n.shopify_id))}return t.sort((i,n)=>{const m=i.last_sourced_at?new Date(i.last_sourced_at).getTime():0,c=n.last_sourced_at?new Date(n.last_sourced_at).getTime():0;if(m!==c)return m-c;const v=i.created_at_shopify?new Date(i.created_at_shopify).getTime():0,b=n.created_at_shopify?new Date(n.created_at_shopify).getTime():0;return v-b}),t}async function ne(t){if(t.length===0)return t;const r=t.map(l=>l.shopify_id),{data:a}=await g.from("sourcing_tasks").select("shopify_product_id, status, source_type").in("shopify_product_id",r).in("status",["pending","not_found"]);if(a&&a.length>0){const l=new Set,i=new Set;for(const n of a)n.shopify_product_id&&(n.status==="pending"&&n.source_type==="stock_take"&&l.add(n.shopify_product_id),n.status==="not_found"&&i.add(n.shopify_product_id));for(const n of t)n.has_pending_stock_take=l.has(n.shopify_id),n.has_missing_flag=i.has(n.shopify_id)}return t}const Le={recycle:"♻️ Recycle",dump:"🗑️ Dump",auction:"🔨 Auction",repair:"🔧 Repair",unsure:"❓ Not sure"};function Os({item:t,tabHint:r,onSource:a,onStockTake:l,onInvestigate:i,onMarkMissing:n,onExclude:m,onSendDecision:c,stockTakePending:v,investigatePending:b,markMissingPending:T,sendDecisionPending:k,queuedDecision:j}){const w=O(t.images),p=$e(t.vendor),f=as(t.vendor),C=ze(t.created_at_shopify),F=t.stock_take_excluded||t.stock_take_exclude_until&&new Date(t.stock_take_exclude_until)>new Date,M=t.created_at_shopify?Math.floor((Date.now()-new Date(t.created_at_shopify).getTime())/(30*864e5)):null,q=xe(t);return e.jsxs(ns,{className:`overflow-hidden ${F?"opacity-50":""}`,children:[e.jsxs("div",{className:"relative group",children:[w?e.jsx("img",{src:w,alt:t.title,className:"w-full h-48 object-cover transition-transform duration-200 group-hover:scale-105"}):e.jsx("div",{className:"w-full h-48 bg-muted flex items-center justify-center text-muted-foreground text-sm",children:"No image"}),e.jsxs("div",{className:"absolute top-2 left-2 flex gap-1 flex-wrap",children:[f?e.jsx(I,{className:"bg-purple-500 text-white",children:"🟣 COR CONSIGN"}):p?e.jsx(I,{className:"bg-warning text-warning-foreground",children:"🟠 CONSIGNMENT"}):null,F&&e.jsxs(I,{variant:"secondary",children:[e.jsx(Ie,{className:"h-3 w-3 mr-1"}),"Excluded"]}),r==="slow-movers"&&M!==null&&e.jsxs(I,{variant:"destructive",children:[M,"mo old"]}),r==="slow-movers"&&e.jsxs(I,{className:de[q.band].className,title:de[q.band].hint,children:[de[q.band].label," · ",q.overdueRatio.toFixed(1),"× normal"]}),r==="high-qty"&&(t.inventory_quantity||0)>1&&e.jsxs(I,{className:"bg-primary text-primary-foreground",children:["Qty: ",t.inventory_quantity]}
6),r==="category"&&t.vendor&&e.jsx(I,{variant:"secondary",children:t.vendor})]})]}),e.jsxs(os,{className:"p-4 space-y-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1 flex-wrap",children:[e.jsx("span",{className:"font-mono font-bold text-sm",children:t.sku||"—"}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["Qty: ",t.inventory_quantity??0]}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["Age: ",C]}),t.price!=null&&e.jsxs("span",{className:"text-xs font-semibold text-foreground",children:["R",Number(t.price).toLocaleString("en-ZA",{minimumFractionDigits:0})]})]}),e.jsx("p",{className:"text-sm text-muted-foreground line-clamp-2",children:t.title}),t.vendor&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:["Vendor: ",t.vendor]}),t.product_type&&e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:t.product_type}),e.jsx("div",{className:"mt-0.5",children:e.jsx(Ts,{shopifyId:t.shopify_id,lastSourcedAt:t.last_sourced_at})}),(t.has_pending_stock_take||t.has_missing_flag||j)&&e.jsxs("div",{className:"flex gap-1 flex-wrap mt-1",children:[t.has_pending_stock_take&&e.jsxs(I,{className:"bg-amber-500/15 text-amber-700 border-amber-300 text-[10px] px-1.5 py-0",children:[e.jsx(Re,{className:"h-2.5 w-2.5 mr-0.5"})," Stock Take Pending"]}),t.has_missing_flag&&e.jsxs(I,{className:"bg-destructive/15 text-destructive border-destructive/30 text-[10px] px-1.5 py-0",children:[e.jsx(he,{className:"h-2.5 w-2.5 mr-0.5"})," On Missing List"]}),j&&e.jsxs(I,{className:"bg-primary/15 text-primary border-primary/30 text-[10px] px-1.5 py-0",title:j.by?`Sent by ${j.by}`:void 0,children:[e.jsx(Me,{className:"h-2.5 w-2.5 mr-0.5"}),"In decision queue",j.action?`: ${Le[j.action]||j.action}`:""]})]})]}),e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[e.jsxs(S,{size:"sm",className:"bg-green-600 hover:bg-green-700 text-white",onClick:a,children:[e.jsx(Pe,{className:"h-3 w-3 mr-1"})," Found"]}),e.jsxs(S,{size:"sm",variant:"outline",onClick:l,disabled:v,children:[e.jsx(rs,{className:"h-3 w-3 mr-1"})," Stock Take"]}),e.jsxs(S,{size:"sm",variant:"outline",className:"text-destructive border-destructive/40 hover:bg-destructive/10 hover:text-destructive",onClick:n,disabled:T,children:[e.jsx(he,{className:"h-3 w-3 mr-1"})," Mark Missing"]}),e.jsxs(S,{size:"sm",variant:"outline",onClick:i,disabled:b,children:[e.jsx(Ke,{className:"h-3 w-3 mr-1"})," Investigate"]}),e.jsx(qs,{shopifyId:t.shopify_id,price:t.price!=null?Number(t.price):null,cost:t.cost!=null?Number(t.cost):null,daysOnFloor:q.daysOnFloor,reason:`Flagged Stock: ${q.daysOnFloor??"?"} days on floor vs ~${q.expectedDays} normal for ${t.product_type||"category"}`}),e.jsxs(me,{children:[e.jsx(pe,{asChild:!0,children:e.jsxs(S,{size:"sm",variant:"outline",disabled:k,children:[e.jsx(Me,{className:"h-3 w-3 mr-1"}),j?`Sent: ${Le[j.action||""]||"Decision"}`:"Send for decision",e.jsx(re,{className:"h-3 w-3 ml-1"})]})}),e.jsxs(fe,{align:"end",children:[e.jsx(L,{onClick:()=>c("recycle"),children:"♻️ Suggest Recycle"}),e.jsx(L,{onClick:()=>c("dump"),children:"🗑️ Suggest Dump"}),e.jsx(L,{onClick:()=>c("auction"),children:"🔨 Suggest Auction"}),e.jsx(L,{onClick:()=>c("repair"),children:"🔧 Suggest Repair"}),e.jsx(L,{onClick:()=>c("unsure"),children:"❓ Not sure — decide for me"})]})]}),e.jsxs(me,{children:[e.jsx(pe,{asChild:!0,children:e.jsxs(S,{size:"sm",variant:"ghost",children:[e.jsx(Ie,{className:"h-3 w-3 mr-1"})," Exclude ",e.jsx(re,{className:"h-3 w-3 ml-1"})]})}),e.jsxs(fe,{align:"end",children:[e.jsx(L,{onClick:()=>m("Service item",null),children:"Service item"}),e.jsx(L,{onClick:()=>m("Not physical stock",null),children:"Not physical stock"}),e.jsx(L,{onClick:()=>m("Temporary - 30 days",30),children:"Exclude for 30 days"}),e.jsx(L,{onClick:()=>m("Temporary - 90 days",90),children:"Exclude for 90 days"}),e.jsx(L,{onClick:()=>m("Permanently excluded",null),children:"Exclude permanently"})]})]})]})]})]})}function oe({items:t,isLoading:r,tabHint:a,emptyMessage:l,onSource:i,onStockTake:n,onInvestigate:m,onMarkMissing:c,onExclude:v,onSendDecision:b,stockTakePending:T,investigatePending:k,markMissingPending:j,sendDecisionPending:w,queuedDecisions:p}){return r?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(P,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):t.length===0?e.jsx("div",{className:"text-center py-12 text-muted-foreground",children:l}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4",children:t.map(f=>e.jsx(Os,{item:f,tabHint:a,onSource:()=>i(f),onStockTake:()=>n(f),onInvestigate:()=>m(f),onMarkMissing:()=>c(f),onExclude:(C,F)=>v(f,C,F),onSendDecision:C=>b(f,C),stockTakePending:T,investigatePending:k,markMissingPending:j,sendDecisionPending:w,queuedDecision:p.get(f.shopify_id)||null},f.shopify_id))})}function qt(){const t=Be(),{user:r}=Oe(),{staffName:a}=ks(),[l,i]=y.useState("untouched"),[n,m]=y.useState(!1),[c,v]=y.useState(null),[b,T]=y.useState(""),[k,j]=y.useState(""),[w,p]=y.useState(0),[f,C]=y.useState([]),[F,M]=y.useState(0);y.useEffect(()=>{const s=setTimeout(()=>{j(b.trim()),p(0),C([]),M(0)},500);return()=>clearTimeout(s)},[b]);const[q,X]=y.useState(null),[ie,H]=y.useState(!1),[$,Q]=y.useState(""),[A,h]=y.useState([]),[E,R]=y.useState(!1),[U,V]=y.useState(!1),{data:J=[],isLoading:we}=z({queryKey:["flagged-untouched",n],enabled:l==="untouched",queryFn:async()=>{const s=new Date(Date.now()-2592e6).toISOString(),o=await ue(),{data:d}=await g.from("shopify_products").select("shopify_id, title, sku, images, inventory_quantity, synced_at, created_at_shopify, product_type, vendor, last_sourced_at, stock_take_excluded, stock_take_exclude_reason, stock_take_exclude_until, price").eq("status","active").gte("inventory_quantity",1).or(`last_sourced_at.is.null,last_sourced_at.lt.${s}`).order("created_at_shopify",{ascending:!0}).limit(400);let u=(d||[]).filter(D=>!o.has(D.shopify_id));n||(u=u.filter(D=>!D.stock_take_excluded&&!(D.stock_take_exclude_until&&new Date(D.stock_take_exclude_until)>new Date)));const x=await ae(u);return(await ne(x)).slice(0,100)}}),{data:be=[],isLoading:ke}=z({queryKey:["flagged-high-qty",n],enabled:l==="high-qty",queryFn:async()=>{const s=new Date(Date.now()-2592e6).toISOString(),o=await ue(),{data:d}=await g.from("shopify_products").select("shopify_id, title, sku, images, inventory_quantity, synced_at, created_at_shopify, product_type, vendor, last_sourced_at, stock_take_excluded, stock_take_exclude_reason, stock_take_exclude_until, price").eq("status","active").gt("inventory_quantity",1).or(`last_sourced_at.is.null,last_sourced_at.lt.${s}`).order("inventory_quantity",{ascending:!1}).limit(400);let u=(d||[]).filter(D=>!o.has(D.shopify_id));n||(u=u.filter(D=>!D.stock_take_excluded&&!(D.stock_take_exclude_until&&new Date(D.stock_take_exclude_until)>new Date)));const x=await ae(u);return(await ne(x)).slice(0,100)}}),{data:Ne=[],isLoading:Se}=z({queryKey:["flagged-slow-movers",n],enabled:l==="slow-movers",queryFn:async()=>{const s=new Date(Date.now()-2592e6).toISOString(),o=new Date(Date.now()-180*864e5).toISOString(),d=await ue(),{data:u}=await g.from("shopify_products").select("shopify_id, title, sku, images, inventory_quantity, synced_at, created_at_shopify, product_type, vendor, last_sourced_at, stock_take_excluded, stock_take_exclude_reason, stock_take_exclude_until, price, cost").eq("status","active").gte("inventory_quantity",1).in("product_type",Ms).lt("created_at_shopify",o).or(`last_sourced_at.is.null,last_sourced_at.lt.${s}`).order("created_at_shopify",{ascending:!0}).limit(1e3);let x=(u||[]).filter(K=>!d.has(K.shopify_id));n||(x=x.filter(K=>!K.stock_take_excluded&&!(K.stock_take_exclude_until&&new Date(K.stock_take_exclude_until)>new Date)));const N=await ae(x);return[...await ne(N)].sort((K,Ye)=>xe(Ye).score-xe(K).score)}}),{data:ce=[]}=z({queryKey:["flagged-top-categories"],enabled:l==="category",queryFn:async()=>{const{data:s}=await g.from("shopify_products").select("product_type, inventory_quantity, images, price").eq("status","active").gte("inventory_quantity",1).not("product_type","is",null);if(!s)return[];const o=new Map;for(const d of s){const u=(d.product_type||"").trim();if(!u||As.has(u.toLowerCase()))continue;const x=o.get(u)||{count:0,value:0,image:""},N=d.inventory_quantity||0;x.count+=N,x.value+=(d.price||0)*N,x.image||(x.image=O(d.images)),o.set(u,x)}return Array.from(o.entries()).map(([d,u])=>({name:d,count:u.count,value:u.value,image:u.image})).sort((d,u)=>u.count-d.count).slice(0,20)}}),{data:We=[],isLoading:Y}=z({queryKey:["flagged-category",k,n,w],enabled:l==="category"&&k.length>=2,queryFn:async()=>{const{data:s,error:o}=await g.rpc("search_category_products",{p_search:k,p_page:w,p_page_size:50,p_show_excluded:n});if(o)throw o;const d=s||[];d.length>0?M(Number(d[0].total_count)):w===0&&M(0);const u=await ae(d),x=await ne(u);return C(w===0?x:N=>
6[...N,...x]),x}}),W=()=>{t.invalidateQueries({queryKey:["flagged-untouched"]}),t.invalidateQueries({queryKey:["flagged-high-qty"]}),t.invalidateQueries({queryKey:["flagged-slow-movers"]}),t.invalidateQueries({queryKey:["flagged-category"]})},He=G({mutationFn:async({shopifyId:s,reason:o,days:d})=>{const u={stock_take_excluded:d===null,stock_take_exclude_reason:o,stock_take_exclude_until:d?new Date(Date.now()+d*864e5).toISOString():null},{error:x}=await g.from("shopify_products").update(u).eq("shopify_id",s);if(x)throw x},onSuccess:()=>{_.success("Item excluded from stock takes"),W()},onError:s=>_.error(s.message)}),Ce=G({mutationFn:async s=>{const{data:o}=await g.from("missing_investigations").select("id, status, a_code, investigation_notes, search_attempts, created_at, started_at, started_by, concluded_at, concluded_by, conclusion_type, conclusion_action, conclusion_notes, merged_with_sku, quantity_removed").eq("shopify_product_id",s.shopify_id).in("status",["active","investigating"]).maybeSingle();if(o)return{record:{...o,shopify_product_id:s.shopify_id},item:s,isExisting:!0};const{data:d,error:u}=await g.from("missing_investigations").insert({shopify_product_id:s.shopify_id,a_code:s.sku||null,status:"active",started_at:new Date().toISOString(),started_by:(r==null?void 0:r.email)||"Staff",investigation_notes:[],search_attempts:[]}).select().single();if(u)throw u;return{record:d,item:s,isExisting:!1}},onSuccess:({record:s,item:o,isExisting:d})=>{d?_.info(`Investigation already open for ${o.sku||o.title} — opening it`):(_.success(`Investigation created for ${o.sku||o.title}`),W(),t.invalidateQueries({queryKey:["missing-investigations"]})),X({...s,product:{title:o.title,sku:o.sku,images:o.images,vendor:o.vendor,inventory_quantity:o.inventory_quantity,synced_at:o.synced_at,created_at_shopify:o.created_at_shopify,price:o.price||null},riskReasons:[]})},onError:s=>_.error(s.message)}),De=G({mutationFn:async s=>{const o=await Es(),{error:d}=await g.from("sourcing_tasks").insert({source_type:"stock_take",status:"pending",priority:"normal",item_id:s.sku||null,item_name:s.title,item_image_url:O(s.images)||null,shopify_product_id:s.shopify_id,assigned_to:o,notes:"Stock take (flagged stock)"});if(d)throw d;return o},onSuccess:s=>{_.success(`Added to sourcing queue → assigned to ${s}`),W()},onError:s=>_.error(s.message)}),qe=async()=>{if($.trim()){R(!0);try{const{data:s}=await g.from("shopify_products").select("shopify_id, sku, title, images, product_type").eq("status","active").or(`title.ilike.%${$.trim()}%,product_type.ilike.%${$.trim()}%`).limit(500);h(s||[])}catch{_.error("Search failed")}finally{R(!1)}}},Ue=async()=>{if(A.length!==0){V(!0);try{const s=await Ls(A.length),o=A.map((N,D)=>({source_type:"stock_take",status:"pending",priority:"normal",item_id:N.sku||null,item_name:N.title,item_image_url:O(N.images)||null,shopify_product_id:N.shopify_id,assigned_to:s[D],notes:`Stock take by category: ${$}`})),{error:d}=await g.from("sourcing_tasks").insert(o);if(d)throw d;const u={};s.forEach(N=>{u[N]=(u[N]||0)+1});const x=Object.entries(u).map(([N,D])=>`${N}: ${D}`).join(", ");_.success(`${o.length} stock take tasks added — ${x}`),H(!1),Q(""),h([]),t.invalidateQueries({queryKey:["sourcing-records"]})}catch(s){_.error(s.message)}finally{V(!1)}}},Te=G({mutationFn:async s=>{const{error:o}=await g.from("sourcing_tasks").insert({shopify_product_id:s.shopify_id,item_name:s.title,item_image_url:O(s.images)||null,status:"not_found",source_type:"stock_take",notes:"Flagged as missing from stock review — inventory NOT adjusted, pending write-off via draft order",sourced_via:"desktop",priority:"high"});if(o)throw o},onSuccess:()=>{_.success("Item added to missing list — go to Stock Issues to create the draft order"),W(),t.invalidateQueries({queryKey:["stock-issues-missing"]}),t.invalidateQueries({queryKey:["stock-issues-counts"]})},onError:s=>_.error(s.message)}),Fe=G({mutationFn:async({item:s,action:o})=>{const{data:d}=await g.from("item_damage_reports").select("id, suggested_action").eq("shopify_product_id",s.shopify_id).eq("status","pen
6ding").maybeSingle();if(d)return{alreadyQueued:!0,action:d.suggested_action};const u=O(s.images),{error:x}=await g.from("item_damage_reports").insert({shopify_product_id:s.shopify_id,a_code:s.sku||null,code_status:s.shopify_id?"found":s.sku?"not_in_system":"no_sticker",damage_types:["clearout suggestion"],severity:"minor",description:`Suggested from Flagged Stock (${s.product_type||"uncategorised"}, age ${ze(s.created_at_shopify)})`,photo_urls:u?[u]:[],reported_by:a||(r==null?void 0:r.email)||"Staff",suggested_action:o,status:"pending"});if(x)throw x;return{alreadyQueued:!1,action:o}},onSuccess:(s,{item:o})=>{s.alreadyQueued?_.info(`${o.sku||o.title} is already in the decision queue${s.action?` (suggested: ${s.action})`:""}`):_.success(`${o.sku||o.title} sent to Stock Issues → Damage for decision`),t.invalidateQueries({queryKey:["stock-issues-damage"]}),t.invalidateQueries({queryKey:["stock-issues-counts"]}),t.invalidateQueries({queryKey:["flagged-queued-decisions"]})},onError:s=>_.error(s.message)}),{data:Ve=new Map}=z({queryKey:["flagged-queued-decisions"],staleTime:6e4,queryFn:async()=>{const{data:s,error:o}=await g.from("item_damage_reports").select("shopify_product_id, suggested_action, reported_by").eq("status","pending").not("shopify_product_id","is",null);if(o)throw o;const d=new Map;for(const u of s||[])u.shopify_product_id&&d.set(u.shopify_product_id,{action:u.suggested_action??null,by:u.reported_by??null});return d}}),ee={onSource:s=>v(s),onStockTake:s=>De.mutate(s),onInvestigate:s=>Ce.mutate(s),onMarkMissing:s=>Te.mutate(s),onExclude:(s,o,d)=>He.mutate({shopifyId:s.shopify_id,reason:o,days:d}),onSendDecision:(s,o)=>Fe.mutate({item:s,action:o}),stockTakePending:De.isPending,investigatePending:Ce.isPending,markMissingPending:Te.isPending,sendDecisionPending:Fe.isPending,queuedDecisions:Ve};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold",children:"Flagged Stock"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:"Items that haven't been touched in 30+ days — sorted by urgency"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs(S,{variant:"outline",onClick:()=>H(!0),children:[e.jsx(ts,{className:"h-4 w-4 mr-2"})," Stock Take by Category"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Show Excluded"}),e.jsx(ds,{checked:n,onCheckedChange:m})]})]})]}),e.jsxs(cs,{value:l,onValueChange:i,children:[e.jsxs(ls,{className:"grid w-full grid-cols-4 h-auto",children:[e.jsxs(se,{value:"untouched",className:"flex flex-col gap-0.5 py-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Re,{className:"h-4 w-4"}),e.jsxs("span",{className:"font-semibold",children:["Untouched Stock",!we&&` (${J.length})`]})]}),e.jsx("span",{className:"text-xs font-normal opacity-70",children:"30+ days unseen · oldest first"})]}),e.jsxs(se,{value:"high-qty",className:"flex flex-col gap-0.5 py-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Ss,{className:"h-4 w-4"}),e.jsxs("span",{className:"font-semibold",children:["High Quantity",!ke&&l==="high-qty"&&` (${be.length})`]})]}),e.jsx("span",{className:"text-xs font-normal opacity-70",children:"Qty > 1 · unverified"})]}),e.jsxs(se,{value:"slow-movers",className:"flex flex-col gap-0.5 py-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Qe,{className:"h-4 w-4"}),e.jsxs("span",{className:"font-semibold",children:["Slow Big Movers",!Se&&l==="slow-movers"&&` (${Ne.length})`]})]}),e.jsx("span",{className:"text-xs font-normal opacity-70",children:"6mo+ big items · investigate why"})]}),e.jsxs(se,{value:"category",className:"flex flex-col gap-0.5 py-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Ae,{className:"h-4 w-4"}),e.jsxs("span",{className:"font-semibold",children:["Category",!Y&&l==="category"&&k&&` (${We.length})`]})]}),e.jsx("span",{className:"text-xs font-normal opacity-70",children:"Browse by type · least sourced first"})]})]}),e.jsx(te,{value:"untouched",className:"mt-4",children:e.jsx(oe,{items:J,isLoading:we,tabHint:"untouched",emptyMessage:"No untouched items found — everything has been verified in the last 30 days 🎉",...ee})}),e.jsx(te,{value:"high-qty",className:"mt-4",children:e.jsx(oe,{items:be,isLoading:ke,tabHint:"high-qty",emptyMessage:"No high-quantity unverified items found",...ee})}),e.jsxs(te,{value:"slow-movers",className:"mt-4",children:[e.jsx("div",{className:"mb-3 p-3 rounded-lg bg-warning/10 border border-warning/30",children:e.jsxs("p",{className:"text-sm text-foreground
6/80",children:[e.jsx(he,{className:"h-4 w-4 inline mr-1.5 mb-0.5"}),"These items should typically sell within 6 months. If they haven't, something may be wrong — price, photos, or they may be missing."]})}),e.jsx(oe,{items:Ne,isLoading:Se,tabHint:"slow-movers",emptyMessage:"No slow-moving big items found",...ee})]}),e.jsxs(te,{value:"category",className:"mt-4",children:[e.jsxs("div",{className:"mb-4 max-w-md",children:[e.jsx(ge,{placeholder:"Search categories or items... e.g. dining table",value:b,onChange:s=>T(s.target.value)}),k.length>=2&&!Y&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["Showing ",f.length," of ",F," items"]})]}),k.length<2&&ce.length>0&&e.jsxs("div",{className:"mb-6",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground mb-3",children:"Top categories by stock volume"}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-3",children:ce.map(s=>e.jsxs("button",{onClick:()=>T(s.name),className:"flex items-center gap-0 rounded-xl border border-border bg-card overflow-hidden hover:shadow-lg hover:scale-[1.02] hover:border-primary/40 transition-all duration-200 text-left group",children:[e.jsx("div",{className:"w-[80px] h-[80px] shrink-0 bg-muted",children:s.image?e.jsx(us,{src:s.image,alt:s.name,width:80,height:80,className:"rounded-none"}):e.jsx("div",{className:"w-full h-full flex items-center justify-center text-muted-foreground",children:e.jsx(Ae,{className:"h-6 w-6"})})}),e.jsxs("div",{className:"flex-1 min-w-0 px-3 py-2 border-l-[3px] border-primary/60",children:[e.jsx("p",{className:"text-sm font-semibold text-foreground truncate group-hover:text-primary transition-colors",children:s.name}),e.jsx("div",{className:"flex items-center gap-2 mt-1",children:e.jsxs(I,{variant:"secondary",className:"text-xs",children:[s.count," in stock"]})}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:["R ",s.value.toLocaleString("en-ZA",{minimumFractionDigits:0,maximumFractionDigits:0})," retail value"]})]})]},s.name))})]}),k.length>=2?e.jsxs(e.Fragment,{children:[e.jsx(oe,{items:f,isLoading:Y&&w===0,tabHint:"category",emptyMessage:`No active items found for "${k}"`,...ee}),f.length<F&&e.jsx("div",{className:"flex justify-center mt-4",children:e.jsxs(S,{variant:"outline",onClick:()=>p(s=>s+1),disabled:Y,children:[Y&&w>0?e.jsx(P,{className:"h-4 w-4 animate-spin mr-2"}):null,"Load More (",f.length," of ",F,")"]})})]}):ce.length===0?e.jsx("div",{className:"text-center py-12 text-muted-foreground",children:"Type a search term above to browse items"}):null]})]}),e.jsx(Ds,{open:!!c,onOpenChange:s=>!s&&v(null),item:c,onComplete:()=>{v(null),W()}}),e.jsx(Ns,{investigation:q,open:!!q,onOpenChange:s=>!s&&X(null),onUpdated:()=>{W(),t.invalidateQueries({queryKey:["missing-investigations"]})}}),e.jsx(ye,{open:ie,onOpenChange:s=>{H(s),s||(Q(""),h([]))},children:e.jsxs(_e,{className:"max-w-lg",children:[e.jsx(ve,{children:e.jsx(je,{children:"Stock Take by Category"})}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Search by keyword or category. All matching items will be added to the sourcing queue as stock take tasks."}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ge,{placeholder:"e.g. dining tables, wood chairs...",value:$,onChange:s=>Q(s.target.value),onKeyDown:s=>s.key==="Enter"&&qe()}),e.jsx(S,{variant:"outline",onClick:qe,disabled:E||!$.trim(),children:E?e.jsx(P,{className:"h-4 w-4 animate-spin"}):e.jsx(Ke,{className:"h-4 w-4"})})]}),A.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs(I,{variant:"secondary",className:"text-sm",children:["✓ Found ",A.length," items"]}),e.jsxs("div",{className:"border rounded-lg divide-y max-h-48 overflow-y-auto",children:[A.slice(0,5).map(s=>e.jsxs("div",{className:"flex items-center gap-3 p-2 text-sm",children:[O(s.images)?e.jsx("img",{src:O(s.images),alt:"",className:"h-8 w-8 rounded object-cover flex-shrink-0"}):e.jsx("div",{className:"h-8 w-8 bg-muted rounded flex-shrink-0"}),e.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:s.sku||"—"}),e.jsx("span",{className:"truncate",children:s.title})]},s.shopify_id)),A.length>5&&e.jsxs("div",{className:"p-2 text-xs text-muted-foreground text-center",children:["+ ",A.length-5," more items"]})]}),e.jsxs("div",{className:"bg-muted/50 rounded-lg p-3 text-sm",children:[e.jsx("p",{className:"font-medium mb-1",children:"Assignment distributed across:"}),e.jsx("div",{className:"flex gap-3",children:B.map(s=>e.jsxs("span",{className:"text-muted-foreground",children:[s,": ~",Math.round(A.length/B.length)]},s))}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Balanced against current pending queue per person"})]}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsx(S,{variant:"outline",className:"flex-1",onClick:()=>{h([]),Q("")},children:"Clear"}),e.jsxs(S,{className:"flex-1",onClick:Ue,disabled:U,children:[U&&e.jsx(P,{className:"h-4 w-4 animate-spin mr-2"}),"Add ",A.length," items to Queue"]})]})]})]})]})})]})}export{qt 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.