1import{x as rt,r as c,b as I,a as it,a5 as lt,c as U,u as ct,j as e,W as dt,B as m,L as re,_ as mt,I as ie,aI as ut,a0 as ht,C as pt,m as ze}from"./index-BRJ5ZK5v.js";import{B as xt}from"./badge-B3_-or2v.js";import{C as K}from"./card-CDridMaN.js";import{D as gt,a as ft,b as yt,c as kt}from"./dialog-BBwNo65S.js";import{L as le}from"./label-DRpmBi18.js";import{S as bt,a as Nt,b as jt,c as wt,d as vt}from"./select-CmaxMc0N.js";import{d as Fe,m as ce,i as de,r as St,c as Be,a as Ct,b as Ae,s as Mt,f as $t,e as Lt,g as qe,h as _e}from"./masterRestockView-DHbHt2yJ.js";import{R as Tt}from"./refresh-cw-BoE-ndpC.js";import{P as Et}from"./printer-7YqO3dxa.js";import{E as It}from"./eye-off-BA6L4_qt.js";import{C as Kt}from"./chevron-up-8zgptxCn.js";import{P as Pt}from"./plus-BykrFEEd.js";import"./index-3cz39GOp.js";import"./index-BdQq_4o_.js";import"./index-CHcawZx6.js";import"./index-DMe0aH8K.js";import"./check-D8iPEp1e.js";const Rt=[["path",{d:"M16 5H3",key:"m91uny"}],["path",{d:"M11 12H3",key:"51ecnj"}],["path",{d:"M16 19H3",key:"zzsher"}],["path",{d:"M18 9v6",key:"1twb98"}],["path",{d:"M21 12h-6",key:"bt1uis"}]],Dt=rt("list-plus",Rt),zt=/^(regular|stock|storage|back\s*stock|label|jar|container|cotton\s*wick|stock\s*cotton\s*wick|brewing)$/i;function Oe(p){return p==="Tea"?"Jar":p==="Herbs"?"Bag":p==="Candles"?"Cotton Wick":"Regular"}function k(p){return p.trim().toLowerCase().replace(/\.$/,"").replace(/\s+/g," ")}const He="masterRestock.shelfGapFilters";function Ft(){try{const p=localStorage.getItem(He),P=p?JSON.parse(p):[];return Array.isArray(P)?P.filter(v=>typeof v=="string"):[]}catch{return[]}}function ss(){const[p,P]=c.useState(""),[v,R]=c.useState(!1),[u,D]=c.useState(!1),[x,S]=c.useState("category"),[d,z]=c.useState(!1),[N,me]=c.useState(!1),[j,ue]=c.useState(!1),[L,Ve]=c.useState(Ft);function Qe(t){Ve(s=>{const n=s.includes(t)?s.filter(i=>i!==t):[...s,t];try{localStorage.setItem(He,JSON.stringify(n))}catch{}return n})}const{data:G=[],isLoading:Ue}=I({queryKey:["/api/restock-items"]}),F=it(),{data:he}=I({queryKey:["/api/reports/tea-make-forecast?category=all"],enabled:_e(u||d,x),staleTime:600*1e3}),{data:pe=[]}=I({queryKey:["/api/restock-items/priority-boosts"],enabled:_e(u||d,x),staleTime:60*1e3}),xe=c.useMemo(()=>{const t=new Map;for(const s of pe)t.set(`${s.restockItemId}|${(s.variantName??"").toLowerCase()}`,s.boost);return t},[pe]),{isAdmin:Ge}=lt(),B=U({mutationFn:async t=>{const s=await fetch("/api/restock-items/priority-feedback",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!s.ok)throw new Error("Failed to save priority change");return s.json()},onSuccess:()=>F.invalidateQueries({queryKey:["/api/restock-items/priority-boosts"]}),onError:()=>T({title:"Couldn't save that priority change",variant:"destructive"})}),ge=c.useMemo(()=>{const t=new Map,s=(()=>{const n=new Date;return`${String(n.getMonth()+1).padStart(2,"0")}-${String(n.getDate()).padStart(2,"0")}`})();for(const n of he?.items??[]){let i=!1;const a=o=>typeof o=="string"&&/^\d{2}-\d{2}$/.test(o);if(n.isLimitedEdition&&a(n.limitedFrom)&&a(n.limitedUntil)){const o=n.limitedFrom,l=n.limitedUntil;i=!(o<=l?s>=o&&s<=l:s>=o||s<=l)}t.set(n.restockItemId,{forecast30:n.forecast30??0,sold90:n.sold90??0,outOfSeason:i})}return t},[he]),{toast:T}=ct(),[fe,A]=c.useState(null),[q,J]=c.useState(""),[f,W]=c.useState(null),[Y,ye]=c.useState(1),[Z,ke]=c.useState(null),[X,_]=c.useState(!1),[O,ee]=c.useState(""),{data:te=[]}=I({queryKey:["/api/make-lists"]}),be=U({mutationFn:async t=>{const s=await fetch("/api/make-lists",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!s.ok)throw new Error("Failed to create make list");return s.json()},onSuccess:()=>F.invalidateQueries({queryKey:["/api/make-lists"]})}),Ne=U({mutationFn:async({listId:t,...s})=>{const n=await fetch(`/api/make-lists/${t}/items`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});if(!n.ok){const i=await n.json().catch(()=>null);throw new Error(i?.message||"Failed to add item to make list")}return n.json()},onSuccess:()=>F.invalidateQueries({queryKey:["/api/make-lists"]})}),je=be.isPending||Ne.isPending;async function Je(){if(!f)return;const t=f.item.squareProductId;if(!t){T({title:"Not linked to Square",description:"This item isn't linked to a Square product, so it can't be added to a make list.",variant:"destructive"});return}const s=Math.floor(Y);if(!Number.isFinite(s)||s<1){T({title:"Invalid quantity",description:"Quantity must be at least 1.",variant:"destructive"});return}try{let n=Z,i=te.find(a=>a.id===n)?.name??"";if(X){if(!O.trim())return;const a=await be.mutateAsync({name:O.trim()});n=a.id,i=a.name}if(!n)return;await Ne.mutateAsync({listId:n,squareProductId:t,productName:f.displayName,quantity:s,finishedVariationName:f.finishedVariationName}),T({title:"Added to make list",description:`${f.displayName} Ã ${Y} â ${i}`}),W(null),_(!1),ee("")}catch(n){T({title:"Couldn't add to make list",description:n instanceof Error?n.message:"Something went wrong",variant:"destructive"})}}function We(t,s,n,i){W({item:t,displayName:s,need:n,finishedVariationName:i}),ye(Math.max(1,Math.ceil(n))),ke(null),_(!1),ee("")}const we=U({mutationFn:async({id:t,data:s})=>{const n=await fetch(`/api/restock-items/${t}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({...s,editedBy:"Master Restock"})});if(!n.ok)throw new Error("Failed to save");return n.json()},onSuccess:()=>{F.invalidateQueries({queryKey:["/api/restock-items"]})}});function ve(t,s){A(t),J(s===null?"":String(s))}function Se(t){const s=Number(q);q.trim()!==""&&Number.isFinite(s)&&s>=0&&t(s),A(null)}const{data:g,isLoading:Ye,isFetching:Ce,refetch:Ze}=I({queryKey:["/api/square/restock-inventory","__all__"],queryFn:async()=>{const t=await fetch("/api/square/restock-inventory",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({})});if(!t.ok)throw new Error("Failed to load live inventory");return t.json()},staleTime:300*1e3});function Me(t){const s=g?.inventory?.[t.id]?.variationStocks;if(!s)return null;let n=s.filter(a=>{const o=(a.name||"").trim();return!(zt.test(o)||/^(stock|label)\s+/i.test(o)||/\b(stock|label)$/i.test(o))});if(t.category==="Potions & Elixirs"){if(n=n.filter(a=>k(a.name||"")==="1 oz"),n.length===0)return null}else if(n.length<2)return null;const i=t.variationTargets||{};return n.map(a=>{let o=i[a.name];if(o===void 0){const l=k(a.name);for(const[r,w]of Object.entries(i))if(k(r)===l){o=w;break}}return o===void 0&&(o=se(t)),{name:(a.name||"").trim(),target:o,count:a.count??0,need:Math.max(0,o-(a.count??0))}})}function H(t){const s=Me(t);return s?s.reduce((n,i)=>n+i.need,0):null}const Xe=2,et=4;function se(t){return de(t)&&t.target<=0?et:t.target}function tt(t){const s=g?.inventory?.[t.id];if(de(t)){const a=s?.regular??null;if(a!==null)return Math.max(0,se(t)-a);const o=H(t);return o!==null?o:0}if(t.category==="Potions & Elixirs")return H(t)??0;if(t.category==="Herbs"){if((s?.stock??null)===null)return 0;const a=s?.stock??0;return a<Xe?Math.min(2,Math.max(0,t.target-a)):0}if(t.category==="Tea"){const a=s?.jar??s?.regular??0;return Math.max(0,t.target-a)}if(t.category==="CBD Tea")return Math.max(0,t.target-(t.shopStock??0));if(t.category==="CBD"){const a=s?.regular??null;if(a!==null)return Math.max(0,t.target-a);const o=H(t);return o!==null?o:Math.max(0,t.target-(t.shopStock??0))}if(t.category==="Candles"){const a=s?.cottonWick??null,o=a!==null?a:t.shopStock,l=(s?.variationStocks??[]).filter(b=>/^stock\b/i.test(b.name.trim())),r=l.some(b=>b.count!==null),w=l.reduce((b,M)=>b+(M.count??0),0),Q=r?Math.max(0,1-w):0;return Math.max(0,t.target-o)+Q}const n=H(t);if(n!==null)return n;const i=s?.regular??s?.jar??null;return i!==null?Math.max(0,t.target-i):Math.max(0,t.target)}const ae=Ue||Ye,$e=Fe(G.filter(t=>t.category==="Candles"&&!["archived","new","seasonal","location"].includes(t.status??"")&&t.target>0&&t.name.toLowerCase().includes(p.toLowerCase()))),st=$e.filter(t=>ce(g?.inventory?.[t.id],!0,!1)).length,at=$e.filter(t=>ce(g?.inventory?.[t.id],!1,!0)).length,E=c.useMemo(()=>{const t=Fe(G.filter(a=>!["archived","new","seasonal","location"].includes(a.status??"")&&(a.target>0||de(a)))),s=new Map,n=(a,o)=>{s.has(a)||s.set(a,[]),s.get(a).push(o)};for(const a of t){if(p&&!a.name.toLowerCase().includes(p.toLowerCase())||(N||j)&&(a.category!=="Candles"||!ce(g?.inventory?.[a.id],N,j)))continue;const o=g?.inventory?.[a.id],l=g?tt(a):0;if(!v&&l<=0&&!(a.category==="Candles"&&(N||j)))continue;const w=!["Herbs","Tea","Candles","CBD Tea"].includes(a.category||"")?Me(a
1):null,Q=St(a);if(w&&w.length>0){const b=v?w:w.filter(h=>h.need>0),M=o?.variationStocks??[],Ie=M.find(h=>k(h.name||"")==="stock"),Ke=b.find(h=>k(h.name)==="1 oz")??b[0];for(const h of b){const $=k(h.name),oe=$.match(/^(root|sacral|solar plexus|heart|throat|third eye|crown)(?: chakra)? 1ml$/)?.[1],ot=a.category==="Potions & Elixirs"?Ie:M.find(C=>{const y=k(C.name||"");return y===`stock ${$}`||y===`${$} stock`})??(oe?M.find(C=>{const y=k(C.name||"");return y===`${oe} stock`||y===`${oe} chakra stock`}):void 0)??(h===Ke?Ie:void 0),Pe=M.find(C=>{const y=k(C.name||"");return y===`label ${$}`||y===`${$} label`}),Re=g?.salesPerMonthByVariation?.[a.id];let De=null;if(Re){for(const[C,y]of Object.entries(Re))if(k(C)===$){De=y;break}}n(Q,{item:a,rowKey:`${a.id}-${h.name}`,displayName:`${a.name} â ${h.name}`,variantName:h.name,target:h.target,regular:h.count,storage:null,shopStock:ot?.count??null,label:Pe?Pe.count??null:h===Ke?o?.label??null:null,salesPerMonth:De,need:h.need})}continue}n(Q,{item:a,rowKey:String(a.id),displayName:a.name,target:se(a),regular:a.category==="Tea"?o?.jar??o?.regular??null:a.category==="Herbs"?o?.stock??null:a.category==="Candles"?Be(o).shelf:o?.regular??o?.jar??null,storage:a.category==="Tea"||a.category==="Herbs"?o?.storage??null:null,shopStock:a.category==="Candles"?Be(o).backStock:a.category==="CBD Tea"?a.shopStock??null:a.category==="CBD"?o?.stock??a.shopStock??null:o?.stock??null,label:o?.label??null,salesPerMonth:g?.salesPerMonth?.[a.id]??null,
1need:l})}return Array.from(s.keys()).sort(Ct).map(a=>{const o=s.get(a);return o.sort((l,r)=>l.displayName.localeCompare(r.displayName,void 0,{sensitivity:"base"})),{category:a,rows:o,totalNeed:o.reduce((l,r)=>l+r.need,0)}})},[G,g,p,v,N,j]),Le=u?Ae({sections:E,view:"ready-to-shelf",sort:x,forecastByItem:ge,boostMap:xe}):d?Ae({sections:E,view:"need-to-make",sort:x,forecastByItem:ge,boostMap:xe}):x==="sales"?Mt(E):E,V=$t(Le,N||j?L.filter(t=>t!=="Candles"):L),Te=V.reduce((t,s)=>t+s.totalNeed,0),ne=V.reduce((t,s)=>t+s.rows.length,0);function Ee(t){return t.replace(/&/g,"&").replace(/</g,"<")}function nt(){const t=V.filter(o=>o.rows.length>0&&o.category!=="Healings & Classes"&&o.category!=="Gift Packages").map(o=>{const l=o.category==="Tea"||o.category==="Herbs";return` 2 <h2>${Ee(o.category)} <span class="count">(${o.rows.length} items · ${o.totalNeed} units needed)</span></h2> 3 <table> 4 <thead><tr><th>Item</th><th class="num">Target</th><th class="num">${Oe(o.category)}</th>${l?'<th class="num">Storage</th>':""}<th class="num">Shop Stock</th><th class="num">Labels</th><th class="num">Sales/Mo</th><th class="num">Need</th><th class="num">Done</th></tr></thead> 5 <tbody> 6 ${o.rows.map(r=>`<tr> 7 <td>${Ee(r.displayName)}${qe(r.item)&&r.shopStock!=null?' <span style="color:#888;font-size:9px;font-weight:normal">1 oz</span>':""}</td> 8 <td class="num">${r.target}</td> 9 <td class="num">${r.regular??"â"}</td> 10 ${l?`<td class="num">${r.storage!=null?Number(r.storage).toFixed(1):"â"}</td>`:""} 11 <td class="num">${r.shopStock??"â"}</td> 12 <td class="num">${r.label??"â"}</td> 13 <td class="num">${r.salesPerMonth??"â"}</td> 14 <td class="num"><strong>${r.need}</strong>${r.need>0&&(r.shopStock??0)>0?` <span style="color:#15803d;font-size:9px;font-weight:600">(shelf ${Math.min(r.need,r.shopStock??0)})</span>`:""}</td> 15 <td class="num check">â</td> 16 </tr>`).join("")} 17 </tbody> 18 </table>`}).join(""),s=`<!DOCTYPE html><html><head><meta charset="utf-8"><title>Master Restock List</title> 19 <style> 20 body { font-family: -apple-system, Helvetica, Arial, sans-serif; padding: 24px; color: #2B4650; } 21 h1 { font-size: 20px; margin: 0 0 4px; } 22 p.meta { font-size: 11px; color: #666; margin: 0 0 16px; } 23 h2 { font-size: 14px; margin: 20px 0 6px; border-bottom: 2px solid #2B4650; padding-bottom: 3px; break-after: avoid; } 24 h2 .count { font-weight: normal; font-size: 11px; color: #666; } 25 table { width: 100%; border-collapse: collapse; font-size: 11px; margin-bottom: 8px; } 26 th, td { border-bottom: 1px solid #ddd; padding: 4px 8px; text-align: left; } 27 th { text-transform: uppercase; font-size: 9px; letter-spacing: 0.05em; color: #666; } 28 td.num, th.num { text-align: center; } 29 td.check { font-size: 14px; } 30 div.variants { font-size: 9px; color: #b91c1c;
30 margin-top: 1px; } 31 tr { break-inside: avoid; } 32 </style></head><body> 33 <h1>Master Restock List</h1> 34 <p class="meta">${ne} items · ${Te} units needed · generated ${new Date().toLocaleString("en-US",{timeZone:"America/New_York"})}${g?.syncedAt?` · Square synced ${new Date(g.syncedAt).toLocaleString("en-US",{timeZone:"America/New_York"})}`:""}</p> 35 ${t} 36 </body></html>`,n=new Blob([s],{type:"text/html;charset=utf-8"}),i=URL.createObjectURL(n),a=window.open(i,"_blank");a&&(a.onload=()=>a.print())}return e.jsxs(dt,{children:[e.jsxs("div",{className:"max-w-[1100px]",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row justify-between items-start sm:items-center mb-6 gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-serif text-primary mb-2","data-testid":"text-master-restock-title",children:"Master Restock List"}),e.jsx("p",{className:"text-muted-foreground",children:"Everything that needs restocking across all categories, based on live Square stock."}),g?.syncedAt&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-1","data-testid":"text-master-restock-synced",children:["Square synced ",new Date(g.syncedAt).toLocaleString("en-US",{timeZone:"America/New_York",month:"short",day:"numeric",hour:"numeric",minute:"2-digit",hour12:!0})]})]}),e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[e.jsxs(m,{variant:"outline",onClick:()=>Ze(),disabled:Ce,"data-testid":"button-refresh-master-restock",children:[Ce?e.jsx(re,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(Tt,{className:"h-4 w-4 mr-2"}),"Refresh"]}),e.jsxs(m,{className:"bg-primary text-white",onClick:nt,disabled:ae||ne===0,"data-testid":"button-print-master-restock",children:[e.jsx(Et,{className:"h-4 w-4 mr-2"}),"Print List"]})]})]}),!ae&&e.jsxs("div",{className:"flex flex-wrap gap-4 mb-6",children:[e.jsxs(K,{className:"p-4",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:"Items Needing Restock"}),e.jsx("div",{className:"text-2xl font-bold text-red-600","data-testid":"text-master-restock-items",children:ne})]}),e.jsxs(K,{className:"p-4",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:"Total Units Needed"}),e.jsx("div",{className:"text-2xl font-bold text-primary","data-testid":"text-master-restock-units",children:Te})]}),e.jsxs(K,{className:"p-4",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:"Categories"}),e.jsx("div",{className:"text-2xl font-bold","data-testid":"text-master-restock-categories",children:E.length})]})]}),e.jsxs("div",{className:"flex flex-col md:flex-row gap-3 mb-4",children:[e.jsxs("div",{className:"relative w-56",children:[e.jsx(mt,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(ie,{placeholder:"Search items...",className:"pl-10 bg-white",value:p,onChange:t=>P(t.target.value),"data-testid":"input-search-master-restock"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(m,{size:"sm",variant:!v&&!u&&!d?"default":"outline",onClick:()=>{R(!1),D(!1),z(!1),S("category")},"data-testid":"filter-master-needs",children:"Needs Restock"}),e.jsx(m,{size:"sm",variant:v&&!u&&!d?"default":"outline",onClick:()=>{R(!0),D(!1),z(!1),S("category")},"data-testid":"filter-master-all",children:"All Items"}),e.jsx(m,{size:"sm",variant:u?"default":"outline",className:u?"bg-green-600 hover:bg-green-700 text-white":"text-green-700 border-green-300 hover:bg-green-50",onClick:()=>{R(!1),D(!0),z(!1),S("category")},"data-testid":"filter-master-ready-to-shelf",children:"Ready to Shelf"}),e.jsx(m,{size:"sm",variant:d?"default":"outline",className:d?"bg-amber-600 hover:bg-amber-700 text-white":"text-amber-700 border-amber-300 hover:bg-amber-50",onClick:()=>{R(!1),D(!1),z(!0),S("category")},"data-testid":"filter-master-need-to-make",children:"Need to Make"})]}),e.jsxs("div",{className:"flex items-center gap-1 rounded-md border bg-white p-1",role:"group","aria-label":u?"Ready to Shelf sort order":d?"Need to Make sort order":"Master Restock sort order",children:[e.jsx("span",{className:"px-2 text-xs font-medium text-muted-foreground",children:"Sort:"}),(u||d)&&e.jsx(m,{size:"sm",variant:x==="priority"?"default":"ghost",className:"h-7 px-2",onClick:()=>S("priority"),"aria-pressed":x==="priority","data-testid":u?"sort-ready-to-shelf-priority":"sort-need-to-make-priority",children:"Priority"}
36),e.jsx(m,{size:"sm",variant:x!=="sales"&&(!u&&!d||x==="category")?"default":"ghost",className:"h-7 px-2",onClick:()=>S("category"),"aria-pressed":x==="category"||!u&&!d&&x!=="sales","data-testid":u?"sort-ready-to-shelf-category":d?"sort-need-to-make-category":"sort-master-category",children:"Category"}),e.jsx(m,{size:"sm",variant:x==="sales"?"default":"ghost",className:"h-7 px-2",onClick:()=>S("sales"),"aria-pressed":x==="sales",title:"Sort highest monthly sales first","data-testid":u?"sort-ready-to-shelf-sales":d?"sort-need-to-make-sales":"sort-master-sales",children:"Sales/Month"})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-4",role:"group","aria-label":"Candle missing inventory filters",children:[e.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"Candles:"}),e.jsxs(m,{size:"sm",variant:N?"default":"outline","aria-pressed":N,onClick:()=>me(t=>!t),"data-testid":"filter-master-candle-missing-shelf",children:["Missing from shelf (",st,")"]}),e.jsxs(m,{size:"sm",variant:j?"default":"outline","aria-pressed":j,onClick:()=>ue(t=>!t),"data-testid":"filter-master-candle-missing-back-stock",children:["Missing from back stock (",at,")"]}),(N||j)&&e.jsx(m,{size:"sm",variant:"ghost",onClick:()=>{me(!1),ue(!1)},children:"Clear missing filters"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Known Square count ⤠0 only (unknown excluded). Both filters show candles missing in both locations; counts follow search."})]}),ae?e.jsxs("div",{className:"flex flex-col items-center justify-center py-20 gap-3",children:[e.jsx(re,{className:"h-8 w-8 animate-spin text-primary"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Checking live Square stock across all categoriesâ¦"})]}):Le.length===0?e.jsxs(K,{className:"p-10 text-center text-muted-foreground",children:[e.jsx(ut,{className:"h-8 w-8 mx-auto mb-3 opacity-40"}),"Nothing needs restocking right now."]}):e.jsx("div",{className:"space-y-6",children:V.map(t=>e.jsxs(K,{className:"overflow-hidden","data-testid":`section-master-${t.category}`,children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 bg-gray-50 border-b",children:[e.jsx("h2",{className:"font-semibold text-lg",style:{color:"#2B4650"},children:t.category}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(xt,{variant:"outline",className:"border-red-200 text-red-600 font-bold",children:[t.totalNeed," needed"]}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[t.rows.length," items"]}),e.jsx(m,{size:"sm",variant:"ghost",className:"text-muted-foreground",title:L.includes(t.category)?"Show items that are also missing back stock":"Hide items with no back stock; show only shelf gaps ready to fill",onClick:()=>Qe(t.category),"aria-pressed":L.includes(t.category),"data-testid":`button-toggle-shelf-gaps-${t.category}`,children:L.includes(t.category)?e.jsx(ht,{className:"h-4 w-4"}):e.jsx(It,{className:"h-4 w-4"})})]})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-[10px] uppercase tracking-wide text-muted-foreground border-b",children:[e.jsx("th",{className:"px-4 py-2 text-left",children:"Item"}),e.jsx("th",{className:"px-4 py-2 text-center",children:"Target"}),e.jsx("th",{className:"px-4 py-2 text-center",children:Oe(t.category)}),(t.category==="Tea"||t.category==="Herbs")&&e.jsx("th",{className:"px-4 py-2 text-center",children:"Storage"}),e.jsx("th",{className:"px-4 py-2 text-center",children:"Shop Stock"}),e.jsx("th",{className:"px-4 py-2 text-center",children:"Labels"}),e.jsx("th",{className:"px-4 py-2 text-center",children:"Sales/Mo"}),e.jsx("th",{className:"px-4 py-2 text-center",children:"Need"}),e.jsx("th",{className:"px-4 py-2 text-center",children:"Make List"})]})}),e.jsx("tbody",{className:"divide-y",children:t.rows.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:t.category==="Tea"||t.category==="Herbs"?10:9,className:"px-4 py-6 text-center text-sm text-muted-foreground",children:"No shelf gaps in this category have back stock available."})}):t.rows.map(s=>e.jsxs("tr",{className:ze(s.need>0&&"bg-red-50/30"),"data-testid":`row-master-${s.rowKey}`,children:[e.jsxs("td",{className:"px-4 py-2 font-medium",style:{color:"#2B4650"},children:[Lt(Ge,u||d,x)&&e.jsxs("span",{className:"inline-flex flex-col mr-2 align-middle",children:[e.jsx("button",{className:"text-muted-foreground hover:text-foreground disabled:opacity-40",title:"Move up â I'd make/shelve this sooner",disabled:B.isPending,onClick:()=>B.mutate({restockItemId:s.item.id,variantName:s.variantName,listType:d?"need_to_make":"ready_to_shelf",direction:1}),"data-testid":`button-priority-up-${s.rowKey}`,children:e.jsx(Kt,{className:"h-3.5 w-3.5"})}),e.jsx("button",{className:"text-muted-foreground hover:text-foreground disabled:opacity-40",title:"Move down â this can wait",disabled:B.isPending,onClick:()=>B.mutate({restockItemId:s.item.id,variantName:s.variantName,listType:d?"need_to_make":"ready_to_shelf",direction:-1}),"data-testid":`button-priority-down-${s.rowKey}`,children:e.jsx(pt,{className:"h-3.5 w-3.5"})})]}),s.displayName,(u||d)&&s.item.category&&e.jsx("span",{className:"ml-2 text-[10px] font-normal uppercase tracking-wide text-muted-foreground","data-testid":`text-category-${s.rowKey}`,children:s.item.category}),qe(s.item)&&s.shopStock!=null&&e.jsx("span",{className:"ml-2 text-xs font-normal text-muted-foreground","data-testid":`text-oz-${s.rowKey}`,children:"1 oz"})]}),e.jsx("td",{className:"px-4 py-2 text-center font-mono",children:fe===`target-${s.rowKey}`?e.jsx("input",{type:"number",min:0,autoFocus:!0,className:"w-16 text-center border rounded px-1 py-0.5 text-sm font-mono",value:q,onChange:n=>J(n.target.value),onBlur:()=>Se(n=>we.mutate({id:s.item.id,data:s.variantName?{variationTargets:{[s.variantName]:n}}:{target:n}})),onKeyDown:n=>{n.key==="Enter"&&n.target.blur(),n.key==="Escape"&&A(null)},"data-testid":`input-target-${s.rowKey}`}):e.jsx("button",{className:"hover:bg-amber-50 rounded px-2 py-0.5 border border-transparent hover:border-amber-200 cursor-pointer font-mono",title:"Click to edit target",onClick:()=>ve(`target-${s.rowKey}`,s.target),"data-testid":`button-edit-target-${s.rowKey}`,children:s.target})}),e.jsx("td",{className:"px-4 py-2 text-center font-mono",children:s.regular??"â"}),(t.category==="Tea"||t.category==="Herbs")&&e.jsx("td",{className:"px-4 py-2 text-center font-mono",children:s.storage!=null?Number(s.storage).toFixed(1):"â"}),e.jsx("td",{className:"px-4 py-2 text-center font-mono",children:(t.category==="CBD Tea"||t.category==="CBD")&&!s.variantName?fe===`stock-${s.rowKey}`?e.jsx("input",{type:"number",min:0,autoFocus:!0,className:"w-16 text-center border rounded px-1 py-0.5 text-sm font-mono",value:q,onChange:n=>J(n.target.value),onBlur:()=>Se(n=>we.mutate({id:s.item.id,data:{shopStock:n}})),onKeyDown:n=>{n.key==="Enter"&&n.target.blur(),n.key==="Escape"&&A(null)},"data-testid":`input-stock-${s.rowKey}`}):e.jsx("button",{className:"hover:bg-amber-50 rounded px-2 py-0.5 border border-transparent hover:border-amber-200 cursor-pointer font-mono",title:"Click to edit shop stock",onClick:()=>ve(`stock-${s.rowKey}`,s.shopStock),"data-testid":`button-edit-stock-${s.rowKey}`,children:s.shopStock??"â"}):s.shopStock??"â"}),e.jsx("td",{className:"px-4 py-2 text-center font-mono","data-testid":`text-labels-${s.rowKey}`,children:s.label??"â"}),e.jsx("td",{className:"px-4 py-2 text-center font-mono","data-testid":`text-sales-mo-${s.rowKey}`,children:s.salesPerMonth??"â"}),e.jsxs("td",{className:"px-4 py-2 text-center",children:[e.jsx("span",{className:ze("font-bold",s.need>0?"text-red-600":"text-green-600"),children:s.need}),s.need>0&&(s.shopStock??0)>0&&e.jsxs("span",{className:"ml-2 inline-block rounded-full bg-green-100 text-green-700 text-[10px] font-semibold px-2 py-0.5 align-middle",title:"Back stock available â shelve it instead of making more","data-testid":`badge-shelf-${s.rowKey}`,children:["Shelf ",Math.min(s.need,s.shopStock??0)]})]}),e.jsx("td",{className:"px-4 py-2 text-center",children:s.item.squareProductId?e.jsxs(m,{size:"sm",variant:"outline",className:"h-7 px-2 text-xs",title:"Add to a make list",onClick:()=>We(s.item,s.displayName,s.need,s.variantName),"data-testid":`button-add-to-list-${s.rowKey}`,children:[e.jsx(Dt,{className:"h-3.5 w-3.5 mr-1"})," List"]}):e.jsx("span",{className:"text-xs text-muted-foreground",title:"Not linked to a Square product",children:"â"})})]},s.rowKey))})]})})]},t.category))})]}),e.jsx(gt,{open:!!f,onOpenChange:t=>{t||W(null)},children:e.jsxs(ft,{className:"sm:max-w-md",children:[e.jsx(yt,{children:e.jsx(kt,{children:"Add to Make List"})}),f&&e.jsxs("div",{className:"space-y-4 py-2",children:[e.jsxs("div",{className:"p-3 bg-gray-50 rounded-lg",children:[e.jsx("p",{className:"font-medium",children:f.displayName}),f.need>0&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Needs ",f.need," right now"]})]}),e.jsxs("div",{children:[e.jsx(le,{children:"Quantity"}),e.jsx(ie,{type:"number",min:1,value:Y,onChange:t=>ye(parseInt(t.target.value)||1),"data-testid":"input-master-list-quantity"})]}),X?e.jsxs("div",{className:"space-y-3 border rounded-lg p-3 bg-blue-50/50",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(le,{className:"text-sm font-medium",children:"New Make List"}),e.jsx(m,{variant:"ghost",size:"sm",className:"h-6 px-2 text-xs",onClick:()=>_(!1),children:"Use existing"})]}),e.jsx(ie,{placeholder:"List name...",value:O,onChange:t=>ee(t.target.value),"data-testid":"input-master-new-list-name"})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx(le,{children:"Select Make List"}),te.length>0?e.jsxs(bt,{value:Z?.toString()||"",onValueChange:t=>ke(parseInt(t)),children:[e.jsx(Nt,{"data-testid":"select-master-make-list",children:e.jsx(jt,{placeholder:"Choose a list..."})}),e.jsx(wt,{children:te.map(t=>e.jsxs(vt,{value:t.id.toString(),children:[t.name," (",t.status,")"]},t.id))})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"No lists yet â create one below."}),e.jsxs(m,{variant:"link",size:"sm",className:"px-0 text-xs",onClick:()=>_(!0),"data-testid":"button-master-create-new-list",children:[e.jsx(Pt,{className:"h-3 w-3 mr-1"})," Create New List"]})]}),e.jsxs(m,{className:"w-full",onClick:Je,disabled:je||(X?!O.trim():!Z),"data-testid":"button-master-confirm-ad
36d-to-list",children:[je&&e.jsx(re,{className:"h-4 w-4 animate-spin mr-2"}),"Add to List"]})]})]})})]})}export{ss 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.