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-46eXiUHP.js";import{t as i}from"./list-table-D-0FOE41.js";import{a,i as o,n as s,r as c,t as l}from"./select-CqarvPvF.js";import{t as u}from"./plus-BEDg_66Y.js";import{t as d}from"./save-D-WHGflg.js";import{Dt as f,Lt as ee,Ra as p,aa as m,on as te,yt as h,za as g}from"./index-B4NicEaS.js";import{t as _}from"./page-content-DdXVZwik.js";import{t as v}from"./badge-DLCseWie.js";import{a as y,i as b,n as x,o as S,t as C}from"./dialog-DMVP2cWs.js";import{t as w}from"./record-actions-BOLlEOQM.js";import{t as T}from"./list-page-header-7ncCnVWg.js";import{t as E}from"./use-server-pagination-BC4JB9I3.js";import{t as D}from"./auth-status-badge-C6fBtAs6.js";var O=e(t(),1),k=n(),A={name:``,description:``,status:`active`};function j(){let[e,t]=(0,O.useState)(``),[n,j]=(0,O.useState)(!1),[M,N]=(0,O.useState)(null),[P,F]=(0,O.useState)(A),[I,L]=(0,O.useState)(!1),R=E(),z=R.buildParams(e?{search:e}:void 0),{data:B,isLoading:V,refetch:H}=ee(z),U=R.getItems(B),[W,{isLoading:G}]=h(),[K,{isLoading:q}]=te(),[J]=f(),Y=()=>{N(null),F(A),L(!1),j(!0)},X=e=>{N(e.id),F({name:e.name,description:e.description||``,status:e.status}),L(!1),j(!0)},Z=e=>{N(e.id),F({name:e.name,description:e.description||``,status:e.status}),L(!0),j(!0)},Q=async e=>{e.preventDefault(),M?await K({id:M,data:P}):await W(P),j(!1)},$=(e,t)=>F(n=>({...n,[e]:t}));return(0,k.jsxs)(_,{children:[(0,k.jsx)(T,{title:`Delivery Terms`,description:`Manage delivery terms master data`,searchPlaceholder:`Search...`,searchValue:e,onSearchChange:e=>{t(e),R.setPage(1)},action:(0,k.jsxs)(g,{onClick:Y,size:`sm`,children:[(0,k.jsx)(u,{className:`mr-2 h-4 w-4`}),` Add Delivery Terms`]})}),(0,k.jsx)(i,{data:U,columns:[{key:`code`,label:`Code`,render:e=>(0,k.jsx)(`span`,{className:`font-mono`,children:e.code})},{key:`name`,label:`Name`,render:e=>(0,k.jsx)(`span`,{className:`font-medium`,children:e.name})},{key:`description`,label:`Description`,render:e=>e.description||`—`},{key:`status`,label:`Status`,render:e=>(0,k.jsx)(v,{variant:e.status===`active`?`default`:`secondary`,children:e.status})},{key:`authorized_status`,label:`Auth`,render:e=>(0,k.jsx)(D,{status:e.authorized_status})},{key:`actions`,label:`Actions`,sortable:!1,render:e=>(0,k.jsx)(w,{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`,...R.tableProps(B)}),(0,k.jsx)(C,{open:n,onOpenChange:j,children:(0,k.jsxs)(x,{className:`sm:max-w-md`,children:[(0,k.jsx)(y,{children:(0,k.jsx)(S,{children:I?`View Delivery Terms`:M?`Edit Delivery Terms`:`New Delivery Terms`})}),(0,k.jsxs)(`form`,{onSubmit:Q,className:`space-y-4`,children:[(0,k.jsxs)(`div`,{className:`space-y-2`,children:[(0,k.jsxs)(m,{children:[`Name `,(0,k.jsx)(`span`,{className:`text-destructive`,children:`*`})]}),(0,k.jsx)(p,{placeholder:`e.g. FOB, CIF`,value:P.name,onChange:e=>$(`name`,e.target.value),required:!0,disabled:I})]}),(0,k.jsxs)(`div`,{className:`space-y-2`,children:[(0,k.jsx)(m,{children:`Description`}),(0,k.jsx)(p,{placeholder:`Description`,value:P.description,onChange:e=>$(`description`,e.target.value),disabled:I})]}),(0,k.jsxs)(`div`,{className:`space-y-2`,children:[(0,k.jsx)(m,{children:`Status`}),(0,k.jsxs)(l,{value:P.status,onValueChange:e=>$(`status`,e),disabled:I,children:[(0,k.jsx)(o,{className:`w-full h-9 text-sm`,children:(0,k.jsx)(a,{})}),(0,k.jsxs)(s,{children:[(0,k.jsx)(c,{value:`active`,children:`Active`}),(0,k.jsx)(c,{value:`inactive`,children:`Inactive`})]})]})]}),(0,k.jsxs)(b,{children:[(0,k.jsx)(g,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>j(!1),children:`Cancel`}),!I&&(0,k.jsxs)(g,{type:`submit`,size:`sm`,disabled:G||q,children:[(0,k.jsx)(d,{className:`mr-2 h-4 w-4`}),G||q?`Saving...`:`Save`]})]})]})]})})]})}export{j as default};