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{r}from"./api-CycUopBp.js";import{t as i}from"./list-table-DNq_Jbx2.js";import{t as a}from"./plus-BEDg_66Y.js";import{t as o}from"./save-D-WHGflg.js";import{Pt as s,Ra as c,Tt as l,Xt as u,aa as d,pn as f,za as p}from"./index-CsuVxiRQ.js";import{t as m}from"./page-content-DdXVZwik.js";import{t as h}from"./badge-DLCseWie.js";import{a as g,i as _,n as v,o as y,t as b}from"./dialog-BT7QjyH-.js";import{t as x}from"./record-actions-BJhHCezi.js";import{t as S}from"./list-page-header-BnFKDjpb.js";import{t as C}from"./use-server-pagination-BC4JB9I3.js";import{t as w}from"./auth-status-badge-C6fBtAs6.js";var T=e(t(),1),E=n(),D={name:``,tax_type:`gst`,rate:``,status:`active`};function O(){let[e,t]=(0,T.useState)(``),[n,O]=(0,T.useState)(!1),[k,A]=(0,T.useState)(null),[j,M]=(0,T.useState)(D),[N,P]=(0,T.useState)(!1),F=C(),I=F.buildParams(e?{search:e}:void 0),{data:L,isLoading:R,refetch:z}=u(I),B=F.getItems(L),[V,{isLoading:H}]=l(),[U,{isLoading:W}]=f(),[G]=s(),K=()=>{A(null),M(D),P(!1),O(!0)},q=e=>{A(e.id),M({name:e.name,tax_type:e.tax_type,rate:e.rate,status:e.status}),P(!1),O(!0)},J=e=>{A(e.id),M({name:e.name,tax_type:e.tax_type,rate:e.rate,status:e.status}),P(!0),O(!0)},Y=async e=>{e.preventDefault(),k?await U({id:k,data:j}):await V(j),O(!1)},X=(e,t)=>M(n=>({...n,[e]:t}));return(0,E.jsxs)(m,{children:[(0,E.jsx)(S,{title:`Taxes`,description:`Manage tax master data`,searchPlaceholder:`Search taxes...`,searchValue:e,onSearchChange:e=>{t(e),F.setPage(1)},action:(0,E.jsxs)(p,{onClick:K,size:`sm`,children:[(0,E.jsx)(a,{className:`mr-2 h-4 w-4`}),` Add Tax`]})}),(0,E.jsx)(i,{data:B,columns:[{key:`code`,label:`Code`,render:e=>(0,E.jsx)(`span`,{className:`font-mono`,children:e.code})},{key:`name`,label:`Name`,render:e=>(0,E.jsx)(`span`,{className:`font-medium`,children:e.name})},{key:`tax_type`,label:`Type`,render:e=>(0,E.jsx)(`span`,{className:`uppercase`,children:e.tax_type})},{key:`rate`,label:`Rate (%)`,className:`text-center`,render:e=>(0,E.jsx)(`span`,{className:`font-mono`,children:e.rate})},{key:`status`,label:`Status`,render:e=>(0,E.jsx)(h,{variant:e.status===`active`?`default`:`secondary`,children:e.status})},{key:`authorized_status`,label:`Auth`,render:e=>(0,E.jsx)(w,{status:e.authorized_status})},{key:`actions`,label:`Actions`,sortable:!1,render:e=>(0,E.jsx)(x,{approval:{entityType:`Tax`,objectId:e.id,contentTypeId:r.TAX,authorizedStatus:e.authorized_status??1,onApprovalChange:()=>z()},onView:()=>J(e),onEdit:()=>q(e),onDelete:()=>G(e.id)})}],isLoading:R,rowKey:e=>e.id,emptyMessage:`No taxes found`,...F.tableProps(L)}),(0,E.jsx)(b,{open:n,onOpenChange:O,children:(0,E.jsxs)(v,{className:`sm:max-w-md`,children:[(0,E.jsx)(g,{children:(0,E.jsx)(y,{children:N?`View Tax`:k?`Edit Tax`:`New Tax`})}),(0,E.jsxs)(`form`,{onSubmit:Y,className:`space-y-4`,children:[(0,E.jsxs)(`div`,{className:`space-y-2`,children:[(0,E.jsxs)(d,{children:[`Tax Name `,(0,E.jsx)(`span`,{className:`text-destructive`,children:`*`})]}),(0,E.jsx)(c,{placeholder:`e.g. GST 18%`,value:j.name,onChange:e=>X(`name`,e.target.value),required:!0,disabled:N})]}),(0,E.jsxs)(`div`,{className:`grid grid-cols-2 gap-4`,children:[(0,E.jsxs)(`div`,{className:`space-y-2`,children:[(0,E.jsxs)(d,{children:[`Tax Type `,(0,E.jsx)(`span`,{className:`text-destructive`,children:`*`})]}),(0,E.jsxs)(`select`,{value:j.tax_type,onChange:e=>X(`tax_type`,e.target.value),className:`w-full border rounded-md px-3 py-2 text-sm h-9`,disabled:N,children:[(0,E.jsx)(`option`,{value:`gst`,children:`GST`}),(0,E.jsx)(`option`,{value:`vat`,children:`VAT`}),(0,E.jsx)(`option`,{value:`custom`,children:`Custom`})]})]}),(0,E.jsxs)(`div`,{className:`space-y-2`,children:[(0,E.jsx)(d,{children:`Rate (%) *`}),(0,E.jsx)(c,{type:`number`,step:`0.01`,placeholder:`18.00`,value:j.rate,onChange:e=>X(`rate`,e.target.value),required:!0,disabled:N})]})]}),(0,E.jsxs)(`div`,{className:`space-y-2`,children:[(0,E.jsx)(d,{children:`Status`}),(0,E.jsxs)(`select`,{value:j.status,onChange:e=>X(`status`,e.target.value),className:`w-full border rounded-md px-3 py-2 text-sm h-9`,disabled:N,children:[(0,E.jsx)(`option`,{value:`active`,children:`Active`}),(0,E.jsx)(`option`,{value:`inactive`,children:`Inactive`})]})]}),(0,E.jsxs)(_,{children:[(0,E.jsx)(p,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>O(!1),children:`Cancel`}),!N&&(0,E.jsxs)(p,{type:`submit`,size:`sm`,disabled:H||W,children:[(0,E.jsx)(o,{className:`mr-2 h-4 w-4`}),H||W?`Saving...`:`Save`]})]})]})]})})]})}export{O as default};