import{a as e,t}from"./react-DK-MTtD8.js";import{s as n}from"./utils-CXcsdpX-.js";import{t as r}from"./list-table-CF_0QrYo.js";import{t as i}from"./plus-CuMPbIyn.js";import{t as a}from"./save-DstqMto4.js";import{i as o,o as s,s as c}from"./Helper-HufwKDkD.js";import{Ra as l,aa as u,xi as d,za as f}from"./index-CvTTLloU.js";import{t as p}from"./page-content-Bh5Zxb_Y.js";import{t as m}from"./badge-CL1e8lO_.js";import{a as h,i as g,n as _,o as v,t as y}from"./dialog-DrW_2c38.js";import{t as b}from"./record-actions-DCNk_Ak0.js";import{t as x}from"./list-page-header-D6ls_V1f.js";import{t as S}from"./use-server-pagination-CR_EVf1w.js";import{t as C}from"./auth-status-badge-BlJK5R24.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};