import{a as e,t}from"./react-D0JuimcS.js";import{o as n}from"./utils-Dac180Gn.js";import{r}from"./api-NMlTtVre.js";import{t as i}from"./list-table-dcNbCPvq.js";import{a,i as o,n as s,r as c,t as l}from"./select-BLbEjWut.js";import{t as u}from"./plus-VCCEyniC.js";import{t as d}from"./save-Cm-Rqwuf.js";import{Ki as f,Yt as p,ga as m,ha as h,kt as g,mt as _,xt as v}from"./index-BP3TYB4i.js";import{t as y}from"./page-content-DDtdeMxM.js";import{t as b}from"./badge-Crg76WQE.js";import{a as x,i as ee,n as S,o as C,t as w}from"./dialog-BeOPOVZK.js";import{t as T}from"./record-actions-DSw1sDLk.js";import{t as E}from"./list-page-header-48VsPegf.js";import{t as D}from"./use-server-pagination-CjwQ90IL.js";import{t as O}from"./auth-status-badge-pVqOsTb5.js";var k=e(t(),1),A=n(),j={name:``,description:``,status:`active`};function M(){let[e,t]=(0,k.useState)(``),[n,M]=(0,k.useState)(!1),[N,P]=(0,k.useState)(null),[F,I]=(0,k.useState)(j),[L,R]=(0,k.useState)(!1),z=D(),{data:B,isLoading:V,refetch:H}=g(z.buildParams(e?{search:e}:void 0)),U=z.getItems(B),[W,{isLoading:G}]=_(),[K,{isLoading:q}]=p(),[J]=v(),Y=()=>{P(null),I(j),R(!1),M(!0)},X=e=>{P(e.id),I({name:e.name,description:e.description||``,status:e.status}),R(!1),M(!0)},Z=e=>{P(e.id),I({name:e.name,description:e.description||``,status:e.status}),R(!0),M(!0)},Q=async e=>{e.preventDefault(),N?await K({id:N,data:F}):await W(F),M(!1)},$=(e,t)=>I(n=>({...n,[e]:t}));return(0,A.jsxs)(y,{children:[(0,A.jsx)(E,{title:`Delivery Terms`,description:`Manage delivery terms master data`,searchPlaceholder:`Search...`,searchValue:e,onSearchChange:e=>{t(e),z.setPage(1)},action:(0,A.jsxs)(m,{onClick:Y,size:`sm`,children:[(0,A.jsx)(u,{className:`mr-2 h-4 w-4`}),` Add Delivery Terms`]})}),(0,A.jsx)(i,{data:U,columns:[{key:`code`,label:`Code`,render:e=>(0,A.jsx)(`span`,{className:`font-mono`,children:e.code})},{key:`name`,label:`Name`,render:e=>(0,A.jsx)(`span`,{className:`font-medium`,children:e.name})},{key:`description`,label:`Description`,render:e=>e.description||`—`},{key:`status`,label:`Status`,render:e=>(0,A.jsx)(b,{variant:e.status===`active`?`default`:`secondary`,children:e.status})},{key:`authorized_status`,label:`Auth`,render:e=>(0,A.jsx)(O,{status:e.authorized_status})},{key:`actions`,label:`Actions`,sortable:!1,render:e=>(0,A.jsx)(T,{approval:{entityType:`DeliveryTerms`,objectId:e.id,contentTypeId:r.DELIVERY_TERMS,authorizedStatus:e.authorized_status??1,onApprovalChange:()=>H()},onView:()=>Z(e),onEdit:()=>X(e),onDelete:()=>J(e.id)})}],isLoading:V,rowKey:e=>e.id,emptyMessage:`No delivery terms found`,...z.tableProps(B)}),(0,A.jsx)(w,{open:n,onOpenChange:M,children:(0,A.jsxs)(S,{className:`sm:max-w-md`,children:[(0,A.jsx)(x,{children:(0,A.jsx)(C,{children:L?`View Delivery Terms`:N?`Edit Delivery Terms`:`New Delivery Terms`})}),(0,A.jsxs)(`form`,{onSubmit:Q,className:`space-y-4`,children:[(0,A.jsxs)(`div`,{className:`space-y-2`,children:[(0,A.jsxs)(f,{children:[`Name `,(0,A.jsx)(`span`,{className:`text-destructive`,children:`*`})]}),(0,A.jsx)(h,{placeholder:`e.g. FOB, CIF`,value:F.name,onChange:e=>$(`name`,e.target.value),required:!0,disabled:L})]}),(0,A.jsxs)(`div`,{className:`space-y-2`,children:[(0,A.jsx)(f,{children:`Description`}),(0,A.jsx)(h,{placeholder:`Description`,value:F.description,onChange:e=>$(`description`,e.target.value),disabled:L})]}),(0,A.jsxs)(`div`,{className:`space-y-2`,children:[(0,A.jsx)(f,{children:`Status`}),(0,A.jsxs)(l,{value:F.status,onValueChange:e=>$(`status`,e),disabled:L,children:[(0,A.jsx)(o,{className:`w-full h-9 text-sm`,children:(0,A.jsx)(a,{})}),(0,A.jsxs)(s,{children:[(0,A.jsx)(c,{value:`active`,children:`Active`}),(0,A.jsx)(c,{value:`inactive`,children:`Inactive`})]})]})]}),(0,A.jsxs)(ee,{children:[(0,A.jsx)(m,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>M(!1),children:`Cancel`}),!L&&(0,A.jsxs)(m,{type:`submit`,size:`sm`,disabled:G||q,children:[(0,A.jsx)(d,{className:`mr-2 h-4 w-4`}),G||q?`Saving...`:`Save`]})]})]})]})})]})}export{M as default};