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-M8Qu8ozW.js";import{a,i as o,n as s,r as c,t as l}from"./select-788h6o8Z.js";import{t as u}from"./plus-VCCEyniC.js";import{t as d}from"./save-Cm-Rqwuf.js";import{Dr as f,Ki as p,Zn as ee,ga as m,ha as h,li as g,zi as _}from"./index-8M5AnKdQ.js";import{t as v}from"./page-content-DDtdeMxM.js";import{t as y}from"./badge-Crg76WQE.js";import{a as b,i as x,n as S,o as C,t as w}from"./dialog-CILF_XUh.js";import{t as T}from"./record-actions-3WNKE8L8.js";import{t as E}from"./list-page-header-DTmo84Zp.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:``,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}]=ee(),[K,{isLoading:q}]=_(),[J]=f(),Y=()=>{P(null),I(j),R(!1),M(!0)},X=e=>{P(e.id),I({name:e.name,status:e.status}),R(!1),M(!0)},Z=e=>{P(e.id),I({name:e.name,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)(v,{children:[(0,A.jsx)(E,{title:`Units of Measure`,description:`Manage UOM master data`,searchPlaceholder:`Search UOM...`,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 UOM`]})}),(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:`status`,label:`Status`,render:e=>(0,A.jsx)(y,{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:`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`,...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)(b,{children:(0,A.jsx)(C,{children:L?`View Unit of Measure`:N?`Edit UOM`:`New UOM`})}),(0,A.jsxs)(`form`,{onSubmit:Q,className:`space-y-4`,children:[(0,A.jsxs)(`div`,{className:`space-y-2`,children:[(0,A.jsxs)(p,{htmlFor:`dlg-name`,children:[`UOM Name `,(0,A.jsx)(`span`,{className:`text-destructive`,children:`*`})]}),(0,A.jsx)(h,{id:`dlg-name`,placeholder:`Enter UOM name`,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)(p,{htmlFor:`dlg-status`,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)(x,{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};