import{u as T,a as H,b as t,j as e,H as V}from"./app-CyJEXGyv.js";import{A as E}from"./app-layout-DbUGBUec.js";import{C as g,a as b,b as v,d as w}from"./card-BjOMVxEn.js";import{C as o}from"./checkbox-GQkAN5_R.js";import{B as K}from"./button-COEJSQkW.js";import{I as C}from"./input-De4RhZu7.js";import q from"./preview-uIckN1R6.js";import"./utils-D3rN0LeJ.js";import"./sheet-D9YCjyPN.js";import"./index-JbHgsFAK.js";import"./index-BiS8IM9B.js";import"./x-CEXz2EER.js";import"./createLucideIcon-DqnlFWer.js";import"./index-CeYyXWc4.js";import"./index-D448AvbX.js";import"./truck-DSNzHzca.js";import"./package-Ca-wQg6n.js";import"./shopping-bag-kX2qM3ec.js";import"./app-logo-icon-bwP4qd8Q.js";import"./bluetooth-context-DlC5mQaA.js";import"./index-BtT9Eyya.js";import"./index-l-_2VD5G.js";import"./sonner-DMUJNVEP.js";function ne(){const{template:m,variants:p}=T().props,{data:r,setData:k}=H({variant_ids:[]}),[n,y]=t.useState(""),[u,x]=t.useState(""),[h,c]=t.useState(!1),[j,_]=t.useState(!0),[f,S]=t.useState(!1),[d,N]=t.useState({});t.useEffect(()=>{if(!n.trim()){x(""),c(!1);return}c(!0);const a=setTimeout(()=>{x(n),c(!1)},300);return()=>clearTimeout(a)},[n]);const B=(a,s)=>{k("variant_ids",s?[...r.variant_ids,a]:r.variant_ids.filter(i=>i!==a)),s&&!d[a]&&N(i=>({...i,[a]:1}))},P=(a,s)=>{N(i=>({...i,[a]:Math.max(1,s)}))},L=p.filter(a=>a.name.toLowerCase().includes(u.toLowerCase())),l=p.filter(a=>r.variant_ids.includes(Number(a.id))).map(a=>({...a,qty:d[Number(a.id)]??1}));return e.jsxs(E,{children:[e.jsx(V,{title:"Generate Barcode"}),e.jsxs("div",{className:"p-4 space-y-6",children:[e.jsxs(g,{className:"no-print",children:[e.jsx(b,{children:e.jsx(v,{children:"Pengaturan Label"})}),e.jsxs(w,{className:"flex flex-wrap gap-6",children:[e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx(o,{checked:j,onChange:a=>_(a.target.checked)}),e.jsx("span",{children:"Tampilkan Nama Variant"})]}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx(o,{checked:f,onChange:a=>S(a.target.checked)}),e.jsx("span",{children:"Tampilkan Harga"})]})]})]}),e.jsxs(g,{className:"no-print",children:[e.jsx(b,{children:e.jsxs(v,{children:["Generate Barcode - ",m.name]})}),e.jsxs(w,{className:"space-y-4",children:[e.jsx(C,{placeholder:"Cari produk berdasarkan nama produk",value:n,onChange:a=>y(a.target.value)}),h&&e.jsx("div",{className:"text-sm text-muted-foreground p-4 flex items-center justify-center",children:"Mencari produk..."}),!h&&u&&e.jsx("div",{className:"space-y-3",children:L.map(a=>e.jsxs("div",{className:"border rounded-lg p-3 space-y-2 flex items-center justify-between gap-4",children:[e.jsxs("label",{className:"flex items-center gap-4",children:[e.jsx(o,{checked:r.variant_ids.includes(Number(a.id)),onChange:s=>B(Number(a.id),s.target.checked)}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:a.name}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[a.barcode," • ",a.unit_name]})]})]}),r.variant_ids.includes(Number(a.id))&&e.jsxs("div",{className:"flex items-center gap-3 pl-8",children:[e.jsx("span",{className:"text-sm",children:"Jumlah label"}),e.jsx(C,{type:"number",min:1,className:"w-24",value:d[Number(a.id)]??1,onChange:s=>P(Number(a.id),Number(s.target.value))})]})]},a.id))})]})]}),l.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("h3",{className:"text-lg font-semibold no-print",children:"Preview Barcode"}),e.jsx("div",{className:"print-wrapper",children:e.jsx("div",{className:"print-canvas",children:e.jsx(q,{template:m,variants:l,showName:j,showPrice:f})})})]}),e.jsx("div",{className:"no-print",children:e.jsx(K,{disabled:l.length===0,onClick:()=>window.print(),children:"Print Barcode"})})]})]})}export{ne as default};
