import{M,r as d,j as u,b as t,B as U,T as f,be as x,bf as A,Q as L,bg as N,bP as v,ap as k,ag as w,by as I,a as G,bQ as O,R as W,A as q,e as D,F,I as y,S as P}from"./index-BiWH3VAt.js";const z=M.injectEndpoints({endpoints:s=>({getUomList:s.query({query:()=>({url:"uom",method:"GET"})}),getUomById:s.query({query:e=>({url:`uom/${e}`,method:"GET"})}),saveUom:s.mutation({query:e=>({url:"uom",method:"POST",body:e})}),updateUom:s.mutation({query:e=>({url:`uom/${e.id}`,method:"PUT",body:e})}),deleteUom:s.mutation({query:e=>({url:`uom/${e}`,method:"DELETE"})}),getUomConversions:s.query({query:()=>({url:"uom/conversions",method:"GET"})}),saveUomConversion:s.mutation({query:e=>({url:"uom/conversions",method:"POST",body:e})})})}),{useLazyGetUomListQuery:X,useGetUomListQuery:j,useSaveUomMutation:B,useUpdateUomMutation:Q,useDeleteUomMutation:H,useGetUomConversionsQuery:Z,useSaveUomConversionMutation:ee}=z,$=["WEIGHT","VOLUME","UNIT","LENGTH"],T={name:"",code:"",uomType:"UNIT",active:!0};function V({open:s,initial:e,onClose:m,onSubmit:l}){const[o,c]=d.useState(T);d.useEffect(()=>{c(e??T)},[e,s]);const r=(a,p)=>c(h=>({...h,[a]:p})),i=()=>{!o.name||!o.code||!o.uomType||l(o)};return u(I,{open:s,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:a=>r("name",a.target.value)}),t(f,{label:"Code *",size:"small",fullWidth:!0,value:o.code??"",onChange:a=>r("code",a.target.value)}),u(x,{size:"small",fullWidth:!0,children:[t(A,{children:"UoM Type *"}),t(N,{label:"UoM Type *",value:o.uomType??"UNIT",onChange:a=>r("uomType",a.target.value),children:$.map(a=>t(L,{value:a,children:a},a))})]}),t(k,{control:t(v,{checked:!!o.active,onChange:a=>r("active",a.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:s}=G(),e=O(),[m,l]=d.useState(!1),[o,c]=d.useState(null),{data:r=[],isLoading:i,error:a}=j(),[p]=B(),[h]=Q(),[C]=H(),b=()=>{c(null),l(!0)},S=n=>{c(n),l(!0)},E=async n=>{if(!await e({message:"Delete this UoM?"}))return;"data"in await C(n)?s("UoM deleted successfully","success"):s("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:b,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:()=>E(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))?(s(`UoM ${o!=null&&o.id?"updated":"created"} successfully`,"success"),l(!1)):s("Failed to save UoM","error")}})]})}export{oe as default};
