import{a as e,t}from"./react-DK-MTtD8.js";import{s as n}from"./utils-CXcsdpX-.js";import{r}from"./api-DcvYaav1.js";import{t as i}from"./list-table-CQD2C7IB.js";import{a,i as o,n as s,r as c,t as l}from"./select-B6Gfe6WE.js";import{t as u}from"./plus-CuMPbIyn.js";import{t as ee}from"./save-DstqMto4.js";import{Br as d,Qi as f,Ra as p,Si as m,aa as h,ur as g,za as _}from"./index-Ct5uU080.js";import{t as v}from"./page-content-Bh5Zxb_Y.js";import{t as y}from"./badge-CL1e8lO_.js";import{a as te,i as b,n as x,o as S,t as C}from"./dialog-DuXDR687.js";import{t as w}from"./record-actions-CTlg0qBJ.js";import{t as T}from"./list-page-header-CePoWpko.js";import{t as E}from"./use-server-pagination-CR_EVf1w.js";import{t as D}from"./auth-status-badge-BlJK5R24.js";var O=e(t(),1),k=n(),A={name:``,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}=m(z),U=R.getItems(B),[W,{isLoading:G}]=g(),[K,{isLoading:q}]=f(),[J]=d(),Y=()=>{N(null),F(A),L(!1),j(!0)},X=e=>{N(e.id),F({name:e.name,status:e.status}),L(!1),j(!0)},Z=e=>{N(e.id),F({name:e.name,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)(v,{children:[(0,k.jsx)(T,{title:`Units of Measure`,description:`Manage UOM master data`,searchPlaceholder:`Search UOM...`,searchValue:e,onSearchChange:e=>{t(e),R.setPage(1)},action:(0,k.jsxs)(_,{onClick:Y,size:`sm`,children:[(0,k.jsx)(u,{className:`mr-2 h-4 w-4`}),` Add UOM`]})}),(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:`status`,label:`Status`,render:e=>(0,k.jsx)(y,{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:`UnitOfMeasure`,objectId:e.id,contentTypeId:r.UOM,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 UOM 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)(te,{children:(0,k.jsx)(S,{children:I?`View Unit of Measure`:M?`Edit UOM`:`New UOM`})}),(0,k.jsxs)(`form`,{onSubmit:Q,className:`space-y-4`,children:[(0,k.jsxs)(`div`,{className:`space-y-2`,children:[(0,k.jsxs)(h,{htmlFor:`dlg-name`,children:[`UOM Name `,(0,k.jsx)(`span`,{className:`text-destructive`,children:`*`})]}),(0,k.jsx)(p,{id:`dlg-name`,placeholder:`Enter UOM name`,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)(h,{htmlFor:`dlg-status`,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)(_,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>j(!1),children:`Cancel`}),!I&&(0,k.jsxs)(_,{type:`submit`,size:`sm`,disabled:G||q,children:[(0,k.jsx)(ee,{className:`mr-2 h-4 w-4`}),G||q?`Saving...`:`Save`]})]})]})]})})]})}export{j as default};