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"./plus-BEDg_66Y.js";import{t as a}from"./save-D-WHGflg.js";import{i as o,o as s,s as c}from"./Helper-DM8_S2CX.js";import{Ra as l,aa as u,xi as d,za as f}from"./index-CsuVxiRQ.js";import{t as p}from"./page-content-DdXVZwik.js";import{t as m}from"./badge-DLCseWie.js";import{a as h,i as g,n as _,o as v,t as y}from"./dialog-BT7QjyH-.js";import{t as b}from"./record-actions-BJhHCezi.js";import{t as x}from"./list-page-header-BnFKDjpb.js";import{t as S}from"./use-server-pagination-BC4JB9I3.js";import{t as C}from"./auth-status-badge-C6fBtAs6.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(),I=F.buildParams(e?{search:e}:void 0),{data:L,isLoading:R,refetch:z}=d(I),B=F.getItems(L),V=()=>{A(null),M(D),P(!1),O(!0)},H=e=>{A(e.id),M({title:e.title,content:e.content||``,category:e.category,status:e.status}),P(!1),O(!0)},U=e=>{A(e.id),M({title:e.title,content:e.content||``,category:e.category,status:e.status}),P(!0),O(!0)},W=async e=>{e.preventDefault(),k?await o(`/masters/terms-and-conditions/${k}/`,j):await s(`/masters/terms-and-conditions/`,j),O(!1),z()},G=async e=>{await c(`/masters/terms-and-conditions/${e}/`),z()},K=(e,t)=>M(n=>({...n,[e]:t})),q=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)(f,{onClick:V,size:`sm`,children:[(0,T.jsx)(i,{className:`mr-2 h-4 w-4`}),` Add Terms & Conditions`]})}),(0,T.jsx)(r,{data:B,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:q(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:()=>U(e),onEdit:()=>H(e),onDelete:()=>G(e.id)})}],isLoading:R,rowKey:e=>e.id,emptyMessage:`No terms and conditions found`,...F.tableProps(L)}),(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:W,className:`space-y-4`,children:[(0,T.jsxs)(`div`,{className:`space-y-2`,children:[(0,T.jsxs)(u,{children:[`Title `,(0,T.jsx)(`span`,{className:`text-destructive`,children:`*`})]}),(0,T.jsx)(l,{placeholder:`e.g. Payment within 30 days`,value:j.title,onChange:e=>K(`title`,e.target.value),required:!0,disabled:N})]}),(0,T.jsxs)(`div`,{className:`space-y-2`,children:[(0,T.jsxs)(u,{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=>K(`content`,e.target.value),required:!0,disabled:N})]}),(0,T.jsxs)(`div`,{className:`space-y-2`,children:[(0,T.jsx)(u,{children:`Category`}),(0,T.jsx)(`select`,{value:j.category,onChange:e=>K(`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)(u,{children:`Status`}),(0,T.jsxs)(`select`,{value:j.status,onChange:e=>K(`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)(f,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>O(!1),children:`Cancel`}),!N&&(0,T.jsxs)(f,{type:`submit`,size:`sm`,children:[(0,T.jsx)(a,{className:`mr-2 h-4 w-4`}),`Save`]})]})]})]})})]})}export{O as default};