import{j as e,b as F,a as E,u as ne}from"./query-PJ0ZdjbV.js";import{f as Cs,a as S,O as As,k as ws,u as ks}from"./vendor-CWhr2lg4.js";import{a2 as ls,b0 as ce,bz as Ze,bf as Ds,ap as Be,p as C,a4 as h,B as w,d as K,h as O,a as us,T as Ps,e as oe,f as me,P as _e,s as Y,t as Z,v as X,w as J,x as q,aa as Ne,ab as ve,ac as be,ad as Se,ae as Ce,q as l,I as N,r as le,af as Ae,Q as we,V as ke,W as De,X as Pe,Y as qe,Z as Fe,_ as Ee,$ as Te,a0 as Ve,ag as $e,ah as Re,ai as Me,aj as M,ak as Ke,y as Oe,b as Xe,at as je}from"./index-BSPIaiZU.js";import{L as qs}from"./layout-dashboard-pgzECxsO.js";import{P as ze,T as gs}from"./tag-Bm4GEpug.js";import{U as ys}from"./user-check-B2v_CMeM.js";import{R as fs}from"./rotate-ccw-u1EtXcFp.js";import{S as cs}from"./shield-7SCLx_iT.js";import{F as is}from"./file-chart-column-increasing-DonUpE5r.js";import{C as rs}from"./chart-column-DbfNf7gS.js";import{P as Fs}from"./page-header-D8tSLbK0.js";import{U as Es}from"./users-round-Co0Z9sI2.js";import{T as Ts}from"./trending-down-BqIHipUb.js";import{A as Ye}from"./arrow-right-Bmt6JCm_.js";import{u as xe,t as ue,o as he,s as p,e as ye,l as We,b as ie,c as Je,a as ge}from"./date-range-picker-BB0TgAn8.js";import{D as Qe}from"./data-table-D_-xOEqd.js";import{B as Ge}from"./badge-C34iUAiA.js";import{A as fe}from"./async-select-BUbwdJEZ.js";import{u as Ie}from"./use-data-table-state-CKRg6qY2.js";import{w as ds,a as es,i as os}from"./date-validation-D9gNvaP9.js";import{E as Le}from"./ellipsis-DaNBIBaV.js";import{S as ms}from"./status-badge-DPaiL_rL.js";import{E as _s}from"./employee-select-DtUobKxP.js";import{C as Ns}from"./circle-check-Dgh1V3VA.js";import{A as Vs}from"./approval-status-pill-FaqYhoSe.js";import{C as $s}from"./circle-x-C0sF-Oht.js";import"./ui-aO-W1bxx.js";import"./chevron-left-DLFf1YD2.js";import"./core-hr.api-MChaGqvv.js";import"./circle-alert-9pjtMKqA.js";import"./send-hExJQKXK.js";/**
 * @license lucide-react v0.469.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const vs=ls("FolderTree",[["path",{d:"M20 10a1 1 0 0 0 1-1V6a1 1 0 0 0-1-1h-2.5a1 1 0 0 1-.8-.4l-.9-1.2A1 1 0 0 0 15 3h-2a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z",key:"hod4my"}],["path",{d:"M20 21a1 1 0 0 0 1-1v-3a1 1 0 0 0-1-1h-2.9a1 1 0 0 1-.88-.55l-.42-.85a1 1 0 0 0-.92-.6H13a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z",key:"w4yl2u"}],["path",{d:"M3 5a2 2 0 0 0 2 2h3",key:"f2jnh7"}],["path",{d:"M3 3v13a2 2 0 0 0 2 2h3",key:"k8epm1"}]]);/**
 * @license lucide-react v0.469.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Rs=ls("QrCode",[["rect",{width:"5",height:"5",x:"3",y:"3",rx:"1",key:"1tu5fj"}],["rect",{width:"5",height:"5",x:"16",y:"3",rx:"1",key:"1v8r4q"}],["rect",{width:"5",height:"5",x:"3",y:"16",rx:"1",key:"1x03jg"}],["path",{d:"M21 16h-3a2 2 0 0 0-2 2v3",key:"177gqh"}],["path",{d:"M21 21v.01",key:"ents32"}],["path",{d:"M12 7v3a2 2 0 0 1-2 2H7",key:"8crl2c"}],["path",{d:"M3 12h.01",key:"nlz23k"}],["path",{d:"M12 3h.01",key:"n36tog"}],["path",{d:"M12 16v.01",key:"133mhm"}],["path",{d:"M16 12h1",key:"1slzba"}],["path",{d:"M21 12v.01",key:"1lwtk9"}],["path",{d:"M12 21v-1",key:"1880an"}]]);/**
 * @license lucide-react v0.469.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const ts=ls("Wrench",[["path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z",key:"cbrjhi"}]]),Ms=[{heading:"Overview",items:[{to:"/assets",label:"Dashboard",description:"Asset overview",icon:qs,permission:["assets","dashboard","read"]}]},{heading:"Inventory",items:[{to:"/assets/assets",label:"Assets",description:"Manage inventory",icon:ze,permission:["assets","asset","read"]},{to:"/assets/categories",label:"Categories",description:"Asset categories",icon:vs,permission:["assets","asset_category","read"]},{to:"/assets/types",label:"Types",description:"Asset types",icon:gs,permission:["assets","asset_type","read"]}]},{heading:"Allocation",items:[{to:"/assets/allocations",label:"Allocations",description:"Assign assets",icon:ys,permission:["assets","asset_allocation","read"]},{to:"/assets/returns",label:"Returns",description:"Process returns",icon:fs,permission:["assets","asset_return","read"]}]},{heading:"Maintenance",items:[{to:"/assets/maintenance",label:"Maintenance",description:"Track maintenance",icon:ts,permission:["assets","asset_maintenance","read"]},{to:"/assets/entitlements",label:"Entitlements",description:"Asset entitlements",icon:cs,permission:["assets","asset_entitlement","read"]}]},{heading:"Configuration",items:[{to:"/assets/settings",label:"Settings",description:"Module config",icon:Ze,permission:["assets","settings","read"]}]},{heading:"Insights",items:[{to:"/assets/reports",label:"Reports",description:"Asset reports",icon:is,permission:["assets","report","read"]},{to:"/assets/analytics",label:"Analytics",description:"Trends & insights",icon:rs,permission:["assets","analytics","read"]}]}];function Ks({item:t,isActive:s}){const n=t.icon;return e.jsxs(ws,{to:t.to,end:t.to==="/assets",className:Be("group relative flex items-center gap-3 rounded-lg px-3 py-2.5 transition-all duration-150",s?"bg-primary-subtle/70":"hover:bg-slate-50"),children:[s&&e.jsx("span",{className:"absolute left-0 top-2.5 bottom-2.5 w-[3px] rounded-r-full bg-primary"}),e.jsx("div",{className:Be("flex h-8 w-8 shrink-0 items-center justify-center rounded-lg transition-colors duration-150",s?"bg-primary/10 text-primary":"bg-slate-100 text-slate-400 group-hover:bg-slate-200/70 group-hover:text-slate-500"),children:e.jsx(n,{className:"h-4 w-4"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:Be("block text-[13px] truncate leading-tight",s?"font-medium text-primary":"font-medium text-slate-700 group-hover:text-slate-900"),children:t.label}),e.jsx("span",{className:Be("block text-[11px] truncate leading-tight mt-0.5",s?"text-primary/60":"text-slate-400"),children:t.description})]})]})}function ma(){const t=Cs(),s=S.useRef(null),{hasPermission:n}=ce();S.useEffect(()=>{var m;(m=s.current)==null||m.scrollTo(0,0)},[t.pathname]);const f=S.useMemo(()=>Ms.map(m=>({...m,items:m.items.filter(y=>n(y.permission[0],y.permission[1],y.permission[2]))})).filter(m=>m.items.length>0),[n]);return e.jsxs("div",{className:"-m-6 flex h-[calc(100%+48px)]",children:[e.jsxs("aside",{className:"w-[260px] shrink-0 border-r border-slate-200/60 bg-white flex flex-col",children:[e.jsxs("div",{className:"shrink-0 px-5 pt-6 pb-4 border-b border-slate-100",children:[e.jsx("h1",{className:"text-[15px] font-semibold text-slate-900 tracking-tight",children:"Asset Management"}),e.jsx("p",{className:"mt-0.5 text-[11px] text-slate-400",children:"Inventory, allocation & tracking"})]}),e.jsx("nav",{className:"flex-1 overflow-y-auto px-3 py-3 scrollbar-thin",children:f.map((m,y)=>e.jsxs("div",{className:Be(y>0&&"mt-6"),children:[e.jsx("p",{className:"mb-2 px-3 text-[11px] font-semibold uppercase tracking-[0.08em] text-slate-400",children:m.heading}),e.jsx("div",{className:"space-y-0.5",children:m.items.map(x=>{const T=x.to==="/assets"?t.pathname==="/assets":Ds(t.pathname,x.to);return e.jsx(Ks,{item:x,isActive:T},x.to)})})]},m.heading))})]}),e.jsx("main",{ref:s,className:"flex-1 min-w-0 overflow-y-auto bg-background scrollbar-thin",children:e.jsx("div",{className:"px-8 py-6 w-full",children:e.jsx(As,{})})})]})}const A="/assets",g={settings:["assets","settings"],categories:["assets","categories"],types:["assets","types"],assets:["assets","assets"],asset:t=>["assets","assets",t],allocations:["assets","allocations"],returns:["assets","returns"],maintenance:["assets","maintenance"],entitlements:["assets","entitlements"],dashboard:["assets","dashboard"],reports:["assets","reports"],analytics:["assets","analytics"]};function Os(){return ne({queryKey:g.settings,queryFn:()=>C.get(`${A}/settings/`).then(t=>t.data)})}function Qs(){const t=F();return E({mutationFn:s=>C.patch(`${A}/settings/`,s).then(n=>n.data),onSuccess:()=>{t.invalidateQueries({queryKey:g.settings}),h.success("Asset settings updated")},onError:()=>h.error("Failed to update asset settings")})}function ss(t){return ne({queryKey:[...g.categories,t],queryFn:()=>C.get(`${A}/categories/`,{params:t}).then(s=>s.data)})}function Is(){const t=F();return E({mutationFn:s=>C.post(`${A}/categories/`,s).then(n=>n.data),onSuccess:()=>{t.invalidateQueries({queryKey:g.categories}),h.success("Category created")},onError:()=>h.error("Failed to create category")})}function Ls(){const t=F();return E({mutationFn:({id:s,...n})=>C.patch(`${A}/categories/${s}/`,n).then(f=>f.data),onSuccess:()=>{t.invalidateQueries({queryKey:g.categories}),h.success("Category updated")},onError:()=>h.error("Failed to update category")})}function Us(){const t=F();return E({mutationFn:s=>C.delete(`${A}/categories/${s}/`),onSuccess:()=>{t.invalidateQueries({queryKey:g.categories}),h.success("Category deleted")},onError:()=>h.error("Failed to delete category")})}function xs(t){return ne({queryKey:[...g.types,t],queryFn:()=>C.get(`${A}/types/`,{params:t}).then(s=>s.data)})}function zs(){const t=F();return E({mutationFn:s=>C.post(`${A}/types/`,s).then(n=>n.data),onSuccess:()=>{t.invalidateQueries({queryKey:g.types}),h.success("Asset type created")},onError:()=>h.error("Failed to create asset type")})}function Gs(){const t=F();return E({mutationFn:({id:s,...n})=>C.patch(`${A}/types/${s}/`,n).then(f=>f.data),onSuccess:()=>{t.invalidateQueries({queryKey:g.types}),h.success("Asset type updated")},onError:()=>h.error("Failed to update asset type")})}function Bs(){const t=F();return E({mutationFn:s=>C.delete(`${A}/types/${s}/`),onSuccess:()=>{t.invalidateQueries({queryKey:g.types}),h.success("Asset type deleted")},onError:()=>h.error("Failed to delete asset type")})}function as(t){return ne({queryKey:[...g.assets,t],queryFn:()=>C.get(`${A}/assets/`,{params:t}).then(s=>s.data)})}function xa(t){return ne({queryKey:g.asset(t),queryFn:()=>C.get(`${A}/assets/${t}/`).then(s=>s.data),enabled:!!t})}function Ws(){const t=F();return E({mutationFn:s=>C.post(`${A}/assets/`,s).then(n=>n.data),onSuccess:()=>{t.invalidateQueries({queryKey:g.assets}),h.success("Asset created")},onError:()=>h.error("Failed to create asset")})}function Hs(){const t=F();return E({mutationFn:({id:s,...n})=>C.patch(`${A}/assets/${s}/`,n).then(f=>f.data),onSuccess:()=>{t.invalidateQueries({queryKey:g.assets}),h.success("Asset updated")},onError:()=>h.error("Failed to update asset")})}function Ys(){const t=F();return E({mutationFn:s=>C.delete(`${A}/assets/${s}/`),onSuccess:()=>{t.invalidateQueries({queryKey:g.assets}),h.success("Asset deleted")},onError:()=>h.error("Failed to delete asset")})}function bs(t){return ne({queryKey:[...g.allocations,t],queryFn:()=>C.get(`${A}/allocations/`,{params:t}).then(s=>s.data)})}function Zs(){const t=F();return E({mutationFn:s=>C.post(`${A}/allocations/`,s).then(n=>n.data),onSuccess:()=>{t.invalidateQueries({queryKey:g.allocations}),t.invalidateQueries({queryKey:g.assets}),h.success("Asset allocated")},onError:()=>h.error("Failed to allocate asset")})}function Xs(){const t=F();return E({mutationFn:({id:s,...n})=>C.patch(`${A}/allocations/${s}/`,n).then(f=>f.data),onSuccess:()=>{t.invalidateQueries({queryKey:g.allocations}),h.success("Allocation updated")},onError:()=>h.error("Failed to update allocation")})}function Js(){const t=F();return E({mutationFn:s=>C.delete(`${A}/allocations/${s}/`),onSuccess:()=>{t.invalidateQueries({queryKey:g.allocations}),t.invalidateQueries({queryKey:g.assets}),h.success("Allocation deleted")},onError:()=>h.error("Failed to delete allocation")})}function et(){const t=F();return E({mutationFn:s=>C.post(`${A}/allocations/${s}/acknowledge/`).then(n=>n.data),onSuccess:()=>{t.invalidateQueries({queryKey:g.allocations}),h.success("Allocation acknowledged")},onError:()=>h.error("Failed to acknowledge allocation")})}function st(t){return ne({queryKey:[...g.returns,t],queryFn:()=>C.get(`${A}/returns/`,{params:t}).then(s=>s.data)})}function tt(){const t=F();return E({mutationFn:s=>C.post(`${A}/returns/`,s).then(n=>n.data),onSuccess:()=>{t.invalidateQueries({queryKey:g.returns}),t.invalidateQueries({queryKey:g.allocations}),t.invalidateQueries({queryKey:g.assets}),h.success("Return recorded")},onError:()=>h.error("Failed to record return")})}function at(){const t=F();return E({mutationFn:({id:s,...n})=>C.patch(`${A}/returns/${s}/`,n).then(f=>f.data),onSuccess:()=>{t.invalidateQueries({queryKey:g.returns}),h.success("Return updated")},onError:()=>h.error("Failed to update return")})}function nt(){const t=F();return E({mutationFn:s=>C.delete(`${A}/returns/${s}/`),onSuccess:()=>{t.invalidateQueries({queryKey:g.returns}),h.success("Return deleted")},onError:()=>h.error("Failed to delete return")})}function it(){const t=F();return E({mutationFn:s=>C.post(`${A}/returns/${s}/accept/`).then(n=>n.data),onSuccess:()=>{t.invalidateQueries({queryKey:g.returns}),t.invalidateQueries({queryKey:g.allocations}),t.invalidateQueries({queryKey:g.assets}),h.success("Return accepted")},onError:()=>h.error("Failed to accept return")})}function rt(){const t=F();return E({mutationFn:s=>C.post(`${A}/returns/${s}/reject/`).then(n=>n.data),onSuccess:()=>{t.invalidateQueries({queryKey:g.returns}),h.success("Return rejected")},onError:()=>h.error("Failed to reject return")})}function lt(t){return ne({queryKey:[...g.maintenance,t],queryFn:()=>C.get(`${A}/maintenance/`,{params:t}).then(s=>s.data)})}function ct(){const t=F();return E({mutationFn:s=>C.post(`${A}/maintenance/`,s).then(n=>n.data),onSuccess:()=>{t.invalidateQueries({queryKey:g.maintenance}),t.invalidateQueries({queryKey:g.assets}),h.success("Maintenance record created")},onError:()=>h.error("Failed to create maintenance record")})}function dt(){const t=F();return E({mutationFn:({id:s,...n})=>C.patch(`${A}/maintenance/${s}/`,n).then(f=>f.data),onSuccess:()=>{t.invalidateQueries({queryKey:g.maintenance}),h.success("Maintenance record updated")},onError:()=>h.error("Failed to update maintenance record")})}function ot(){const t=F();return E({mutationFn:s=>C.delete(`${A}/maintenance/${s}/`),onSuccess:()=>{t.invalidateQueries({queryKey:g.maintenance}),h.success("Maintenance record deleted")},onError:()=>h.error("Failed to delete maintenance record")})}function mt(t){return ne({queryKey:[...g.entitlements,t],queryFn:()=>C.get(`${A}/entitlements/`,{params:t}).then(s=>s.data)})}function xt(){const t=F();return E({mutationFn:s=>C.post(`${A}/entitlements/`,s).then(n=>n.data),onSuccess:()=>{t.invalidateQueries({queryKey:g.entitlements}),h.success("Entitlement created")},onError:()=>h.error("Failed to create entitlement")})}function ut(){const t=F();return E({mutationFn:({id:s,...n})=>C.patch(`${A}/entitlements/${s}/`,n).then(f=>f.data),onSuccess:()=>{t.invalidateQueries({queryKey:g.entitlements}),h.success("Entitlement updated")},onError:()=>h.error("Failed to update entitlement")})}function ht(){const t=F();return E({mutationFn:s=>C.delete(`${A}/entitlements/${s}/`),onSuccess:()=>{t.invalidateQueries({queryKey:g.entitlements}),h.success("Entitlement deleted")},onError:()=>h.error("Failed to delete entitlement")})}function pt(){return ne({queryKey:g.dashboard,queryFn:()=>C.get(`${A}/dashboard/`).then(t=>t.data)})}function ua(t){return ne({queryKey:[...g.reports,t],queryFn:()=>C.get(`${A}/reports/`,{params:t}).then(s=>s.data)})}function ha(t){return ne({queryKey:[...g.analytics,t],queryFn:()=>C.get(`${A}/analytics/`,{params:t}).then(s=>s.data)})}function pa(){const t=ks(),{data:s,isLoading:n}=pt();return e.jsxs("div",{children:[e.jsx(Fs,{title:"Asset Dashboard",description:"Overview of asset inventory, allocations, and maintenance across your organization.",actions:e.jsxs(w,{size:"sm",onClick:()=>t("/assets/assets"),children:[e.jsx(ze,{className:"mr-1.5 h-3.5 w-3.5"})," View Assets"]})}),e.jsxs("div",{className:"grid grid-cols-4 gap-4 mb-6",children:[e.jsx(K,{children:e.jsx(O,{className:"pt-5 pb-4 px-5",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-9 w-9 items-center justify-center rounded-lg bg-primary/10",children:e.jsx(ze,{className:"h-4.5 w-4.5 text-primary"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] font-medium text-slate-400 uppercase tracking-wider",children:"Total Assets"}),e.jsx("p",{className:"text-[22px] font-semibold text-slate-900 leading-tight",children:n?"...":(s==null?void 0:s.total_assets)??0})]})]})})}),e.jsx(K,{children:e.jsx(O,{className:"pt-5 pb-4 px-5",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-9 w-9 items-center justify-center rounded-lg bg-emerald-500/10",children:e.jsx(cs,{className:"h-4.5 w-4.5 text-emerald-500"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] font-medium text-slate-400 uppercase tracking-wider",children:"Available"}),e.jsx("p",{className:"text-[22px] font-semibold text-slate-900 leading-tight",children:n?"...":(s==null?void 0:s.available_assets)??0})]})]})})}),e.jsx(K,{children:e.jsx(O,{className:"pt-5 pb-4 px-5",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-9 w-9 items-center justify-center rounded-lg bg-amber-500/10",children:e.jsx(Es,{className:"h-4.5 w-4.5 text-amber-500"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] font-medium text-slate-400 uppercase tracking-wider",children:"Allocated"}),e.jsx("p",{className:"text-[22px] font-semibold text-slate-900 leading-tight",children:n?"...":(s==null?void 0:s.allocated_assets)??0})]})]})})}),e.jsx(K,{children:e.jsx(O,{className:"pt-5 pb-4 px-5",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-9 w-9 items-center justify-center rounded-lg bg-orange-500/10",children:e.jsx(ts,{className:"h-4.5 w-4.5 text-orange-500"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] font-medium text-slate-400 uppercase tracking-wider",children:"In Maintenance"}),e.jsx("p",{className:"text-[22px] font-semibold text-slate-900 leading-tight",children:n?"...":(s==null?void 0:s.in_maintenance)??0})]})]})})})]}),e.jsxs("div",{className:"grid grid-cols-4 gap-4 mb-6",children:[e.jsx(K,{children:e.jsx(O,{className:"pt-5 pb-4 px-5",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-9 w-9 items-center justify-center rounded-lg bg-red-500/10",children:e.jsx(Ts,{className:"h-4.5 w-4.5 text-red-500"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] font-medium text-slate-400 uppercase tracking-wider",children:"Retired"}),e.jsx("p",{className:"text-[22px] font-semibold text-slate-900 leading-tight",children:n?"...":(s==null?void 0:s.retired_assets)??0})]})]})})}),e.jsx(K,{children:e.jsx(O,{className:"pt-5 pb-4 px-5",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-9 w-9 items-center justify-center rounded-lg bg-violet-500/10",children:e.jsx(us,{className:"h-4.5 w-4.5 text-violet-500"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] font-medium text-slate-400 uppercase tracking-wider",children:"Pending Returns"}),e.jsx("p",{className:"text-[22px] font-semibold text-slate-900 leading-tight",children:n?"...":(s==null?void 0:s.pending_returns)??0})]})]})})}),e.jsx(K,{children:e.jsx(O,{className:"pt-5 pb-4 px-5",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-9 w-9 items-center justify-center rounded-lg bg-yellow-500/10",children:e.jsx(Ps,{className:"h-4.5 w-4.5 text-yellow-500"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] font-medium text-slate-400 uppercase tracking-wider",children:"Expiring Warranties"}),e.jsx("p",{className:"text-[22px] font-semibold text-slate-900 leading-tight",children:n?"...":(s==null?void 0:s.expiring_warranties)??0})]})]})})}),e.jsx(K,{children:e.jsx(O,{className:"pt-5 pb-4 px-5",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-9 w-9 items-center justify-center rounded-lg bg-blue-500/10",children:e.jsx(ze,{className:"h-4.5 w-4.5 text-blue-500"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] font-medium text-slate-400 uppercase tracking-wider",children:"Total Value"}),e.jsx("p",{className:"text-[22px] font-semibold text-slate-900 leading-tight",children:n?"...":`$${((s==null?void 0:s.total_value)??0).toLocaleString()}`})]})]})})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-6",children:[e.jsxs(K,{children:[e.jsx(oe,{className:"pb-3",children:e.jsx("div",{className:"flex items-center justify-between",children:e.jsx(me,{className:"text-[14px]",children:"Quick Actions"})})}),e.jsx(O,{children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs(w,{variant:"ghost",className:"w-full justify-between h-12 px-4",onClick:()=>t("/assets/allocations"),children:[e.jsx("span",{className:"text-[13px]",children:"Allocate an Asset"}),e.jsx(Ye,{className:"h-3.5 w-3.5 text-slate-400"})]}),e.jsxs(w,{variant:"ghost",className:"w-full justify-between h-12 px-4",onClick:()=>t("/assets/returns"),children:[e.jsx("span",{className:"text-[13px]",children:"Process a Return"}),e.jsx(Ye,{className:"h-3.5 w-3.5 text-slate-400"})]}),e.jsxs(w,{variant:"ghost",className:"w-full justify-between h-12 px-4",onClick:()=>t("/assets/maintenance"),children:[e.jsx("span",{className:"text-[13px]",children:"Schedule Maintenance"}),e.jsx(Ye,{className:"h-3.5 w-3.5 text-slate-400"})]})]})})]}),e.jsxs(K,{children:[e.jsx(oe,{className:"pb-3",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(me,{className:"text-[14px]",children:"Recent Activity"}),e.jsxs(w,{variant:"ghost",size:"sm",className:"h-7 text-[12px] gap-1",onClick:()=>t("/assets/assets"),children:["View all ",e.jsx(Ye,{className:"h-3 w-3"})]})]})}),e.jsx(O,{children:n?e.jsx("div",{className:"space-y-3",children:[1,2,3].map(f=>e.jsx("div",{className:"h-14 rounded-lg skeleton-shimmer"},f))}):e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-center",children:[e.jsx(us,{className:"h-8 w-8 text-slate-300 mb-2"}),e.jsx("p",{className:"text-[13px] text-slate-500",children:"No recent activity"})]})})]})]})]})}const jt={available:"success",allocated:"default",in_maintenance:"warning",retired:"secondary",disposed:"destructive",lost:"destructive"},gt={new:"success",excellent:"success",good:"default",fair:"warning",poor:"destructive",damaged:"destructive"},hs=[{value:"available",label:"Available"},{value:"allocated",label:"Allocated"},{value:"in_maintenance",label:"In Maintenance"},{value:"retired",label:"Retired"},{value:"disposed",label:"Disposed"},{value:"lost",label:"Lost"}],ps=[{value:"new",label:"New"},{value:"excellent",label:"Excellent"},{value:"good",label:"Good"},{value:"fair",label:"Fair"},{value:"poor",label:"Poor"},{value:"damaged",label:"Damaged"}],yt=ds(he({name:p().min(1,"Name is required"),asset_code:p().min(1,"Asset code is required"),category:p().min(1,"Category is required"),asset_type:p().optional().or(We("")),serial_number:p().optional(),model_number:p().optional(),manufacturer:p().optional(),description:p().optional(),purchase_date:es(),purchase_cost:p().optional(),vendor:p().optional(),invoice_number:p().optional(),warranty_start:p().optional(),warranty_end:p().optional(),location:p().optional(),status:ye(["available","allocated","in_maintenance","retired","disposed","lost"]),condition:ye(["new","excellent","good","fair","poor","damaged"]),notes:p().optional()}),"warranty_start","warranty_end");function ja(){const[t,s]=S.useState(!1),[n,f]=S.useState(null),[m,y]=S.useState(null),[x,T]=S.useState(""),[u,Q]=S.useState(""),{hasPermission:I,requirePermission:L}=ce(),U=I("assets","asset","create"),H=I("assets","asset","update"),z=I("assets","asset","delete"),{pagination:ee,setPagination:G,sorting:se,setSorting:k,globalFilter:te,setGlobalFilter:V,queryParams:D}=Ie(),ae={...D,...x&&{status:x},...u&&{condition:u}},{data:P,isLoading:$}=as(ae),d=Ws(),B=Hs(),W=Ys(),[v,R]=S.useState(""),{data:a}=ss({page_size:100,search:v||void 0}),_=(a==null?void 0:a.results)??[],[re,j]=S.useState(""),{data:b}=xs({page_size:100,search:re||void 0}),pe=(b==null?void 0:b.results)??[],i=xe({resolver:ue(yt),defaultValues:{status:"available",condition:"new"}});function o(){L("assets","asset","create")&&(f(null),i.reset({name:"",asset_code:"",category:"",asset_type:"",serial_number:"",model_number:"",manufacturer:"",description:"",purchase_date:"",purchase_cost:"",vendor:"",invoice_number:"",warranty_start:"",warranty_end:"",location:"",status:"available",condition:"new",notes:""}),s(!0))}function de(r){L("assets","asset","update")&&(f(r),i.reset({name:r.name,asset_code:r.asset_code,category:r.category,asset_type:r.asset_type??"",serial_number:r.serial_number,model_number:r.model_number,manufacturer:r.manufacturer,description:r.description,purchase_date:r.purchase_date??"",purchase_cost:r.purchase_cost,vendor:r.vendor,invoice_number:r.invoice_number,warranty_start:r.warranty_start??"",warranty_end:r.warranty_end??"",location:r.location,status:r.status,condition:r.condition,notes:r.notes}),s(!0))}function He(r){const Ue={...r,asset_type:r.asset_type||null,purchase_date:r.purchase_date||null,warranty_start:r.warranty_start||null,warranty_end:r.warranty_end||null};n?B.mutate({id:n.id,...Ue},{onSuccess:()=>{s(!1),i.reset()}}):d.mutate(Ue,{onSuccess:()=>{s(!1),i.reset()}})}function c(r){T(r==="__all__"?"":r),G(Ue=>({...Ue,pageIndex:0}))}function ns(r){Q(r==="__all__"?"":r),G(Ue=>({...Ue,pageIndex:0}))}const Ss=[{key:"name",header:"Asset",render:r=>e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-slate-900",children:r.name}),e.jsx("p",{className:"text-[12px] text-slate-400 mt-0.5",children:r.asset_code})]})},{key:"category_name",header:"Category",className:"w-32",render:r=>e.jsx("span",{className:"text-[12px] text-slate-600",children:r.category_name??"--"})},{key:"serial_number",header:"Serial No.",className:"w-32",render:r=>e.jsx("span",{className:"text-[12px] text-slate-600",children:r.serial_number||"--"})},{key:"manufacturer",header:"Manufacturer",className:"w-32",render:r=>e.jsx("span",{className:"text-[12px] text-slate-600",children:r.manufacturer||"--"})},{key:"purchase_cost",header:"Cost",className:"w-24",render:r=>e.jsx("span",{className:"text-[12px] text-slate-600",children:r.purchase_cost?`$${r.purchase_cost}`:"--"})},{key:"condition",header:"Condition",className:"w-24",render:r=>e.jsx(Ge,{variant:gt[r.condition],className:"text-[11px]",children:r.condition})},{key:"status",header:"Status",className:"w-28",render:r=>e.jsx(Ge,{variant:jt[r.status],className:"text-[11px]",children:r.status.replace("_"," ")})},{key:"actions",header:"",className:"w-10",render:r=>e.jsxs($e,{children:[e.jsx(Re,{asChild:!0,children:e.jsxs(w,{variant:"ghost",size:"icon-sm",children:[e.jsx(Le,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Actions"})]})}),e.jsxs(Me,{align:"end",className:"w-44",children:[H&&e.jsx(M,{className:"gap-2 text-[13px]",onClick:()=>de(r),children:"Edit"}),z&&e.jsxs(e.Fragment,{children:[e.jsx(Ke,{}),e.jsxs(M,{className:"gap-2 text-[13px] text-red-600 focus:text-red-600 focus:bg-red-50",onClick:()=>y(r),children:[e.jsx(Oe,{className:"h-3.5 w-3.5"}),"Delete"]})]})]})]})}];return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"text-[16px] font-semibold text-slate-900 flex items-center gap-2",children:[e.jsx(ze,{className:"h-5 w-5 text-primary"})," Assets"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"Manage your asset inventory"})]}),U&&e.jsxs(w,{size:"sm",onClick:o,children:[e.jsx(_e,{className:"mr-1.5 h-3.5 w-3.5"})," New Asset"]})]}),e.jsx(Qe,{actions:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(Y,{value:x,onValueChange:c,children:[e.jsx(Z,{className:"w-[140px] h-9",children:e.jsx(X,{placeholder:"All statuses"})}),e.jsxs(J,{children:[e.jsx(q,{value:"__all__",children:"All Statuses"}),hs.map(r=>e.jsx(q,{value:r.value,children:r.label},r.value))]})]}),e.jsxs(Y,{value:u,onValueChange:ns,children:[e.jsx(Z,{className:"w-[140px] h-9",children:e.jsx(X,{placeholder:"All conditions"})}),e.jsxs(J,{children:[e.jsx(q,{value:"__all__",children:"All Conditions"}),ps.map(r=>e.jsx(q,{value:r.value,children:r.label},r.value))]})]})]}),columns:Ss,data:(P==null?void 0:P.results)??[],isLoading:$,rowKey:r=>r.id,searchKeys:["name","asset_code","serial_number","manufacturer"],searchPlaceholder:"Search assets...",emptyMessage:"No assets found",emptyDescription:"Add your first asset to get started.",totalCount:(P==null?void 0:P.count)??0,pagination:ee,onPaginationChange:G,sorting:se,onSortingChange:k,globalFilter:te,onGlobalFilterChange:V}),e.jsx(Ne,{open:t,onOpenChange:s,children:e.jsxs(ve,{size:"lg",children:[e.jsxs(be,{children:[e.jsx(Se,{children:n?"Edit Asset":"New Asset"}),e.jsx(Ce,{children:n?"Update asset details.":"Register a new asset in inventory."})]}),e.jsxs("form",{onSubmit:i.handleSubmit(He),className:"flex-1 overflow-y-auto px-6 py-5 space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Name *"}),e.jsx(N,{className:"mt-1.5",...i.register("name"),placeholder:"Asset name"}),i.formState.errors.name&&e.jsx("p",{className:"text-[12px] text-red-600 mt-1",children:i.formState.errors.name.message})]}),e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Asset Code *"}),e.jsx(N,{className:"mt-1.5",...i.register("asset_code"),placeholder:"e.g. AST-001"}),i.formState.errors.asset_code&&e.jsx("p",{className:"text-[12px] text-red-600 mt-1",children:i.formState.errors.asset_code.message})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Category *"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(fe,{value:i.watch("category")??null,onValueChange:r=>i.setValue("category",r,{shouldValidate:!0}),onSearch:R,selectedLabel:n==null?void 0:n.category_name,options:_.map(r=>({value:r.id,label:r.name,hint:r.code})),placeholder:"Select category",searchPlaceholder:"Search categories..."})}),i.formState.errors.category&&e.jsx("p",{className:"text-[12px] text-red-600 mt-1",children:i.formState.errors.category.message})]}),e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Asset Type"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(fe,{value:i.watch("asset_type")||null,onValueChange:r=>i.setValue("asset_type",r),onSearch:j,selectedLabel:n==null?void 0:n.asset_type_name,options:pe.map(r=>({value:r.id,label:r.name,hint:r.code})),placeholder:"Select type",searchPlaceholder:"Search types..."})})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Serial Number"}),e.jsx(N,{className:"mt-1.5",...i.register("serial_number"),placeholder:"e.g. SN-12345"})]}),e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Model Number"}),e.jsx(N,{className:"mt-1.5",...i.register("model_number"),placeholder:"e.g. MBP-2024"})]})]}),e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Manufacturer"}),e.jsx(N,{className:"mt-1.5",...i.register("manufacturer"),placeholder:"e.g. Apple, Dell"})]}),e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Description"}),e.jsx(le,{className:"mt-1.5",...i.register("description"),rows:2,placeholder:"Asset description..."})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Purchase Date"}),e.jsx(N,{className:"mt-1.5",type:"date",...i.register("purchase_date")})]}),e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Purchase Cost"}),e.jsx(N,{className:"mt-1.5",type:"number",step:"0.01",...i.register("purchase_cost"),placeholder:"0.00"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Vendor"}),e.jsx(N,{className:"mt-1.5",...i.register("vendor"),placeholder:"Vendor name"})]}),e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Invoice Number"}),e.jsx(N,{className:"mt-1.5",...i.register("invoice_number"),placeholder:"INV-001"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Warranty Start"}),e.jsx(N,{className:"mt-1.5",type:"date",...i.register("warranty_start"),max:i.watch("warranty_end")||void 0})]}),e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Warranty End"}),e.jsx(N,{className:"mt-1.5",type:"date",...i.register("warranty_end"),min:i.watch("warranty_start")||void 0})]})]}),e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Location"}),e.jsx(N,{className:"mt-1.5",...i.register("location"),placeholder:"e.g. Floor 3, Building A"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Status *"}),e.jsxs(Y,{value:i.watch("status"),onValueChange:r=>i.setValue("status",r),children:[e.jsx(Z,{className:"mt-1.5",children:e.jsx(X,{placeholder:"Select status"})}),e.jsx(J,{children:hs.map(r=>e.jsx(q,{value:r.value,children:r.label},r.value))})]})]}),e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Condition *"}),e.jsxs(Y,{value:i.watch("condition"),onValueChange:r=>i.setValue("condition",r),children:[e.jsx(Z,{className:"mt-1.5",children:e.jsx(X,{placeholder:"Select condition"})}),e.jsx(J,{children:ps.map(r=>e.jsx(q,{value:r.value,children:r.label},r.value))})]})]})]}),e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Notes"}),e.jsx(le,{className:"mt-1.5",...i.register("notes"),rows:3,placeholder:"Any additional notes..."})]})]}),e.jsxs(Ae,{children:[e.jsx(w,{type:"button",variant:"outline",onClick:()=>s(!1),children:"Cancel"}),e.jsx(w,{onClick:i.handleSubmit(He),disabled:d.isPending||B.isPending,children:d.isPending||B.isPending?"Saving...":n?"Update":"Create"})]})]})}),e.jsx(we,{open:!!m,onOpenChange:r=>!r&&y(null),children:e.jsxs(ke,{children:[e.jsx(De,{children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx(Pe,{variant:"destructive"}),e.jsxs("div",{children:[e.jsx(qe,{children:"Delete Asset"}),e.jsxs(Fe,{children:["Are you sure you want to delete"," ",e.jsx("span",{className:"font-medium text-slate-700",children:m==null?void 0:m.name}),"? This action cannot be undone."]})]})]})}),e.jsxs(Ee,{children:[e.jsx(Te,{onClick:()=>y(null),children:"Cancel"}),e.jsx(Ve,{variant:"destructive",onClick:()=>{m&&W.mutate(m.id),y(null)},children:"Delete"})]})]})})]})}const ft=he({name:p().min(1,"Name is required"),code:p().min(1,"Code is required"),description:p().optional(),parent:p().optional().or(We("")),depreciation_rate:p().optional(),useful_life_months:Je.number().int().min(0).optional(),is_active:ie()});function ga(){const[t,s]=S.useState(!1),[n,f]=S.useState(null),[m,y]=S.useState(null),{hasPermission:x,requirePermission:T}=ce(),u=x("assets","asset_category","create"),Q=x("assets","asset_category","update"),I=x("assets","asset_category","delete"),{pagination:L,setPagination:U,sorting:H,setSorting:z,globalFilter:ee,setGlobalFilter:G,queryParams:se}=Ie(),{data:k,isLoading:te}=ss(se),V=Is(),D=Ls(),ae=Us(),{data:P}=ss({page_size:100}),$=(P==null?void 0:P.results)??[],d=xe({resolver:ue(ft),defaultValues:{is_active:!0}});function B(){T("assets","asset_category","create")&&(f(null),d.reset({name:"",code:"",description:"",parent:"",depreciation_rate:"",useful_life_months:0,is_active:!0}),s(!0))}function W(a){T("assets","asset_category","update")&&(f(a),d.reset({name:a.name,code:a.code,description:a.description,parent:a.parent??"",depreciation_rate:a.depreciation_rate,useful_life_months:a.useful_life_months,is_active:a.is_active}),s(!0))}function v(a){const _={...a,parent:a.parent||null};n?D.mutate({id:n.id,..._},{onSuccess:()=>{s(!1),d.reset()}}):V.mutate(_,{onSuccess:()=>{s(!1),d.reset()}})}const R=[{key:"name",header:"Category",render:a=>e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-slate-900",children:a.name}),e.jsx("p",{className:"text-[12px] text-slate-400 mt-0.5",children:a.code})]})},{key:"parent_name",header:"Parent",className:"w-32",render:a=>e.jsx("span",{className:"text-[12px] text-slate-600",children:a.parent_name??"--"})},{key:"depreciation_rate",header:"Depreciation",className:"w-28",render:a=>e.jsx("span",{className:"text-[12px] text-slate-600",children:a.depreciation_rate?`${a.depreciation_rate}%`:"--"})},{key:"useful_life_months",header:"Useful Life",className:"w-28",render:a=>e.jsx("span",{className:"text-[12px] text-slate-600",children:a.useful_life_months?`${a.useful_life_months} months`:"--"})},{key:"children_count",header:"Children",className:"w-20",render:a=>e.jsx("span",{className:"text-[12px] text-slate-600",children:a.children_count??0})},{key:"is_active",header:"Active",className:"w-24",render:a=>e.jsx(ms,{status:a.is_active?"active":"inactive"})},{key:"created_at",header:"Created",className:"w-28",render:a=>e.jsx("span",{className:"text-[12px] text-slate-400",children:new Date(a.created_at).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"})})},{key:"actions",header:"",className:"w-10",render:a=>e.jsxs($e,{children:[e.jsx(Re,{asChild:!0,children:e.jsxs(w,{variant:"ghost",size:"icon-sm",children:[e.jsx(Le,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Actions"})]})}),e.jsxs(Me,{align:"end",className:"w-44",children:[Q&&e.jsx(M,{className:"gap-2 text-[13px]",onClick:()=>W(a),children:"Edit"}),I&&e.jsxs(e.Fragment,{children:[e.jsx(Ke,{}),e.jsxs(M,{className:"gap-2 text-[13px] text-red-600 focus:text-red-600 focus:bg-red-50",onClick:()=>y(a),children:[e.jsx(Oe,{className:"h-3.5 w-3.5"}),"Delete"]})]})]})]})}];return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"text-[16px] font-semibold text-slate-900 flex items-center gap-2",children:[e.jsx(vs,{className:"h-5 w-5 text-primary"})," Asset Categories"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"Organize assets into categories"})]}),u&&e.jsxs(w,{size:"sm",onClick:B,children:[e.jsx(_e,{className:"mr-1.5 h-3.5 w-3.5"})," New Category"]})]}),e.jsx(Qe,{columns:R,data:(k==null?void 0:k.results)??[],isLoading:te,rowKey:a=>a.id,searchKeys:["name","code"],searchPlaceholder:"Search categories...",emptyMessage:"No categories found",emptyDescription:"Add your first asset category to get started.",totalCount:(k==null?void 0:k.count)??0,pagination:L,onPaginationChange:U,sorting:H,onSortingChange:z,globalFilter:ee,onGlobalFilterChange:G}),e.jsx(Ne,{open:t,onOpenChange:s,children:e.jsxs(ve,{children:[e.jsxs(be,{children:[e.jsx(Se,{children:n?"Edit Category":"New Category"}),e.jsx(Ce,{children:n?"Update category details.":"Add a new asset category."})]}),e.jsxs("form",{onSubmit:d.handleSubmit(v),className:"flex-1 overflow-y-auto px-6 py-5 space-y-4",children:[e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Name *"}),e.jsx(N,{className:"mt-1.5",...d.register("name"),placeholder:"Category name"}),d.formState.errors.name&&e.jsx("p",{className:"text-[12px] text-red-600 mt-1",children:d.formState.errors.name.message})]}),e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Code *"}),e.jsx(N,{className:"mt-1.5",...d.register("code"),placeholder:"e.g. IT-EQUIP"}),d.formState.errors.code&&e.jsx("p",{className:"text-[12px] text-red-600 mt-1",children:d.formState.errors.code.message})]}),e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Parent Category"}),e.jsxs(Y,{value:d.watch("parent")||"__none__",onValueChange:a=>d.setValue("parent",a==="__none__"?"":a),children:[e.jsx(Z,{className:"mt-1.5",children:e.jsx(X,{placeholder:"None (top-level)"})}),e.jsxs(J,{children:[e.jsx(q,{value:"__none__",children:"None (top-level)"}),$.filter(a=>a.id!==(n==null?void 0:n.id)).map(a=>e.jsx(q,{value:a.id,children:a.name},a.id))]})]})]}),e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Description"}),e.jsx(le,{className:"mt-1.5",...d.register("description"),rows:3,placeholder:"Category description..."})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Depreciation Rate (%)"}),e.jsx(N,{className:"mt-1.5",type:"number",step:"0.01",...d.register("depreciation_rate"),placeholder:"e.g. 15.00"})]}),e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Useful Life (months)"}),e.jsx(N,{className:"mt-1.5",type:"number",...d.register("useful_life_months"),placeholder:"e.g. 60"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Xe,{checked:d.watch("is_active"),onCheckedChange:a=>d.setValue("is_active",!!a)}),e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Active"})]})]}),e.jsxs(Ae,{children:[e.jsx(w,{type:"button",variant:"outline",onClick:()=>s(!1),children:"Cancel"}),e.jsx(w,{onClick:d.handleSubmit(v),disabled:V.isPending||D.isPending,children:V.isPending||D.isPending?"Saving...":n?"Update":"Create"})]})]})}),e.jsx(we,{open:!!m,onOpenChange:a=>!a&&y(null),children:e.jsxs(ke,{children:[e.jsx(De,{children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx(Pe,{variant:"destructive"}),e.jsxs("div",{children:[e.jsx(qe,{children:"Delete Category"}),e.jsxs(Fe,{children:["Are you sure you want to delete"," ",e.jsx("span",{className:"font-medium text-slate-700",children:m==null?void 0:m.name}),"? This action cannot be undone."]})]})]})}),e.jsxs(Ee,{children:[e.jsx(Te,{onClick:()=>y(null),children:"Cancel"}),e.jsx(Ve,{variant:"destructive",onClick:()=>{m&&ae.mutate(m.id),y(null)},children:"Delete"})]})]})})]})}const _t=he({name:p().min(1,"Name is required"),code:p().min(1,"Code is required"),category:p().min(1,"Category is required"),description:p().optional(),is_active:ie()});function ya(){const[t,s]=S.useState(!1),[n,f]=S.useState(null),[m,y]=S.useState(null),{hasPermission:x,requirePermission:T}=ce(),u=x("assets","asset_type","create"),Q=x("assets","asset_type","update"),I=x("assets","asset_type","delete"),{pagination:L,setPagination:U,sorting:H,setSorting:z,globalFilter:ee,setGlobalFilter:G,queryParams:se}=Ie(),{data:k,isLoading:te}=xs(se),V=zs(),D=Gs(),ae=Bs(),[P,$]=S.useState(""),{data:d,isLoading:B}=ss({search:P||void 0}),W=(d==null?void 0:d.results)??[],v=xe({resolver:ue(_t),defaultValues:{is_active:!0}});function R(){T("assets","asset_type","create")&&(f(null),v.reset({name:"",code:"",category:"",description:"",is_active:!0}),s(!0))}function a(j){T("assets","asset_type","update")&&(f(j),v.reset({name:j.name,code:j.code,category:j.category,description:j.description,is_active:j.is_active}),s(!0))}function _(j){n?D.mutate({id:n.id,...j},{onSuccess:()=>{s(!1),v.reset()}}):V.mutate(j,{onSuccess:()=>{s(!1),v.reset()}})}const re=[{key:"name",header:"Type",render:j=>e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-slate-900",children:j.name}),e.jsx("p",{className:"text-[12px] text-slate-400 mt-0.5",children:j.code})]})},{key:"category_name",header:"Category",className:"w-36",render:j=>e.jsx("span",{className:"text-[12px] text-slate-600",children:j.category_name??"--"})},{key:"description",header:"Description",render:j=>e.jsx("span",{className:"text-[12px] text-slate-600 line-clamp-1",children:j.description||"--"})},{key:"is_active",header:"Active",className:"w-24",render:j=>e.jsx(ms,{status:j.is_active?"active":"inactive"})},{key:"created_at",header:"Created",className:"w-28",render:j=>e.jsx("span",{className:"text-[12px] text-slate-400",children:new Date(j.created_at).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"})})},{key:"actions",header:"",className:"w-10",render:j=>e.jsxs($e,{children:[e.jsx(Re,{asChild:!0,children:e.jsxs(w,{variant:"ghost",size:"icon-sm",children:[e.jsx(Le,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Actions"})]})}),e.jsxs(Me,{align:"end",className:"w-44",children:[Q&&e.jsx(M,{className:"gap-2 text-[13px]",onClick:()=>a(j),children:"Edit"}),I&&e.jsxs(e.Fragment,{children:[e.jsx(Ke,{}),e.jsxs(M,{className:"gap-2 text-[13px] text-red-600 focus:text-red-600 focus:bg-red-50",onClick:()=>y(j),children:[e.jsx(Oe,{className:"h-3.5 w-3.5"}),"Delete"]})]})]})]})}];return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"text-[16px] font-semibold text-slate-900 flex items-center gap-2",children:[e.jsx(gs,{className:"h-5 w-5 text-primary"})," Asset Types"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"Define types within asset categories"})]}),u&&e.jsxs(w,{size:"sm",onClick:R,children:[e.jsx(_e,{className:"mr-1.5 h-3.5 w-3.5"})," New Type"]})]}),e.jsx(Qe,{columns:re,data:(k==null?void 0:k.results)??[],isLoading:te,rowKey:j=>j.id,searchKeys:["name","code","category_name"],searchPlaceholder:"Search types...",emptyMessage:"No asset types found",emptyDescription:"Add your first asset type to get started.",totalCount:(k==null?void 0:k.count)??0,pagination:L,onPaginationChange:U,sorting:H,onSortingChange:z,globalFilter:ee,onGlobalFilterChange:G}),e.jsx(Ne,{open:t,onOpenChange:s,children:e.jsxs(ve,{children:[e.jsxs(be,{children:[e.jsx(Se,{children:n?"Edit Type":"New Type"}),e.jsx(Ce,{children:n?"Update asset type details.":"Add a new asset type."})]}),e.jsxs("form",{onSubmit:v.handleSubmit(_),className:"flex-1 overflow-y-auto px-6 py-5 space-y-4",children:[e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Name *"}),e.jsx(N,{className:"mt-1.5",...v.register("name"),placeholder:"Type name"}),v.formState.errors.name&&e.jsx("p",{className:"text-[12px] text-red-600 mt-1",children:v.formState.errors.name.message})]}),e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Code *"}),e.jsx(N,{className:"mt-1.5",...v.register("code"),placeholder:"e.g. LAPTOP"}),v.formState.errors.code&&e.jsx("p",{className:"text-[12px] text-red-600 mt-1",children:v.formState.errors.code.message})]}),e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Category *"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(fe,{value:v.watch("category")??"",onValueChange:j=>v.setValue("category",j,{shouldValidate:!0}),onSearch:$,isLoading:B,options:W.map(j=>({value:j.id,label:j.name,hint:j.code})),placeholder:"Select category",searchPlaceholder:"Search categories..."})}),v.formState.errors.category&&e.jsx("p",{className:"text-[12px] text-red-600 mt-1",children:v.formState.errors.category.message})]}),e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Description"}),e.jsx(le,{className:"mt-1.5",...v.register("description"),rows:3,placeholder:"Type description..."})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Xe,{checked:v.watch("is_active"),onCheckedChange:j=>v.setValue("is_active",!!j)}),e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Active"})]})]}),e.jsxs(Ae,{children:[e.jsx(w,{type:"button",variant:"outline",onClick:()=>s(!1),children:"Cancel"}),e.jsx(w,{onClick:v.handleSubmit(_),disabled:V.isPending||D.isPending,children:V.isPending||D.isPending?"Saving...":n?"Update":"Create"})]})]})}),e.jsx(we,{open:!!m,onOpenChange:j=>!j&&y(null),children:e.jsxs(ke,{children:[e.jsx(De,{children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx(Pe,{variant:"destructive"}),e.jsxs("div",{children:[e.jsx(qe,{children:"Delete Asset Type"}),e.jsxs(Fe,{children:["Are you sure you want to delete"," ",e.jsx("span",{className:"font-medium text-slate-700",children:m==null?void 0:m.name}),"? This action cannot be undone."]})]})]})}),e.jsxs(Ee,{children:[e.jsx(Te,{onClick:()=>y(null),children:"Cancel"}),e.jsx(Ve,{variant:"destructive",onClick:()=>{m&&ae.mutate(m.id),y(null)},children:"Delete"})]})]})})]})}const Nt={active:"success",returned:"default",transferred:"warning",lost_reported:"destructive"},vt={pending:"warning",acknowledged:"success",disputed:"destructive"},bt=[{value:"new",label:"New"},{value:"excellent",label:"Excellent"},{value:"good",label:"Good"},{value:"fair",label:"Fair"},{value:"poor",label:"Poor"},{value:"damaged",label:"Damaged"}],St=ds(he({asset:p().min(1,"Asset is required"),employee:p().min(1,"Employee is required"),allocation_date:os("Allocation date is required"),expected_return_date:es(),purpose:p().optional(),condition_at_allocation:ye(["new","excellent","good","fair","poor","damaged"]),deposit_amount:p().optional(),notes:p().optional()}),"allocation_date","expected_return_date");function fa(){const[t,s]=S.useState(!1),[n,f]=S.useState(null),[m,y]=S.useState(null),[x,T]=S.useState(""),{hasPermission:u,requirePermission:Q}=ce(),I=u("assets","asset_allocation","create"),L=u("assets","asset_allocation","update"),U=u("assets","asset_allocation","delete"),{pagination:H,setPagination:z,sorting:ee,setSorting:G,globalFilter:se,setGlobalFilter:k,queryParams:te}=Ie(),V={...te,...x&&{status:x}},{data:D,isLoading:ae}=bs(V),P=Zs(),$=Xs(),d=Js(),B=et(),[W,v]=S.useState(""),{data:R}=as({page_size:100,status:"available",search:W||void 0}),a=(R==null?void 0:R.results)??[],_=xe({resolver:ue(St),defaultValues:{condition_at_allocation:"good"}});function re(){Q("assets","asset_allocation","create")&&(f(null),_.reset({asset:"",employee:"",allocation_date:"",expected_return_date:"",purpose:"",condition_at_allocation:"good",deposit_amount:"",notes:""}),s(!0))}function j(o){Q("assets","asset_allocation","update")&&(f(o),_.reset({asset:o.asset,employee:o.employee,allocation_date:o.allocation_date,expected_return_date:o.expected_return_date??"",purpose:o.purpose,condition_at_allocation:o.condition_at_allocation,deposit_amount:o.deposit_amount,notes:o.notes}),s(!0))}function b(o){const de={...o,expected_return_date:o.expected_return_date||null};n?$.mutate({id:n.id,...de},{onSuccess:()=>{s(!1),_.reset()}}):P.mutate(de,{onSuccess:()=>{s(!1),_.reset()}})}function pe(o){T(o==="__all__"?"":o),z(de=>({...de,pageIndex:0}))}const i=[{key:"asset_name",header:"Asset",render:o=>e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-slate-900",children:o.asset_name??"--"}),e.jsx("p",{className:"text-[12px] text-slate-400 mt-0.5",children:o.asset_code??"--"})]})},{key:"employee_name",header:"Employee",className:"w-36",render:o=>e.jsx("span",{className:"text-[12px] text-slate-600",children:o.employee_name??"--"})},{key:"allocation_date",header:"Allocated",className:"w-28",render:o=>e.jsx("span",{className:"text-[12px] text-slate-600",children:new Date(o.allocation_date).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"})})},{key:"expected_return_date",header:"Expected Return",className:"w-28",render:o=>e.jsx("span",{className:"text-[12px] text-slate-600",children:o.expected_return_date?new Date(o.expected_return_date).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"}):"--"})},{key:"acknowledgement_status",header:"Acknowledged",className:"w-28",render:o=>e.jsx(Ge,{variant:vt[o.acknowledgement_status],className:"text-[11px]",children:o.acknowledgement_status})},{key:"status",header:"Status",className:"w-28",render:o=>e.jsx(Ge,{variant:Nt[o.status],className:"text-[11px]",children:o.status.replace("_"," ")})},{key:"actions",header:"",className:"w-10",render:o=>e.jsxs($e,{children:[e.jsx(Re,{asChild:!0,children:e.jsxs(w,{variant:"ghost",size:"icon-sm",children:[e.jsx(Le,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Actions"})]})}),e.jsxs(Me,{align:"end",className:"w-44",children:[L&&e.jsx(M,{className:"gap-2 text-[13px]",onClick:()=>j(o),children:"Edit"}),L&&o.acknowledgement_status==="pending"&&o.status==="active"&&e.jsxs(M,{className:"gap-2 text-[13px]",onClick:()=>B.mutate(o.id),children:[e.jsx(Ns,{className:"h-3.5 w-3.5 text-slate-400"}),"Acknowledge"]}),U&&e.jsxs(e.Fragment,{children:[e.jsx(Ke,{}),e.jsxs(M,{className:"gap-2 text-[13px] text-red-600 focus:text-red-600 focus:bg-red-50",onClick:()=>y(o),children:[e.jsx(Oe,{className:"h-3.5 w-3.5"}),"Delete"]})]})]})]})}];return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"text-[16px] font-semibold text-slate-900 flex items-center gap-2",children:[e.jsx(ys,{className:"h-5 w-5 text-primary"})," Asset Allocations"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"Assign and track asset allocations"})]}),I&&e.jsxs(w,{size:"sm",onClick:re,children:[e.jsx(_e,{className:"mr-1.5 h-3.5 w-3.5"})," New Allocation"]})]}),e.jsx(Qe,{actions:e.jsxs(Y,{value:x,onValueChange:pe,children:[e.jsx(Z,{className:"w-[140px] h-9",children:e.jsx(X,{placeholder:"All statuses"})}),e.jsxs(J,{children:[e.jsx(q,{value:"__all__",children:"All Statuses"}),e.jsx(q,{value:"active",children:"Active"}),e.jsx(q,{value:"returned",children:"Returned"}),e.jsx(q,{value:"transferred",children:"Transferred"}),e.jsx(q,{value:"lost_reported",children:"Lost"})]})]}),columns:i,data:(D==null?void 0:D.results)??[],isLoading:ae,rowKey:o=>o.id,searchKeys:["asset_name","asset_code","employee_name"],searchPlaceholder:"Search allocations...",emptyMessage:"No allocations found",emptyDescription:"Create your first asset allocation to get started.",totalCount:(D==null?void 0:D.count)??0,pagination:H,onPaginationChange:z,sorting:ee,onSortingChange:G,globalFilter:se,onGlobalFilterChange:k}),e.jsx(Ne,{open:t,onOpenChange:s,children:e.jsxs(ve,{children:[e.jsxs(be,{children:[e.jsx(Se,{children:n?"Edit Allocation":"New Allocation"}),e.jsx(Ce,{children:n?"Update allocation details.":"Allocate an asset to an employee."})]}),e.jsxs("form",{onSubmit:_.handleSubmit(b),className:"flex-1 overflow-y-auto px-6 py-5 space-y-4",children:[e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Asset *"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(fe,{value:_.watch("asset")??null,onValueChange:o=>_.setValue("asset",o,{shouldValidate:!0}),onSearch:v,selectedLabel:(n==null?void 0:n.asset_name)??void 0,options:a.map(o=>({value:o.id,label:o.name,hint:o.asset_code})),placeholder:"Select asset",searchPlaceholder:"Search assets..."})}),_.formState.errors.asset&&e.jsx("p",{className:"text-[12px] text-red-600 mt-1",children:_.formState.errors.asset.message})]}),e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Employee *"}),e.jsx(_s,{value:_.watch("employee")??"",onValueChange:o=>_.setValue("employee",o,{shouldValidate:!0}),placeholder:"Select employee",className:"mt-1.5"}),_.formState.errors.employee&&e.jsx("p",{className:"text-[12px] text-red-600 mt-1",children:_.formState.errors.employee.message})]}),e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Allocation Date *"}),e.jsx(N,{className:"mt-1.5",type:"date",..._.register("allocation_date"),max:_.watch("expected_return_date")||void 0}),_.formState.errors.allocation_date&&e.jsx("p",{className:"text-[12px] text-red-600 mt-1",children:_.formState.errors.allocation_date.message})]}),e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Expected Return Date"}),e.jsx(N,{className:"mt-1.5",type:"date",..._.register("expected_return_date"),min:_.watch("allocation_date")||void 0})]}),e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Purpose"}),e.jsx(N,{className:"mt-1.5",..._.register("purpose"),placeholder:"Reason for allocation"})]}),e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Condition at Allocation"}),e.jsxs(Y,{value:_.watch("condition_at_allocation"),onValueChange:o=>_.setValue("condition_at_allocation",o),children:[e.jsx(Z,{className:"mt-1.5",children:e.jsx(X,{placeholder:"Select condition"})}),e.jsx(J,{children:bt.map(o=>e.jsx(q,{value:o.value,children:o.label},o.value))})]})]}),e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Deposit Amount"}),e.jsx(N,{className:"mt-1.5",type:"number",step:"0.01",..._.register("deposit_amount"),placeholder:"0.00"})]}),e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Notes"}),e.jsx(le,{className:"mt-1.5",..._.register("notes"),rows:3,placeholder:"Any additional notes..."})]})]}),e.jsxs(Ae,{children:[e.jsx(w,{type:"button",variant:"outline",onClick:()=>s(!1),children:"Cancel"}),e.jsx(w,{onClick:_.handleSubmit(b),disabled:P.isPending||$.isPending,children:P.isPending||$.isPending?"Saving...":n?"Update":"Allocate"})]})]})}),e.jsx(we,{open:!!m,onOpenChange:o=>!o&&y(null),children:e.jsxs(ke,{children:[e.jsx(De,{children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx(Pe,{variant:"destructive"}),e.jsxs("div",{children:[e.jsx(qe,{children:"Delete Allocation"}),e.jsxs(Fe,{children:["Are you sure you want to delete this allocation for"," ",e.jsx("span",{className:"font-medium text-slate-700",children:m==null?void 0:m.asset_name}),"? This action cannot be undone."]})]})]})}),e.jsxs(Ee,{children:[e.jsx(Te,{onClick:()=>y(null),children:"Cancel"}),e.jsx(Ve,{variant:"destructive",onClick:()=>{m&&d.mutate(m.id),y(null)},children:"Delete"})]})]})})]})}function Ct(t){switch(t){case"accepted":case"accepted_with_damage":return"approved";case"rejected":return"rejected";case"pending_inspection":default:return"pending"}}const At=[{value:"new",label:"New"},{value:"excellent",label:"Excellent"},{value:"good",label:"Good"},{value:"fair",label:"Fair"},{value:"poor",label:"Poor"},{value:"damaged",label:"Damaged"}],wt=he({allocation:p().min(1,"Allocation is required"),asset:p().min(1,"Asset is required"),employee:p().min(1,"Employee is required"),return_date:os("Return date is required"),condition_at_return:ye(["new","excellent","good","fair","poor","damaged"]),damage_description:p().optional(),damage_cost:p().optional(),deposit_refunded:p().optional(),deposit_deducted:p().optional(),remarks:p().optional()});function _a(){const[t,s]=S.useState(!1),[n,f]=S.useState(null),[m,y]=S.useState(null),[x,T]=S.useState(""),[u,Q]=S.useState(""),[I,L]=S.useState(""),{hasPermission:U,requirePermission:H}=ce(),z=U("assets","asset_return","create"),ee=U("assets","asset_return","update"),G=U("assets","asset_return","approve"),{pagination:se,setPagination:k,sorting:te,setSorting:V,globalFilter:D,setGlobalFilter:ae,queryParams:P}=Ie(),$={...P,...x&&{status:x}},{data:d,isLoading:B}=st($),{data:W}=bs({search:u||void 0}),{data:v}=as({search:I||void 0}),R=tt(),a=at(),_=nt(),re=it(),j=rt(),b=xe({resolver:ue(wt),defaultValues:{condition_at_return:"good"}});function pe(){H("assets","asset_return","create")&&(f(null),b.reset({allocation:"",asset:"",employee:"",return_date:"",condition_at_return:"good",damage_description:"",damage_cost:"",deposit_refunded:"",deposit_deducted:"",remarks:""}),s(!0))}function i(c){H("assets","asset_return","update")&&(f(c),b.reset({allocation:c.allocation,asset:c.asset,employee:c.employee,return_date:c.return_date,condition_at_return:c.condition_at_return,damage_description:c.damage_description,damage_cost:c.damage_cost,deposit_refunded:c.deposit_refunded,deposit_deducted:c.deposit_deducted,remarks:c.remarks}),s(!0))}function o(c){n?a.mutate({id:n.id,...c},{onSuccess:()=>{s(!1),b.reset()}}):R.mutate(c,{onSuccess:()=>{s(!1),b.reset()}})}function de(c){T(c==="__all__"?"":c),k(ns=>({...ns,pageIndex:0}))}const He=[{key:"asset_name",header:"Asset",render:c=>e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-slate-900",children:c.asset_name??"--"}),e.jsx("p",{className:"text-[12px] text-slate-400 mt-0.5",children:c.employee_name??"--"})]})},{key:"return_date",header:"Return Date",className:"w-28",render:c=>e.jsx("span",{className:"text-[12px] text-slate-600",children:new Date(c.return_date).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"})})},{key:"condition_at_return",header:"Condition",className:"w-24",render:c=>e.jsx("span",{className:"text-[12px] text-slate-600 capitalize",children:c.condition_at_return})},{key:"damage_cost",header:"Damage Cost",className:"w-24",render:c=>e.jsx("span",{className:"text-[12px] text-slate-600",children:c.damage_cost?`$${c.damage_cost}`:"--"})},{key:"received_by_name",header:"Received By",className:"w-32",render:c=>e.jsx("span",{className:"text-[12px] text-slate-600",children:c.received_by_name??"--"})},{key:"status",header:"Status",className:"w-32",render:c=>e.jsxs("div",{className:"inline-flex items-center gap-1.5",children:[e.jsx(Vs,{status:Ct(c.status)}),c.status==="accepted_with_damage"&&e.jsx("span",{className:"text-[10.5px] text-[#92400e]",children:"w/ damage"})]})},{key:"actions",header:"",className:"w-10",render:c=>e.jsxs($e,{children:[e.jsx(Re,{asChild:!0,children:e.jsxs(w,{variant:"ghost",size:"icon-sm",children:[e.jsx(Le,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Actions"})]})}),e.jsxs(Me,{align:"end",className:"w-44",children:[ee&&e.jsx(M,{className:"gap-2 text-[13px]",onClick:()=>i(c),children:"Edit"}),G&&c.status==="pending_inspection"&&e.jsxs(e.Fragment,{children:[e.jsxs(M,{className:"gap-2 text-[13px]",onClick:()=>re.mutate(c.id),children:[e.jsx(Ns,{className:"h-3.5 w-3.5 text-slate-400"}),"Accept"]}),e.jsxs(M,{className:"gap-2 text-[13px]",onClick:()=>j.mutate(c.id),children:[e.jsx($s,{className:"h-3.5 w-3.5 text-slate-400"}),"Reject"]})]}),e.jsx(Ke,{}),e.jsxs(M,{className:"gap-2 text-[13px] text-red-600 focus:text-red-600 focus:bg-red-50",onClick:()=>y(c),children:[e.jsx(Oe,{className:"h-3.5 w-3.5"}),"Delete"]})]})]})}];return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"text-[16px] font-semibold text-slate-900 flex items-center gap-2",children:[e.jsx(fs,{className:"h-5 w-5 text-primary"})," Asset Returns"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"Process and inspect asset returns"})]}),z&&e.jsxs(w,{size:"sm",onClick:pe,children:[e.jsx(_e,{className:"mr-1.5 h-3.5 w-3.5"})," New Return"]})]}),e.jsx(Qe,{actions:e.jsxs(Y,{value:x,onValueChange:de,children:[e.jsx(Z,{className:"w-[160px] h-9",children:e.jsx(X,{placeholder:"All statuses"})}),e.jsxs(J,{children:[e.jsx(q,{value:"__all__",children:"All Statuses"}),e.jsx(q,{value:"pending_inspection",children:"Pending Inspection"}),e.jsx(q,{value:"accepted",children:"Accepted"}),e.jsx(q,{value:"accepted_with_damage",children:"With Damage"}),e.jsx(q,{value:"rejected",children:"Rejected"})]})]}),columns:He,data:(d==null?void 0:d.results)??[],isLoading:B,rowKey:c=>c.id,searchKeys:["asset_name","employee_name"],searchPlaceholder:"Search returns...",emptyMessage:"No returns found",emptyDescription:"No asset returns have been recorded yet.",totalCount:(d==null?void 0:d.count)??0,pagination:se,onPaginationChange:k,sorting:te,onSortingChange:V,globalFilter:D,onGlobalFilterChange:ae}),e.jsx(Ne,{open:t,onOpenChange:s,children:e.jsxs(ve,{children:[e.jsxs(be,{children:[e.jsx(Se,{children:n?"Edit Return":"New Return"}),e.jsx(Ce,{children:n?"Update return details.":"Record an asset return."})]}),e.jsxs("form",{onSubmit:b.handleSubmit(o),className:"flex-1 overflow-y-auto px-6 py-5 space-y-4",children:[e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Allocation *"}),e.jsx(fe,{className:"mt-1.5",value:b.watch("allocation")??null,onValueChange:c=>b.setValue("allocation",c,{shouldValidate:!0}),onSearch:Q,selectedLabel:n?`${n.asset_name??"Allocation"}${n.employee_name?` — ${n.employee_name}`:""}`:void 0,options:((W==null?void 0:W.results)??[]).map(c=>({value:c.id,label:`${c.asset_name??c.asset_code??"Asset"} — ${c.employee_name??""}`.trim(),hint:c.allocation_date})),placeholder:"Select allocation",searchPlaceholder:"Search allocations..."}),b.formState.errors.allocation&&e.jsx("p",{className:"text-[12px] text-red-600 mt-1",children:b.formState.errors.allocation.message})]}),e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Asset *"}),e.jsx(fe,{className:"mt-1.5",value:b.watch("asset")??null,onValueChange:c=>b.setValue("asset",c,{shouldValidate:!0}),onSearch:L,selectedLabel:n==null?void 0:n.asset_name,options:((v==null?void 0:v.results)??[]).map(c=>({value:c.id,label:c.name,hint:c.asset_code})),placeholder:"Select asset",searchPlaceholder:"Search assets..."}),b.formState.errors.asset&&e.jsx("p",{className:"text-[12px] text-red-600 mt-1",children:b.formState.errors.asset.message})]}),e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Employee *"}),e.jsx(_s,{value:b.watch("employee")??"",onValueChange:c=>b.setValue("employee",c,{shouldValidate:!0}),placeholder:"Select employee",className:"mt-1.5"}),b.formState.errors.employee&&e.jsx("p",{className:"text-[12px] text-red-600 mt-1",children:b.formState.errors.employee.message})]}),e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Return Date *"}),e.jsx(N,{className:"mt-1.5",type:"date",...b.register("return_date")}),b.formState.errors.return_date&&e.jsx("p",{className:"text-[12px] text-red-600 mt-1",children:b.formState.errors.return_date.message})]}),e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Condition at Return"}),e.jsxs(Y,{value:b.watch("condition_at_return"),onValueChange:c=>b.setValue("condition_at_return",c),children:[e.jsx(Z,{className:"mt-1.5",children:e.jsx(X,{placeholder:"Select condition"})}),e.jsx(J,{children:At.map(c=>e.jsx(q,{value:c.value,children:c.label},c.value))})]})]}),e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Damage Description"}),e.jsx(le,{className:"mt-1.5",...b.register("damage_description"),rows:2,placeholder:"Describe any damage..."})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Damage Cost"}),e.jsx(N,{className:"mt-1.5",type:"number",step:"0.01",...b.register("damage_cost"),placeholder:"0.00"})]}),e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Deposit Refunded"}),e.jsx(N,{className:"mt-1.5",type:"number",step:"0.01",...b.register("deposit_refunded"),placeholder:"0.00"})]})]}),e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Deposit Deducted"}),e.jsx(N,{className:"mt-1.5",type:"number",step:"0.01",...b.register("deposit_deducted"),placeholder:"0.00"})]}),e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Remarks"}),e.jsx(le,{className:"mt-1.5",...b.register("remarks"),rows:3,placeholder:"Additional remarks..."})]})]}),e.jsxs(Ae,{children:[e.jsx(w,{type:"button",variant:"outline",onClick:()=>s(!1),children:"Cancel"}),e.jsx(w,{onClick:b.handleSubmit(o),disabled:R.isPending||a.isPending,children:R.isPending||a.isPending?"Saving...":n?"Update":"Record Return"})]})]})}),e.jsx(we,{open:!!m,onOpenChange:c=>!c&&y(null),children:e.jsxs(ke,{children:[e.jsx(De,{children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx(Pe,{variant:"destructive"}),e.jsxs("div",{children:[e.jsx(qe,{children:"Delete Return"}),e.jsxs(Fe,{children:["Are you sure you want to delete this return record for"," ",e.jsx("span",{className:"font-medium text-slate-700",children:m==null?void 0:m.asset_name}),"? This action cannot be undone."]})]})]})}),e.jsxs(Ee,{children:[e.jsx(Te,{onClick:()=>y(null),children:"Cancel"}),e.jsx(Ve,{variant:"destructive",onClick:()=>{m&&_.mutate(m.id),y(null)},children:"Delete"})]})]})})]})}const kt={scheduled:"default",in_progress:"warning",completed:"success",cancelled:"destructive"},Dt=[{value:"preventive",label:"Preventive"},{value:"corrective",label:"Corrective"},{value:"emergency",label:"Emergency"}],js=[{value:"scheduled",label:"Scheduled"},{value:"in_progress",label:"In Progress"},{value:"completed",label:"Completed"},{value:"cancelled",label:"Cancelled"}],Pt=he({asset:p().min(1,"Asset is required"),maintenance_type:ye(["preventive","corrective","emergency"]),description:p().min(1,"Description is required"),scheduled_date:os("Scheduled date is required"),completed_date:es(),cost:p().optional(),vendor:p().optional(),next_maintenance_date:es(),status:ye(["scheduled","in_progress","completed","cancelled"]),notes:p().optional()});function Na(){const[t,s]=S.useState(!1),[n,f]=S.useState(null),[m,y]=S.useState(null),[x,T]=S.useState(""),{hasPermission:u,requirePermission:Q}=ce(),I=u("assets","asset_maintenance","create"),L=u("assets","asset_maintenance","update"),U=u("assets","asset_maintenance","delete"),{pagination:H,setPagination:z,sorting:ee,setSorting:G,globalFilter:se,setGlobalFilter:k,queryParams:te}=Ie(),V={...te,...x&&{status:x}},{data:D,isLoading:ae}=lt(V),P=ct(),$=dt(),d=ot(),[B,W]=S.useState(""),{data:v}=as({page_size:100,search:B||void 0}),R=(v==null?void 0:v.results)??[],a=xe({resolver:ue(Pt),defaultValues:{maintenance_type:"preventive",status:"scheduled"}});function _(){Q("assets","asset_maintenance","create")&&(f(null),a.reset({asset:"",maintenance_type:"preventive",description:"",scheduled_date:"",completed_date:"",cost:"",vendor:"",next_maintenance_date:"",status:"scheduled",notes:""}),s(!0))}function re(i){Q("assets","asset_maintenance","update")&&(f(i),a.reset({asset:i.asset,maintenance_type:i.maintenance_type,description:i.description,scheduled_date:i.scheduled_date,completed_date:i.completed_date??"",cost:i.cost,vendor:i.vendor,next_maintenance_date:i.next_maintenance_date??"",status:i.status,notes:i.notes}),s(!0))}function j(i){const o={...i,completed_date:i.completed_date||null,next_maintenance_date:i.next_maintenance_date||null};n?$.mutate({id:n.id,...o},{onSuccess:()=>{s(!1),a.reset()}}):P.mutate(o,{onSuccess:()=>{s(!1),a.reset()}})}function b(i){T(i==="__all__"?"":i),z(o=>({...o,pageIndex:0}))}const pe=[{key:"asset_name",header:"Asset",render:i=>e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-slate-900",children:i.asset_name??"--"}),e.jsx("p",{className:"text-[12px] text-slate-400 mt-0.5 capitalize",children:i.maintenance_type})]})},{key:"description",header:"Description",render:i=>e.jsx("span",{className:"text-[12px] text-slate-600 line-clamp-1",children:i.description})},{key:"scheduled_date",header:"Scheduled",className:"w-28",render:i=>e.jsx("span",{className:"text-[12px] text-slate-600",children:new Date(i.scheduled_date).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"})})},{key:"completed_date",header:"Completed",className:"w-28",render:i=>e.jsx("span",{className:"text-[12px] text-slate-600",children:i.completed_date?new Date(i.completed_date).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"}):"--"})},{key:"cost",header:"Cost",className:"w-24",render:i=>e.jsx("span",{className:"text-[12px] text-slate-600",children:i.cost?`$${i.cost}`:"--"})},{key:"vendor",header:"Vendor",className:"w-32",render:i=>e.jsx("span",{className:"text-[12px] text-slate-600",children:i.vendor||"--"})},{key:"status",header:"Status",className:"w-28",render:i=>e.jsx(Ge,{variant:kt[i.status],className:"text-[11px]",children:i.status.replace("_"," ")})},{key:"actions",header:"",className:"w-10",render:i=>e.jsxs($e,{children:[e.jsx(Re,{asChild:!0,children:e.jsxs(w,{variant:"ghost",size:"icon-sm",children:[e.jsx(Le,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Actions"})]})}),e.jsxs(Me,{align:"end",className:"w-44",children:[L&&e.jsx(M,{className:"gap-2 text-[13px]",onClick:()=>re(i),children:"Edit"}),U&&e.jsxs(e.Fragment,{children:[e.jsx(Ke,{}),e.jsxs(M,{className:"gap-2 text-[13px] text-red-600 focus:text-red-600 focus:bg-red-50",onClick:()=>y(i),children:[e.jsx(Oe,{className:"h-3.5 w-3.5"}),"Delete"]})]})]})]})}];return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"text-[16px] font-semibold text-slate-900 flex items-center gap-2",children:[e.jsx(ts,{className:"h-5 w-5 text-primary"})," Asset Maintenance"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"Schedule and track asset maintenance"})]}),I&&e.jsxs(w,{size:"sm",onClick:_,children:[e.jsx(_e,{className:"mr-1.5 h-3.5 w-3.5"})," New Maintenance"]})]}),e.jsx(Qe,{actions:e.jsxs(Y,{value:x,onValueChange:b,children:[e.jsx(Z,{className:"w-[140px] h-9",children:e.jsx(X,{placeholder:"All statuses"})}),e.jsxs(J,{children:[e.jsx(q,{value:"__all__",children:"All Statuses"}),js.map(i=>e.jsx(q,{value:i.value,children:i.label},i.value))]})]}),columns:pe,data:(D==null?void 0:D.results)??[],isLoading:ae,rowKey:i=>i.id,searchKeys:["asset_name","description","vendor"],searchPlaceholder:"Search maintenance...",emptyMessage:"No maintenance records found",emptyDescription:"Schedule your first maintenance task to get started.",totalCount:(D==null?void 0:D.count)??0,pagination:H,onPaginationChange:z,sorting:ee,onSortingChange:G,globalFilter:se,onGlobalFilterChange:k}),e.jsx(Ne,{open:t,onOpenChange:s,children:e.jsxs(ve,{size:"lg",children:[e.jsxs(be,{children:[e.jsx(Se,{children:n?"Edit Maintenance":"New Maintenance"}),e.jsx(Ce,{children:n?"Update maintenance details.":"Schedule a new maintenance task."})]}),e.jsxs("form",{onSubmit:a.handleSubmit(j),className:"flex-1 overflow-y-auto px-6 py-5 space-y-4",children:[e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Asset *"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(fe,{value:a.watch("asset")??null,onValueChange:i=>a.setValue("asset",i,{shouldValidate:!0}),onSearch:W,selectedLabel:(n==null?void 0:n.asset_name)??void 0,options:R.map(i=>({value:i.id,label:i.name,hint:i.asset_code})),placeholder:"Select asset",searchPlaceholder:"Search assets..."})}),a.formState.errors.asset&&e.jsx("p",{className:"text-[12px] text-red-600 mt-1",children:a.formState.errors.asset.message})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Type *"}),e.jsxs(Y,{value:a.watch("maintenance_type"),onValueChange:i=>a.setValue("maintenance_type",i),children:[e.jsx(Z,{className:"mt-1.5",children:e.jsx(X,{placeholder:"Select type"})}),e.jsx(J,{children:Dt.map(i=>e.jsx(q,{value:i.value,children:i.label},i.value))})]})]}),e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Status *"}),e.jsxs(Y,{value:a.watch("status"),onValueChange:i=>a.setValue("status",i),children:[e.jsx(Z,{className:"mt-1.5",children:e.jsx(X,{placeholder:"Select status"})}),e.jsx(J,{children:js.map(i=>e.jsx(q,{value:i.value,children:i.label},i.value))})]})]})]}),e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Description *"}),e.jsx(le,{className:"mt-1.5",...a.register("description"),rows:2,placeholder:"Describe the maintenance task..."}),a.formState.errors.description&&e.jsx("p",{className:"text-[12px] text-red-600 mt-1",children:a.formState.errors.description.message})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Scheduled Date *"}),e.jsx(N,{className:"mt-1.5",type:"date",...a.register("scheduled_date")}),a.formState.errors.scheduled_date&&e.jsx("p",{className:"text-[12px] text-red-600 mt-1",children:a.formState.errors.scheduled_date.message})]}),e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Completed Date"}),e.jsx(N,{className:"mt-1.5",type:"date",...a.register("completed_date")})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Cost"}),e.jsx(N,{className:"mt-1.5",type:"number",step:"0.01",...a.register("cost"),placeholder:"0.00"})]}),e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Vendor"}),e.jsx(N,{className:"mt-1.5",...a.register("vendor"),placeholder:"Vendor name"})]})]}),e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Next Maintenance Date"}),e.jsx(N,{className:"mt-1.5",type:"date",...a.register("next_maintenance_date")})]}),e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Notes"}),e.jsx(le,{className:"mt-1.5",...a.register("notes"),rows:3,placeholder:"Any additional notes..."})]})]}),e.jsxs(Ae,{children:[e.jsx(w,{type:"button",variant:"outline",onClick:()=>s(!1),children:"Cancel"}),e.jsx(w,{onClick:a.handleSubmit(j),disabled:P.isPending||$.isPending,children:P.isPending||$.isPending?"Saving...":n?"Update":"Create"})]})]})}),e.jsx(we,{open:!!m,onOpenChange:i=>!i&&y(null),children:e.jsxs(ke,{children:[e.jsx(De,{children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx(Pe,{variant:"destructive"}),e.jsxs("div",{children:[e.jsx(qe,{children:"Delete Maintenance Record"}),e.jsxs(Fe,{children:["Are you sure you want to delete this maintenance record for"," ",e.jsx("span",{className:"font-medium text-slate-700",children:m==null?void 0:m.asset_name}),"? This action cannot be undone."]})]})]})}),e.jsxs(Ee,{children:[e.jsx(Te,{onClick:()=>y(null),children:"Cancel"}),e.jsx(Ve,{variant:"destructive",onClick:()=>{m&&d.mutate(m.id),y(null)},children:"Delete"})]})]})})]})}const qt=ds(he({grade:p().optional().or(We("")),department:p().optional().or(We("")),designation:p().optional().or(We("")),asset_type:p().min(1,"Asset type is required"),quantity:Je.number().int().min(1,"Quantity must be at least 1"),is_mandatory:ie(),effective_from:p().min(1,"Effective from is required"),effective_to:p().optional(),is_active:ie()}),"effective_from","effective_to");function va(){const[t,s]=S.useState(!1),[n,f]=S.useState(null),[m,y]=S.useState(null),{hasPermission:x,requirePermission:T}=ce(),u=x("assets","asset_entitlement","create"),Q=x("assets","asset_entitlement","update"),I=x("assets","asset_entitlement","delete"),{pagination:L,setPagination:U,sorting:H,setSorting:z,globalFilter:ee,setGlobalFilter:G,queryParams:se}=Ie(),{data:k,isLoading:te}=mt(se),V=xt(),D=ut(),ae=ht(),{data:P}=xs({page_size:100}),$=(P==null?void 0:P.results)??[],d=xe({resolver:ue(qt),defaultValues:{is_mandatory:!1,is_active:!0,quantity:1}});function B(){T("assets","asset_entitlement","create")&&(f(null),d.reset({grade:"",department:"",designation:"",asset_type:"",quantity:1,is_mandatory:!1,effective_from:"",effective_to:"",is_active:!0}),s(!0))}function W(a){T("assets","asset_entitlement","update")&&(f(a),d.reset({grade:a.grade??"",department:a.department??"",designation:a.designation??"",asset_type:a.asset_type,quantity:a.quantity,is_mandatory:a.is_mandatory,effective_from:a.effective_from,effective_to:a.effective_to??"",is_active:a.is_active}),s(!0))}function v(a){const _={...a,grade:a.grade||null,department:a.department||null,designation:a.designation||null,effective_to:a.effective_to||null};n?D.mutate({id:n.id,..._},{onSuccess:()=>{s(!1),d.reset()}}):V.mutate(_,{onSuccess:()=>{s(!1),d.reset()}})}const R=[{key:"asset_type_name",header:"Asset Type",render:a=>e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-slate-900",children:a.asset_type_name??"--"}),e.jsxs("p",{className:"text-[12px] text-slate-400 mt-0.5",children:["Qty: ",a.quantity]})]})},{key:"grade_name",header:"Grade",className:"w-28",render:a=>e.jsx("span",{className:"text-[12px] text-slate-600",children:a.grade_name??"All"})},{key:"department_name",header:"Department",className:"w-32",render:a=>e.jsx("span",{className:"text-[12px] text-slate-600",children:a.department_name??"All"})},{key:"designation_name",header:"Designation",className:"w-32",render:a=>e.jsx("span",{className:"text-[12px] text-slate-600",children:a.designation_name??"All"})},{key:"is_mandatory",header:"Mandatory",className:"w-24",render:a=>e.jsx(Ge,{variant:a.is_mandatory?"warning":"secondary",className:"text-[11px]",children:a.is_mandatory?"Yes":"No"})},{key:"effective_from",header:"Effective From",className:"w-28",render:a=>e.jsx("span",{className:"text-[12px] text-slate-600",children:new Date(a.effective_from).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"})})},{key:"is_active",header:"Active",className:"w-24",render:a=>e.jsx(ms,{status:a.is_active?"active":"inactive"})},{key:"actions",header:"",className:"w-10",render:a=>e.jsxs($e,{children:[e.jsx(Re,{asChild:!0,children:e.jsxs(w,{variant:"ghost",size:"icon-sm",children:[e.jsx(Le,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Actions"})]})}),e.jsxs(Me,{align:"end",className:"w-44",children:[Q&&e.jsx(M,{className:"gap-2 text-[13px]",onClick:()=>W(a),children:"Edit"}),I&&e.jsxs(e.Fragment,{children:[e.jsx(Ke,{}),e.jsxs(M,{className:"gap-2 text-[13px] text-red-600 focus:text-red-600 focus:bg-red-50",onClick:()=>y(a),children:[e.jsx(Oe,{className:"h-3.5 w-3.5"}),"Delete"]})]})]})]})}];return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"text-[16px] font-semibold text-slate-900 flex items-center gap-2",children:[e.jsx(cs,{className:"h-5 w-5 text-primary"})," Asset Entitlements"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"Define asset entitlements by grade, department, or designation"})]}),u&&e.jsxs(w,{size:"sm",onClick:B,children:[e.jsx(_e,{className:"mr-1.5 h-3.5 w-3.5"})," New Entitlement"]})]}),e.jsx(Qe,{columns:R,data:(k==null?void 0:k.results)??[],isLoading:te,rowKey:a=>a.id,searchKeys:["asset_type_name","grade_name","department_name","designation_name"],searchPlaceholder:"Search entitlements...",emptyMessage:"No entitlements found",emptyDescription:"Define your first asset entitlement to get started.",totalCount:(k==null?void 0:k.count)??0,pagination:L,onPaginationChange:U,sorting:H,onSortingChange:z,globalFilter:ee,onGlobalFilterChange:G}),e.jsx(Ne,{open:t,onOpenChange:s,children:e.jsxs(ve,{children:[e.jsxs(be,{children:[e.jsx(Se,{children:n?"Edit Entitlement":"New Entitlement"}),e.jsx(Ce,{children:n?"Update entitlement details.":"Define a new asset entitlement rule."})]}),e.jsxs("form",{onSubmit:d.handleSubmit(v),className:"flex-1 overflow-y-auto px-6 py-5 space-y-4",children:[e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Asset Type *"}),e.jsxs(Y,{value:d.watch("asset_type")??"",onValueChange:a=>d.setValue("asset_type",a,{shouldValidate:!0}),children:[e.jsx(Z,{className:"mt-1.5",children:e.jsx(X,{placeholder:"Select asset type"})}),e.jsx(J,{children:$.map(a=>e.jsx(q,{value:a.id,children:a.name},a.id))})]}),d.formState.errors.asset_type&&e.jsx("p",{className:"text-[12px] text-red-600 mt-1",children:d.formState.errors.asset_type.message})]}),e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Quantity *"}),e.jsx(N,{className:"mt-1.5",type:"number",min:1,...d.register("quantity")}),d.formState.errors.quantity&&e.jsx("p",{className:"text-[12px] text-red-600 mt-1",children:d.formState.errors.quantity.message})]}),e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Grade ID"}),e.jsx(N,{className:"mt-1.5",...d.register("grade"),placeholder:"Leave empty for all grades"})]}),e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Department ID"}),e.jsx(N,{className:"mt-1.5",...d.register("department"),placeholder:"Leave empty for all departments"})]}),e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Designation ID"}),e.jsx(N,{className:"mt-1.5",...d.register("designation"),placeholder:"Leave empty for all designations"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Effective From *"}),e.jsx(N,{className:"mt-1.5",type:"date",...d.register("effective_from"),max:d.watch("effective_to")||void 0}),d.formState.errors.effective_from&&e.jsx("p",{className:"text-[12px] text-red-600 mt-1",children:d.formState.errors.effective_from.message})]}),e.jsxs("div",{children:[e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Effective To"}),e.jsx(N,{className:"mt-1.5",type:"date",...d.register("effective_to"),min:d.watch("effective_from")||void 0})]})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Xe,{checked:d.watch("is_mandatory"),onCheckedChange:a=>d.setValue("is_mandatory",!!a)}),e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Mandatory"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Xe,{checked:d.watch("is_active"),onCheckedChange:a=>d.setValue("is_active",!!a)}),e.jsx(l,{className:"text-[12px] font-medium text-slate-500",children:"Active"})]})]})]}),e.jsxs(Ae,{children:[e.jsx(w,{type:"button",variant:"outline",onClick:()=>s(!1),children:"Cancel"}),e.jsx(w,{onClick:d.handleSubmit(v),disabled:V.isPending||D.isPending,children:V.isPending||D.isPending?"Saving...":n?"Update":"Create"})]})]})}),e.jsx(we,{open:!!m,onOpenChange:a=>!a&&y(null),children:e.jsxs(ke,{children:[e.jsx(De,{children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx(Pe,{variant:"destructive"}),e.jsxs("div",{children:[e.jsx(qe,{children:"Delete Entitlement"}),e.jsxs(Fe,{children:["Are you sure you want to delete this entitlement for"," ",e.jsx("span",{className:"font-medium text-slate-700",children:m==null?void 0:m.asset_type_name}),"? This action cannot be undone."]})]})]})}),e.jsxs(Ee,{children:[e.jsx(Te,{onClick:()=>y(null),children:"Cancel"}),e.jsx(Ve,{variant:"destructive",onClick:()=>{m&&ae.mutate(m.id),y(null)},children:"Delete"})]})]})})]})}const Ft=he({auto_assign_on_joining:ie(),require_return_on_exit:ie(),condition_check_on_return:ie(),depreciation_enabled:ie(),depreciation_method:ye(["straight_line","declining_balance","units_of_production"]),maintenance_reminder_days:Je.number().int().min(1),warranty_expiry_reminder_days:Je.number().int().min(1),barcode_enabled:ie(),auto_generate_asset_code:ie(),asset_code_prefix:p().min(1,"Prefix is required"),allow_multiple_allocation:ie()}),Et=[{value:"straight_line",label:"Straight Line"},{value:"declining_balance",label:"Declining Balance"},{value:"units_of_production",label:"Units of Production"}];function ba(){const{data:t,isLoading:s}=Os(),n=Qs(),{hasPermission:f,requirePermission:m}=ce(),y=f("assets","settings","update"),x=xe({resolver:ue(Ft),defaultValues:{auto_assign_on_joining:!1,require_return_on_exit:!0,condition_check_on_return:!0,depreciation_enabled:!1,depreciation_method:"straight_line",maintenance_reminder_days:7,warranty_expiry_reminder_days:30,barcode_enabled:!1,auto_generate_asset_code:!0,asset_code_prefix:"AST",allow_multiple_allocation:!1}});S.useEffect(()=>{t&&x.reset({auto_assign_on_joining:t.auto_assign_on_joining,require_return_on_exit:t.require_return_on_exit,condition_check_on_return:t.condition_check_on_return,depreciation_enabled:t.depreciation_enabled,depreciation_method:t.depreciation_method,maintenance_reminder_days:t.maintenance_reminder_days,warranty_expiry_reminder_days:t.warranty_expiry_reminder_days,barcode_enabled:t.barcode_enabled,auto_generate_asset_code:t.auto_generate_asset_code,asset_code_prefix:t.asset_code_prefix,allow_multiple_allocation:t.allow_multiple_allocation})},[t,x]);function T(u){m("assets","settings","update")&&n.mutate(u)}return s?e.jsxs("div",{children:[e.jsx("div",{className:"flex items-center justify-between mb-6",children:e.jsxs("div",{children:[e.jsxs("h2",{className:"text-[16px] font-semibold text-slate-900 flex items-center gap-2",children:[e.jsx(Ze,{className:"h-5 w-5 text-primary"})," Asset Settings"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"Configure asset module settings"})]})}),e.jsx("div",{className:"space-y-4",children:[1,2,3,4].map(u=>e.jsx("div",{className:"h-32 rounded-lg skeleton-shimmer"},u))})]}):e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"text-[16px] font-semibold text-slate-900 flex items-center gap-2",children:[e.jsx(Ze,{className:"h-5 w-5 text-primary"})," Asset Settings"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"Configure asset module settings"})]}),y&&e.jsx(w,{size:"sm",disabled:!x.formState.isDirty||n.isPending,onClick:x.handleSubmit(T),children:n.isPending?"Saving...":"Save Changes"})]}),e.jsxs("form",{onSubmit:x.handleSubmit(T),className:"space-y-4",children:[e.jsxs(K,{children:[e.jsx(oe,{children:e.jsxs(me,{className:"text-[14px] font-semibold flex items-center gap-2",children:[e.jsx(ze,{className:"h-4 w-4 text-slate-400"})," Allocation"]})}),e.jsxs(O,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(l,{className:"text-[13px] font-medium text-slate-700",children:"Auto-assign on Joining"}),e.jsx("p",{className:"text-[12px] text-slate-400 mt-0.5",children:"Automatically assign entitled assets when an employee joins"})]}),e.jsx(ge,{name:"auto_assign_on_joining",control:x.control,render:({field:u})=>e.jsx(je,{checked:u.value,onCheckedChange:u.onChange})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(l,{className:"text-[13px] font-medium text-slate-700",children:"Require Return on Exit"}),e.jsx("p",{className:"text-[12px] text-slate-400 mt-0.5",children:"Enforce asset return during employee exit process"})]}),e.jsx(ge,{name:"require_return_on_exit",control:x.control,render:({field:u})=>e.jsx(je,{checked:u.value,onCheckedChange:u.onChange})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(l,{className:"text-[13px] font-medium text-slate-700",children:"Condition Check on Return"}),e.jsx("p",{className:"text-[12px] text-slate-400 mt-0.5",children:"Require condition assessment when an asset is returned"})]}),e.jsx(ge,{name:"condition_check_on_return",control:x.control,render:({field:u})=>e.jsx(je,{checked:u.value,onCheckedChange:u.onChange})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(l,{className:"text-[13px] font-medium text-slate-700",children:"Allow Multiple Allocation"}),e.jsx("p",{className:"text-[12px] text-slate-400 mt-0.5",children:"Allow an asset to be allocated to multiple employees"})]}),e.jsx(ge,{name:"allow_multiple_allocation",control:x.control,render:({field:u})=>e.jsx(je,{checked:u.value,onCheckedChange:u.onChange})})]})]})]}),e.jsxs(K,{children:[e.jsx(oe,{children:e.jsxs(me,{className:"text-[14px] font-semibold flex items-center gap-2",children:[e.jsx(Ze,{className:"h-4 w-4 text-slate-400"})," Depreciation"]})}),e.jsxs(O,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(l,{className:"text-[13px] font-medium text-slate-700",children:"Depreciation Enabled"}),e.jsx("p",{className:"text-[12px] text-slate-400 mt-0.5",children:"Calculate and track asset depreciation"})]}),e.jsx(ge,{name:"depreciation_enabled",control:x.control,render:({field:u})=>e.jsx(je,{checked:u.value,onCheckedChange:u.onChange})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(l,{className:"text-[13px] font-medium text-slate-700",children:"Depreciation Method"}),e.jsx("p",{className:"text-[12px] text-slate-400 mt-0.5",children:"Default method for calculating depreciation"})]}),e.jsxs(Y,{value:x.watch("depreciation_method"),onValueChange:u=>x.setValue("depreciation_method",u,{shouldDirty:!0}),children:[e.jsx(Z,{className:"w-48",children:e.jsx(X,{placeholder:"Select method"})}),e.jsx(J,{children:Et.map(u=>e.jsx(q,{value:u.value,children:u.label},u.value))})]})]})]})]}),e.jsxs(K,{children:[e.jsx(oe,{children:e.jsxs(me,{className:"text-[14px] font-semibold flex items-center gap-2",children:[e.jsx(ts,{className:"h-4 w-4 text-slate-400"})," Maintenance & Warranty"]})}),e.jsxs(O,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(l,{className:"text-[13px] font-medium text-slate-700",children:"Maintenance Reminder Days"}),e.jsx("p",{className:"text-[12px] text-slate-400 mt-0.5",children:"Days before scheduled maintenance to send reminders"})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(N,{className:"w-20 text-center",type:"number",min:1,...x.register("maintenance_reminder_days")}),e.jsx("span",{className:"text-[12px] text-slate-400",children:"days"})]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(l,{className:"text-[13px] font-medium text-slate-700",children:"Warranty Expiry Reminder Days"}),e.jsx("p",{className:"text-[12px] text-slate-400 mt-0.5",children:"Days before warranty expiry to send notifications"})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(N,{className:"w-20 text-center",type:"number",min:1,...x.register("warranty_expiry_reminder_days")}),e.jsx("span",{className:"text-[12px] text-slate-400",children:"days"})]})]})]})]}),e.jsxs(K,{children:[e.jsx(oe,{children:e.jsxs(me,{className:"text-[14px] font-semibold flex items-center gap-2",children:[e.jsx(Rs,{className:"h-4 w-4 text-slate-400"})," Asset Codes & Barcode"]})}),e.jsxs(O,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(l,{className:"text-[13px] font-medium text-slate-700",children:"Barcode Enabled"}),e.jsx("p",{className:"text-[12px] text-slate-400 mt-0.5",children:"Enable barcode generation and scanning for assets"})]}),e.jsx(ge,{name:"barcode_enabled",control:x.control,render:({field:u})=>e.jsx(je,{checked:u.value,onCheckedChange:u.onChange})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(l,{className:"text-[13px] font-medium text-slate-700",children:"Auto-generate Asset Code"}),e.jsx("p",{className:"text-[12px] text-slate-400 mt-0.5",children:"Automatically generate unique asset codes"})]}),e.jsx(ge,{name:"auto_generate_asset_code",control:x.control,render:({field:u})=>e.jsx(je,{checked:u.value,onCheckedChange:u.onChange})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(l,{className:"text-[13px] font-medium text-slate-700",children:"Asset Code Prefix"}),e.jsx("p",{className:"text-[12px] text-slate-400 mt-0.5",children:"Prefix used when auto-generating asset codes"})]}),e.jsx(N,{className:"w-24 text-center",...x.register("asset_code_prefix"),placeholder:"AST"})]})]})]})]})]})}function Sa(){return e.jsxs("div",{children:[e.jsx("div",{className:"flex items-center justify-between mb-6",children:e.jsxs("div",{children:[e.jsxs("h2",{className:"text-[16px] font-semibold text-slate-900 flex items-center gap-2",children:[e.jsx(is,{className:"h-5 w-5 text-primary"})," Asset Reports"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"View asset reports and inventory metrics"})]})}),e.jsxs(K,{children:[e.jsx(oe,{children:e.jsx(me,{className:"text-[14px] font-semibold",children:"Report Center"})}),e.jsx(O,{children:e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[e.jsx(is,{className:"h-10 w-10 text-slate-300 mb-3"}),e.jsx("p",{className:"text-[14px] font-medium text-slate-600",children:"Coming Soon"}),e.jsx("p",{className:"text-[13px] text-slate-400 mt-1 max-w-sm",children:"Generate asset inventory reports, allocation summaries, and depreciation schedules."})]})})]})]})}function Ca(){return e.jsxs("div",{children:[e.jsx("div",{className:"flex items-center justify-between mb-6",children:e.jsxs("div",{children:[e.jsxs("h2",{className:"text-[16px] font-semibold text-slate-900 flex items-center gap-2",children:[e.jsx(rs,{className:"h-5 w-5 text-primary"})," Asset Analytics"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"Explore asset utilization trends and cost analytics"})]})}),e.jsxs(K,{children:[e.jsx(oe,{children:e.jsx(me,{className:"text-[14px] font-semibold",children:"Analytics Dashboard"})}),e.jsx(O,{children:e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[e.jsx(rs,{className:"h-10 w-10 text-slate-300 mb-3"}),e.jsx("p",{className:"text-[14px] font-medium text-slate-600",children:"Coming Soon"}),e.jsx("p",{className:"text-[13px] text-slate-400 mt-1 max-w-sm",children:"Analyze asset utilization, depreciation trends, maintenance costs, and allocation patterns."})]})})]})]})}export{fa as AssetAllocationsPage,Ca as AssetAnalyticsPage,ga as AssetCategoriesPage,va as AssetEntitlementsPage,Na as AssetMaintenancePage,Sa as AssetReportsPage,_a as AssetReturnsPage,ba as AssetSettingsPage,ya as AssetTypesPage,pa as AssetsDashboardPage,ma as AssetsLayout,ja as AssetsPage,it as useAcceptReturn,et as useAcknowledgeAllocation,bs as useAssetAllocations,ha as useAssetAnalytics,ss as useAssetCategories,pt as useAssetDashboard,xa as useAssetDetail,mt as useAssetEntitlements,lt as useAssetMaintenance,ua as useAssetReports,st as useAssetReturns,Os as useAssetSettings,xs as useAssetTypes,as as useAssets,Ws as useCreateAsset,Zs as useCreateAssetAllocation,Is as useCreateAssetCategory,xt as useCreateAssetEntitlement,ct as useCreateAssetMaintenance,tt as useCreateAssetReturn,zs as useCreateAssetType,Ys as useDeleteAsset,Js as useDeleteAssetAllocation,Us as useDeleteAssetCategory,ht as useDeleteAssetEntitlement,ot as useDeleteAssetMaintenance,nt as useDeleteAssetReturn,Bs as useDeleteAssetType,rt as useRejectReturn,Hs as useUpdateAsset,Xs as useUpdateAssetAllocation,Ls as useUpdateAssetCategory,ut as useUpdateAssetEntitlement,dt as useUpdateAssetMaintenance,at as useUpdateAssetReturn,Qs as useUpdateAssetSettings,Gs as useUpdateAssetType};
