import{H as g,r as d,j as u,b as t,B as U,T as f,aM as x,aN as A,a5 as L,aO as N,b6 as v,b7 as k,a6 as w,a$ as I,a as O,b8 as G,P as W,A as q,e as D,E as F,I as y,S as P}from"./index-DWFi48i_.js";const z=g.injectEndpoints({endpoints:a=>({getUomList:a.query({query:()=>({url:"uom",method:"GET"})}),getUomById:a.query({query:e=>({url:`uom/${e}`,method:"GET"})}),saveUom:a.mutation({query:e=>({url:"uom",method:"POST",body:e})}),updateUom:a.mutation({query:e=>({url:`uom/${e.id}`,method:"PUT",body:e})}),deleteUom:a.mutation({query:e=>({url:`uom/${e}`,method:"DELETE"})}),getUomConversions:a.query({query:()=>({url:"uom/conversions",method:"GET"})}),saveUomConversion:a.mutation({query:e=>({url:"uom/conversions",method:"POST",body:e})})})}),{useLazyGetUomListQuery:X,useGetUomListQuery:j,useSaveUomMutation:B,useUpdateUomMutation:H,useDeleteUomMutation:$,useGetUomConversionsQuery:Z,useSaveUomConversionMutation:ee}=z,Q=["WEIGHT","VOLUME","UNIT","LENGTH"],T={name:"",code:"",uomType:"UNIT",active:!0};function V({open:a,initial:e,onClose:m,onSubmit:l}){const[o,c]=d.useState(T);d.useEffect(()=>{c(e??T)},[e,a]);const r=(s,p)=>c(h=>({...h,[s]:p})),i=()=>{!o.name||!o.code||!o.uomType||l(o)};return u(I,{open:a,title:e!=null&&e.id?"Edit UoM":"Add UoM",onClose:m,maxWidth:"sm",children:[u(U,{display:"flex",flexDirection:"column",gap:2,pt:1,children:[t(f,{label:"Name *",size:"small",fullWidth:!0,value:o.name??"",onChange:s=>r("name",s.target.value)}),t(f,{label:"Code *",size:"small",fullWidth:!0,value:o.code??"",onChange:s=>r("code",s.target.value)}),u(x,{size:"small",fullWidth:!0,children:[t(A,{children:"UoM Type *"}),t(N,{label:"UoM Type *",value:o.uomType??"UNIT",onChange:s=>r("uomType",s.target.value),children:Q.map(s=>t(L,{value:s,children:s},s))})]}),t(k,{control:t(v,{checked:!!o.active,onChange:s=>r("active",s.target.checked)}),label:"Active"})]}),t(w,{onSubmit:i,submitLabel:e!=null&&e.id?"Update":"Save",submitBtnType:"submit"})]})}const _={WEIGHT:"primary",VOLUME:"secondary",UNIT:"success",LENGTH:"warning"};function oe(){const{openSnackbar:a}=O(),e=G(),[m,l]=d.useState(!1),[o,c]=d.useState(null),{data:r=[],isLoading:i,error:s}=j(),[p]=B(),[h]=H(),[C]=$(),E=()=>{c(null),l(!0)},S=n=>{c(n),l(!0)},M=async n=>{if(!await e({message:"Delete this UoM?"}))return;"data"in await C(n)?a("UoM deleted successfully","success"):a("Failed to delete UoM","error")};return u(U,{p:2,children:[u(W,{children:[t(U,{display:"flex",justifyContent:"flex-end",mb:2,children:t(q,{btnType:"create",onClick:E,children:"Add UoM"})}),t(D,{columns:[{field:"name",headerName:"Name",flex:1,minWidth:160},{field:"code",headerName:"Code",flex:1,minWidth:100},{field:"uomType",headerName:"Type",flex:1,minWidth:120,renderCell:n=>t(F,{label:n.value,color:_[n.value]??"default",size:"small"})},{field:"active",headerName:"Active",flex:1,minWidth:80,renderCell:n=>t(v,{checked:!!n.value,disabled:!0,size:"small"})},{field:"actions",headerName:"Actions",flex:1,minWidth:120,sortable:!1,renderCell:n=>u(P,{direction:"row",spacing:1,children:[t(y,{type:"Edit",onClick:()=>S(n.row)}),t(y,{type:"Delete",onClick:()=>M(n.row.id)})]})}],rows:r,loading:i})]}),t(V,{open:m,initial:o,onClose:()=>l(!1),onSubmit:async n=>{"data"in(o!=null&&o.id?await h({...n,id:o.id}):await p(n))?(a(`UoM ${o!=null&&o.id?"updated":"created"} successfully`,"success"),l(!1)):a("Failed to save UoM","error")}})]})}export{oe as default};
