import{a as e,t}from"./react-D0JuimcS.js";import{o as n}from"./utils-Dac180Gn.js";import{t as r}from"./list-table-M8Qu8ozW.js";import{t as i}from"./plus-VCCEyniC.js";import{t as a}from"./save-Cm-Rqwuf.js";import{i as o,o as s,s as c}from"./Helper-7k0HBglN.js";import{Ki as l,ci as u,ga as d,ha as f}from"./index-8M5AnKdQ.js";import{t as p}from"./page-content-DDtdeMxM.js";import{t as m}from"./badge-Crg76WQE.js";import{a as h,i as g,n as _,o as v,t as y}from"./dialog-CILF_XUh.js";import{t as b}from"./record-actions-3WNKE8L8.js";import{t as x}from"./list-page-header-DTmo84Zp.js";import{t as S}from"./use-server-pagination-CjwQ90IL.js";import{t as C}from"./auth-status-badge-pVqOsTb5.js";var w=e(t(),1),T=n(),E=[{value:`general`,label:`General`},{value:`payment`,label:`Payment`},{value:`delivery`,label:`Delivery`},{value:`warranty`,label:`Warranty`},{value:`penalty`,label:`Penalty`},{value:`other`,label:`Other`}],D={title:``,content:``,category:`general`,status:`active`};function O(){let[e,t]=(0,w.useState)(``),[n,O]=(0,w.useState)(!1),[k,A]=(0,w.useState)(null),[j,M]=(0,w.useState)(D),[N,P]=(0,w.useState)(!1),F=S(),{data:I,isLoading:L,refetch:R}=u(F.buildParams(e?{search:e}:void 0)),z=F.getItems(I),B=()=>{A(null),M(D),P(!1),O(!0)},V=e=>{A(e.id),M({title:e.title,content:e.content||``,category:e.category,status:e.status}),P(!1),O(!0)},H=e=>{A(e.id),M({title:e.title,content:e.content||``,category:e.category,status:e.status}),P(!0),O(!0)},U=async e=>{e.preventDefault(),k?await o(`/masters/terms-and-conditions/${k}/`,j):await s(`/masters/terms-and-conditions/`,j),O(!1),R()},W=async e=>{await c(`/masters/terms-and-conditions/${e}/`),R()},G=(e,t)=>M(n=>({...n,[e]:t})),K=e=>E.find(t=>t.value===e)?.label||e;return(0,T.jsxs)(p,{children:[(0,T.jsx)(x,{title:`Terms & Conditions`,description:`Manage terms and conditions master data`,searchPlaceholder:`Search...`,searchValue:e,onSearchChange:e=>{t(e),F.setPage(1)},action:(0,T.jsxs)(d,{onClick:B,size:`sm`,children:[(0,T.jsx)(i,{className:`mr-2 h-4 w-4`}),` Add Terms & Conditions`]})}),(0,T.jsx)(r,{data:z,columns:[{key:`code`,label:`Code`,render:e=>(0,T.jsx)(`span`,{className:`font-mono`,children:e.code})},{key:`title`,label:`Title`,render:e=>(0,T.jsx)(`span`,{className:`font-medium`,children:e.title})},{key:`category`,label:`Category`,render:e=>(0,T.jsx)(m,{variant:`outline`,children:K(e.category)})},{key:`status`,label:`Status`,render:e=>(0,T.jsx)(m,{variant:e.status===`active`?`default`:`secondary`,children:e.status})},{key:`authorized_status`,label:`Auth`,render:e=>(0,T.jsx)(C,{status:e.authorized_status??1})},{key:`actions`,label:`Actions`,sortable:!1,render:e=>(0,T.jsx)(b,{onView:()=>H(e),onEdit:()=>V(e),onDelete:()=>W(e.id)})}],isLoading:L,rowKey:e=>e.id,emptyMessage:`No terms and conditions found`,...F.tableProps(I)}),(0,T.jsx)(y,{open:n,onOpenChange:O,children:(0,T.jsxs)(_,{className:`sm:max-w-lg`,children:[(0,T.jsx)(h,{children:(0,T.jsx)(v,{children:N?`View Terms & Conditions`:k?`Edit Terms & Conditions`:`New Terms & Conditions`})}),(0,T.jsxs)(`form`,{onSubmit:U,className:`space-y-4`,children:[(0,T.jsxs)(`div`,{className:`space-y-2`,children:[(0,T.jsxs)(l,{children:[`Title `,(0,T.jsx)(`span`,{className:`text-destructive`,children:`*`})]}),(0,T.jsx)(f,{placeholder:`e.g. Payment within 30 days`,value:j.title,onChange:e=>G(`title`,e.target.value),required:!0,disabled:N})]}),(0,T.jsxs)(`div`,{className:`space-y-2`,children:[(0,T.jsxs)(l,{children:[`Content `,(0,T.jsx)(`span`,{className:`text-destructive`,children:`*`})]}),(0,T.jsx)(`textarea`,{className:`w-full border rounded-md px-3 py-2 text-sm min-h-[100px] resize-y`,placeholder:`Full text of the clause...`,value:j.content,onChange:e=>G(`content`,e.target.value),required:!0,disabled:N})]}),(0,T.jsxs)(`div`,{className:`space-y-2`,children:[(0,T.jsx)(l,{children:`Category`}),(0,T.jsx)(`select`,{value:j.category,onChange:e=>G(`category`,e.target.value),className:`w-full border rounded-md px-3 py-2 text-sm h-9`,disabled:N,children:E.map(e=>(0,T.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),(0,T.jsxs)(`div`,{className:`space-y-2`,children:[(0,T.jsx)(l,{children:`Status`}),(0,T.jsxs)(`select`,{value:j.status,onChange:e=>G(`status`,e.target.value),className:`w-full border rounded-md px-3 py-2 text-sm h-9`,disabled:N,children:[(0,T.jsx)(`option`,{value:`active`,children:`Active`}),(0,T.jsx)(`option`,{value:`inactive`,children:`Inactive`})]})]}),(0,T.jsxs)(g,{children:[(0,T.jsx)(d,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>O(!1),children:`Cancel`}),!N&&(0,T.jsxs)(d,{type:`submit`,size:`sm`,children:[(0,T.jsx)(a,{className:`mr-2 h-4 w-4`}),`Save`]})]})]})]})})]})}export{O as default};