1import{r as x,j as e}from"./react-vendor-DTEXiHme.js";import{l as g,i as j,P as b,d as N}from"./index-uBhdqU9F.js";import{F as m}from"./folder-open-DrEz1CRk.js";import"./excel-CPlAJqTR.js";import"./radix-C8G44Doi.js";function y(t,a){var c,i;const s=new Map;for(const r of t)s.set(r.record_id,{record_id:r.record_id,name:r.name,depth:r.depth,parent_id:r.parent_id,children:[],products:[]});const d=[];for(const r of a){const l=(i=(c=r.relationships)==null?void 0:c.product_category)==null?void 0:i.record_id;l&&s.has(l)?s.get(l).products.push(r):d.push(r)}const o=[];for(const r of s.values())r.parent_id&&s.has(r.parent_id)?s.get(r.parent_id).children.push(r):o.push(r);const n=r=>{r.sort((l,f)=>l.name.localeCompare(f.name));for(const l of r)n(l.children)};return n(o),{tree:o,uncategorized:d}}function u({node:t,onProductClick:a}){const[s,d]=x.useState(!0),o=t.products.length+t.children.reduce((n,c)=>n+h(c),0);return e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>d(!s),className:"w-full flex items-center gap-2 px-3 py-2 hover:bg-muted/30 rounded-lg transition-colors",children:[s?e.jsx(g,{className:"h-3.5 w-3.5 text-muted-foreground flex-shrink-0"}):e.jsx(j,{className:"h-3.5 w-3.5 text-muted-foreground flex-shrink-0"}),e.jsx(m,{className:"h-3.5 w-3.5 text-amber-500 flex-shrink-0"}),e.jsx("span",{className:"text-sm font-medium truncate",children:t.name}),e.jsx("span",{className:"text-[10px] text-muted-foreground ml-auto tabular-nums",children:o})]}),s&&e.jsxs("div",{className:"ml-5 border-l border-border/50 pl-2",children:[t.children.map(n=>e.jsx(u,{node:n,onProductClick:a},n.record_id)),t.products.map(n=>e.jsx(p,{record:n,onClick:a},n.record_id)),t.children.length===0&&t.products.length===0&&e.jsx("div",{className:"px-3 py-1.5 text-xs text-muted-foreground italic",children:"Empty category"})]})]})}function p({record:t,onClick:a}){var o;const s=((o=t.attributes)==null?void 0:o.title)||"Untitled",d=t.status??"draft";return e.jsxs("button",{onClick:()=>a==null?void 0:a(t.record_id),className:"w-full flex items-center gap-2 px-3 py-1.5 hover:bg-muted/30 rounded-lg transition-colors",children:[e.jsx(b,{className:"h-3.5 w-3.5 text-muted-foreground flex-shrink-0"}),e.jsx("span",{className:"text-xs truncate flex-1 text-left",children:s}),e.jsx("span",{className:N("text-[9px] px-1.5 py-0.5 rounded-full flex-shrink-0",d==="active"&&"bg-green-100 text-green-700 dark:bg-green-900 dark:text-green-300",d==="draft"&&"bg-amber-100 text-amber-700 dark:bg-amber-900 dark:text-amber-300",d==="archived"&&"bg-gray-100 text-gray-500 dark:bg-gray-800 dark:text-gray-400"),children:d})]})}function h(t){return t.products.length+t.children.reduce((a,s)=>a+h(s),0)}function z({records:t,categories:a,isLoading:s,onProductClick:d}){const{tree:o,uncategorized:n}=x.useMemo(()=>y(a,t),[a,t]);return s?e.jsx("div",{className:"flex items-center justify-center py-16 text-sm text-muted-foreground",children:"Loading taxonomyâ¦"}):e.jsxs("div",{className:"p-4",children:[o.map(c=>e.jsx(u,{node:c,onProductClick:d},c.record_id)),n.length>0&&e.jsxs("div",{className:"mt-4",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2",children:[e.jsx(m,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:"Uncategorized"}),e.jsx("span",{className:"text-[10px] text-muted-foreground ml-auto tabular-nums",children:n.length})]}),e.jsx("div",{className:"ml-5 border-l border-border/50 pl-2",children:n.map(c=>e.jsx(p,{record:c,onClick:d},c.record_id))})]}),o.length===0&&n.length===0&&e.jsx("div",{className:"flex items-center justify-center py-16 text-sm text-muted-foreground",children:"No products in this view."})]})}export{z as ProductsTaxonomyView};
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.