1import{w as S,i as $,r as j,a as C,c as N,j as e,a6 as k,L as w,B as n,ab as y,ac as P,b as m}from"./index-DQRZPzqR.js";import{L as E,g as V}from"./Layout-Bn407Rjh.js";import{P as R}from"./package-x-B6o5raSJ.js";import"./chart-no-axes-column-8R6ZplEH.js";import"./users-G1WI2zrz.js";import"./triangle-alert-3RlYCIqx.js";import"./mail-DfJNwXQX.js";import"./graduation-cap-CvGA7XSh.js";import"./trending-up-DOgi-3vC.js";import"./file-text-BQdsZdj4.js";import"./link-2-B3Gbj_7o.js";const p=()=>({"x-admin-token":V()});function L(r){try{return JSON.parse(r||"[]")[0]??null}catch{return null}}function M(r){try{const s=JSON.parse(r||"{}"),i=s.Size||s["Shoe Size UK"]||null,l=s.Colour||s.Color||null;return[i,l].filter(Boolean).join(" / ")||"No size/colour data"}catch{return"No size/colour data"}}function J(){const{toast:r}=S(),s=$(),[i,l]=j.useState("products"),[a,h]=j.useState(0),o=50,{data:g,isLoading:c}=C({queryKey:["/api/admin/dedup-review"],queryFn:()=>m("GET","/api/admin/dedup-review",void 0,p()).then(t=>t.json())}),b=N({mutationFn:t=>m("POST",`/api/admin/dedup-review/restore-product/${t}`,void 0,p()),onSuccess:()=>{s.invalidateQueries({queryKey:["/api/admin/dedup-review"]}),r({title:"Product restored to active"})},onError:()=>r({title:"Error restoring product",variant:"destructive"})}),v=N({mutationFn:t=>m("POST",`/api/admin/dedup-review/restore-variant/${t}`,void 0,p()),onSuccess:()=>{s.invalidateQueries({queryKey:["/api/admin/dedup-review"]}),r({title:"Variant restored"})},onError:()=>r({title:"Error restoring variant",variant:"destructive"})}),x=g?.archivedProducts??[],d=g?.mergedVariants??[],u=Math.max(1,Math.ceil(d.length/o)),z=d.slice(a*o,(a+1)*o);return e.jsxs("div",{className:"p-6 space-y-6",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-lg font-black uppercase tracking-tight text-foreground flex items-center gap-2",children:[e.jsx(E,{size:16,className:"text-amber-400"}),"Duplicate Review"]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:"Products and variants removed as duplicates. Nothing is ever deleted, everything here can be restored."})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"bg-card border border-card-border rounded p-4",children:[e.jsx("p",{className:"text-xs text-muted-foreground uppercase tracking-wider mb-1",children:"Archived Duplicate Products"}),e.jsx("p",{className:"text-2xl font-black text-foreground",children:c?"â":x.length}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"whole product rows hidden from storefront"})]}),e.jsxs("div",{className:"bg-card border border-card-border rounded p-4",children:[e.jsx("p",{className:"text-xs text-muted-foreground uppercase tracking-wider mb-1",children:"Merged Duplicate Variants"}),e.jsx("p",{className:"text-2xl font-black text-foreground",children:c?"â":d.length}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"redundant size/colour rows hidden inside products"})]})]}),e.jsxs("div",{className:"flex gap-2 border-b border-border",children:[e.jsxs("button",{onClick:()=>l("products"),className:`px-3 py-2 text-xs font-bold uppercase tracking-wider border-b-2 transition-colors ${i==="products"?"border-blue-500 text-foreground":"border-transparent text-muted-foreground hover:text-foreground"}`,"data-testid":"tab-archived-products",children:["Archived Products (",x.length,")"]}),e.jsxs("button",{onClick:()=>l("variants"),className:`px-3 py-2 text-xs font-bold uppercase tracking-wider border-b-2 transition-colors ${i==="variants"?"border-blue-500 text-foreground":"border-transparent text-muted-foreground hover:text-foreground"}`,"data-testid":"tab-merged-variants",children:["Merged Variants (",d.length,")"]})]}),c&&e.jsx("div",{className:"bg-card border border-card-border rounded p-8 text-center text-sm text-muted-foreground",children:"Loading..."}),!c&&i==="products"&&(x.length===0?e.jsx("div",{className:"bg-card border border-card-border rounded p-8 text-center",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"No archived duplicate products."})}):e.jsx("div",{className:"bg-card border border-card-border rounded overflow-hidden",children:e.jsx("div",{className:"divide-y divide-border",children:x.map(t=>{const f=L(t.images);return e.jsxs("div",{className:"flex items-center gap-4 px-4 py-3","data-testid":`row-archived-product-${t.id}`,children:[f?e.jsx("img",{src:f,alt:t.name,className:"w-12 h-12 object-cover rounded flex-shrink-0 bg-muted"}):e.jsx("div",{className:"w-12 h-12 rounded flex-shrink-0 bg-muted flex items-center justify-center",children:e.jsx(R,{size:16,className:"text-muted-foreground"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"text-sm font-medium text-foreground truncate",children:t.name}),e.jsxs(k,{variant:"secondary",className:"text-xs flex-shrink-0",children:["#",t.id]})]}),e.jsx("p",{className:"text-xs text-muted-foreground font-mono",children:t.sku}),e.jsx("p",{className:"text-xs text-amber-500 mt-1",children:t.adminNote})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx(w,{href:`/admin/products/${t.id}`,"data-testid":`link-edit-product-${t.id}`,children:e.jsxs(n,{variant:"outline",size:"sm",className:"text-xs gap-1",children:["Edit ",e.jsx(y,{size:11})]})}),e.jsxs(n,{variant:"outline",size:"sm",className:"text-xs gap-1",onClick:()=>b.mutate(t.id),disabled:b.isPending,"data-testid":`button-restore-product-${t.id}`,children:[e.jsx(P,{size:11})," Restore"]})]})]},t.id)})})})),!c&&i==="variants"&&(d.length===0?e.jsx("div",{className:"bg-card border border-card-border rounded p-8 text-center",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"No merged duplicate variants."})}):e.jsxs("div",{className:"bg-card border border-card-border rounded overflow-hidden",children:[e.jsx("div",{className:"divide-y divide-border",children:z.map(t=>e.jsxs("div",{className:"flex items-center gap-4 px-4 py-3","data-testid":`row-merged-variant-${t.id}`,children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"text-sm font-medium text-foreground truncate",children:t.productName}),e.jsxs(k,{variant:"secondary",className:"text-xs flex-shrink-0",children:["variant #",t.id]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground font-mono",children:[t.sku," · ",M(t.attributes)]}),e.jsx("p",{className:"text-xs text-amber-500 mt-1",children:t.mergedNote})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx(w,{href:`/admin/products/${t.productId}`,"data-testid":`link-edit-variant-product-${t.productId}`,children:e.jsxs(n,{variant:"outline",size:"sm",className:"text-xs gap-1",children:["View Product ",e.jsx(y,{size:11})]})}),e.jsxs(n,{variant:"outline",size:"sm",className:"text-xs gap-1",onClick:()=>v.mutate(t.id),disabled:v.isPending,"data-testid":`button-restore-variant-${t.id}`,children:[e.jsx(P,{size:11})," Restore"]})]})]},t.id))}),e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-t border-border",children:[e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Showing ",a*o+1,"-",Math.min((a+1)*o,d.length)," of ",d.length]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(n,{variant:"outline",size:"sm",className:"text-xs",onClick:()=>h(t=>Math.max(0,t-1)),disabled:a===0,"data-testid":"button-variants-prev-page",children:"Previous"}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["Page ",a+1," of ",u]}
1),e.jsx(n,{variant:"outline",size:"sm",className:"text-xs",onClick:()=>h(t=>Math.min(u-1,t+1)),disabled:a>=u-1,"data-testid":"button-variants-next-page",children:"Next"})]})]})]}))]})}export{J 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.