import{n as e,r as t}from"./rolldown-runtime-hePW80VL.js";import{n,t as r}from"./jsx-runtime-DE3RlOCf.js";import{O as i}from"./index.esm-LYJbezK8.js";import{t as a}from"./package-Mf_iN3FS.js";import{t as o}from"./plus-DGR5k6Bn.js";import{t as s}from"./x-Du0SjteG.js";import{t as c}from"./utils-kzSVkeKt.js";import{t as l}from"./ProductSelectModal-DEBlrQaE.js";var u=e({AlternateProductsTableField:()=>p}),d=t(n(),1),f=t(r(),1);function p({value:e=[],onChange:t,disabled:n,apiPrefix:r=`product-masters`,label:u=`Alternate Product`,error:p}){let[m,h]=(0,d.useState)(!1),g=n=>{let r=new Set(e.map(e=>String(e.id)));t([...e,...n.filter(e=>!r.has(String(e.id)))])},_=n=>{t(e.filter(e=>String(e.id)!==n))};return(0,f.jsxs)(`div`,{className:`space-y-1.5`,children:[e.length>0&&(0,f.jsx)(`div`,{className:`rounded-md border border-border overflow-hidden`,children:(0,f.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,f.jsx)(`thead`,{children:(0,f.jsxs)(`tr`,{className:`bg-muted/50 border-b border-border`,children:[(0,f.jsx)(`th`,{className:`px-2 py-1.5 text-left text-[10px] font-semibold uppercase tracking-wider text-muted-foreground`,children:`#`}),(0,f.jsx)(`th`,{className:`px-2 py-1.5 text-left text-[10px] font-semibold uppercase tracking-wider text-muted-foreground`,children:`Name`}),(0,f.jsx)(`th`,{className:`px-2 py-1.5 text-left text-[10px] font-semibold uppercase tracking-wider text-muted-foreground`,children:`Code`}),(0,f.jsx)(`th`,{className:`px-2 py-1.5 w-7`})]})}),(0,f.jsx)(`tbody`,{children:e.map((e,t)=>(0,f.jsxs)(`tr`,{className:c(`border-t border-border`,t%2==0?`bg-background`:`bg-muted/20`),children:[(0,f.jsx)(`td`,{className:`px-2 py-1.5 text-muted-foreground tabular-nums`,children:t+1}),(0,f.jsx)(`td`,{className:`px-2 py-1.5 text-foreground font-medium truncate max-w-[160px]`,children:e.name||e.display||e.code||`—`}),(0,f.jsx)(`td`,{className:`px-2 py-1.5 text-muted-foreground font-mono truncate max-w-[100px]`,children:e.code||`—`}),(0,f.jsx)(`td`,{className:`px-2 py-1.5 text-right`,children:!n&&(0,f.jsx)(`button`,{type:`button`,onClick:()=>_(String(e.id)),className:`text-muted-foreground hover:text-destructive transition-colors`,children:(0,f.jsx)(s,{className:`h-3 w-3`})})})]},e.id||t))})]})}),e.length===0&&(0,f.jsxs)(`div`,{className:`flex items-center gap-2 rounded-md border border-dashed border-border px-3 py-2 text-xs text-muted-foreground`,children:[(0,f.jsx)(a,{className:`h-3.5 w-3.5 shrink-0`}),`No `,u.toLowerCase(),`s selected`]}),!n&&(0,f.jsxs)(i,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>h(!0),className:`h-7 text-xs gap-1.5`,children:[(0,f.jsx)(o,{className:`h-3 w-3`}),`Add `,u]}),p&&(0,f.jsx)(`p`,{className:`text-[11px] text-destructive mt-0.5`,children:p}),(0,f.jsx)(l,{open:m,onClose:()=>h(!1),onSelect:()=>{},multiSelect:!0,onMultiSelect:g,initialMultiSelected:e,apiPrefix:r,label:u})]})}export{u as n,p as t};