import{i as e}from"./rolldown-runtime-Dd_uD5pT.js";import{t}from"./react-BatatxyT.js";import{s as n}from"./utils-BO1RPuol.js";import{t as r}from"./list-table-DNq_Jbx2.js";import{t as i}from"./funnel-CzLimyxu.js";import{t as a}from"./pencil-BqU8IP9o.js";import{t as o}from"./plus-BEDg_66Y.js";import{n as s,t as c}from"./filter-sheet-guEWYDqt.js";import{t as l}from"./trash-2-C4tYX-tx.js";import{Hr as u,os as d,v as f,x as p,za as m}from"./index-CsuVxiRQ.js";import{t as h}from"./page-content-DdXVZwik.js";import{t as g}from"./badge-DLCseWie.js";import{t as _}from"./delete-dialog-Dh646Vw6.js";import{t as v}from"./list-page-header-BnFKDjpb.js";var y=e(t(),1),b=n(),x={tender_summary:`Enquiry Summary`,enquiry:`Enquiry`,purchase_quotation:`Purchase Quotation`,vendor_comparison:`Vendor Comparison`,budget_enquiry:`Offer`,sales_order:`Sales Order`,sales_invoice:`Sales Invoice`,purchase_order:`Purchase Order`,service_invoice:`Service Invoice`};function S(){let e=d(),[t,n]=(0,y.useState)(``),[S,C]=(0,y.useState)(`all`),[w,T]=(0,y.useState)(`all`),[E,D]=(0,y.useState)(`all`),[O,k]=(0,y.useState)(!1),A={};S!==`all`&&(A.document_type=S),w!==`all`&&(A.branch=w),E!==`all`&&(A.is_active=E);let{data:j=[],isLoading:M}=p(Object.keys(A).length?A:void 0),{data:N=[]}=u(),[P]=f(),[F,I]=(0,y.useState)(null),[L,R]=(0,y.useState)(!1),z=j.filter(e=>!t||e.name.toLowerCase().includes(t.toLowerCase())),B=async()=>{if(F){R(!0);try{await P(F)}finally{R(!1),I(null)}}},V=()=>{C(`all`),T(`all`),D(`all`)},H=[S,w,E].filter(e=>e!==`all`).length;return(0,b.jsxs)(h,{children:[(0,b.jsx)(v,{title:`Print Templates`,description:`Manage PDF print templates for documents`,searchPlaceholder:`Search templates...`,searchValue:t,onSearchChange:n,action:(0,b.jsxs)(m,{onClick:()=>e(`/settings/print-templates/new`),size:`sm`,children:[(0,b.jsx)(o,{className:`mr-2 h-4 w-4`}),` Create Template`]}),filter:(0,b.jsxs)(m,{variant:`outline`,size:`sm`,onClick:()=>k(!0),className:`relative`,children:[(0,b.jsx)(i,{className:`mr-2 h-4 w-4`}),` Filters`,H>0&&(0,b.jsx)(g,{variant:`destructive`,className:`ml-2 size-5 p-0 flex items-center justify-center text-[10px]`,children:H})]})}),(0,b.jsx)(r,{data:z,columns:[{key:`name`,label:`Name`,render:e=>(0,b.jsx)(`span`,{className:`font-medium`,children:e.name})},{key:`document_type`,label:`Document Type`,render:e=>x[e.document_type]||e.document_type},{key:`branch_name`,label:`Branch`,render:e=>e.branch_name||`—`},{key:`is_default`,label:`Default`,render:e=>e.is_default?(0,b.jsx)(g,{variant:`default`,children:`Default`}):null},{key:`is_active`,label:`Active`,render:e=>(0,b.jsx)(g,{variant:e.is_active?`default`:`secondary`,children:e.is_active?`Active`:`Inactive`})},{key:`actions`,label:`Actions`,sortable:!1,render:t=>(0,b.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,b.jsx)(m,{variant:`ghost`,size:`icon`,className:`size-8`,onClick:()=>e(`/settings/print-templates/${t.id}/edit`),children:(0,b.jsx)(a,{className:`size-4`})}),(0,b.jsx)(m,{variant:`ghost`,size:`icon`,className:`size-8 text-destructive`,onClick:()=>I(t.id),children:(0,b.jsx)(l,{className:`size-4`})})]})}],isLoading:M,rowKey:e=>e.id,emptyMessage:`No print templates found`}),(0,b.jsxs)(s,{open:O,onOpenChange:k,onClear:V,children:[(0,b.jsx)(c,{label:`Document Type`,value:S,onChange:C,placeholder:`All Document Types`,options:Object.entries(x).map(([e,t])=>({value:e,label:t}))}),(0,b.jsx)(c,{label:`Branch`,value:w,onChange:T,placeholder:`All Branches`,options:N.map(e=>({value:String(e.id),label:e.name}))}),(0,b.jsx)(c,{label:`Status`,value:E,onChange:D,placeholder:`All Status`,options:[{value:`true`,label:`Active`},{value:`false`,label:`Inactive`}]})]}),(0,b.jsx)(_,{open:!!F,onOpenChange:e=>{e||I(null)},title:`Delete Template`,description:`Are you sure you want to delete this print template?`,isDeleting:L,onConfirm:B})]})}export{S as default};