import{a as e,t}from"./react-D0JuimcS.js";import{o as n}from"./utils-Dac180Gn.js";import{t as r}from"./list-table-dcNbCPvq.js";import{t as i}from"./funnel-BDsPorMA.js";import{t as a}from"./pencil-COtUf-LL.js";import{t as o}from"./plus-VCCEyniC.js";import{n as s,t as c}from"./filter-sheet-Baado-aR.js";import{t as l}from"./trash-2-D_alEpce.js";import{Fo as u,ga as d,kr as f,v as p,x as m}from"./index-BP3TYB4i.js";import{t as h}from"./page-content-DDtdeMxM.js";import{t as g}from"./badge-Crg76WQE.js";import{t as _}from"./delete-dialog-lcfaabJj.js";import{t as v}from"./list-page-header-48VsPegf.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=u(),[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}=m(Object.keys(A).length?A:void 0),{data:N=[]}=f(),[P]=p(),[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)(d,{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)(d,{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)(d,{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)(d,{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};