import{j as e,u as ce,b as V,a as T}from"./query-PJ0ZdjbV.js";import{a as j,k as qs,O as Ps}from"./vendor-CWhr2lg4.js";import{a2 as Xe,b0 as Oe,T as es,U as ss,ar as Es,c3 as ts,o as xs,ap as Rs,p as f,a4 as p,B as C,P as ke,s as $,t as O,v as I,w as U,x as r,aa as ve,ab as fe,ac as Se,ad as Ne,ae as Ce,q as m,r as He,I as F,af as be,Q as ue,V as me,W as he,Y as pe,Z as xe,_ as je,$ as ye,a0 as ge,ag as Ee,ah as Re,ai as De,aj as te,b5 as Te,y as Ve,a as js,b as ys,d as Ge,e as Je,f as Ze,h as Be,N as gs,L as Ds,a8 as _s,a7 as Ts,g as Vs,bz as Ls}from"./index-BSPIaiZU.js";import{L as $s}from"./layout-dashboard-pgzECxsO.js";import{F as ns}from"./file-text-BeBoTfpI.js";import{C as ls}from"./calendar-BZ611BSN.js";import{F as vs}from"./file-pen-BsSJrcIJ.js";import{M as fs}from"./mail-Bu7DITgC.js";import{F as is}from"./file-spreadsheet-BN0hmWpo.js";import{F as Ss}from"./file-chart-column-increasing-DonUpE5r.js";import{G as Os}from"./gavel-BRZt127W.js";import{C as as}from"./chart-column-DbfNf7gS.js";import{B as Ns}from"./building-2-boIK6K2k.js";import{u as Fe,t as Ae,o as we,s as b,e as le,b as Cs,c as Ie}from"./date-range-picker-BB0TgAn8.js";import{B as ne}from"./badge-C34iUAiA.js";import{D as oe}from"./data-table-D_-xOEqd.js";import{u as de}from"./use-data-table-state-CKRg6qY2.js";import{E as cs}from"./employee-select-DtUobKxP.js";import{U as Is}from"./user-select-kmNhZyc9.js";import{i as Me,a as We,w as os}from"./date-validation-D9gNvaP9.js";import{F as Us}from"./file-search-Xio2ch8J.js";import{E as Le}from"./ellipsis-DaNBIBaV.js";import{P as Qs}from"./play-N42nmD6a.js";import{C as Ks}from"./circle-check-Dgh1V3VA.js";import{C as Ms}from"./circle-x-C0sF-Oht.js";import{P as $e}from"./pencil-Dl5fXQYl.js";import{S as zs}from"./status-badge-DPaiL_rL.js";import{S as bs}from"./shield-7SCLx_iT.js";import{S as Ue}from"./skeleton-CfUgaIb_.js";import{T as ks}from"./trending-up-Cognoqa9.js";import{A as _e}from"./async-select-BUbwdJEZ.js";import{u as Qe,e as ds,B as Gs}from"./system-admin.api-BT5u-_A_.js";import{C as Bs}from"./clipboard-list-DCTO70_z.js";import"./ui-aO-W1bxx.js";import"./chevron-left-DLFf1YD2.js";import"./core-hr.api-MChaGqvv.js";import"./accounts.api-DU956vCW.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 Ws=Xe("Equal",[["line",{x1:"5",x2:"19",y1:"9",y2:"9",key:"1nwqeh"}],["line",{x1:"5",x2:"19",y1:"15",y2:"15",key:"g8yjpy"}]]);/**
 * @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 Hs=Xe("Factory",[["path",{d:"M2 20a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V8l-7 5V8l-7 5V4a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2Z",key:"159hny"}],["path",{d:"M17 18h1",key:"uldtlt"}],["path",{d:"M12 18h1",key:"s9uhes"}],["path",{d:"M7 18h1",key:"1neino"}]]);/**
 * @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 Ys=Xe("HandMetal",[["path",{d:"M18 12.5V10a2 2 0 0 0-2-2a2 2 0 0 0-2 2v1.4",key:"wc6myp"}],["path",{d:"M14 11V9a2 2 0 1 0-4 0v2",key:"94qvcw"}],["path",{d:"M10 10.5V5a2 2 0 1 0-4 0v9",key:"m1ah89"}],["path",{d:"m7 15-1.76-1.76a2 2 0 0 0-2.83 2.82l3.6 3.6C7.5 21.14 9.2 22 12 22h2a8 8 0 0 0 8-8V7a2 2 0 1 0-4 0v5",key:"t1skq1"}]]);/**
 * @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 Fs=Xe("HardHat",[["path",{d:"M10 10V5a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v5",key:"1p9q5i"}],["path",{d:"M14 6a6 6 0 0 1 6 6v3",key:"1hnv84"}],["path",{d:"M4 15v-3a6 6 0 0 1 6-6",key:"9ciidu"}],["rect",{x:"2",y:"15",width:"20",height:"4",rx:"1",key:"g3x8cw"}]]),Js=[{label:"Overview",items:[{to:"/compliance/dashboard",label:"Dashboard",icon:$s,permission:["compliance","configuration","read"]}]},{label:"Statutory Filings",items:[{to:"/compliance/filings",label:"Filings",icon:ns,permission:["compliance","filing","read"]},{to:"/compliance/calendar",label:"Calendar",icon:ls,permission:["compliance","calendar","read"]},{to:"/compliance/amendments",label:"Amendments",icon:vs,permission:["compliance","amendment","read"]}]},{label:"Enforcement",items:[{to:"/compliance/penalties",label:"Penalties",icon:es,permission:["compliance","penalty","read"]},{to:"/compliance/correspondence",label:"Correspondence",icon:fs,permission:["compliance","correspondence","read"]}]},{label:"Labour Compliance",items:[{to:"/compliance/factory-registers",label:"Factory Registers",icon:Hs,permission:["compliance","factory_register","read"]},{to:"/compliance/contractors",label:"Contractors",icon:Fs,permission:["compliance","contractor","read"]},{to:"/compliance/contract-workers",label:"Contract Workers",icon:ss,permission:["compliance","contract_worker","read"]},{to:"/compliance/wage-audits",label:"Wage Audits",icon:Es,permission:["compliance","wage_audit","read"]}]},{label:"Reports & Tax",items:[{to:"/compliance/form16",label:"Form 16",icon:is,permission:["payroll","form16","read"]},{to:"/compliance/reports",label:"Reports",icon:Ss,permission:["compliance","configuration","read"]},{to:"/compliance/labour-codes",label:"Labour Codes",icon:Os,permission:["compliance","configuration","read"]}]},{label:"Enterprise",items:[{to:"/compliance/statutory-updates",label:"Statutory Updates",icon:ts,permission:["compliance","statutory_update","read"]},{to:"/compliance/posh",label:"POSH Compliance",icon:xs,permission:["compliance","posh","read"]},{to:"/compliance/pay-equity",label:"Pay Equity",icon:Ws,permission:["compliance","pay_equity","read"]},{to:"/compliance/scores",label:"Compliance Scores",icon:as,permission:["compliance","score","read"]},{to:"/compliance/establishments",label:"Establishments",icon:Ns,permission:["compliance","establishment","read"]}]}];function or(){const{hasPermission:a}=Oe(),t=j.useMemo(()=>Js.map(n=>({...n,items:n.items.filter(x=>a(x.permission[0],x.permission[1],x.permission[2]))})).filter(n=>n.items.length>0),[a]);return e.jsxs("div",{className:"flex gap-6",children:[e.jsx("nav",{className:"w-[220px] shrink-0",children:e.jsx("div",{className:"sticky top-6 space-y-5",children:t.map(n=>e.jsxs("div",{children:[e.jsx("p",{className:"mb-1.5 px-2 text-[11px] font-semibold uppercase tracking-wider text-slate-400",children:n.label}),e.jsx("ul",{className:"space-y-0.5",children:n.items.map(x=>e.jsx("li",{children:e.jsxs(qs,{to:x.to,className:({isActive:i})=>Rs("flex items-center gap-2 rounded-lg px-2 py-1.5 text-[13px] font-medium transition-colors",i?"bg-primary/10 text-primary":"text-slate-600 hover:bg-slate-100 hover:text-slate-900"),children:[e.jsx(x.icon,{className:"h-4 w-4 shrink-0"}),x.label]})},x.to))})]},n.label))})}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx(Ps,{})})]})}const qe="/compliance",Pe={retentionPolicies:["retention-policies"],dsarRequests:["dsar-requests"],consentRecords:["consent-records"]};function Zs(a){return ce({queryKey:[...Pe.retentionPolicies,a],queryFn:()=>f.get(`${qe}/retention-policies/`,{params:a}).then(t=>t.data)})}function Xs(){const a=V();return T({mutationFn:t=>f.post(`${qe}/retention-policies/`,t).then(n=>n.data),onSuccess:()=>{a.invalidateQueries({queryKey:Pe.retentionPolicies}),p.success("Retention policy created successfully.")},onError:()=>p.error("Failed to create retention policy.")})}function et(){const a=V();return T({mutationFn:({id:t,...n})=>f.patch(`${qe}/retention-policies/${t}/`,n).then(x=>x.data),onSuccess:()=>{a.invalidateQueries({queryKey:Pe.retentionPolicies}),p.success("Retention policy updated.")},onError:()=>p.error("Failed to update retention policy.")})}function st(){const a=V();return T({mutationFn:t=>f.delete(`${qe}/retention-policies/${t}/`).then(n=>n.data),onSuccess:()=>{a.invalidateQueries({queryKey:Pe.retentionPolicies}),p.success("Retention policy deleted.")},onError:()=>p.error("Failed to delete retention policy.")})}function tt(a){return ce({queryKey:[...Pe.dsarRequests,a],queryFn:()=>f.get(`${qe}/dsar/`,{params:a}).then(t=>t.data)})}function nt(){const a=V();return T({mutationFn:t=>f.post(`${qe}/dsar/`,t).then(n=>n.data),onSuccess:()=>{a.invalidateQueries({queryKey:Pe.dsarRequests}),p.success("DSAR request created successfully.")},onError:()=>p.error("Failed to create DSAR request.")})}function at(){const a=V();return T({mutationFn:({id:t,...n})=>f.patch(`${qe}/dsar/${t}/`,n).then(x=>x.data),onSuccess:()=>{a.invalidateQueries({queryKey:Pe.dsarRequests}),p.success("DSAR request updated.")},onError:()=>p.error("Failed to update DSAR request.")})}function rt(){const a=V();return T({mutationFn:t=>f.delete(`${qe}/dsar/${t}/`).then(n=>n.data),onSuccess:()=>{a.invalidateQueries({queryKey:Pe.dsarRequests}),p.success("DSAR request deleted.")},onError:()=>p.error("Failed to delete DSAR request.")})}function it(){const a=V();return T({mutationFn:t=>f.post(`${qe}/dsar/${t}/process/`).then(n=>n.data),onSuccess:()=>{a.invalidateQueries({queryKey:Pe.dsarRequests}),p.success("DSAR request is now being processed.")},onError:()=>p.error("Failed to process DSAR request.")})}function lt(){const a=V();return T({mutationFn:t=>f.post(`${qe}/dsar/${t}/complete/`).then(n=>n.data),onSuccess:()=>{a.invalidateQueries({queryKey:Pe.dsarRequests}),p.success("DSAR request completed.")},onError:()=>p.error("Failed to complete DSAR request.")})}function ct(){const a=V();return T({mutationFn:({id:t,reason:n})=>f.post(`${qe}/dsar/${t}/reject/`,{reason:n}).then(x=>x.data),onSuccess:()=>{a.invalidateQueries({queryKey:Pe.dsarRequests}),p.success("DSAR request rejected.")},onError:()=>p.error("Failed to reject DSAR request.")})}function ot(a){return ce({queryKey:[...Pe.consentRecords,a],queryFn:()=>f.get(`${qe}/consent/`,{params:a}).then(t=>t.data)})}function dt(){const a=V();return T({mutationFn:t=>f.post(`${qe}/consent/`,t).then(n=>n.data),onSuccess:()=>{a.invalidateQueries({queryKey:Pe.consentRecords}),p.success("Consent record created successfully.")},onError:()=>p.error("Failed to create consent record.")})}function ut(){const a=V();return T({mutationFn:({id:t,...n})=>f.patch(`${qe}/consent/${t}/`,n).then(x=>x.data),onSuccess:()=>{a.invalidateQueries({queryKey:Pe.consentRecords}),p.success("Consent record updated.")},onError:()=>p.error("Failed to update consent record.")})}function mt(){const a=V();return T({mutationFn:t=>f.delete(`${qe}/consent/${t}/`).then(n=>n.data),onSuccess:()=>{a.invalidateQueries({queryKey:Pe.consentRecords}),p.success("Consent record deleted.")},onError:()=>p.error("Failed to delete consent record.")})}function ht(){const a=V();return T({mutationFn:t=>f.post(`${qe}/consent/${t}/withdraw/`).then(n=>n.data),onSuccess:()=>{a.invalidateQueries({queryKey:Pe.consentRecords}),p.success("Consent withdrawn successfully.")},onError:()=>p.error("Failed to withdraw consent.")})}const pt=we({employee:b().min(1,"Employee ID is required"),request_type:le(["access","erasure","portability","rectification"],{required_error:"Request type is required"}),description:b().optional(),due_date:Me("Due date is required"),assigned_to:b().optional()}),xt={pending:"secondary",in_progress:"warning",completed:"success",rejected:"destructive"},jt={pending:"Pending",in_progress:"In Progress",completed:"Completed",rejected:"Rejected"},yt={access:"Access",erasure:"Erasure",portability:"Portability",rectification:"Rectification"};function dr(){const[a,t]=j.useState(!1),[n,x]=j.useState(null),[i,y]=j.useState(null),[g,D]=j.useState(null),[S,W]=j.useState(""),[w,K]=j.useState(""),[Y,H]=j.useState(""),{hasPermission:Q}=Oe(),z=Q("compliance","dsar","create"),L=Q("compliance","dsar","update"),{pagination:ee,setPagination:q,sorting:G,setSorting:h,globalFilter:v,setGlobalFilter:J,queryParams:B}=de(),Z={...B,...w&&{request_type:w},...Y&&{status:Y}},{data:l,isLoading:o}=tt(Z),N=nt(),M=at(),_=rt(),ae=it(),se=lt(),X=ct(),u=Fe({resolver:Ae(pt),defaultValues:{employee:"",request_type:"access",description:"",due_date:"",assigned_to:""}});function s(){x(null),u.reset({employee:"",request_type:"access",description:"",due_date:"",assigned_to:""}),t(!0)}function k(P){x(P),u.reset({employee:P.employee,request_type:P.request_type,description:P.description,due_date:P.due_date,assigned_to:P.assigned_to??""}),t(!0)}function A(P){const Ke={employee:P.employee,request_type:P.request_type,description:P.description,due_date:P.due_date,...P.assigned_to?{assigned_to:P.assigned_to}:{}};n?M.mutate({id:n.id,...Ke},{onSuccess:()=>t(!1)}):N.mutate(Ke,{onSuccess:()=>t(!1)})}function d(){i&&_.mutate(i.id,{onSuccess:()=>y(null)})}function ie(){g&&S.trim()&&X.mutate({id:g.id,reason:S.trim()},{onSuccess:()=>{D(null),W("")}})}function ze(P){K(P==="__all__"?"":P),q(Ke=>({...Ke,pageIndex:0}))}function c(P){H(P==="__all__"?"":P),q(Ke=>({...Ke,pageIndex:0}))}const re=[{key:"employee_name",header:"Employee",render:P=>e.jsx("span",{className:"font-medium text-slate-900",children:P.employee_name??"—"})},{key:"request_type",header:"Request Type",render:P=>e.jsx(ne,{variant:"outline",children:yt[P.request_type]})},{key:"status",header:"Status",render:P=>e.jsx(ne,{variant:xt[P.status],children:jt[P.status]})},{key:"due_date",header:"Due Date",render:P=>P.due_date?new Date(P.due_date).toLocaleDateString():"—"},{key:"assigned_to_display",header:"Assigned To",render:P=>P.assigned_to_display??"—"},{key:"created_at",header:"Created",render:P=>new Date(P.created_at).toLocaleDateString()},{key:"actions",header:"",className:"w-10",render:P=>e.jsxs(ue,{open:(i==null?void 0:i.id)===P.id,onOpenChange:Ke=>!Ke&&y(null),children:[e.jsxs(Ee,{children:[e.jsx(Re,{asChild:!0,children:e.jsx(C,{variant:"ghost",size:"icon-sm",children:e.jsx(Le,{className:"h-4 w-4"})})}),e.jsxs(De,{align:"end",children:[L&&P.status==="pending"&&e.jsxs(te,{onClick:()=>ae.mutate(P.id),children:[e.jsx(Qs,{className:"mr-2 h-3.5 w-3.5"})," Process"]}),L&&(P.status==="pending"||P.status==="in_progress")&&e.jsxs(te,{onClick:()=>se.mutate(P.id),children:[e.jsx(Ks,{className:"mr-2 h-3.5 w-3.5"})," Complete"]}),L&&(P.status==="pending"||P.status==="in_progress")&&e.jsxs(te,{onClick:()=>{D(P),W("")},children:[e.jsx(Ms,{className:"mr-2 h-3.5 w-3.5"})," Reject"]}),L&&e.jsxs(te,{onClick:()=>k(P),children:[e.jsx($e,{className:"mr-2 h-3.5 w-3.5"})," Edit"]}),L&&e.jsx(Te,{asChild:!0,children:e.jsxs(te,{className:"text-red-600",onClick:()=>y(P),children:[e.jsx(Ve,{className:"mr-2 h-3.5 w-3.5"})," Delete"]})})]})]}),e.jsxs(me,{children:[e.jsxs(he,{children:[e.jsx(pe,{children:"Delete DSAR request?"}),e.jsxs(xe,{children:["This will permanently delete the ",i==null?void 0:i.request_type," request for ",e.jsx("strong",{children:i==null?void 0:i.employee_name}),"."]})]}),e.jsxs(je,{children:[e.jsx(ye,{children:"Cancel"}),e.jsx(ge,{variant:"destructive",onClick:d,children:"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(Us,{className:"h-5 w-5 text-primary"})," Data Subject Requests"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"Manage GDPR data access, erasure, and portability requests"})]}),z&&e.jsxs(C,{size:"sm",onClick:s,children:[e.jsx(ke,{className:"mr-1.5 h-3.5 w-3.5"})," New Request"]})]}),e.jsx(oe,{columns:re,data:(l==null?void 0:l.results)??[],isLoading:o,searchPlaceholder:"Search requests...",emptyMessage:"No DSAR requests yet",emptyDescription:"Create your first data subject request.",totalCount:(l==null?void 0:l.count)??0,pagination:ee,onPaginationChange:q,sorting:G,onSortingChange:h,globalFilter:v,onGlobalFilterChange:J,actions:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs($,{value:w||"__all__",onValueChange:ze,children:[e.jsx(O,{className:"w-[150px] h-9",children:e.jsx(I,{placeholder:"All types"})}),e.jsxs(U,{children:[e.jsx(r,{value:"__all__",children:"All Types"}),e.jsx(r,{value:"access",children:"Access"}),e.jsx(r,{value:"erasure",children:"Erasure"}),e.jsx(r,{value:"portability",children:"Portability"}),e.jsx(r,{value:"rectification",children:"Rectification"})]})]}),e.jsxs($,{value:Y||"__all__",onValueChange:c,children:[e.jsx(O,{className:"w-[150px] h-9",children:e.jsx(I,{placeholder:"All statuses"})}),e.jsxs(U,{children:[e.jsx(r,{value:"__all__",children:"All Statuses"}),e.jsx(r,{value:"pending",children:"Pending"}),e.jsx(r,{value:"in_progress",children:"In Progress"}),e.jsx(r,{value:"completed",children:"Completed"}),e.jsx(r,{value:"rejected",children:"Rejected"})]})]})]})}),e.jsx(ve,{open:a,onOpenChange:t,children:e.jsxs(fe,{size:"lg",children:[e.jsxs(Se,{children:[e.jsx(Ne,{children:n?"Edit DSAR Request":"New DSAR Request"}),e.jsx(Ce,{children:n?"Update the data subject request details.":"Submit a new data subject access request."})]}),e.jsxs("form",{onSubmit:u.handleSubmit(A),className:"flex-1 overflow-y-auto px-6 py-5 space-y-4",children:[e.jsxs("div",{children:[e.jsx(m,{children:"Employee *"}),e.jsx(cs,{value:u.watch("employee")??"",onValueChange:P=>u.setValue("employee",P,{shouldValidate:!0}),className:"mt-1.5"}),u.formState.errors.employee&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:u.formState.errors.employee.message})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Request Type *"}),e.jsxs($,{value:u.watch("request_type"),onValueChange:P=>u.setValue("request_type",P),children:[e.jsx(O,{className:"mt-1.5",children:e.jsx(I,{placeholder:"Select type"})}),e.jsxs(U,{children:[e.jsx(r,{value:"access",children:"Access"}),e.jsx(r,{value:"erasure",children:"Erasure"}),e.jsx(r,{value:"portability",children:"Portability"}),e.jsx(r,{value:"rectification",children:"Rectification"})]})]}),u.formState.errors.request_type&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:u.formState.errors.request_type.message})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Description"}),e.jsx(He,{...u.register("description"),className:"mt-1.5",rows:3,placeholder:"Details about the request..."})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(m,{children:"Due Date *"}),e.jsx(F,{...u.register("due_date"),type:"date",className:"mt-1.5"}),u.formState.errors.due_date&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:u.formState.errors.due_date.message})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Assigned To"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(Is,{value:u.watch("assigned_to")??"",onValueChange:P=>u.setValue("assigned_to",P),placeholder:"Select user (optional)"})})]})]})]}),e.jsxs(be,{children:[e.jsx(C,{variant:"outline",onClick:()=>t(!1),children:"Cancel"}),e.jsx(C,{onClick:u.handleSubmit(A),disabled:N.isPending||M.isPending,children:n?"Save Changes":"Create Request"})]})]})}),e.jsx(ue,{open:!!g,onOpenChange:P=>{P||(D(null),W(""))},children:e.jsxs(me,{children:[e.jsxs(he,{children:[e.jsx(pe,{children:"Reject DSAR Request"}),e.jsxs(xe,{children:["Provide a reason for rejecting the ",g==null?void 0:g.request_type," request for ",e.jsx("strong",{children:g==null?void 0:g.employee_name}),"."]})]}),e.jsxs("div",{className:"px-6 pb-2",children:[e.jsx(m,{children:"Rejection Reason *"}),e.jsx(He,{value:S,onChange:P=>W(P.target.value),className:"mt-1.5",rows:3,placeholder:"Explain why this request is being rejected..."})]}),e.jsxs(je,{children:[e.jsx(ye,{children:"Cancel"}),e.jsx(ge,{variant:"destructive",onClick:ie,disabled:!S.trim()||X.isPending,children:"Reject Request"})]})]})})]})}const gt=we({resource_type:b().min(1,"Resource type is required"),retention_days:Ie.number().min(1,"Must be at least 1 day"),action:le(["anonymize","delete","archive"],{required_error:"Action is required"}),description:b().optional(),is_active:Cs().optional()}),_t={anonymize:"secondary",delete:"destructive",archive:"outline"},vt={anonymize:"Anonymize",delete:"Delete",archive:"Archive"};function ur(){const[a,t]=j.useState(!1),[n,x]=j.useState(null),[i,y]=j.useState(null),[g,D]=j.useState(""),[S,W]=j.useState(""),{hasPermission:w}=Oe(),K=w("compliance","retention_policy","create"),Y=w("compliance","retention_policy","update"),{pagination:H,setPagination:Q,sorting:z,setSorting:L,globalFilter:ee,setGlobalFilter:q,queryParams:G}=de(),h={...G,...g&&{action:g},...S&&{is_active:S}},{data:v,isLoading:J}=Zs(h),B=Xs(),Z=et(),l=st(),o=Fe({resolver:Ae(gt),defaultValues:{resource_type:"",retention_days:365,action:"archive",description:"",is_active:!0}});function N(){x(null),o.reset({resource_type:"",retention_days:365,action:"archive",description:"",is_active:!0}),t(!0)}function M(s){x(s),o.reset({resource_type:s.resource_type,retention_days:s.retention_days,action:s.action,description:s.description,is_active:s.is_active}),t(!0)}function _(s){const k={resource_type:s.resource_type,retention_days:s.retention_days,action:s.action,description:s.description,is_active:s.is_active};n?Z.mutate({id:n.id,...k},{onSuccess:()=>t(!1)}):B.mutate(k,{onSuccess:()=>t(!1)})}function ae(){i&&l.mutate(i.id,{onSuccess:()=>y(null)})}function se(s){D(s==="__all__"?"":s),Q(k=>({...k,pageIndex:0}))}function X(s){W(s==="__all__"?"":s),Q(k=>({...k,pageIndex:0}))}const u=[{key:"resource_type",header:"Resource Type",render:s=>e.jsx("span",{className:"font-medium text-slate-900",children:s.resource_type})},{key:"retention_days",header:"Retention Period",render:s=>`${s.retention_days} days`},{key:"action",header:"Action",render:s=>e.jsx(ne,{variant:_t[s.action],children:vt[s.action]})},{key:"description",header:"Description",render:s=>e.jsx("span",{className:"text-slate-600 truncate max-w-[200px] block",children:s.description||"—"})},{key:"is_active",header:"Status",render:s=>e.jsx(zs,{status:s.is_active?"active":"inactive"})},{key:"actions",header:"",className:"w-10",render:s=>e.jsxs(ue,{open:(i==null?void 0:i.id)===s.id,onOpenChange:k=>!k&&y(null),children:[e.jsxs(Ee,{children:[e.jsx(Re,{asChild:!0,children:e.jsx(C,{variant:"ghost",size:"icon-sm",children:e.jsx(Le,{className:"h-4 w-4"})})}),e.jsxs(De,{align:"end",children:[Y&&e.jsxs(te,{onClick:()=>M(s),children:[e.jsx($e,{className:"mr-2 h-3.5 w-3.5"})," Edit"]}),Y&&e.jsx(Te,{asChild:!0,children:e.jsxs(te,{className:"text-red-600",onClick:()=>y(s),children:[e.jsx(Ve,{className:"mr-2 h-3.5 w-3.5"})," Delete"]})})]})]}),e.jsxs(me,{children:[e.jsxs(he,{children:[e.jsx(pe,{children:"Delete retention policy?"}),e.jsxs(xe,{children:["This will permanently delete the retention policy for",e.jsxs("strong",{children:[" ",i==null?void 0:i.resource_type]}),"."]})]}),e.jsxs(je,{children:[e.jsx(ye,{children:"Cancel"}),e.jsx(ge,{variant:"destructive",onClick:ae,children:"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(js,{className:"h-5 w-5 text-primary"})," Data Retention"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"Configure how long data is retained before archival or deletion"})]}),K&&e.jsxs(C,{size:"sm",onClick:N,children:[e.jsx(ke,{className:"mr-1.5 h-3.5 w-3.5"})," Add Policy"]})]}),e.jsx(oe,{columns:u,data:(v==null?void 0:v.results)??[],isLoading:J,searchPlaceholder:"Search policies...",emptyMessage:"No retention policies yet",emptyDescription:"Create your first data retention policy.",totalCount:(v==null?void 0:v.count)??0,pagination:H,onPaginationChange:Q,sorting:z,onSortingChange:L,globalFilter:ee,onGlobalFilterChange:q,actions:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs($,{value:g||"__all__",onValueChange:se,children:[e.jsx(O,{className:"w-[140px] h-9",children:e.jsx(I,{placeholder:"All actions"})}),e.jsxs(U,{children:[e.jsx(r,{value:"__all__",children:"All Actions"}),e.jsx(r,{value:"anonymize",children:"Anonymize"}),e.jsx(r,{value:"delete",children:"Delete"}),e.jsx(r,{value:"archive",children:"Archive"})]})]}),e.jsxs($,{value:S||"__all__",onValueChange:X,children:[e.jsx(O,{className:"w-[140px] h-9",children:e.jsx(I,{placeholder:"All statuses"})}),e.jsxs(U,{children:[e.jsx(r,{value:"__all__",children:"All Statuses"}),e.jsx(r,{value:"true",children:"Active"}),e.jsx(r,{value:"false",children:"Inactive"})]})]})]})}),e.jsx(ve,{open:a,onOpenChange:t,children:e.jsxs(fe,{size:"lg",children:[e.jsxs(Se,{children:[e.jsx(Ne,{children:n?"Edit Retention Policy":"New Retention Policy"}),e.jsx(Ce,{children:n?"Update the data retention policy.":"Define how long a resource type is retained before action is taken."})]}),e.jsxs("form",{onSubmit:o.handleSubmit(_),className:"flex-1 overflow-y-auto px-6 py-5 space-y-4",children:[e.jsxs("div",{children:[e.jsx(m,{children:"Resource Type *"}),e.jsx(F,{...o.register("resource_type"),className:"mt-1.5",placeholder:"e.g. employee_records, payslips"}),o.formState.errors.resource_type&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:o.formState.errors.resource_type.message})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(m,{children:"Retention Days *"}),e.jsx(F,{...o.register("retention_days"),type:"number",min:1,className:"mt-1.5",placeholder:"365"}),o.formState.errors.retention_days&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:o.formState.errors.retention_days.message})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Action *"}),e.jsxs($,{value:o.watch("action"),onValueChange:s=>o.setValue("action",s),children:[e.jsx(O,{className:"mt-1.5",children:e.jsx(I,{placeholder:"Select action"})}),e.jsxs(U,{children:[e.jsx(r,{value:"anonymize",children:"Anonymize"}),e.jsx(r,{value:"delete",children:"Delete"}),e.jsx(r,{value:"archive",children:"Archive"})]})]}),o.formState.errors.action&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:o.formState.errors.action.message})]})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Description"}),e.jsx(He,{...o.register("description"),className:"mt-1.5",rows:3,placeholder:"Describe when and why this retention policy applies..."})]}),e.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[e.jsx(ys,{id:"is_active",checked:o.watch("is_active"),onCheckedChange:s=>o.setValue("is_active",!!s)}),e.jsx(m,{htmlFor:"is_active",className:"cursor-pointer",children:"Active"})]})]}),e.jsxs(be,{children:[e.jsx(C,{variant:"outline",onClick:()=>t(!1),children:"Cancel"}),e.jsx(C,{onClick:o.handleSubmit(_),disabled:B.isPending||Z.isPending,children:n?"Save Changes":"Create Policy"})]})]})})]})}const ft=we({employee:b().min(1,"Employee ID is required"),consent_type:b().min(1,"Consent type is required"),notes:b().optional()}),St={granted:"success",withdrawn:"secondary"},Nt={granted:"Granted",withdrawn:"Withdrawn"};function mr(){const[a,t]=j.useState(!1),[n,x]=j.useState(null),[i,y]=j.useState(null),[g,D]=j.useState(null),[S,W]=j.useState(""),[w,K]=j.useState(""),{pagination:Y,setPagination:H,sorting:Q,setSorting:z,globalFilter:L,setGlobalFilter:ee,queryParams:q}=de(),G={...q,...S&&{status:S},...w&&{consent_type:w}},{data:h,isLoading:v}=ot(G),J=dt(),B=ut(),Z=mt(),l=ht(),o=Fe({resolver:Ae(ft),defaultValues:{employee:"",consent_type:"",notes:""}});function N(){x(null),o.reset({employee:"",consent_type:"",notes:""}),t(!0)}function M(A){x(A),o.reset({employee:A.employee,consent_type:A.consent_type,notes:A.notes}),t(!0)}function _(A){const d={employee:A.employee,consent_type:A.consent_type,notes:A.notes};n?B.mutate({id:n.id,...d},{onSuccess:()=>t(!1)}):J.mutate(d,{onSuccess:()=>t(!1)})}function ae(){i&&Z.mutate(i.id,{onSuccess:()=>y(null)})}function se(){g&&l.mutate(g.id,{onSuccess:()=>D(null)})}function X(A){W(A==="__all__"?"":A),H(d=>({...d,pageIndex:0}))}function u(A){K(A==="__all__"?"":A),H(d=>({...d,pageIndex:0}))}const s=Array.from(new Set(((h==null?void 0:h.results)??[]).map(A=>A.consent_type).filter(Boolean))),k=[{key:"employee_name",header:"Employee",render:A=>e.jsx("span",{className:"font-medium text-slate-900",children:A.employee_name??"—"})},{key:"consent_type",header:"Consent Type",render:A=>A.consent_type},{key:"status",header:"Status",render:A=>e.jsx(ne,{variant:St[A.status],children:Nt[A.status]})},{key:"granted_at",header:"Granted At",render:A=>A.granted_at?new Date(A.granted_at).toLocaleDateString():"—"},{key:"withdrawn_at",header:"Withdrawn At",render:A=>A.withdrawn_at?new Date(A.withdrawn_at).toLocaleDateString():"—"},{key:"ip_address",header:"IP Address",render:A=>e.jsx("span",{className:"font-mono text-[12px] text-slate-500",children:A.ip_address??"—"})},{key:"actions",header:"",className:"w-10",render:A=>e.jsxs(ue,{open:(i==null?void 0:i.id)===A.id,onOpenChange:d=>!d&&y(null),children:[e.jsxs(Ee,{children:[e.jsx(Re,{asChild:!0,children:e.jsx(C,{variant:"ghost",size:"icon-sm",children:e.jsx(Le,{className:"h-4 w-4"})})}),e.jsxs(De,{align:"end",children:[A.status==="granted"&&e.jsxs(te,{onClick:()=>D(A),children:[e.jsx(Ys,{className:"mr-2 h-3.5 w-3.5"})," Withdraw"]}),e.jsxs(te,{onClick:()=>M(A),children:[e.jsx($e,{className:"mr-2 h-3.5 w-3.5"})," Edit"]}),e.jsx(Te,{asChild:!0,children:e.jsxs(te,{className:"text-red-600",onClick:()=>y(A),children:[e.jsx(Ve,{className:"mr-2 h-3.5 w-3.5"})," Delete"]})})]})]}),e.jsxs(me,{children:[e.jsxs(he,{children:[e.jsx(pe,{children:"Delete consent record?"}),e.jsxs(xe,{children:["This will permanently delete the ",e.jsx("strong",{children:i==null?void 0:i.consent_type})," consent record for ",e.jsx("strong",{children:i==null?void 0:i.employee_name}),"."]})]}),e.jsxs(je,{children:[e.jsx(ye,{children:"Cancel"}),e.jsx(ge,{variant:"destructive",onClick:ae,children:"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(bs,{className:"h-5 w-5 text-primary"})," Consent Records"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"Track employee data processing consent status"})]}),e.jsxs(C,{size:"sm",onClick:N,children:[e.jsx(ke,{className:"mr-1.5 h-3.5 w-3.5"})," Add Consent"]})]}),e.jsx(oe,{columns:k,data:(h==null?void 0:h.results)??[],isLoading:v,searchPlaceholder:"Search consent records...",emptyMessage:"No consent records yet",emptyDescription:"Create your first consent record.",totalCount:(h==null?void 0:h.count)??0,pagination:Y,onPaginationChange:H,sorting:Q,onSortingChange:z,globalFilter:L,onGlobalFilterChange:ee,actions:e.jsxs("div",{className:"flex items-center gap-2",children:[s.length>0&&e.jsxs($,{value:w||"__all__",onValueChange:u,children:[e.jsx(O,{className:"w-[160px] h-9",children:e.jsx(I,{placeholder:"All types"})}),e.jsxs(U,{children:[e.jsx(r,{value:"__all__",children:"All Types"}),s.map(A=>e.jsx(r,{value:A,children:A},A))]})]}),e.jsxs($,{value:S||"__all__",onValueChange:X,children:[e.jsx(O,{className:"w-[140px] h-9",children:e.jsx(I,{placeholder:"All statuses"})}),e.jsxs(U,{children:[e.jsx(r,{value:"__all__",children:"All Statuses"}),e.jsx(r,{value:"granted",children:"Granted"}),e.jsx(r,{value:"withdrawn",children:"Withdrawn"})]})]})]})}),e.jsx(ve,{open:a,onOpenChange:t,children:e.jsxs(fe,{size:"lg",children:[e.jsxs(Se,{children:[e.jsx(Ne,{children:n?"Edit Consent Record":"New Consent Record"}),e.jsx(Ce,{children:n?"Update the consent record details.":"Record a new data processing consent from an employee."})]}),e.jsxs("form",{onSubmit:o.handleSubmit(_),className:"flex-1 overflow-y-auto px-6 py-5 space-y-4",children:[e.jsxs("div",{children:[e.jsx(m,{children:"Employee *"}),e.jsx(cs,{value:o.watch("employee")??"",onValueChange:A=>o.setValue("employee",A,{shouldValidate:!0}),className:"mt-1.5"}),o.formState.errors.employee&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:o.formState.errors.employee.message})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Consent Type *"}),e.jsx(F,{...o.register("consent_type"),className:"mt-1.5",placeholder:"e.g. data_processing, marketing_emails"}),o.formState.errors.consent_type&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:o.formState.errors.consent_type.message})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Notes"}),e.jsx(He,{...o.register("notes"),className:"mt-1.5",rows:3,placeholder:"Additional notes about this consent..."})]})]}),e.jsxs(be,{children:[e.jsx(C,{variant:"outline",onClick:()=>t(!1),children:"Cancel"}),e.jsx(C,{onClick:o.handleSubmit(_),disabled:J.isPending||B.isPending,children:n?"Save Changes":"Create Consent"})]})]})}),e.jsx(ue,{open:!!g,onOpenChange:A=>!A&&D(null),children:e.jsxs(me,{children:[e.jsxs(he,{children:[e.jsx(pe,{children:"Withdraw consent?"}),e.jsxs(xe,{children:["This will withdraw the ",e.jsx("strong",{children:g==null?void 0:g.consent_type})," consent for ",e.jsx("strong",{children:g==null?void 0:g.employee_name}),". This action can be reversed by granting consent again."]})]}),e.jsxs(je,{children:[e.jsx(ye,{children:"Cancel"}),e.jsx(ge,{variant:"destructive",onClick:se,disabled:l.isPending,children:"Withdraw Consent"})]})]})})]})}const R="/compliance",E={filings:["compliance","filings"],calendar:["compliance","calendar"],amendments:["compliance","amendments"],penalties:["compliance","penalties"],correspondence:["compliance","correspondence"],factoryRegisters:["compliance","factory-registers"],contractors:["compliance","contractors"],contractWorkers:["compliance","contract-workers"],wageAudits:["compliance","wage-audits"],statutoryUpdates:["compliance","statutory-updates"],posh:["compliance","posh"],payEquity:["compliance","pay-equity"],scores:["compliance","scores"],establishments:["compliance","establishments"],dashboard:["compliance","dashboard"],reports:["compliance","reports"],form16:["compliance","form16"]};function us(a){return ce({queryKey:[...E.filings,a],queryFn:()=>f.get(`${R}/filings/`,{params:a}).then(t=>t.data)})}function Ct(){const a=V();return T({mutationFn:t=>f.post(`${R}/filings/`,t).then(n=>n.data),onSuccess:()=>{a.invalidateQueries({queryKey:E.filings}),p.success("Filing created successfully.")},onError:()=>p.error("Failed to create filing.")})}function bt(){const a=V();return T({mutationFn:({id:t,...n})=>f.patch(`${R}/filings/${t}/`,n).then(x=>x.data),onSuccess:()=>{a.invalidateQueries({queryKey:E.filings}),p.success("Filing updated.")},onError:()=>p.error("Failed to update filing.")})}function kt(){const a=V();return T({mutationFn:t=>f.delete(`${R}/filings/${t}/`).then(n=>n.data),onSuccess:()=>{a.invalidateQueries({queryKey:E.filings}),p.success("Filing deleted.")},onError:()=>p.error("Failed to delete filing.")})}function Ft(a){return ce({queryKey:[...E.calendar,a],queryFn:()=>f.get(`${R}/calendar/`,{params:a}).then(t=>t.data)})}function At(){const a=V();return T({mutationFn:t=>f.post(`${R}/calendar/`,t).then(n=>n.data),onSuccess:()=>{a.invalidateQueries({queryKey:E.calendar}),p.success("Calendar entry created successfully.")},onError:()=>p.error("Failed to create calendar entry.")})}function wt(){const a=V();return T({mutationFn:({id:t,...n})=>f.patch(`${R}/calendar/${t}/`,n).then(x=>x.data),onSuccess:()=>{a.invalidateQueries({queryKey:E.calendar}),p.success("Calendar entry updated.")},onError:()=>p.error("Failed to update calendar entry.")})}function qt(){const a=V();return T({mutationFn:t=>f.delete(`${R}/calendar/${t}/`).then(n=>n.data),onSuccess:()=>{a.invalidateQueries({queryKey:E.calendar}),p.success("Calendar entry deleted.")},onError:()=>p.error("Failed to delete calendar entry.")})}function Pt(a){return ce({queryKey:[...E.amendments,a],queryFn:()=>f.get(`${R}/amendments/`,{params:a}).then(t=>t.data)})}function Et(){const a=V();return T({mutationFn:t=>f.post(`${R}/amendments/`,t).then(n=>n.data),onSuccess:()=>{a.invalidateQueries({queryKey:E.amendments}),p.success("Amendment created successfully.")},onError:()=>p.error("Failed to create amendment.")})}function Rt(){const a=V();return T({mutationFn:({id:t,...n})=>f.patch(`${R}/amendments/${t}/`,n).then(x=>x.data),onSuccess:()=>{a.invalidateQueries({queryKey:E.amendments}),p.success("Amendment updated.")},onError:()=>p.error("Failed to update amendment.")})}function Dt(){const a=V();return T({mutationFn:t=>f.delete(`${R}/amendments/${t}/`).then(n=>n.data),onSuccess:()=>{a.invalidateQueries({queryKey:E.amendments}),p.success("Amendment deleted.")},onError:()=>p.error("Failed to delete amendment.")})}function Tt(a){return ce({queryKey:[...E.penalties,a],queryFn:()=>f.get(`${R}/penalties/`,{params:a}).then(t=>t.data)})}function Vt(){const a=V();return T({mutationFn:t=>f.post(`${R}/penalties/`,t).then(n=>n.data),onSuccess:()=>{a.invalidateQueries({queryKey:E.penalties}),p.success("Penalty record created successfully.")},onError:()=>p.error("Failed to create penalty record.")})}function Lt(){const a=V();return T({mutationFn:({id:t,...n})=>f.patch(`${R}/penalties/${t}/`,n).then(x=>x.data),onSuccess:()=>{a.invalidateQueries({queryKey:E.penalties}),p.success("Penalty record updated.")},onError:()=>p.error("Failed to update penalty record.")})}function $t(){const a=V();return T({mutationFn:t=>f.delete(`${R}/penalties/${t}/`).then(n=>n.data),onSuccess:()=>{a.invalidateQueries({queryKey:E.penalties}),p.success("Penalty record deleted.")},onError:()=>p.error("Failed to delete penalty record.")})}function Ot(a){return ce({queryKey:[...E.correspondence,a],queryFn:()=>f.get(`${R}/correspondence/`,{params:a}).then(t=>t.data)})}function It(){const a=V();return T({mutationFn:t=>f.post(`${R}/correspondence/`,t).then(n=>n.data),onSuccess:()=>{a.invalidateQueries({queryKey:E.correspondence}),p.success("Correspondence created successfully.")},onError:()=>p.error("Failed to create correspondence.")})}function Ut(){const a=V();return T({mutationFn:({id:t,...n})=>f.patch(`${R}/correspondence/${t}/`,n).then(x=>x.data),onSuccess:()=>{a.invalidateQueries({queryKey:E.correspondence}),p.success("Correspondence updated.")},onError:()=>p.error("Failed to update correspondence.")})}function Qt(){const a=V();return T({mutationFn:t=>f.delete(`${R}/correspondence/${t}/`).then(n=>n.data),onSuccess:()=>{a.invalidateQueries({queryKey:E.correspondence}),p.success("Correspondence deleted.")},onError:()=>p.error("Failed to delete correspondence.")})}function Kt(a){return ce({queryKey:[...E.factoryRegisters,a],queryFn:()=>f.get(`${R}/factory-registers/`,{params:a}).then(t=>t.data)})}function Mt(){const a=V();return T({mutationFn:t=>f.post(`${R}/factory-registers/`,t).then(n=>n.data),onSuccess:()=>{a.invalidateQueries({queryKey:E.factoryRegisters}),p.success("Factory register created successfully.")},onError:()=>p.error("Failed to create factory register.")})}function zt(){const a=V();return T({mutationFn:({id:t,...n})=>f.patch(`${R}/factory-registers/${t}/`,n).then(x=>x.data),onSuccess:()=>{a.invalidateQueries({queryKey:E.factoryRegisters}),p.success("Factory register updated.")},onError:()=>p.error("Failed to update factory register.")})}function Gt(){const a=V();return T({mutationFn:t=>f.delete(`${R}/factory-registers/${t}/`).then(n=>n.data),onSuccess:()=>{a.invalidateQueries({queryKey:E.factoryRegisters}),p.success("Factory register deleted.")},onError:()=>p.error("Failed to delete factory register.")})}function As(a){return ce({queryKey:[...E.contractors,a],queryFn:()=>f.get(`${R}/contractors/`,{params:a}).then(t=>t.data)})}function Bt(){const a=V();return T({mutationFn:t=>f.post(`${R}/contractors/`,t).then(n=>n.data),onSuccess:()=>{a.invalidateQueries({queryKey:E.contractors}),p.success("Contractor created successfully.")},onError:()=>p.error("Failed to create contractor.")})}function Wt(){const a=V();return T({mutationFn:({id:t,...n})=>f.patch(`${R}/contractors/${t}/`,n).then(x=>x.data),onSuccess:()=>{a.invalidateQueries({queryKey:E.contractors}),p.success("Contractor updated.")},onError:()=>p.error("Failed to update contractor.")})}function Ht(){const a=V();return T({mutationFn:t=>f.delete(`${R}/contractors/${t}/`).then(n=>n.data),onSuccess:()=>{a.invalidateQueries({queryKey:E.contractors}),p.success("Contractor deleted.")},onError:()=>p.error("Failed to delete contractor.")})}function ws(a){return ce({queryKey:[...E.contractWorkers,a],queryFn:()=>f.get(`${R}/contract-workers/`,{params:a}).then(t=>t.data)})}function Yt(){const a=V();return T({mutationFn:t=>f.post(`${R}/contract-workers/`,t).then(n=>n.data),onSuccess:()=>{a.invalidateQueries({queryKey:E.contractWorkers}),p.success("Contract worker created successfully.")},onError:()=>p.error("Failed to create contract worker.")})}function Jt(){const a=V();return T({mutationFn:({id:t,...n})=>f.patch(`${R}/contract-workers/${t}/`,n).then(x=>x.data),onSuccess:()=>{a.invalidateQueries({queryKey:E.contractWorkers}),p.success("Contract worker updated.")},onError:()=>p.error("Failed to update contract worker.")})}function Zt(){const a=V();return T({mutationFn:t=>f.delete(`${R}/contract-workers/${t}/`).then(n=>n.data),onSuccess:()=>{a.invalidateQueries({queryKey:E.contractWorkers}),p.success("Contract worker deleted.")},onError:()=>p.error("Failed to delete contract worker.")})}function Xt(a){return ce({queryKey:[...E.wageAudits,a],queryFn:()=>f.get(`${R}/wage-audits/`,{params:a}).then(t=>t.data)})}function en(){const a=V();return T({mutationFn:t=>f.post(`${R}/wage-audits/`,t).then(n=>n.data),onSuccess:()=>{a.invalidateQueries({queryKey:E.wageAudits}),p.success("Wage audit created successfully.")},onError:()=>p.error("Failed to create wage audit.")})}function sn(a){return ce({queryKey:[...E.statutoryUpdates,a],queryFn:()=>f.get(`${R}/statutory-updates/`,{params:a}).then(t=>t.data)})}function tn(){const a=V();return T({mutationFn:t=>f.post(`${R}/statutory-updates/`,t).then(n=>n.data),onSuccess:()=>{a.invalidateQueries({queryKey:E.statutoryUpdates}),p.success("Statutory update created successfully.")},onError:()=>p.error("Failed to create statutory update.")})}function nn(){const a=V();return T({mutationFn:({id:t,...n})=>f.patch(`${R}/statutory-updates/${t}/`,n).then(x=>x.data),onSuccess:()=>{a.invalidateQueries({queryKey:E.statutoryUpdates}),p.success("Statutory update updated.")},onError:()=>p.error("Failed to update statutory update.")})}function an(){const a=V();return T({mutationFn:t=>f.delete(`${R}/statutory-updates/${t}/`).then(n=>n.data),onSuccess:()=>{a.invalidateQueries({queryKey:E.statutoryUpdates}),p.success("Statutory update deleted.")},onError:()=>p.error("Failed to delete statutory update.")})}function rn(a){return ce({queryKey:[...E.posh,a],queryFn:()=>f.get(`${R}/posh/`,{params:a}).then(t=>t.data)})}function ln(){const a=V();return T({mutationFn:t=>f.post(`${R}/posh/`,t).then(n=>n.data),onSuccess:()=>{a.invalidateQueries({queryKey:E.posh}),p.success("POSH compliance record created successfully.")},onError:()=>p.error("Failed to create POSH record.")})}function cn(){const a=V();return T({mutationFn:({id:t,...n})=>f.patch(`${R}/posh/${t}/`,n).then(x=>x.data),onSuccess:()=>{a.invalidateQueries({queryKey:E.posh}),p.success("POSH compliance record updated.")},onError:()=>p.error("Failed to update POSH record.")})}function on(){const a=V();return T({mutationFn:t=>f.delete(`${R}/posh/${t}/`).then(n=>n.data),onSuccess:()=>{a.invalidateQueries({queryKey:E.posh}),p.success("POSH compliance record deleted.")},onError:()=>p.error("Failed to delete POSH record.")})}function dn(a){return ce({queryKey:[...E.payEquity,a],queryFn:()=>f.get(`${R}/pay-equity/`,{params:a}).then(t=>t.data)})}function un(){const a=V();return T({mutationFn:t=>f.post(`${R}/pay-equity/`,t).then(n=>n.data),onSuccess:()=>{a.invalidateQueries({queryKey:E.payEquity}),p.success("Pay equity audit created successfully.")},onError:()=>p.error("Failed to create pay equity audit.")})}function mn(){const a=V();return T({mutationFn:({id:t,...n})=>f.patch(`${R}/pay-equity/${t}/`,n).then(x=>x.data),onSuccess:()=>{a.invalidateQueries({queryKey:E.payEquity}),p.success("Pay equity audit updated.")},onError:()=>p.error("Failed to update pay equity audit.")})}function hn(){const a=V();return T({mutationFn:t=>f.delete(`${R}/pay-equity/${t}/`).then(n=>n.data),onSuccess:()=>{a.invalidateQueries({queryKey:E.payEquity}),p.success("Pay equity audit deleted.")},onError:()=>p.error("Failed to delete pay equity audit.")})}function pn(a){return ce({queryKey:[...E.scores,a],queryFn:()=>f.get(`${R}/scores/`,{params:a}).then(t=>t.data)})}function xn(a){return ce({queryKey:[...E.establishments,a],queryFn:()=>f.get(`${R}/establishments/`,{params:a}).then(t=>t.data)})}function jn(){const a=V();return T({mutationFn:t=>f.post(`${R}/establishments/`,t).then(n=>n.data),onSuccess:()=>{a.invalidateQueries({queryKey:E.establishments}),p.success("Establishment created successfully.")},onError:()=>p.error("Failed to create establishment.")})}function yn(){const a=V();return T({mutationFn:({id:t,...n})=>f.patch(`${R}/establishments/${t}/`,n).then(x=>x.data),onSuccess:()=>{a.invalidateQueries({queryKey:E.establishments}),p.success("Establishment updated.")},onError:()=>p.error("Failed to update establishment.")})}function gn(){const a=V();return T({mutationFn:t=>f.delete(`${R}/establishments/${t}/`).then(n=>n.data),onSuccess:()=>{a.invalidateQueries({queryKey:E.establishments}),p.success("Establishment deleted.")},onError:()=>p.error("Failed to delete establishment.")})}function _n(a){return ce({queryKey:[...E.dashboard,a],queryFn:()=>f.get(`${R}/dashboard/`,{params:a}).then(t=>t.data)})}function vn(a){return ce({queryKey:[...E.reports,a],queryFn:()=>f.get(`${R}/reports/`,{params:a}).then(t=>t.data),enabled:!1})}function fn(a){return ce({queryKey:[...E.form16,a],queryFn:()=>f.get("/payroll/form16/",{params:a}).then(t=>t.data)})}function Sn(){const a=V();return T({mutationFn:t=>f.post("/payroll/form16/generate/",t).then(n=>n.data),onSuccess:()=>{a.invalidateQueries({queryKey:E.form16}),p.success("Form 16 batch generation initiated.")},onError:()=>p.error("Failed to generate Form 16 batch.")})}function Nn(){return T({mutationFn:a=>f.get(`/payroll/form16/${a}/download/`,{responseType:"blob"}).then(t=>t.data),onError:()=>p.error("Failed to download Form 16.")})}function Ye({icon:a,label:t,value:n,color:x,loading:i}){return e.jsx(Ge,{children:e.jsxs(Be,{className:"flex items-center gap-4 p-5",children:[e.jsx("div",{className:`flex h-10 w-10 shrink-0 items-center justify-center rounded-xl ${x}`,children:e.jsx(a,{className:"h-5 w-5 text-white"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-[12px] font-medium text-slate-400",children:t}),i?e.jsx(Ue,{className:"mt-1 h-6 w-16"}):e.jsx("p",{className:"text-xl font-bold text-slate-900",children:n})]})]})})}const Cn={green:"success",yellow:"warning",red:"destructive"},bn={pending:"secondary",generated:"outline",validated:"outline",submitted:"warning",acknowledged:"success",rejected:"destructive",amended:"secondary"};function hr(){var n,x,i;const{data:a,isLoading:t}=_n();return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-6",children:[e.jsxs("h2",{className:"text-[16px] font-semibold text-slate-900 flex items-center gap-2",children:[e.jsx(as,{className:"h-5 w-5 text-primary"})," Compliance Dashboard"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"Overview of statutory compliance health and upcoming deadlines"})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-5 mb-6",children:[e.jsx(Ye,{icon:xs,label:"Overall Score",value:(a==null?void 0:a.overall_score)??"--",color:"bg-primary",loading:t}),e.jsx(Ye,{icon:ks,label:"On-Time Filings",value:(a==null?void 0:a.filings_on_time_pct)!=null?`${a.filings_on_time_pct}%`:"--",color:"bg-emerald-500",loading:t}),e.jsx(Ye,{icon:ns,label:"Pending Filings",value:(a==null?void 0:a.pending_filings)??"--",color:"bg-amber-500",loading:t}),e.jsx(Ye,{icon:es,label:"Open Penalties",value:(a==null?void 0:a.open_penalties)??"--",color:"bg-red-500",loading:t}),e.jsx(Ye,{icon:js,label:"Overdue Items",value:(a==null?void 0:a.overdue_items)??"--",color:"bg-orange-500",loading:t})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-6 lg:grid-cols-2",children:[e.jsxs(Ge,{children:[e.jsx(Je,{children:e.jsx(Ze,{className:"text-[14px]",children:"Upcoming Deadlines"})}),e.jsx(Be,{children:t?e.jsx("div",{className:"space-y-3",children:Array.from({length:4}).map((y,g)=>e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(Ue,{className:"h-4 w-48"}),e.jsx(Ue,{className:"h-5 w-16"})]},g))}):(n=a==null?void 0:a.upcoming_deadlines)!=null&&n.length?e.jsx("ul",{className:"divide-y divide-slate-100",children:a.upcoming_deadlines.map(y=>e.jsxs("li",{className:"flex items-center justify-between py-2.5",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-[13px] font-medium text-slate-900 truncate",children:y.description}),e.jsxs("p",{className:"text-[12px] text-slate-400",children:[y.compliance_type.toUpperCase()," -- Due ",new Date(y.due_date).toLocaleDateString()]})]}),e.jsx(ne,{variant:Cn[y.risk_level]??"secondary",className:"ml-3 shrink-0",children:y.risk_level==="green"?"On Track":y.risk_level==="yellow"?"Due Soon":"Overdue"})]},y.id))}):e.jsx("p",{className:"py-6 text-center text-[13px] text-slate-400",children:"No upcoming deadlines"})})]}),e.jsxs(Ge,{children:[e.jsx(Je,{children:e.jsx(Ze,{className:"text-[14px]",children:"Recent Filings"})}),e.jsx(Be,{children:t?e.jsx("div",{className:"space-y-3",children:Array.from({length:4}).map((y,g)=>e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(Ue,{className:"h-4 w-48"}),e.jsx(Ue,{className:"h-5 w-16"})]},g))}):(x=a==null?void 0:a.recent_filings)!=null&&x.length?e.jsx("ul",{className:"divide-y divide-slate-100",children:a.recent_filings.map(y=>e.jsxs("li",{className:"flex items-center justify-between py-2.5",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-[13px] font-medium text-slate-900 truncate",children:y.filing_type.replace(/_/g," ").toUpperCase()}),e.jsxs("p",{className:"text-[12px] text-slate-400",children:[y.period," -- Rs. ",Number(y.total_amount).toLocaleString("en-IN")]})]}),e.jsx(ne,{variant:bn[y.status]??"secondary",className:"ml-3 shrink-0",children:y.status.replace(/_/g," ")})]},y.id))}):e.jsx("p",{className:"py-6 text-center text-[13px] text-slate-400",children:"No recent filings"})})]}),e.jsxs(Ge,{children:[e.jsx(Je,{children:e.jsx(Ze,{className:"text-[14px]",children:"Compliance Score Trend"})}),e.jsx(Be,{children:t?e.jsx("div",{className:"space-y-3",children:Array.from({length:4}).map((y,g)=>e.jsx(Ue,{className:"h-4 w-full"},g))}):(i=a==null?void 0:a.score_trend)!=null&&i.length?e.jsx("div",{className:"space-y-2",children:a.score_trend.map((y,g)=>e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-[12px] text-slate-400 w-20 shrink-0",children:new Date(y.date).toLocaleDateString("en-IN",{month:"short",year:"numeric"})}),e.jsx("div",{className:"flex-1 h-4 bg-slate-100 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-primary rounded-full transition-all",style:{width:`${Math.min(y.score,100)}%`}})}),e.jsx("span",{className:"text-[12px] font-semibold text-slate-700 w-10 text-right",children:y.score})]},g))}):e.jsx("p",{className:"py-6 text-center text-[13px] text-slate-400",children:"No score data available"})})]}),e.jsxs(Ge,{children:[e.jsx(Je,{children:e.jsx(Ze,{className:"text-[14px]",children:"Penalty Summary"})}),e.jsx(Be,{children:t?e.jsxs("div",{className:"space-y-3",children:[e.jsx(Ue,{className:"h-6 w-32"}),e.jsx(Ue,{className:"h-4 w-full"}),e.jsx(Ue,{className:"h-4 w-3/4"})]}):a!=null&&a.penalty_summary?e.jsxs("div",{children:[e.jsxs("p",{className:"text-2xl font-bold text-slate-900 mb-1",children:["Rs. ",Number(a.penalty_summary.total_amount).toLocaleString("en-IN")]}),e.jsxs("p",{className:"text-[12px] text-slate-400 mb-4",children:[a.penalty_summary.count," ",a.penalty_summary.count===1?"penalty":"penalties"," this year"]}),a.penalty_summary.by_type&&Object.entries(a.penalty_summary.by_type).length>0&&e.jsx("div",{className:"space-y-1.5",children:Object.entries(a.penalty_summary.by_type).map(([y,g])=>e.jsxs("div",{className:"flex items-center justify-between text-[13px]",children:[e.jsx("span",{className:"text-slate-600",children:y.replace(/_/g," ")}),e.jsx("span",{className:"font-medium text-slate-900",children:g})]},y))})]}):e.jsx("p",{className:"py-6 text-center text-[13px] text-slate-400",children:"No penalty data available"})})]})]})]})}const kn=we({company:b().min(1,"Company is required"),filing_type:le(["pf_ecr","esi_return","pt_return","tds_24q","form16"],{required_error:"Filing type is required"}),period_month:Ie.number().min(1).max(12).nullable().optional(),period_year:Ie.number().min(2020,"Year is required"),period_quarter:Ie.number().min(1).max(4).nullable().optional(),financial_year:b().min(1,"Financial year is required"),due_date:Me("Due date is required"),submission_date:We(),total_amount:b().optional(),employee_count:Ie.number().min(0).optional()}),Fn={pending:"secondary",generated:"outline",validated:"outline",submitted:"warning",acknowledged:"success",rejected:"destructive",amended:"secondary"},An={pending:"Pending",generated:"Generated",validated:"Validated",submitted:"Submitted",acknowledged:"Acknowledged",rejected:"Rejected",amended:"Amended"},ms={pf_ecr:"PF ECR",esi_return:"ESI Return",pt_return:"PT Return",tds_24q:"TDS 24Q",form16:"Form 16"};function pr(){const[a,t]=j.useState(!1),[n,x]=j.useState(null),[i,y]=j.useState(null),[g,D]=j.useState(""),[S,W]=j.useState(""),{hasPermission:w}=Oe(),K=w("compliance","filing","create"),Y=w("compliance","filing","update"),{pagination:H,setPagination:Q,sorting:z,setSorting:L,globalFilter:ee,setGlobalFilter:q,queryParams:G}=de(),h={...G,...g&&{filing_type:g},...S&&{status:S}},{data:v,isLoading:J}=us(h),B=Ct(),Z=bt(),l=kt(),[o,N]=j.useState(""),{data:M}=Qe({search:o||void 0}),_=Fe({resolver:Ae(kn),defaultValues:{company:"",filing_type:"pf_ecr",period_month:null,period_year:new Date().getFullYear(),period_quarter:null,financial_year:"",due_date:"",submission_date:"",total_amount:"0",employee_count:0}});function ae(){x(null),_.reset({company:"",filing_type:"pf_ecr",period_month:null,period_year:new Date().getFullYear(),period_quarter:null,financial_year:"",due_date:"",submission_date:"",total_amount:"0",employee_count:0}),t(!0)}function se(d){x(d),_.reset({company:d.company,filing_type:d.filing_type,period_month:d.period_month,period_year:d.period_year,period_quarter:d.period_quarter,financial_year:d.financial_year,due_date:d.due_date,submission_date:d.submission_date??"",total_amount:d.total_amount,employee_count:d.employee_count}),t(!0)}function X(d){const ie={company:d.company,filing_type:d.filing_type,period_month:d.period_month??void 0,period_year:d.period_year,period_quarter:d.period_quarter??void 0,financial_year:d.financial_year,due_date:d.due_date,submission_date:d.submission_date||void 0,total_amount:d.total_amount,employee_count:d.employee_count};n?Z.mutate({id:n.id,...ie},{onSuccess:()=>t(!1)}):B.mutate(ie,{onSuccess:()=>t(!1)})}function u(){i&&l.mutate(i.id,{onSuccess:()=>y(null)})}function s(d){D(d==="__all__"?"":d),Q(ie=>({...ie,pageIndex:0}))}function k(d){W(d==="__all__"?"":d),Q(ie=>({...ie,pageIndex:0}))}const A=[{key:"filing_type",header:"Type",render:d=>e.jsx(ne,{variant:"outline",children:ms[d.filing_type]})},{key:"period",header:"Period",render:d=>d.period_month?`${String(d.period_month).padStart(2,"0")}/${d.period_year}`:d.period_quarter?`Q${d.period_quarter}/${d.period_year}`:String(d.period_year)},{key:"financial_year",header:"FY",render:d=>d.financial_year},{key:"due_date",header:"Due Date",render:d=>new Date(d.due_date).toLocaleDateString()},{key:"total_amount",header:"Amount",render:d=>e.jsxs("span",{className:"font-mono text-[13px]",children:["Rs. ",Number(d.total_amount).toLocaleString("en-IN")]})},{key:"employee_count",header:"Employees",render:d=>d.employee_count},{key:"status",header:"Status",render:d=>e.jsx(ne,{variant:Fn[d.status],children:An[d.status]})},{key:"actions",header:"",className:"w-10",render:d=>e.jsxs(ue,{open:(i==null?void 0:i.id)===d.id,onOpenChange:ie=>!ie&&y(null),children:[e.jsxs(Ee,{children:[e.jsx(Re,{asChild:!0,children:e.jsx(C,{variant:"ghost",size:"icon-sm",children:e.jsx(Le,{className:"h-4 w-4"})})}),e.jsxs(De,{align:"end",children:[Y&&e.jsxs(te,{onClick:()=>se(d),children:[e.jsx($e,{className:"mr-2 h-3.5 w-3.5"})," Edit"]}),Y&&e.jsx(Te,{asChild:!0,children:e.jsxs(te,{className:"text-red-600",onClick:()=>y(d),children:[e.jsx(Ve,{className:"mr-2 h-3.5 w-3.5"})," Delete"]})})]})]}),e.jsxs(me,{children:[e.jsxs(he,{children:[e.jsx(pe,{children:"Delete filing?"}),e.jsxs(xe,{children:["This will permanently delete the"," ",e.jsx("strong",{children:i?ms[i.filing_type]:""})," filing."]})]}),e.jsxs(je,{children:[e.jsx(ye,{children:"Cancel"}),e.jsx(ge,{variant:"destructive",onClick:u,children:"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(ns,{className:"h-5 w-5 text-primary"})," Statutory Filings"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"Manage PF ECR, ESI, PT, TDS and other statutory filing records"})]}),K&&e.jsxs(C,{size:"sm",onClick:ae,children:[e.jsx(ke,{className:"mr-1.5 h-3.5 w-3.5"})," New Filing"]})]}),e.jsx(oe,{columns:A,data:(v==null?void 0:v.results)??[],isLoading:J,searchPlaceholder:"Search filings...",emptyMessage:"No statutory filings yet",emptyDescription:"Create your first statutory filing record.",totalCount:(v==null?void 0:v.count)??0,pagination:H,onPaginationChange:Q,sorting:z,onSortingChange:L,globalFilter:ee,onGlobalFilterChange:q,actions:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs($,{value:g||"__all__",onValueChange:s,children:[e.jsx(O,{className:"w-[140px] h-9",children:e.jsx(I,{placeholder:"All types"})}),e.jsxs(U,{children:[e.jsx(r,{value:"__all__",children:"All Types"}),e.jsx(r,{value:"pf_ecr",children:"PF ECR"}),e.jsx(r,{value:"esi_return",children:"ESI Return"}),e.jsx(r,{value:"pt_return",children:"PT Return"}),e.jsx(r,{value:"tds_24q",children:"TDS 24Q"}),e.jsx(r,{value:"form16",children:"Form 16"})]})]}),e.jsxs($,{value:S||"__all__",onValueChange:k,children:[e.jsx(O,{className:"w-[150px] h-9",children:e.jsx(I,{placeholder:"All statuses"})}),e.jsxs(U,{children:[e.jsx(r,{value:"__all__",children:"All Statuses"}),e.jsx(r,{value:"pending",children:"Pending"}),e.jsx(r,{value:"generated",children:"Generated"}),e.jsx(r,{value:"validated",children:"Validated"}),e.jsx(r,{value:"submitted",children:"Submitted"}),e.jsx(r,{value:"acknowledged",children:"Acknowledged"}),e.jsx(r,{value:"rejected",children:"Rejected"}),e.jsx(r,{value:"amended",children:"Amended"})]})]})]})}),e.jsx(ve,{open:a,onOpenChange:t,children:e.jsxs(fe,{size:"lg",children:[e.jsxs(Se,{children:[e.jsx(Ne,{children:n?"Edit Filing":"New Statutory Filing"}),e.jsx(Ce,{children:n?"Update the statutory filing details.":"Create a new statutory filing record."})]}),e.jsxs("form",{onSubmit:_.handleSubmit(X),className:"flex-1 overflow-y-auto px-6 py-5 space-y-4",children:[e.jsxs("div",{children:[e.jsx(m,{children:"Company *"}),e.jsx(_e,{value:_.watch("company")??null,onValueChange:d=>_.setValue("company",d,{shouldValidate:!0}),onSearch:N,selectedLabel:(n==null?void 0:n.company_name)??void 0,options:((M==null?void 0:M.results)??[]).map(d=>({value:d.id,label:d.name,hint:d.code})),placeholder:"Select company",searchPlaceholder:"Search companies...",className:"mt-1.5"}),_.formState.errors.company&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:_.formState.errors.company.message})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(m,{children:"Filing Type *"}),e.jsxs($,{value:_.watch("filing_type"),onValueChange:d=>_.setValue("filing_type",d),children:[e.jsx(O,{className:"mt-1.5",children:e.jsx(I,{placeholder:"Select type"})}),e.jsxs(U,{children:[e.jsx(r,{value:"pf_ecr",children:"PF ECR"}),e.jsx(r,{value:"esi_return",children:"ESI Return"}),e.jsx(r,{value:"pt_return",children:"PT Return"}),e.jsx(r,{value:"tds_24q",children:"TDS 24Q"}),e.jsx(r,{value:"form16",children:"Form 16"})]})]})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Financial Year *"}),e.jsx(F,{..._.register("financial_year"),className:"mt-1.5",placeholder:"e.g. 2025-2026"}),_.formState.errors.financial_year&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:_.formState.errors.financial_year.message})]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsxs("div",{children:[e.jsx(m,{children:"Period Year *"}),e.jsx(F,{..._.register("period_year"),type:"number",className:"mt-1.5"}),_.formState.errors.period_year&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:_.formState.errors.period_year.message})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Period Month"}),e.jsx(F,{..._.register("period_month"),type:"number",min:1,max:12,className:"mt-1.5",placeholder:"1-12"})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Period Quarter"}),e.jsx(F,{..._.register("period_quarter"),type:"number",min:1,max:4,className:"mt-1.5",placeholder:"1-4"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(m,{children:"Due Date *"}),e.jsx(F,{..._.register("due_date"),type:"date",className:"mt-1.5"}),_.formState.errors.due_date&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:_.formState.errors.due_date.message})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Submission Date"}),e.jsx(F,{..._.register("submission_date"),type:"date",className:"mt-1.5"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(m,{children:"Total Amount"}),e.jsx(F,{..._.register("total_amount"),type:"number",step:"0.01",className:"mt-1.5",placeholder:"0.00"})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Employee Count"}),e.jsx(F,{..._.register("employee_count"),type:"number",className:"mt-1.5",placeholder:"0"})]})]})]}),e.jsxs(be,{children:[e.jsx(C,{variant:"outline",onClick:()=>t(!1),children:"Cancel"}),e.jsx(C,{onClick:_.handleSubmit(X),disabled:B.isPending||Z.isPending,children:n?"Save Changes":"Create Filing"})]})]})})]})}const wn=we({company:b().min(1,"Company is required"),compliance_type:le(["pf","esi","pt","tds","factory_act"],{required_error:"Compliance type is required"}),description:b().min(1,"Description is required"),due_date:Me("Due date is required"),recurrence:le(["monthly","quarterly","annual"],{required_error:"Recurrence is required"}),status:le(["upcoming","due_soon","overdue","completed"]).optional(),risk_level:le(["green","yellow","red"]).optional()}),qn={green:"success",yellow:"warning",red:"destructive"},Pn={green:"On Track",yellow:"Due Soon",red:"Overdue"},En={upcoming:"Upcoming",due_soon:"Due Soon",overdue:"Overdue",completed:"Completed"},Rn={upcoming:"outline",due_soon:"warning",overdue:"destructive",completed:"success"},Dn={pf:"Provident Fund",esi:"ESI",pt:"Professional Tax",tds:"TDS",factory_act:"Factory Act"};function xr(){const[a,t]=j.useState(!1),[n,x]=j.useState(null),[i,y]=j.useState(null),[g,D]=j.useState(""),[S,W]=j.useState(""),{pagination:w,setPagination:K,sorting:Y,setSorting:H,globalFilter:Q,setGlobalFilter:z,queryParams:L}=de(),ee={...L,...g&&{compliance_type:g},...S&&{status:S}},{data:q,isLoading:G}=Ft(ee),h=At(),v=wt(),J=qt(),[B,Z]=j.useState(""),{data:l}=Qe({search:B||void 0}),o=Fe({resolver:Ae(wn),defaultValues:{company:"",compliance_type:"pf",description:"",due_date:"",recurrence:"monthly",status:"upcoming",risk_level:"green"}});function N(){x(null),o.reset({company:"",compliance_type:"pf",description:"",due_date:"",recurrence:"monthly",status:"upcoming",risk_level:"green"}),t(!0)}function M(s){x(s),o.reset({company:s.company,compliance_type:s.compliance_type,description:s.description,due_date:s.due_date,recurrence:s.recurrence,status:s.status,risk_level:s.risk_level}),t(!0)}function _(s){const k={company:s.company,compliance_type:s.compliance_type,description:s.description,due_date:s.due_date,recurrence:s.recurrence,status:s.status,risk_level:s.risk_level};n?v.mutate({id:n.id,...k},{onSuccess:()=>t(!1)}):h.mutate(k,{onSuccess:()=>t(!1)})}function ae(){i&&J.mutate(i.id,{onSuccess:()=>y(null)})}function se(s){D(s==="__all__"?"":s),K(k=>({...k,pageIndex:0}))}function X(s){W(s==="__all__"?"":s),K(k=>({...k,pageIndex:0}))}const u=[{key:"compliance_type",header:"Type",render:s=>e.jsx(ne,{variant:"outline",children:Dn[s.compliance_type]})},{key:"description",header:"Description",render:s=>e.jsx("span",{className:"font-medium text-slate-900",children:s.description})},{key:"due_date",header:"Due Date",render:s=>{const k=new Date(s.due_date),d=k<new Date&&s.status!=="completed";return e.jsx("span",{className:d?"text-red-600 font-medium":"",children:k.toLocaleDateString()})}},{key:"recurrence",header:"Recurrence",render:s=>s.recurrence.charAt(0).toUpperCase()+s.recurrence.slice(1)},{key:"status",header:"Status",render:s=>e.jsx(ne,{variant:Rn[s.status],children:En[s.status]})},{key:"risk_level",header:"Risk",render:s=>e.jsx(ne,{variant:qn[s.risk_level],children:Pn[s.risk_level]})},{key:"actions",header:"",className:"w-10",render:s=>e.jsxs(ue,{open:(i==null?void 0:i.id)===s.id,onOpenChange:k=>!k&&y(null),children:[e.jsxs(Ee,{children:[e.jsx(Re,{asChild:!0,children:e.jsx(C,{variant:"ghost",size:"icon-sm",children:e.jsx(Le,{className:"h-4 w-4"})})}),e.jsxs(De,{align:"end",children:[e.jsxs(te,{onClick:()=>M(s),children:[e.jsx($e,{className:"mr-2 h-3.5 w-3.5"})," Edit"]}),e.jsx(Te,{asChild:!0,children:e.jsxs(te,{className:"text-red-600",onClick:()=>y(s),children:[e.jsx(Ve,{className:"mr-2 h-3.5 w-3.5"})," Delete"]})})]})]}),e.jsxs(me,{children:[e.jsxs(he,{children:[e.jsx(pe,{children:"Delete calendar entry?"}),e.jsxs(xe,{children:["This will permanently delete the entry for"," ",e.jsx("strong",{children:i==null?void 0:i.description}),"."]})]}),e.jsxs(je,{children:[e.jsx(ye,{children:"Cancel"}),e.jsx(ge,{variant:"destructive",onClick:ae,children:"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(ls,{className:"h-5 w-5 text-primary"})," Compliance Calendar"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"Track all statutory compliance deadlines and due dates"})]}),e.jsxs(C,{size:"sm",onClick:N,children:[e.jsx(ke,{className:"mr-1.5 h-3.5 w-3.5"})," Add Entry"]})]}),e.jsx(oe,{columns:u,data:(q==null?void 0:q.results)??[],isLoading:G,searchPlaceholder:"Search calendar...",emptyMessage:"No calendar entries yet",emptyDescription:"Add your first compliance deadline.",totalCount:(q==null?void 0:q.count)??0,pagination:w,onPaginationChange:K,sorting:Y,onSortingChange:H,globalFilter:Q,onGlobalFilterChange:z,actions:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs($,{value:g||"__all__",onValueChange:se,children:[e.jsx(O,{className:"w-[160px] h-9",children:e.jsx(I,{placeholder:"All types"})}),e.jsxs(U,{children:[e.jsx(r,{value:"__all__",children:"All Types"}),e.jsx(r,{value:"pf",children:"Provident Fund"}),e.jsx(r,{value:"esi",children:"ESI"}),e.jsx(r,{value:"pt",children:"Professional Tax"}),e.jsx(r,{value:"tds",children:"TDS"}),e.jsx(r,{value:"factory_act",children:"Factory Act"})]})]}),e.jsxs($,{value:S||"__all__",onValueChange:X,children:[e.jsx(O,{className:"w-[140px] h-9",children:e.jsx(I,{placeholder:"All statuses"})}),e.jsxs(U,{children:[e.jsx(r,{value:"__all__",children:"All Statuses"}),e.jsx(r,{value:"upcoming",children:"Upcoming"}),e.jsx(r,{value:"due_soon",children:"Due Soon"}),e.jsx(r,{value:"overdue",children:"Overdue"}),e.jsx(r,{value:"completed",children:"Completed"})]})]})]})}),e.jsx(ve,{open:a,onOpenChange:t,children:e.jsxs(fe,{size:"lg",children:[e.jsxs(Se,{children:[e.jsx(Ne,{children:n?"Edit Calendar Entry":"New Calendar Entry"}),e.jsx(Ce,{children:n?"Update the compliance calendar entry.":"Add a new compliance deadline to the calendar."})]}),e.jsxs("form",{onSubmit:o.handleSubmit(_),className:"flex-1 overflow-y-auto px-6 py-5 space-y-4",children:[e.jsxs("div",{children:[e.jsx(m,{children:"Company *"}),e.jsx(_e,{value:o.watch("company")??null,onValueChange:s=>o.setValue("company",s,{shouldValidate:!0}),onSearch:Z,selectedLabel:(n==null?void 0:n.company_name)??void 0,options:((l==null?void 0:l.results)??[]).map(s=>({value:s.id,label:s.name,hint:s.code})),placeholder:"Select company",searchPlaceholder:"Search companies...",className:"mt-1.5"}),o.formState.errors.company&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:o.formState.errors.company.message})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(m,{children:"Compliance Type *"}),e.jsxs($,{value:o.watch("compliance_type"),onValueChange:s=>o.setValue("compliance_type",s),children:[e.jsx(O,{className:"mt-1.5",children:e.jsx(I,{})}),e.jsxs(U,{children:[e.jsx(r,{value:"pf",children:"Provident Fund"}),e.jsx(r,{value:"esi",children:"ESI"}),e.jsx(r,{value:"pt",children:"Professional Tax"}),e.jsx(r,{value:"tds",children:"TDS"}),e.jsx(r,{value:"factory_act",children:"Factory Act"})]})]})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Recurrence *"}),e.jsxs($,{value:o.watch("recurrence"),onValueChange:s=>o.setValue("recurrence",s),children:[e.jsx(O,{className:"mt-1.5",children:e.jsx(I,{})}),e.jsxs(U,{children:[e.jsx(r,{value:"monthly",children:"Monthly"}),e.jsx(r,{value:"quarterly",children:"Quarterly"}),e.jsx(r,{value:"annual",children:"Annual"})]})]})]})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Description *"}),e.jsx(F,{...o.register("description"),className:"mt-1.5",placeholder:"e.g. PF ECR filing for January"}),o.formState.errors.description&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:o.formState.errors.description.message})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsxs("div",{children:[e.jsx(m,{children:"Due Date *"}),e.jsx(F,{...o.register("due_date"),type:"date",className:"mt-1.5"}),o.formState.errors.due_date&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:o.formState.errors.due_date.message})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Status"}),e.jsxs($,{value:o.watch("status")??"upcoming",onValueChange:s=>o.setValue("status",s),children:[e.jsx(O,{className:"mt-1.5",children:e.jsx(I,{})}),e.jsxs(U,{children:[e.jsx(r,{value:"upcoming",children:"Upcoming"}),e.jsx(r,{value:"due_soon",children:"Due Soon"}),e.jsx(r,{value:"overdue",children:"Overdue"}),e.jsx(r,{value:"completed",children:"Completed"})]})]})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Risk Level"}),e.jsxs($,{value:o.watch("risk_level")??"green",onValueChange:s=>o.setValue("risk_level",s),children:[e.jsx(O,{className:"mt-1.5",children:e.jsx(I,{})}),e.jsxs(U,{children:[e.jsx(r,{value:"green",children:"On Track"}),e.jsx(r,{value:"yellow",children:"Due Soon"}),e.jsx(r,{value:"red",children:"Overdue"})]})]})]})]})]}),e.jsxs(be,{children:[e.jsx(C,{variant:"outline",onClick:()=>t(!1),children:"Cancel"}),e.jsx(C,{onClick:o.handleSubmit(_),disabled:h.isPending||v.isPending,children:n?"Save Changes":"Add Entry"})]})]})})]})}const Tn={pf_ecr:"PF ECR",esi_return:"ESI Return",pt_return:"PT Return",tds_24q:"TDS 24Q",form16:"Form 16"};function Vn(a){const t=a.period_month?`${String(a.period_month).padStart(2,"0")}/${a.period_year}`:a.period_quarter?`Q${a.period_quarter}/${a.period_year}`:String(a.period_year);return`${Tn[a.filing_type]} — ${t}`}const Ln=we({original_filing:b().min(1,"Original filing is required"),amendment_reason:b().min(1,"Reason is required"),portal_token:b().optional(),status:le(["pending","approved","submitted"]).optional()}),$n={pending:"secondary",approved:"success",submitted:"warning"},On={pending:"Pending",approved:"Approved",submitted:"Submitted"};function jr(){const[a,t]=j.useState(!1),[n,x]=j.useState(null),[i,y]=j.useState(null),[g,D]=j.useState(""),{hasPermission:S}=Oe(),W=S("compliance","amendment","create"),{pagination:w,setPagination:K,sorting:Y,setSorting:H,globalFilter:Q,setGlobalFilter:z,queryParams:L}=de(),ee={...L,...g&&{status:g}},{data:q,isLoading:G}=Pt(ee),h=Et(),v=Rt(),J=Dt(),[B,Z]=j.useState(""),{data:l}=us({search:B||void 0}),o=Fe({resolver:Ae(Ln),defaultValues:{original_filing:"",amendment_reason:"",portal_token:"",status:"pending"}});function N(){x(null),o.reset({original_filing:"",amendment_reason:"",portal_token:"",status:"pending"}),t(!0)}function M(u){x(u),o.reset({original_filing:u.original_filing,amendment_reason:u.amendment_reason,portal_token:u.portal_token,status:u.status}),t(!0)}function _(u){const s={original_filing:u.original_filing,amendment_reason:u.amendment_reason,portal_token:u.portal_token,status:u.status};n?v.mutate({id:n.id,...s},{onSuccess:()=>t(!1)}):h.mutate(s,{onSuccess:()=>t(!1)})}function ae(){i&&J.mutate(i.id,{onSuccess:()=>y(null)})}function se(u){D(u==="__all__"?"":u),K(s=>({...s,pageIndex:0}))}const X=[{key:"original_filing_display",header:"Original Filing",render:u=>e.jsx("span",{className:"font-medium text-slate-900",children:u.original_filing_display??u.original_filing.substring(0,8)})},{key:"amendment_reason",header:"Reason",render:u=>e.jsx("span",{className:"text-slate-600 truncate max-w-[250px] block",children:u.amendment_reason})},{key:"status",header:"Status",render:u=>e.jsx(ne,{variant:$n[u.status],children:On[u.status]})},{key:"approved_by_display",header:"Approved By",render:u=>u.approved_by_display??"--"},{key:"submitted_at",header:"Submitted At",render:u=>u.submitted_at?new Date(u.submitted_at).toLocaleDateString():"--"},{key:"created_at",header:"Created",render:u=>new Date(u.created_at).toLocaleDateString()},{key:"actions",header:"",className:"w-10",render:u=>e.jsxs(ue,{open:(i==null?void 0:i.id)===u.id,onOpenChange:s=>!s&&y(null),children:[e.jsxs(Ee,{children:[e.jsx(Re,{asChild:!0,children:e.jsx(C,{variant:"ghost",size:"icon-sm",children:e.jsx(Le,{className:"h-4 w-4"})})}),e.jsxs(De,{align:"end",children:[W&&e.jsxs(te,{onClick:()=>M(u),children:[e.jsx($e,{className:"mr-2 h-3.5 w-3.5"})," Edit"]}),W&&e.jsx(Te,{asChild:!0,children:e.jsxs(te,{className:"text-red-600",onClick:()=>y(u),children:[e.jsx(Ve,{className:"mr-2 h-3.5 w-3.5"})," Delete"]})})]})]}),e.jsxs(me,{children:[e.jsxs(he,{children:[e.jsx(pe,{children:"Delete amendment?"}),e.jsx(xe,{children:"This will permanently delete the amendment record."})]}),e.jsxs(je,{children:[e.jsx(ye,{children:"Cancel"}),e.jsx(ge,{variant:"destructive",onClick:ae,children:"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"})," Amendments"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"Track amendments to previously submitted statutory filings"})]}),W&&e.jsxs(C,{size:"sm",onClick:N,children:[e.jsx(ke,{className:"mr-1.5 h-3.5 w-3.5"})," New Amendment"]})]}),e.jsx(oe,{columns:X,data:(q==null?void 0:q.results)??[],isLoading:G,searchPlaceholder:"Search amendments...",emptyMessage:"No amendments yet",emptyDescription:"Create your first filing amendment.",totalCount:(q==null?void 0:q.count)??0,pagination:w,onPaginationChange:K,sorting:Y,onSortingChange:H,globalFilter:Q,onGlobalFilterChange:z,actions:e.jsxs($,{value:g||"__all__",onValueChange:se,children:[e.jsx(O,{className:"w-[140px] h-9",children:e.jsx(I,{placeholder:"All statuses"})}),e.jsxs(U,{children:[e.jsx(r,{value:"__all__",children:"All Statuses"}),e.jsx(r,{value:"pending",children:"Pending"}),e.jsx(r,{value:"approved",children:"Approved"}),e.jsx(r,{value:"submitted",children:"Submitted"})]})]})}),e.jsx(ve,{open:a,onOpenChange:t,children:e.jsxs(fe,{size:"lg",children:[e.jsxs(Se,{children:[e.jsx(Ne,{children:n?"Edit Amendment":"New Amendment"}),e.jsx(Ce,{children:n?"Update the amendment details.":"File an amendment to a submitted filing."})]}),e.jsxs("form",{onSubmit:o.handleSubmit(_),className:"flex-1 overflow-y-auto px-6 py-5 space-y-4",children:[e.jsxs("div",{children:[e.jsx(m,{children:"Original Filing *"}),e.jsx(_e,{value:o.watch("original_filing")??null,onValueChange:u=>o.setValue("original_filing",u,{shouldValidate:!0}),onSearch:Z,selectedLabel:(n==null?void 0:n.original_filing_display)??void 0,options:((l==null?void 0:l.results)??[]).map(u=>({value:u.id,label:Vn(u)})),placeholder:"Select filing",searchPlaceholder:"Search filings...",className:"mt-1.5"}),o.formState.errors.original_filing&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:o.formState.errors.original_filing.message})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Amendment Reason *"}),e.jsx(He,{...o.register("amendment_reason"),className:"mt-1.5",rows:3,placeholder:"Describe what needs to be amended and why..."}),o.formState.errors.amendment_reason&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:o.formState.errors.amendment_reason.message})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(m,{children:"Portal Token"}),e.jsx(F,{...o.register("portal_token"),className:"mt-1.5",placeholder:"Optional"})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Status"}),e.jsxs($,{value:o.watch("status")??"pending",onValueChange:u=>o.setValue("status",u),children:[e.jsx(O,{className:"mt-1.5",children:e.jsx(I,{})}),e.jsxs(U,{children:[e.jsx(r,{value:"pending",children:"Pending"}),e.jsx(r,{value:"approved",children:"Approved"}),e.jsx(r,{value:"submitted",children:"Submitted"})]})]})]})]})]}),e.jsxs(be,{children:[e.jsx(C,{variant:"outline",onClick:()=>t(!1),children:"Cancel"}),e.jsx(C,{onClick:o.handleSubmit(_),disabled:h.isPending||v.isPending,children:n?"Save Changes":"Create Amendment"})]})]})})]})}const In={pf_ecr:"PF ECR",esi_return:"ESI Return",pt_return:"PT Return",tds_24q:"TDS 24Q",form16:"Form 16"};function Un(a){const t=a.period_month?`${String(a.period_month).padStart(2,"0")}/${a.period_year}`:a.period_quarter?`Q${a.period_quarter}/${a.period_year}`:String(a.period_year);return`${In[a.filing_type]} — ${t}`}const Qn=os(we({company:b().min(1,"Company is required"),filing:b().optional(),compliance_type:b().min(1,"Compliance type is required"),penalty_type:le(["late_filing","incorrect_filing","non_compliance"],{required_error:"Penalty type is required"}),amount:b().min(1,"Amount is required"),interest:b().optional(),authority:b().min(1,"Authority is required"),notice_date:We(),due_date:We(),status:le(["open","paid","appealed","closed"]).optional()}),"notice_date","due_date"),Kn={open:"destructive",paid:"success",appealed:"warning",closed:"secondary"},Mn={open:"Open",paid:"Paid",appealed:"Appealed",closed:"Closed"},hs={late_filing:"Late Filing",incorrect_filing:"Incorrect Filing",non_compliance:"Non-Compliance"};function yr(){const[a,t]=j.useState(!1),[n,x]=j.useState(null),[i,y]=j.useState(null),[g,D]=j.useState(""),[S,W]=j.useState(""),{hasPermission:w}=Oe(),K=w("compliance","penalty","update"),{pagination:Y,setPagination:H,sorting:Q,setSorting:z,globalFilter:L,setGlobalFilter:ee,queryParams:q}=de(),G={...q,...g&&{penalty_type:g},...S&&{status:S}},{data:h,isLoading:v}=Tt(G),J=Vt(),B=Lt(),Z=$t(),l=Fe({resolver:Ae(Qn),defaultValues:{company:"",filing:"",compliance_type:"",penalty_type:"late_filing",amount:"",interest:"0",authority:"",notice_date:"",due_date:"",status:"open"}}),[o,N]=j.useState(""),{data:M}=Qe({search:o||void 0}),[_,ae]=j.useState(""),se=l.watch("company"),{data:X}=us({search:_||void 0,...se?{company:se}:{}});function u(){x(null),l.reset({company:"",filing:"",compliance_type:"",penalty_type:"late_filing",amount:"",interest:"0",authority:"",notice_date:"",due_date:"",status:"open"}),t(!0)}function s(c){x(c),l.reset({company:c.company,filing:c.filing??"",compliance_type:c.compliance_type,penalty_type:c.penalty_type,amount:c.amount,interest:c.interest,authority:c.authority,notice_date:c.notice_date??"",due_date:c.due_date??"",status:c.status}),t(!0)}function k(c){const re={company:c.company,filing:c.filing||void 0,compliance_type:c.compliance_type,penalty_type:c.penalty_type,amount:c.amount,interest:c.interest,authority:c.authority,notice_date:c.notice_date||void 0,due_date:c.due_date||void 0,status:c.status};n?B.mutate({id:n.id,...re},{onSuccess:()=>t(!1)}):J.mutate(re,{onSuccess:()=>t(!1)})}function A(){i&&Z.mutate(i.id,{onSuccess:()=>y(null)})}function d(c){D(c==="__all__"?"":c),H(re=>({...re,pageIndex:0}))}function ie(c){W(c==="__all__"?"":c),H(re=>({...re,pageIndex:0}))}const ze=[{key:"penalty_type",header:"Type",render:c=>e.jsx(ne,{variant:"outline",children:hs[c.penalty_type]})},{key:"compliance_type",header:"Compliance",render:c=>e.jsx("span",{className:"font-medium text-slate-900",children:c.compliance_type.toUpperCase()})},{key:"authority",header:"Authority",render:c=>c.authority},{key:"amount",header:"Amount",render:c=>e.jsxs("span",{className:"font-mono text-[13px] font-medium text-red-600",children:["Rs. ",Number(c.amount).toLocaleString("en-IN")]})},{key:"interest",header:"Interest",render:c=>e.jsxs("span",{className:"font-mono text-[13px] text-slate-500",children:["Rs. ",Number(c.interest).toLocaleString("en-IN")]})},{key:"due_date",header:"Due Date",render:c=>c.due_date?new Date(c.due_date).toLocaleDateString():"--"},{key:"status",header:"Status",render:c=>e.jsx(ne,{variant:Kn[c.status],children:Mn[c.status]})},{key:"actions",header:"",className:"w-10",render:c=>e.jsxs(ue,{open:(i==null?void 0:i.id)===c.id,onOpenChange:re=>!re&&y(null),children:[e.jsxs(Ee,{children:[e.jsx(Re,{asChild:!0,children:e.jsx(C,{variant:"ghost",size:"icon-sm",children:e.jsx(Le,{className:"h-4 w-4"})})}),e.jsxs(De,{align:"end",children:[K&&e.jsxs(te,{onClick:()=>s(c),children:[e.jsx($e,{className:"mr-2 h-3.5 w-3.5"})," Edit"]}),K&&e.jsx(Te,{asChild:!0,children:e.jsxs(te,{className:"text-red-600",onClick:()=>y(c),children:[e.jsx(Ve,{className:"mr-2 h-3.5 w-3.5"})," Delete"]})})]})]}),e.jsxs(me,{children:[e.jsxs(he,{children:[e.jsx(pe,{children:"Delete penalty record?"}),e.jsxs(xe,{children:["This will permanently delete the"," ",e.jsx("strong",{children:i?hs[i.penalty_type]:""})," ","penalty of ",e.jsxs("strong",{children:["Rs. ",i?Number(i.amount).toLocaleString("en-IN"):""]}),"."]})]}),e.jsxs(je,{children:[e.jsx(ye,{children:"Cancel"}),e.jsx(ge,{variant:"destructive",onClick:A,children:"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(es,{className:"h-5 w-5 text-primary"})," Penalties"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"Track statutory non-compliance penalties and their resolution"})]}),K&&e.jsxs(C,{size:"sm",onClick:u,children:[e.jsx(ke,{className:"mr-1.5 h-3.5 w-3.5"})," Record Penalty"]})]}),e.jsx(oe,{columns:ze,data:(h==null?void 0:h.results)??[],isLoading:v,searchPlaceholder:"Search penalties...",emptyMessage:"No penalty records",emptyDescription:"No statutory penalties have been recorded.",totalCount:(h==null?void 0:h.count)??0,pagination:Y,onPaginationChange:H,sorting:Q,onSortingChange:z,globalFilter:L,onGlobalFilterChange:ee,actions:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs($,{value:g||"__all__",onValueChange:d,children:[e.jsx(O,{className:"w-[150px] h-9",children:e.jsx(I,{placeholder:"All types"})}),e.jsxs(U,{children:[e.jsx(r,{value:"__all__",children:"All Types"}),e.jsx(r,{value:"late_filing",children:"Late Filing"}),e.jsx(r,{value:"incorrect_filing",children:"Incorrect Filing"}),e.jsx(r,{value:"non_compliance",children:"Non-Compliance"})]})]}),e.jsxs($,{value:S||"__all__",onValueChange:ie,children:[e.jsx(O,{className:"w-[130px] h-9",children:e.jsx(I,{placeholder:"All statuses"})}),e.jsxs(U,{children:[e.jsx(r,{value:"__all__",children:"All Statuses"}),e.jsx(r,{value:"open",children:"Open"}),e.jsx(r,{value:"paid",children:"Paid"}),e.jsx(r,{value:"appealed",children:"Appealed"}),e.jsx(r,{value:"closed",children:"Closed"})]})]})]})}),e.jsx(ve,{open:a,onOpenChange:t,children:e.jsxs(fe,{size:"lg",children:[e.jsxs(Se,{children:[e.jsx(Ne,{children:n?"Edit Penalty":"Record Penalty"}),e.jsx(Ce,{children:n?"Update the penalty record details.":"Record a new statutory penalty."})]}),e.jsxs("form",{onSubmit:l.handleSubmit(k),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(m,{children:"Company *"}),e.jsx(_e,{value:l.watch("company")??null,onValueChange:c=>{l.setValue("company",c,{shouldValidate:!0}),l.setValue("filing","",{shouldValidate:!0})},onSearch:N,selectedLabel:(n==null?void 0:n.company_name)??void 0,options:((M==null?void 0:M.results)??[]).map(c=>({value:c.id,label:c.name,hint:c.code})),placeholder:"Select company",searchPlaceholder:"Search companies...",className:"mt-1.5"}),l.formState.errors.company&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:l.formState.errors.company.message})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Filing"}),e.jsx(_e,{value:l.watch("filing")??null,onValueChange:c=>l.setValue("filing",c,{shouldValidate:!0}),onSearch:ae,options:((X==null?void 0:X.results)??[]).map(c=>({value:c.id,label:Un(c)})),placeholder:"Select filing (optional)",searchPlaceholder:"Search filings...",className:"mt-1.5"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(m,{children:"Compliance Type *"}),e.jsx(F,{...l.register("compliance_type"),className:"mt-1.5",placeholder:"e.g. pf, esi, pt"}),l.formState.errors.compliance_type&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:l.formState.errors.compliance_type.message})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Penalty Type *"}),e.jsxs($,{value:l.watch("penalty_type"),onValueChange:c=>l.setValue("penalty_type",c),children:[e.jsx(O,{className:"mt-1.5",children:e.jsx(I,{})}),e.jsxs(U,{children:[e.jsx(r,{value:"late_filing",children:"Late Filing"}),e.jsx(r,{value:"incorrect_filing",children:"Incorrect Filing"}),e.jsx(r,{value:"non_compliance",children:"Non-Compliance"})]})]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(m,{children:"Amount *"}),e.jsx(F,{...l.register("amount"),type:"number",step:"0.01",className:"mt-1.5",placeholder:"0.00"}),l.formState.errors.amount&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:l.formState.errors.amount.message})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Interest"}),e.jsx(F,{...l.register("interest"),type:"number",step:"0.01",className:"mt-1.5",placeholder:"0.00"})]})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Authority *"}),e.jsx(F,{...l.register("authority"),className:"mt-1.5",placeholder:"e.g. EPFO, ESIC"}),l.formState.errors.authority&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:l.formState.errors.authority.message})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsxs("div",{children:[e.jsx(m,{children:"Notice Date"}),e.jsx(F,{...l.register("notice_date"),type:"date",className:"mt-1.5",max:l.watch("due_date")||void 0})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Due Date"}),e.jsx(F,{...l.register("due_date"),type:"date",className:"mt-1.5",min:l.watch("notice_date")||void 0})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Status"}),e.jsxs($,{value:l.watch("status")??"open",onValueChange:c=>l.setValue("status",c),children:[e.jsx(O,{className:"mt-1.5",children:e.jsx(I,{})}),e.jsxs(U,{children:[e.jsx(r,{value:"open",children:"Open"}),e.jsx(r,{value:"paid",children:"Paid"}),e.jsx(r,{value:"appealed",children:"Appealed"}),e.jsx(r,{value:"closed",children:"Closed"})]})]})]})]})]}),e.jsxs(be,{children:[e.jsx(C,{variant:"outline",onClick:()=>t(!1),children:"Cancel"}),e.jsx(C,{onClick:l.handleSubmit(k),disabled:J.isPending||B.isPending,children:n?"Save Changes":"Record Penalty"})]})]})})]})}const zn=os(we({company:b().min(1,"Company is required"),authority:b().min(1,"Authority is required"),reference_number:b().optional(),correspondence_type:le(["notice","inquiry","response","acknowledgment"],{required_error:"Correspondence type is required"}),subject:b().min(1,"Subject is required"),communication_date:Me("Communication date is required"),response_due_date:We(),status:le(["received","in_progress","responded","closed"]).optional(),assigned_to:b().optional()}),"communication_date","response_due_date"),Gn={received:"warning",in_progress:"secondary",responded:"success",closed:"secondary"},Bn={received:"Received",in_progress:"In Progress",responded:"Responded",closed:"Closed"},Wn={notice:"Notice",inquiry:"Inquiry",response:"Response",acknowledgment:"Acknowledgment"};function gr(){const[a,t]=j.useState(!1),[n,x]=j.useState(null),[i,y]=j.useState(null),[g,D]=j.useState(""),[S,W]=j.useState(""),{hasPermission:w}=Oe(),K=w("compliance","correspondence","create"),Y=w("compliance","correspondence","update"),{pagination:H,setPagination:Q,sorting:z,setSorting:L,globalFilter:ee,setGlobalFilter:q,queryParams:G}=de(),h={...G,...g&&{correspondence_type:g},...S&&{status:S}},{data:v,isLoading:J}=Ot(h),B=It(),Z=Ut(),l=Qt(),[o,N]=j.useState(""),{data:M}=Qe({search:o||void 0}),_=Fe({resolver:Ae(zn),defaultValues:{company:"",authority:"",reference_number:"",correspondence_type:"notice",subject:"",communication_date:"",response_due_date:"",status:"received",assigned_to:""}});function ae(){x(null),_.reset({company:"",authority:"",reference_number:"",correspondence_type:"notice",subject:"",communication_date:"",response_due_date:"",status:"received",assigned_to:""}),t(!0)}function se(d){x(d),_.reset({company:d.company,authority:d.authority,reference_number:d.reference_number,correspondence_type:d.correspondence_type,subject:d.subject,communication_date:d.communication_date,response_due_date:d.response_due_date??"",status:d.status,assigned_to:d.assigned_to??""}),t(!0)}function X(d){const ie={company:d.company,authority:d.authority,reference_number:d.reference_number||void 0,correspondence_type:d.correspondence_type,subject:d.subject,communication_date:d.communication_date,response_due_date:d.response_due_date||void 0,status:d.status,assigned_to:d.assigned_to||void 0};n?Z.mutate({id:n.id,...ie},{onSuccess:()=>t(!1)}):B.mutate(ie,{onSuccess:()=>t(!1)})}function u(){i&&l.mutate(i.id,{onSuccess:()=>y(null)})}function s(d){D(d==="__all__"?"":d),Q(ie=>({...ie,pageIndex:0}))}function k(d){W(d==="__all__"?"":d),Q(ie=>({...ie,pageIndex:0}))}const A=[{key:"authority",header:"Authority",render:d=>e.jsx("span",{className:"font-medium text-slate-900",children:d.authority})},{key:"reference_number",header:"Reference No.",render:d=>e.jsx("span",{className:"font-mono text-[13px]",children:d.reference_number||"--"})},{key:"correspondence_type",header:"Type",render:d=>e.jsx(ne,{variant:"outline",children:Wn[d.correspondence_type]})},{key:"subject",header:"Subject",render:d=>e.jsx("span",{className:"truncate max-w-[200px] inline-block",children:d.subject})},{key:"communication_date",header:"Date",render:d=>new Date(d.communication_date).toLocaleDateString()},{key:"response_due_date",header:"Response Due",render:d=>d.response_due_date?new Date(d.response_due_date).toLocaleDateString():"--"},{key:"status",header:"Status",render:d=>e.jsx(ne,{variant:Gn[d.status],children:Bn[d.status]})},{key:"actions",header:"",className:"w-10",render:d=>e.jsxs(ue,{open:(i==null?void 0:i.id)===d.id,onOpenChange:ie=>!ie&&y(null),children:[e.jsxs(Ee,{children:[e.jsx(Re,{asChild:!0,children:e.jsx(C,{variant:"ghost",size:"icon-sm",children:e.jsx(Le,{className:"h-4 w-4"})})}),e.jsxs(De,{align:"end",children:[Y&&e.jsxs(te,{onClick:()=>se(d),children:[e.jsx($e,{className:"mr-2 h-3.5 w-3.5"})," Edit"]}),Y&&e.jsx(Te,{asChild:!0,children:e.jsxs(te,{className:"text-red-600",onClick:()=>y(d),children:[e.jsx(Ve,{className:"mr-2 h-3.5 w-3.5"})," Delete"]})})]})]}),e.jsxs(me,{children:[e.jsxs(he,{children:[e.jsx(pe,{children:"Delete correspondence?"}),e.jsxs(xe,{children:["This will permanently delete the correspondence"," ",e.jsx("strong",{children:(i==null?void 0:i.reference_number)||(i==null?void 0:i.subject)})," from"," ",e.jsx("strong",{children:i==null?void 0:i.authority}),"."]})]}),e.jsxs(je,{children:[e.jsx(ye,{children:"Cancel"}),e.jsx(ge,{variant:"destructive",onClick:u,children:"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"})," Regulatory Correspondence"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"Manage regulatory notices, inquiries, and responses"})]}),K&&e.jsxs(C,{size:"sm",onClick:ae,children:[e.jsx(ke,{className:"mr-1.5 h-3.5 w-3.5"})," Add Correspondence"]})]}),e.jsx(oe,{columns:A,data:(v==null?void 0:v.results)??[],isLoading:J,searchPlaceholder:"Search correspondence...",emptyMessage:"No correspondence records",emptyDescription:"No regulatory correspondence has been recorded.",totalCount:(v==null?void 0:v.count)??0,pagination:H,onPaginationChange:Q,sorting:z,onSortingChange:L,globalFilter:ee,onGlobalFilterChange:q,actions:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs($,{value:g||"__all__",onValueChange:s,children:[e.jsx(O,{className:"w-[160px] h-9",children:e.jsx(I,{placeholder:"All types"})}),e.jsxs(U,{children:[e.jsx(r,{value:"__all__",children:"All Types"}),e.jsx(r,{value:"notice",children:"Notice"}),e.jsx(r,{value:"inquiry",children:"Inquiry"}),e.jsx(r,{value:"response",children:"Response"}),e.jsx(r,{value:"acknowledgment",children:"Acknowledgment"})]})]}),e.jsxs($,{value:S||"__all__",onValueChange:k,children:[e.jsx(O,{className:"w-[140px] h-9",children:e.jsx(I,{placeholder:"All statuses"})}),e.jsxs(U,{children:[e.jsx(r,{value:"__all__",children:"All Statuses"}),e.jsx(r,{value:"received",children:"Received"}),e.jsx(r,{value:"in_progress",children:"In Progress"}),e.jsx(r,{value:"responded",children:"Responded"}),e.jsx(r,{value:"closed",children:"Closed"})]})]})]})}),e.jsx(ve,{open:a,onOpenChange:t,children:e.jsxs(fe,{size:"lg",children:[e.jsxs(Se,{children:[e.jsx(Ne,{children:n?"Edit Correspondence":"Add Correspondence"}),e.jsx(Ce,{children:n?"Update the correspondence details.":"Record a new regulatory correspondence."})]}),e.jsxs("form",{onSubmit:_.handleSubmit(X),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(m,{children:"Company *"}),e.jsx(_e,{value:_.watch("company")??null,onValueChange:d=>_.setValue("company",d,{shouldValidate:!0}),onSearch:N,selectedLabel:(n==null?void 0:n.company_name)??void 0,options:((M==null?void 0:M.results)??[]).map(d=>({value:d.id,label:d.name,hint:d.code})),placeholder:"Select company",searchPlaceholder:"Search companies...",className:"mt-1.5"}),_.formState.errors.company&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:_.formState.errors.company.message})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Authority *"}),e.jsx(F,{..._.register("authority"),className:"mt-1.5",placeholder:"e.g. EPFO, ESIC"}),_.formState.errors.authority&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:_.formState.errors.authority.message})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(m,{children:"Reference Number"}),e.jsx(F,{..._.register("reference_number"),className:"mt-1.5",placeholder:"Reference no."})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Correspondence Type *"}),e.jsxs($,{value:_.watch("correspondence_type"),onValueChange:d=>_.setValue("correspondence_type",d),children:[e.jsx(O,{className:"mt-1.5",children:e.jsx(I,{})}),e.jsxs(U,{children:[e.jsx(r,{value:"notice",children:"Notice"}),e.jsx(r,{value:"inquiry",children:"Inquiry"}),e.jsx(r,{value:"response",children:"Response"}),e.jsx(r,{value:"acknowledgment",children:"Acknowledgment"})]})]})]})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Subject *"}),e.jsx(F,{..._.register("subject"),className:"mt-1.5",placeholder:"Correspondence subject"}),_.formState.errors.subject&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:_.formState.errors.subject.message})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsxs("div",{children:[e.jsx(m,{children:"Communication Date *"}),e.jsx(F,{..._.register("communication_date"),type:"date",className:"mt-1.5",max:_.watch("response_due_date")||void 0}),_.formState.errors.communication_date&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:_.formState.errors.communication_date.message})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Response Due Date"}),e.jsx(F,{..._.register("response_due_date"),type:"date",className:"mt-1.5",min:_.watch("communication_date")||void 0})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Status"}),e.jsxs($,{value:_.watch("status")??"received",onValueChange:d=>_.setValue("status",d),children:[e.jsx(O,{className:"mt-1.5",children:e.jsx(I,{})}),e.jsxs(U,{children:[e.jsx(r,{value:"received",children:"Received"}),e.jsx(r,{value:"in_progress",children:"In Progress"}),e.jsx(r,{value:"responded",children:"Responded"}),e.jsx(r,{value:"closed",children:"Closed"})]})]})]})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Assigned To"}),e.jsx(cs,{value:_.watch("assigned_to")??"",onValueChange:d=>_.setValue("assigned_to",d,{shouldValidate:!0}),className:"mt-1.5"})]})]}),e.jsxs(be,{children:[e.jsx(C,{variant:"outline",onClick:()=>t(!1),children:"Cancel"}),e.jsx(C,{onClick:_.handleSubmit(X),disabled:B.isPending||Z.isPending,children:n?"Save Changes":"Add Correspondence"})]})]})})]})}const Hn=we({company:b().min(1,"Company is required"),branch:b().min(1,"Branch is required"),register_type:le(["muster_roll","overtime","leave","accident","hazard"],{required_error:"Register type is required"}),month:Ie.number().min(1,"Month is required").max(12,"Month must be 1-12"),year:Ie.number().min(2e3,"Year is required").max(2099,"Invalid year"),status:le(["draft","finalized","submitted"]).optional()}),Yn={draft:"secondary",finalized:"warning",submitted:"success"},Jn={draft:"Draft",finalized:"Finalized",submitted:"Submitted"},ps={muster_roll:"Muster Roll",overtime:"Overtime",leave:"Leave",accident:"Accident",hazard:"Hazard"};function _r(){const[a,t]=j.useState(!1),[n,x]=j.useState(null),[i,y]=j.useState(null),[g,D]=j.useState(""),[S,W]=j.useState(""),{hasPermission:w}=Oe(),K=w("compliance","factory_register","create"),{pagination:Y,setPagination:H,sorting:Q,setSorting:z,globalFilter:L,setGlobalFilter:ee,queryParams:q}=de(),G={...q,...g&&{register_type:g},...S&&{status:S}},{data:h,isLoading:v}=Kt(G),J=Mt(),B=zt(),Z=Gt(),l=Fe({resolver:Ae(Hn),defaultValues:{company:"",branch:"",register_type:"muster_roll",month:new Date().getMonth()+1,year:new Date().getFullYear(),status:"draft"}}),[o,N]=j.useState(""),{data:M}=Qe({search:o||void 0}),[_,ae]=j.useState(""),se=l.watch("company"),{data:X}=ds({search:_||void 0,...se?{company:se}:{}});function u(){x(null),l.reset({company:"",branch:"",register_type:"muster_roll",month:new Date().getMonth()+1,year:new Date().getFullYear(),status:"draft"}),t(!0)}function s(c){x(c),l.reset({company:c.company,branch:c.branch,register_type:c.register_type,month:c.month,year:c.year,status:c.status}),t(!0)}function k(c){const re={company:c.company,branch:c.branch,register_type:c.register_type,month:c.month,year:c.year,status:c.status};n?B.mutate({id:n.id,...re},{onSuccess:()=>t(!1)}):J.mutate(re,{onSuccess:()=>t(!1)})}function A(){i&&Z.mutate(i.id,{onSuccess:()=>y(null)})}function d(c){D(c==="__all__"?"":c),H(re=>({...re,pageIndex:0}))}function ie(c){W(c==="__all__"?"":c),H(re=>({...re,pageIndex:0}))}const ze=[{key:"branch_name",header:"Branch",render:c=>e.jsx("span",{className:"font-medium text-slate-900",children:c.branch_name??c.branch})},{key:"register_type",header:"Register Type",render:c=>e.jsx(ne,{variant:"outline",children:ps[c.register_type]})},{key:"month",header:"Month / Year",render:c=>e.jsxs("span",{className:"text-slate-700",children:[String(c.month).padStart(2,"0")," / ",c.year]})},{key:"status",header:"Status",render:c=>e.jsx(ne,{variant:Yn[c.status],children:Jn[c.status]})},{key:"actions",header:"",className:"w-10",render:c=>e.jsxs(ue,{open:(i==null?void 0:i.id)===c.id,onOpenChange:re=>!re&&y(null),children:[e.jsxs(Ee,{children:[e.jsx(Re,{asChild:!0,children:e.jsx(C,{variant:"ghost",size:"icon-sm",children:e.jsx(Le,{className:"h-4 w-4"})})}),e.jsxs(De,{align:"end",children:[K&&e.jsxs(te,{onClick:()=>s(c),children:[e.jsx($e,{className:"mr-2 h-3.5 w-3.5"})," Edit"]}),K&&e.jsx(Te,{asChild:!0,children:e.jsxs(te,{className:"text-red-600",onClick:()=>y(c),children:[e.jsx(Ve,{className:"mr-2 h-3.5 w-3.5"})," Delete"]})})]})]}),e.jsxs(me,{children:[e.jsxs(he,{children:[e.jsx(pe,{children:"Delete factory register?"}),e.jsxs(xe,{children:["This will permanently delete the"," ",e.jsx("strong",{children:i?ps[i.register_type]:""})," ","register for ",e.jsxs("strong",{children:[i==null?void 0:i.month,"/",i==null?void 0:i.year]}),"."]})]}),e.jsxs(je,{children:[e.jsx(ye,{children:"Cancel"}),e.jsx(ge,{variant:"destructive",onClick:A,children:"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(Bs,{className:"h-5 w-5 text-primary"})," Factory Registers"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"Manage statutory factory registers and submissions"})]}),K&&e.jsxs(C,{size:"sm",onClick:u,children:[e.jsx(ke,{className:"mr-1.5 h-3.5 w-3.5"})," Add Register"]})]}),e.jsx(oe,{columns:ze,data:(h==null?void 0:h.results)??[],isLoading:v,searchPlaceholder:"Search registers...",emptyMessage:"No factory registers",emptyDescription:"No factory registers have been created.",totalCount:(h==null?void 0:h.count)??0,pagination:Y,onPaginationChange:H,sorting:Q,onSortingChange:z,globalFilter:L,onGlobalFilterChange:ee,actions:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs($,{value:g||"__all__",onValueChange:d,children:[e.jsx(O,{className:"w-[150px] h-9",children:e.jsx(I,{placeholder:"All types"})}),e.jsxs(U,{children:[e.jsx(r,{value:"__all__",children:"All Types"}),e.jsx(r,{value:"muster_roll",children:"Muster Roll"}),e.jsx(r,{value:"overtime",children:"Overtime"}),e.jsx(r,{value:"leave",children:"Leave"}),e.jsx(r,{value:"accident",children:"Accident"}),e.jsx(r,{value:"hazard",children:"Hazard"})]})]}),e.jsxs($,{value:S||"__all__",onValueChange:ie,children:[e.jsx(O,{className:"w-[130px] h-9",children:e.jsx(I,{placeholder:"All statuses"})}),e.jsxs(U,{children:[e.jsx(r,{value:"__all__",children:"All Statuses"}),e.jsx(r,{value:"draft",children:"Draft"}),e.jsx(r,{value:"finalized",children:"Finalized"}),e.jsx(r,{value:"submitted",children:"Submitted"})]})]})]})}),e.jsx(ve,{open:a,onOpenChange:t,children:e.jsxs(fe,{size:"lg",children:[e.jsxs(Se,{children:[e.jsx(Ne,{children:n?"Edit Register":"Add Register"}),e.jsx(Ce,{children:n?"Update the factory register details.":"Create a new factory register entry."})]}),e.jsxs("form",{onSubmit:l.handleSubmit(k),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(m,{children:"Company *"}),e.jsx(_e,{value:l.watch("company")??null,onValueChange:c=>{l.setValue("company",c,{shouldValidate:!0}),l.setValue("branch","",{shouldValidate:!0})},onSearch:N,selectedLabel:(n==null?void 0:n.company_name)??void 0,options:((M==null?void 0:M.results)??[]).map(c=>({value:c.id,label:c.name,hint:c.code})),placeholder:"Select company",searchPlaceholder:"Search companies...",className:"mt-1.5"}),l.formState.errors.company&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:l.formState.errors.company.message})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Branch *"}),e.jsx(_e,{value:l.watch("branch")??null,onValueChange:c=>l.setValue("branch",c,{shouldValidate:!0}),onSearch:ae,selectedLabel:(n==null?void 0:n.branch_name)??void 0,options:((X==null?void 0:X.results)??[]).map(c=>({value:c.id,label:c.name,hint:c.code})),placeholder:se?"Select branch":"Select company first",searchPlaceholder:"Search branches...",disabled:!se,className:"mt-1.5"}),l.formState.errors.branch&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:l.formState.errors.branch.message})]})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Register Type *"}),e.jsxs($,{value:l.watch("register_type"),onValueChange:c=>l.setValue("register_type",c),children:[e.jsx(O,{className:"mt-1.5",children:e.jsx(I,{})}),e.jsxs(U,{children:[e.jsx(r,{value:"muster_roll",children:"Muster Roll"}),e.jsx(r,{value:"overtime",children:"Overtime"}),e.jsx(r,{value:"leave",children:"Leave"}),e.jsx(r,{value:"accident",children:"Accident"}),e.jsx(r,{value:"hazard",children:"Hazard"})]})]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsxs("div",{children:[e.jsx(m,{children:"Month *"}),e.jsx(F,{...l.register("month"),type:"number",min:1,max:12,className:"mt-1.5",placeholder:"1-12"}),l.formState.errors.month&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:l.formState.errors.month.message})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Year *"}),e.jsx(F,{...l.register("year"),type:"number",min:2e3,max:2099,className:"mt-1.5",placeholder:"2025"}),l.formState.errors.year&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:l.formState.errors.year.message})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Status"}),e.jsxs($,{value:l.watch("status")??"draft",onValueChange:c=>l.setValue("status",c),children:[e.jsx(O,{className:"mt-1.5",children:e.jsx(I,{})}),e.jsxs(U,{children:[e.jsx(r,{value:"draft",children:"Draft"}),e.jsx(r,{value:"finalized",children:"Finalized"}),e.jsx(r,{value:"submitted",children:"Submitted"})]})]})]})]})]}),e.jsxs(be,{children:[e.jsx(C,{variant:"outline",onClick:()=>t(!1),children:"Cancel"}),e.jsx(C,{onClick:l.handleSubmit(k),disabled:J.isPending||B.isPending,children:n?"Save Changes":"Add Register"})]})]})})]})}const Zn=we({company:b().min(1,"Company is required"),name:b().min(1,"Name is required"),license_number:b().min(1,"License number is required"),contact_person:b().min(1,"Contact person is required"),phone:b().min(1,"Phone is required"),email:b().email("Valid email is required"),address:b().optional(),registration_date:Me("Registration date is required"),status:le(["active","suspended","terminated"]).optional()}),Xn={active:"success",suspended:"warning",terminated:"destructive"},ea={active:"Active",suspended:"Suspended",terminated:"Terminated"};function vr(){const[a,t]=j.useState(!1),[n,x]=j.useState(null),[i,y]=j.useState(null),[g,D]=j.useState(""),{hasPermission:S}=Oe(),W=S("compliance","contractor","create"),w=S("compliance","contractor","update"),{pagination:K,setPagination:Y,sorting:H,setSorting:Q,globalFilter:z,setGlobalFilter:L,queryParams:ee}=de(),q={...ee,...g&&{status:g}},{data:G,isLoading:h}=As(q),v=Bt(),J=Wt(),B=Ht(),[Z,l]=j.useState(""),{data:o}=Qe({search:Z||void 0}),N=Fe({resolver:Ae(Zn),defaultValues:{company:"",name:"",license_number:"",contact_person:"",phone:"",email:"",address:"",registration_date:"",status:"active"}});function M(){x(null),N.reset({company:"",name:"",license_number:"",contact_person:"",phone:"",email:"",address:"",registration_date:"",status:"active"}),t(!0)}function _(s){x(s),N.reset({company:s.company,name:s.name,license_number:s.license_number,contact_person:s.contact_person,phone:s.phone,email:s.email,address:s.address,registration_date:s.registration_date,status:s.status}),t(!0)}function ae(s){const k={company:s.company,name:s.name,license_number:s.license_number,contact_person:s.contact_person,phone:s.phone,email:s.email,address:s.address||void 0,registration_date:s.registration_date,status:s.status};n?J.mutate({id:n.id,...k},{onSuccess:()=>t(!1)}):v.mutate(k,{onSuccess:()=>t(!1)})}function se(){i&&B.mutate(i.id,{onSuccess:()=>y(null)})}function X(s){D(s==="__all__"?"":s),Y(k=>({...k,pageIndex:0}))}const u=[{key:"name",header:"Name",render:s=>e.jsx("span",{className:"font-medium text-slate-900",children:s.name})},{key:"license_number",header:"License No.",render:s=>e.jsx("span",{className:"font-mono text-[13px]",children:s.license_number})},{key:"contact_person",header:"Contact Person",render:s=>s.contact_person},{key:"phone",header:"Phone",render:s=>s.phone},{key:"email",header:"Email",render:s=>e.jsx("span",{className:"text-[13px] text-slate-500",children:s.email})},{key:"registration_date",header:"Registered",render:s=>new Date(s.registration_date).toLocaleDateString()},{key:"status",header:"Status",render:s=>e.jsx(ne,{variant:Xn[s.status],children:ea[s.status]})},{key:"actions",header:"",className:"w-10",render:s=>e.jsxs(ue,{open:(i==null?void 0:i.id)===s.id,onOpenChange:k=>!k&&y(null),children:[e.jsxs(Ee,{children:[e.jsx(Re,{asChild:!0,children:e.jsx(C,{variant:"ghost",size:"icon-sm",children:e.jsx(Le,{className:"h-4 w-4"})})}),e.jsxs(De,{align:"end",children:[w&&e.jsxs(te,{onClick:()=>_(s),children:[e.jsx($e,{className:"mr-2 h-3.5 w-3.5"})," Edit"]}),w&&e.jsx(Te,{asChild:!0,children:e.jsxs(te,{className:"text-red-600",onClick:()=>y(s),children:[e.jsx(Ve,{className:"mr-2 h-3.5 w-3.5"})," Delete"]})})]})]}),e.jsxs(me,{children:[e.jsxs(he,{children:[e.jsx(pe,{children:"Delete contractor?"}),e.jsxs(xe,{children:["This will permanently delete contractor"," ",e.jsx("strong",{children:i==null?void 0:i.name})," (License: ",i==null?void 0:i.license_number,")."]})]}),e.jsxs(je,{children:[e.jsx(ye,{children:"Cancel"}),e.jsx(ge,{variant:"destructive",onClick:se,children:"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"})," Contractors"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"Manage contractor registrations and compliance tracking"})]}),W&&e.jsxs(C,{size:"sm",onClick:M,children:[e.jsx(ke,{className:"mr-1.5 h-3.5 w-3.5"})," Add Contractor"]})]}),e.jsx(oe,{columns:u,data:(G==null?void 0:G.results)??[],isLoading:h,searchPlaceholder:"Search contractors...",emptyMessage:"No contractors",emptyDescription:"No contractors have been registered.",totalCount:(G==null?void 0:G.count)??0,pagination:K,onPaginationChange:Y,sorting:H,onSortingChange:Q,globalFilter:z,onGlobalFilterChange:L,actions:e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs($,{value:g||"__all__",onValueChange:X,children:[e.jsx(O,{className:"w-[140px] h-9",children:e.jsx(I,{placeholder:"All statuses"})}),e.jsxs(U,{children:[e.jsx(r,{value:"__all__",children:"All Statuses"}),e.jsx(r,{value:"active",children:"Active"}),e.jsx(r,{value:"suspended",children:"Suspended"}),e.jsx(r,{value:"terminated",children:"Terminated"})]})]})})}),e.jsx(ve,{open:a,onOpenChange:t,children:e.jsxs(fe,{size:"lg",children:[e.jsxs(Se,{children:[e.jsx(Ne,{children:n?"Edit Contractor":"Add Contractor"}),e.jsx(Ce,{children:n?"Update the contractor details.":"Register a new contractor."})]}),e.jsxs("form",{onSubmit:N.handleSubmit(ae),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(m,{children:"Company *"}),e.jsx(_e,{value:N.watch("company")??null,onValueChange:s=>N.setValue("company",s,{shouldValidate:!0}),onSearch:l,selectedLabel:(n==null?void 0:n.company_name)??void 0,options:((o==null?void 0:o.results)??[]).map(s=>({value:s.id,label:s.name,hint:s.code})),placeholder:"Select company",searchPlaceholder:"Search companies...",className:"mt-1.5"}),N.formState.errors.company&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:N.formState.errors.company.message})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Contractor Name *"}),e.jsx(F,{...N.register("name"),className:"mt-1.5",placeholder:"Contractor name"}),N.formState.errors.name&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:N.formState.errors.name.message})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(m,{children:"License Number *"}),e.jsx(F,{...N.register("license_number"),className:"mt-1.5",placeholder:"License number"}),N.formState.errors.license_number&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:N.formState.errors.license_number.message})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Contact Person *"}),e.jsx(F,{...N.register("contact_person"),className:"mt-1.5",placeholder:"Contact person"}),N.formState.errors.contact_person&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:N.formState.errors.contact_person.message})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(m,{children:"Phone *"}),e.jsx(gs,{...N.register("phone"),className:"mt-1.5",placeholder:"Phone number"}),N.formState.errors.phone&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:N.formState.errors.phone.message})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Email *"}),e.jsx(F,{...N.register("email"),type:"email",className:"mt-1.5",placeholder:"Email address"}),N.formState.errors.email&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:N.formState.errors.email.message})]})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Address"}),e.jsx(F,{...N.register("address"),className:"mt-1.5",placeholder:"Full address"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(m,{children:"Registration Date *"}),e.jsx(F,{...N.register("registration_date"),type:"date",className:"mt-1.5"}),N.formState.errors.registration_date&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:N.formState.errors.registration_date.message})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Status"}),e.jsxs($,{value:N.watch("status")??"active",onValueChange:s=>N.setValue("status",s),children:[e.jsx(O,{className:"mt-1.5",children:e.jsx(I,{})}),e.jsxs(U,{children:[e.jsx(r,{value:"active",children:"Active"}),e.jsx(r,{value:"suspended",children:"Suspended"}),e.jsx(r,{value:"terminated",children:"Terminated"})]})]})]})]})]}),e.jsxs(be,{children:[e.jsx(C,{variant:"outline",onClick:()=>t(!1),children:"Cancel"}),e.jsx(C,{onClick:N.handleSubmit(ae),disabled:v.isPending||J.isPending,children:n?"Save Changes":"Add Contractor"})]})]})})]})}const sa=os(we({contractor:b().min(1,"Contractor is required"),name:b().min(1,"Name is required"),external_id:b().min(1,"External ID is required"),phone:b().optional(),skill_category:b().min(1,"Skill category is required"),wage_category:b().min(1,"Wage category is required"),joining_date:Me("Joining date is required"),exit_date:We(),documents_status:le(["pending","complete","incomplete"]).optional(),status:le(["active","inactive","exited"]).optional()}),"joining_date","exit_date"),ta={active:"success",inactive:"secondary",exited:"destructive"},na={active:"Active",inactive:"Inactive",exited:"Exited"},aa={pending:"warning",complete:"success",incomplete:"destructive"},ra={pending:"Pending",complete:"Complete",incomplete:"Incomplete"};function fr(){const[a,t]=j.useState(!1),[n,x]=j.useState(null),[i,y]=j.useState(null),[g,D]=j.useState(""),[S,W]=j.useState(""),{pagination:w,setPagination:K,sorting:Y,setSorting:H,globalFilter:Q,setGlobalFilter:z,queryParams:L}=de(),ee={...L,...g&&{status:g},...S&&{documents_status:S}},{data:q,isLoading:G}=ws(ee),h=Yt(),v=Jt(),J=Zt(),[B,Z]=j.useState(""),{data:l}=As({search:B||void 0}),o=Fe({resolver:Ae(sa),defaultValues:{contractor:"",name:"",external_id:"",phone:"",skill_category:"",wage_category:"",joining_date:"",exit_date:"",documents_status:"pending",status:"active"}});function N(){x(null),o.reset({contractor:"",name:"",external_id:"",phone:"",skill_category:"",wage_category:"",joining_date:"",exit_date:"",documents_status:"pending",status:"active"}),t(!0)}function M(s){x(s),o.reset({contractor:s.contractor,name:s.name,external_id:s.external_id,phone:s.phone,skill_category:s.skill_category,wage_category:s.wage_category,joining_date:s.joining_date,exit_date:s.exit_date??"",documents_status:s.documents_status,status:s.status}),t(!0)}function _(s){const k={contractor:s.contractor,name:s.name,external_id:s.external_id,phone:s.phone||void 0,skill_category:s.skill_category,wage_category:s.wage_category,joining_date:s.joining_date,exit_date:s.exit_date||void 0,documents_status:s.documents_status,status:s.status};n?v.mutate({id:n.id,...k},{onSuccess:()=>t(!1)}):h.mutate(k,{onSuccess:()=>t(!1)})}function ae(){i&&J.mutate(i.id,{onSuccess:()=>y(null)})}function se(s){D(s==="__all__"?"":s),K(k=>({...k,pageIndex:0}))}function X(s){W(s==="__all__"?"":s),K(k=>({...k,pageIndex:0}))}const u=[{key:"name",header:"Name",render:s=>e.jsx("span",{className:"font-medium text-slate-900",children:s.name})},{key:"contractor_name",header:"Contractor",render:s=>s.contractor_name??s.contractor},{key:"skill_category",header:"Skill",render:s=>s.skill_category},{key:"wage_category",header:"Wage Category",render:s=>s.wage_category},{key:"joining_date",header:"Joined",render:s=>new Date(s.joining_date).toLocaleDateString()},{key:"documents_status",header:"Documents",render:s=>e.jsx(ne,{variant:aa[s.documents_status],children:ra[s.documents_status]})},{key:"status",header:"Status",render:s=>e.jsx(ne,{variant:ta[s.status],children:na[s.status]})},{key:"actions",header:"",className:"w-10",render:s=>e.jsxs(ue,{open:(i==null?void 0:i.id)===s.id,onOpenChange:k=>!k&&y(null),children:[e.jsxs(Ee,{children:[e.jsx(Re,{asChild:!0,children:e.jsx(C,{variant:"ghost",size:"icon-sm",children:e.jsx(Le,{className:"h-4 w-4"})})}),e.jsxs(De,{align:"end",children:[e.jsxs(te,{onClick:()=>M(s),children:[e.jsx($e,{className:"mr-2 h-3.5 w-3.5"})," Edit"]}),e.jsx(Te,{asChild:!0,children:e.jsxs(te,{className:"text-red-600",onClick:()=>y(s),children:[e.jsx(Ve,{className:"mr-2 h-3.5 w-3.5"})," Delete"]})})]})]}),e.jsxs(me,{children:[e.jsxs(he,{children:[e.jsx(pe,{children:"Delete contract worker?"}),e.jsxs(xe,{children:["This will permanently delete worker"," ",e.jsx("strong",{children:i==null?void 0:i.name})," (ID: ",i==null?void 0:i.external_id,")."]})]}),e.jsxs(je,{children:[e.jsx(ye,{children:"Cancel"}),e.jsx(ge,{variant:"destructive",onClick:ae,children:"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(ss,{className:"h-5 w-5 text-primary"})," Contract Workers"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"Track contract labour details, documents, and compliance"})]}),e.jsxs(C,{size:"sm",onClick:N,children:[e.jsx(ke,{className:"mr-1.5 h-3.5 w-3.5"})," Add Worker"]})]}),e.jsx(oe,{columns:u,data:(q==null?void 0:q.results)??[],isLoading:G,searchPlaceholder:"Search workers...",emptyMessage:"No contract workers",emptyDescription:"No contract workers have been registered.",totalCount:(q==null?void 0:q.count)??0,pagination:w,onPaginationChange:K,sorting:Y,onSortingChange:H,globalFilter:Q,onGlobalFilterChange:z,actions:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs($,{value:S||"__all__",onValueChange:X,children:[e.jsx(O,{className:"w-[150px] h-9",children:e.jsx(I,{placeholder:"All documents"})}),e.jsxs(U,{children:[e.jsx(r,{value:"__all__",children:"All Documents"}),e.jsx(r,{value:"pending",children:"Pending"}),e.jsx(r,{value:"complete",children:"Complete"}),e.jsx(r,{value:"incomplete",children:"Incomplete"})]})]}),e.jsxs($,{value:g||"__all__",onValueChange:se,children:[e.jsx(O,{className:"w-[130px] h-9",children:e.jsx(I,{placeholder:"All statuses"})}),e.jsxs(U,{children:[e.jsx(r,{value:"__all__",children:"All Statuses"}),e.jsx(r,{value:"active",children:"Active"}),e.jsx(r,{value:"inactive",children:"Inactive"}),e.jsx(r,{value:"exited",children:"Exited"})]})]})]})}),e.jsx(ve,{open:a,onOpenChange:t,children:e.jsxs(fe,{size:"lg",children:[e.jsxs(Se,{children:[e.jsx(Ne,{children:n?"Edit Contract Worker":"Add Contract Worker"}),e.jsx(Ce,{children:n?"Update the contract worker details.":"Register a new contract worker."})]}),e.jsxs("form",{onSubmit:o.handleSubmit(_),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(m,{children:"Contractor *"}),e.jsx(_e,{value:o.watch("contractor")??null,onValueChange:s=>o.setValue("contractor",s,{shouldValidate:!0}),onSearch:Z,selectedLabel:(n==null?void 0:n.contractor_name)??void 0,options:((l==null?void 0:l.results)??[]).map(s=>({value:s.id,label:s.name,hint:s.license_number})),placeholder:"Select contractor",searchPlaceholder:"Search contractors...",className:"mt-1.5"}),o.formState.errors.contractor&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:o.formState.errors.contractor.message})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Worker Name *"}),e.jsx(F,{...o.register("name"),className:"mt-1.5",placeholder:"Full name"}),o.formState.errors.name&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:o.formState.errors.name.message})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(m,{children:"External ID *"}),e.jsx(F,{...o.register("external_id"),className:"mt-1.5",placeholder:"External worker ID"}),o.formState.errors.external_id&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:o.formState.errors.external_id.message})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Phone"}),e.jsx(gs,{...o.register("phone"),className:"mt-1.5",placeholder:"Phone number"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(m,{children:"Skill Category *"}),e.jsx(F,{...o.register("skill_category"),className:"mt-1.5",placeholder:"e.g. Skilled, Semi-skilled"}),o.formState.errors.skill_category&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:o.formState.errors.skill_category.message})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Wage Category *"}),e.jsx(F,{...o.register("wage_category"),className:"mt-1.5",placeholder:"e.g. Category A"}),o.formState.errors.wage_category&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:o.formState.errors.wage_category.message})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(m,{children:"Joining Date *"}),e.jsx(F,{...o.register("joining_date"),type:"date",className:"mt-1.5",max:o.watch("exit_date")||void 0}),o.formState.errors.joining_date&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:o.formState.errors.joining_date.message})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Exit Date"}),e.jsx(F,{...o.register("exit_date"),type:"date",className:"mt-1.5",min:o.watch("joining_date")||void 0})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(m,{children:"Documents Status"}),e.jsxs($,{value:o.watch("documents_status")??"pending",onValueChange:s=>o.setValue("documents_status",s),children:[e.jsx(O,{className:"mt-1.5",children:e.jsx(I,{})}),e.jsxs(U,{children:[e.jsx(r,{value:"pending",children:"Pending"}),e.jsx(r,{value:"complete",children:"Complete"}),e.jsx(r,{value:"incomplete",children:"Incomplete"})]})]})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Status"}),e.jsxs($,{value:o.watch("status")??"active",onValueChange:s=>o.setValue("status",s),children:[e.jsx(O,{className:"mt-1.5",children:e.jsx(I,{})}),e.jsxs(U,{children:[e.jsx(r,{value:"active",children:"Active"}),e.jsx(r,{value:"inactive",children:"Inactive"}),e.jsx(r,{value:"exited",children:"Exited"})]})]})]})]})]}),e.jsxs(be,{children:[e.jsx(C,{variant:"outline",onClick:()=>t(!1),children:"Cancel"}),e.jsx(C,{onClick:o.handleSubmit(_),disabled:h.isPending||v.isPending,children:n?"Save Changes":"Add Worker"})]})]})})]})}const ia=we({worker:b().min(1,"Worker is required"),audit_month:Ie.number().min(1,"Month is required").max(12,"Month must be 1-12"),audit_year:Ie.number().min(2e3,"Year is required").max(2099,"Invalid year"),prevailing_wage:b().min(1,"Prevailing wage is required"),actual_wage:b().min(1,"Actual wage is required"),compliance_status:le(["compliant","non_compliant","remediated"],{required_error:"Compliance status is required"}),remediation_action:b().optional()}),la={compliant:"success",non_compliant:"destructive",remediated:"warning"},ca={compliant:"Compliant",non_compliant:"Non-Compliant",remediated:"Remediated"};function Sr(){const[a,t]=j.useState(!1),[n,x]=j.useState(""),{hasPermission:i}=Oe(),y=i("compliance","wage_audit","create"),{pagination:g,setPagination:D,sorting:S,setSorting:W,globalFilter:w,setGlobalFilter:K,queryParams:Y}=de(),H={...Y,...n&&{compliance_status:n}},{data:Q,isLoading:z}=Xt(H),L=en(),[ee,q]=j.useState(""),{data:G}=ws({search:ee||void 0}),h=Fe({resolver:Ae(ia),defaultValues:{worker:"",audit_month:new Date().getMonth()+1,audit_year:new Date().getFullYear(),prevailing_wage:"",actual_wage:"",compliance_status:"compliant",remediation_action:""}});function v(){h.reset({worker:"",audit_month:new Date().getMonth()+1,audit_year:new Date().getFullYear(),prevailing_wage:"",actual_wage:"",compliance_status:"compliant",remediation_action:""}),t(!0)}function J(l){const o={worker:l.worker,audit_month:l.audit_month,audit_year:l.audit_year,prevailing_wage:l.prevailing_wage,actual_wage:l.actual_wage,compliance_status:l.compliance_status,remediation_action:l.remediation_action||void 0};L.mutate(o,{onSuccess:()=>t(!1)})}function B(l){x(l==="__all__"?"":l),D(o=>({...o,pageIndex:0}))}const Z=[{key:"worker_name",header:"Worker",render:l=>e.jsx("span",{className:"font-medium text-slate-900",children:l.worker_name??l.worker})},{key:"audit_month",header:"Audit Month / Year",render:l=>e.jsxs("span",{className:"text-slate-700",children:[String(l.audit_month).padStart(2,"0")," / ",l.audit_year]})},{key:"prevailing_wage",header:"Prevailing Wage",render:l=>e.jsxs("span",{className:"font-mono text-[13px] text-slate-700",children:["Rs. ",Number(l.prevailing_wage).toLocaleString("en-IN")]})},{key:"actual_wage",header:"Actual Wage",render:l=>e.jsxs("span",{className:"font-mono text-[13px] text-slate-700",children:["Rs. ",Number(l.actual_wage).toLocaleString("en-IN")]})},{key:"discrepancy_amount",header:"Discrepancy",render:l=>{const o=Number(l.discrepancy_amount);return e.jsxs("span",{className:`font-mono text-[13px] font-medium ${o>0?"text-red-600":"text-green-600"}`,children:["Rs. ",o.toLocaleString("en-IN")]})}},{key:"compliance_status",header:"Compliance",render:l=>e.jsx(ne,{variant:la[l.compliance_status],children:ca[l.compliance_status]})}];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"})," Wage Audits"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"Audit contract worker wages against prevailing rates"})]}),y&&e.jsxs(C,{size:"sm",onClick:v,children:[e.jsx(ke,{className:"mr-1.5 h-3.5 w-3.5"})," Add Audit"]})]}),e.jsx(oe,{columns:Z,data:(Q==null?void 0:Q.results)??[],isLoading:z,searchPlaceholder:"Search audits...",emptyMessage:"No wage audits",emptyDescription:"No wage audits have been recorded.",totalCount:(Q==null?void 0:Q.count)??0,pagination:g,onPaginationChange:D,sorting:S,onSortingChange:W,globalFilter:w,onGlobalFilterChange:K,actions:e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs($,{value:n||"__all__",onValueChange:B,children:[e.jsx(O,{className:"w-[160px] h-9",children:e.jsx(I,{placeholder:"All statuses"})}),e.jsxs(U,{children:[e.jsx(r,{value:"__all__",children:"All Statuses"}),e.jsx(r,{value:"compliant",children:"Compliant"}),e.jsx(r,{value:"non_compliant",children:"Non-Compliant"}),e.jsx(r,{value:"remediated",children:"Remediated"})]})]})})}),e.jsx(ve,{open:a,onOpenChange:t,children:e.jsxs(fe,{size:"lg",children:[e.jsxs(Se,{children:[e.jsx(Ne,{children:"Add Wage Audit"}),e.jsx(Ce,{children:"Record a new wage audit."})]}),e.jsxs("form",{onSubmit:h.handleSubmit(J),className:"flex-1 overflow-y-auto px-6 py-5 space-y-4",children:[e.jsxs("div",{children:[e.jsx(m,{children:"Worker *"}),e.jsx(_e,{value:h.watch("worker")??null,onValueChange:l=>h.setValue("worker",l,{shouldValidate:!0}),onSearch:q,options:((G==null?void 0:G.results)??[]).map(l=>({value:l.id,label:l.name,hint:l.external_id})),placeholder:"Select worker",searchPlaceholder:"Search workers...",className:"mt-1.5"}),h.formState.errors.worker&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:h.formState.errors.worker.message})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(m,{children:"Audit Month *"}),e.jsx(F,{...h.register("audit_month"),type:"number",min:1,max:12,className:"mt-1.5",placeholder:"1-12"}),h.formState.errors.audit_month&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:h.formState.errors.audit_month.message})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Audit Year *"}),e.jsx(F,{...h.register("audit_year"),type:"number",min:2e3,max:2099,className:"mt-1.5",placeholder:"2025"}),h.formState.errors.audit_year&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:h.formState.errors.audit_year.message})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(m,{children:"Prevailing Wage *"}),e.jsx(F,{...h.register("prevailing_wage"),type:"number",step:"0.01",className:"mt-1.5",placeholder:"0.00"}),h.formState.errors.prevailing_wage&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:h.formState.errors.prevailing_wage.message})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Actual Wage *"}),e.jsx(F,{...h.register("actual_wage"),type:"number",step:"0.01",className:"mt-1.5",placeholder:"0.00"}),h.formState.errors.actual_wage&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:h.formState.errors.actual_wage.message})]})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Compliance Status *"}),e.jsxs($,{value:h.watch("compliance_status"),onValueChange:l=>h.setValue("compliance_status",l),children:[e.jsx(O,{className:"mt-1.5",children:e.jsx(I,{})}),e.jsxs(U,{children:[e.jsx(r,{value:"compliant",children:"Compliant"}),e.jsx(r,{value:"non_compliant",children:"Non-Compliant"}),e.jsx(r,{value:"remediated",children:"Remediated"})]})]})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Remediation Action"}),e.jsx(F,{...h.register("remediation_action"),className:"mt-1.5",placeholder:"Describe remediation action taken"})]})]}),e.jsxs(be,{children:[e.jsx(C,{variant:"outline",onClick:()=>t(!1),children:"Cancel"}),e.jsx(C,{onClick:h.handleSubmit(J),disabled:L.isPending,children:"Add Audit"})]})]})})]})}const oa=we({law_code:b().min(1,"Law code is required"),amendment_title:b().min(1,"Title is required"),amendment_date:Me("Amendment date is required"),effective_from:b().min(1,"Effective date is required"),description:b().min(1,"Description is required"),source_url:b().optional(),status:le(["notified","assessed","applied","deferred"]).optional()}),da={notified:"secondary",assessed:"warning",applied:"success",deferred:"outline"};function Nr(){const[a,t]=j.useState(!1),[n,x]=j.useState(null),[i,y]=j.useState(null),{hasPermission:g}=Oe(),D=g("compliance","statutory_update","update"),{pagination:S,setPagination:W,sorting:w,setSorting:K,globalFilter:Y,setGlobalFilter:H,queryParams:Q}=de(),{data:z,isLoading:L}=sn(Q),ee=tn(),q=nn(),G=an(),h=Fe({resolver:Ae(oa),defaultValues:{law_code:"",amendment_title:"",amendment_date:"",effective_from:"",description:"",source_url:"",status:"notified"}});function v(){x(null),h.reset({law_code:"",amendment_title:"",amendment_date:"",effective_from:"",description:"",source_url:"",status:"notified"}),t(!0)}function J(o){x(o),h.reset({law_code:o.law_code,amendment_title:o.amendment_title,amendment_date:o.amendment_date,effective_from:o.effective_from,description:o.description,source_url:o.source_url,status:o.status}),t(!0)}function B(o){const N={...o};n?q.mutate({id:n.id,...N},{onSuccess:()=>t(!1)}):ee.mutate(N,{onSuccess:()=>t(!1)})}function Z(){i&&G.mutate(i.id,{onSuccess:()=>y(null)})}const l=[{key:"law_code",header:"Law Code",render:o=>e.jsx("span",{className:"font-medium text-slate-900",children:o.law_code})},{key:"amendment_title",header:"Title",render:o=>e.jsx("span",{className:"truncate max-w-[200px] block",children:o.amendment_title})},{key:"amendment_date",header:"Amendment Date",render:o=>new Date(o.amendment_date).toLocaleDateString()},{key:"effective_from",header:"Effective From",render:o=>new Date(o.effective_from).toLocaleDateString()},{key:"status",header:"Status",render:o=>e.jsx(ne,{variant:da[o.status],children:o.status})},{key:"auto_applied",header:"Auto Applied",render:o=>o.auto_applied?e.jsx(ne,{variant:"success",children:"Yes"}):e.jsx(ne,{variant:"outline",children:"No"})},{key:"actions",header:"",className:"w-10",render:o=>e.jsxs(ue,{open:(i==null?void 0:i.id)===o.id,onOpenChange:N=>!N&&y(null),children:[e.jsxs(Ee,{children:[e.jsx(Re,{asChild:!0,children:e.jsx(C,{variant:"ghost",size:"icon-sm",children:e.jsx(Le,{className:"h-4 w-4"})})}),e.jsxs(De,{align:"end",children:[D&&e.jsxs(te,{onClick:()=>J(o),children:[e.jsx($e,{className:"mr-2 h-3.5 w-3.5"})," Edit"]}),D&&e.jsx(Te,{asChild:!0,children:e.jsxs(te,{className:"text-red-600",onClick:()=>y(o),children:[e.jsx(Ve,{className:"mr-2 h-3.5 w-3.5"})," Delete"]})})]})]}),e.jsxs(me,{children:[e.jsxs(he,{children:[e.jsx(pe,{children:"Delete statutory update?"}),e.jsx(xe,{children:"This action cannot be undone."})]}),e.jsxs(je,{children:[e.jsx(ye,{children:"Cancel"}),e.jsx(ge,{variant:"destructive",onClick:Z,children:"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"})," Statutory Updates"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"Track regulatory amendments and their impact"})]}),D&&e.jsxs(C,{size:"sm",onClick:v,children:[e.jsx(ke,{className:"mr-1.5 h-3.5 w-3.5"})," New Update"]})]}),e.jsx(oe,{columns:l,data:(z==null?void 0:z.results)??[],isLoading:L,searchPlaceholder:"Search statutory updates...",emptyMessage:"No statutory updates",emptyDescription:"Add regulatory amendments to track.",totalCount:(z==null?void 0:z.count)??0,pagination:S,onPaginationChange:W,sorting:w,onSortingChange:K,globalFilter:Y,onGlobalFilterChange:H}),e.jsx(ve,{open:a,onOpenChange:t,children:e.jsxs(fe,{size:"lg",children:[e.jsxs(Se,{children:[e.jsx(Ne,{children:n?"Edit Statutory Update":"New Statutory Update"}),e.jsx(Ce,{children:n?"Update the regulatory amendment details.":"Record a new regulatory amendment."})]}),e.jsxs("form",{onSubmit:h.handleSubmit(B),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(m,{children:"Law Code *"}),e.jsx(F,{...h.register("law_code"),className:"mt-1.5",placeholder:"e.g. EPF_ACT_1952"}),h.formState.errors.law_code&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:h.formState.errors.law_code.message})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Status"}),e.jsxs($,{value:h.watch("status")??"notified",onValueChange:o=>h.setValue("status",o),children:[e.jsx(O,{className:"mt-1.5",children:e.jsx(I,{})}),e.jsxs(U,{children:[e.jsx(r,{value:"notified",children:"Notified"}),e.jsx(r,{value:"assessed",children:"Assessed"}),e.jsx(r,{value:"applied",children:"Applied"}),e.jsx(r,{value:"deferred",children:"Deferred"})]})]})]})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Amendment Title *"}),e.jsx(F,{...h.register("amendment_title"),className:"mt-1.5",placeholder:"Title of the amendment"}),h.formState.errors.amendment_title&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:h.formState.errors.amendment_title.message})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(m,{children:"Amendment Date *"}),e.jsx(F,{...h.register("amendment_date"),type:"date",className:"mt-1.5"})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Effective From *"}),e.jsx(F,{...h.register("effective_from"),type:"date",className:"mt-1.5"})]})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Description *"}),e.jsx(He,{...h.register("description"),className:"mt-1.5",rows:3,placeholder:"Describe the amendment and its impact..."})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Source URL"}),e.jsx(F,{...h.register("source_url"),className:"mt-1.5",placeholder:"https://..."})]})]}),e.jsxs(be,{children:[e.jsx(C,{variant:"outline",onClick:()=>t(!1),children:"Cancel"}),e.jsx(C,{onClick:h.handleSubmit(B),disabled:ee.isPending||q.isPending,children:n?"Save Changes":"Create Update"})]})]})})]})}const ua=we({company:b().min(1,"Company is required"),branch:b().optional(),financial_year:b().min(1,"Financial year is required"),external_member_name:b().optional(),external_member_org:b().optional(),last_training_date:We(),complaints_received_ytd:Ie.number().min(0).optional(),complaints_resolved_ytd:Ie.number().min(0).optional(),annual_report_filed:Cs().optional(),annual_report_date:We()});function Cr(){const[a,t]=j.useState(!1),[n,x]=j.useState(null),[i,y]=j.useState(null),{hasPermission:g}=Oe(),D=g("compliance","posh","create"),S=g("compliance","posh","update"),{pagination:W,setPagination:w,sorting:K,setSorting:Y,globalFilter:H,setGlobalFilter:Q,queryParams:z}=de(),{data:L,isLoading:ee}=rn(z),q=ln(),G=cn(),h=on(),v=Fe({resolver:Ae(ua),defaultValues:{company:"",branch:"",financial_year:"",external_member_name:"",external_member_org:"",last_training_date:"",complaints_received_ytd:0,complaints_resolved_ytd:0,annual_report_filed:!1,annual_report_date:""}}),[J,B]=j.useState(""),{data:Z}=Qe({search:J||void 0}),[l,o]=j.useState(""),N=v.watch("company"),{data:M}=ds({search:l||void 0,...N?{company:N}:{}});function _(){x(null),v.reset({company:"",branch:"",financial_year:"",external_member_name:"",external_member_org:"",last_training_date:"",complaints_received_ytd:0,complaints_resolved_ytd:0,annual_report_filed:!1,annual_report_date:""}),t(!0)}function ae(s){x(s),v.reset({company:s.company,branch:s.branch??"",financial_year:s.financial_year,external_member_name:s.external_member_name,external_member_org:s.external_member_org,last_training_date:s.last_training_date??"",complaints_received_ytd:s.complaints_received_ytd,complaints_resolved_ytd:s.complaints_resolved_ytd,annual_report_filed:s.annual_report_filed,annual_report_date:s.annual_report_date??""}),t(!0)}function se(s){const k={company:s.company,branch:s.branch||void 0,financial_year:s.financial_year,external_member_name:s.external_member_name||void 0,external_member_org:s.external_member_org||void 0,last_training_date:s.last_training_date||void 0,complaints_received_ytd:s.complaints_received_ytd,complaints_resolved_ytd:s.complaints_resolved_ytd,annual_report_filed:s.annual_report_filed,annual_report_date:s.annual_report_date||void 0};n?G.mutate({id:n.id,...k},{onSuccess:()=>t(!1)}):q.mutate(k,{onSuccess:()=>t(!1)})}function X(){i&&h.mutate(i.id,{onSuccess:()=>y(null)})}const u=[{key:"company_name",header:"Company",render:s=>e.jsx("span",{className:"font-medium text-slate-900",children:s.company_name??s.company})},{key:"branch_name",header:"Branch",render:s=>s.branch_name??s.branch??"--"},{key:"financial_year",header:"FY",render:s=>e.jsx("span",{className:"font-mono text-[13px]",children:s.financial_year})},{key:"icc_members",header:"ICC Members",render:s=>{var k;return e.jsx("span",{className:"font-medium text-slate-700",children:((k=s.icc_members)==null?void 0:k.length)??0})}},{key:"complaints_received_ytd",header:"Received YTD",render:s=>s.complaints_received_ytd},{key:"complaints_resolved_ytd",header:"Resolved YTD",render:s=>s.complaints_resolved_ytd},{key:"annual_report_filed",header:"Annual Report",render:s=>e.jsx(ne,{variant:s.annual_report_filed?"success":"destructive",children:s.annual_report_filed?"Yes":"No"})},{key:"last_training_date",header:"Last Training",render:s=>s.last_training_date?new Date(s.last_training_date).toLocaleDateString():"--"},{key:"actions",header:"",className:"w-10",render:s=>e.jsxs(ue,{open:(i==null?void 0:i.id)===s.id,onOpenChange:k=>!k&&y(null),children:[e.jsxs(Ee,{children:[e.jsx(Re,{asChild:!0,children:e.jsx(C,{variant:"ghost",size:"icon-sm",children:e.jsx(Le,{className:"h-4 w-4"})})}),e.jsxs(De,{align:"end",children:[S&&e.jsxs(te,{onClick:()=>ae(s),children:[e.jsx($e,{className:"mr-2 h-3.5 w-3.5"})," Edit"]}),S&&e.jsx(Te,{asChild:!0,children:e.jsxs(te,{className:"text-red-600",onClick:()=>y(s),children:[e.jsx(Ve,{className:"mr-2 h-3.5 w-3.5"})," Delete"]})})]})]}),e.jsxs(me,{children:[e.jsxs(he,{children:[e.jsx(pe,{children:"Delete POSH record?"}),e.jsxs(xe,{children:["This will permanently delete the POSH compliance record for"," ",e.jsx("strong",{children:(i==null?void 0:i.company_name)??(i==null?void 0:i.company)})," ","(FY: ",i==null?void 0:i.financial_year,")."]})]}),e.jsxs(je,{children:[e.jsx(ye,{children:"Cancel"}),e.jsx(ge,{variant:"destructive",onClick:X,children:"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(bs,{className:"h-5 w-5 text-primary"})," POSH Compliance"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"Track POSH (Prevention of Sexual Harassment) compliance across establishments"})]}),D&&e.jsxs(C,{size:"sm",onClick:_,children:[e.jsx(ke,{className:"mr-1.5 h-3.5 w-3.5"})," Add Record"]})]}),e.jsx(oe,{columns:u,data:(L==null?void 0:L.results)??[],isLoading:ee,searchPlaceholder:"Search POSH records...",emptyMessage:"No POSH records",emptyDescription:"No POSH compliance records have been created.",totalCount:(L==null?void 0:L.count)??0,pagination:W,onPaginationChange:w,sorting:K,onSortingChange:Y,globalFilter:H,onGlobalFilterChange:Q}),e.jsx(ve,{open:a,onOpenChange:t,children:e.jsxs(fe,{size:"lg",children:[e.jsxs(Se,{children:[e.jsx(Ne,{children:n?"Edit POSH Record":"Add POSH Record"}),e.jsx(Ce,{children:n?"Update the POSH compliance details.":"Create a new POSH compliance record."})]}),e.jsxs("form",{onSubmit:v.handleSubmit(se),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(m,{children:"Company *"}),e.jsx(_e,{value:v.watch("company")??null,onValueChange:s=>{v.setValue("company",s,{shouldValidate:!0}),v.setValue("branch","",{shouldValidate:!0})},onSearch:B,selectedLabel:(n==null?void 0:n.company_name)??void 0,options:((Z==null?void 0:Z.results)??[]).map(s=>({value:s.id,label:s.name,hint:s.code})),placeholder:"Select company",searchPlaceholder:"Search companies...",className:"mt-1.5"}),v.formState.errors.company&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:v.formState.errors.company.message})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Branch"}),e.jsx(_e,{value:v.watch("branch")??null,onValueChange:s=>v.setValue("branch",s,{shouldValidate:!0}),onSearch:o,selectedLabel:(n==null?void 0:n.branch_name)??void 0,options:((M==null?void 0:M.results)??[]).map(s=>({value:s.id,label:s.name,hint:s.code})),placeholder:N?"Select branch (optional)":"Select company first",searchPlaceholder:"Search branches...",disabled:!N,className:"mt-1.5"})]})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Financial Year *"}),e.jsx(F,{...v.register("financial_year"),className:"mt-1.5",placeholder:"e.g. 2025-26"}),v.formState.errors.financial_year&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:v.formState.errors.financial_year.message})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(m,{children:"External Member Name"}),e.jsx(F,{...v.register("external_member_name"),className:"mt-1.5",placeholder:"Name of external ICC member"})]}),e.jsxs("div",{children:[e.jsx(m,{children:"External Member Organization"}),e.jsx(F,{...v.register("external_member_org"),className:"mt-1.5",placeholder:"Organization name"})]})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Last Training Date"}),e.jsx(F,{...v.register("last_training_date"),type:"date",className:"mt-1.5"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(m,{children:"Complaints Received YTD"}),e.jsx(F,{...v.register("complaints_received_ytd"),type:"number",min:0,className:"mt-1.5",placeholder:"0"})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Complaints Resolved YTD"}),e.jsx(F,{...v.register("complaints_resolved_ytd"),type:"number",min:0,className:"mt-1.5",placeholder:"0"})]})]}),e.jsxs("div",{className:"flex items-center gap-3 pt-1",children:[e.jsx(ys,{id:"annual_report_filed",checked:v.watch("annual_report_filed")??!1,onCheckedChange:s=>v.setValue("annual_report_filed",s===!0)}),e.jsx(m,{htmlFor:"annual_report_filed",className:"cursor-pointer",children:"Annual report filed"})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Annual Report Date"}),e.jsx(F,{...v.register("annual_report_date"),type:"date",className:"mt-1.5"})]})]}),e.jsxs(be,{children:[e.jsx(C,{variant:"outline",onClick:()=>t(!1),children:"Cancel"}),e.jsx(C,{onClick:v.handleSubmit(se),disabled:q.isPending||G.isPending,children:n?"Save Changes":"Add Record"})]})]})})]})}const ma=we({company:b().min(1,"Company is required"),department:b().optional(),audit_date:Me("Audit date is required"),overall_gap_pct:b().optional(),risk_level:le(["green","yellow","red"]).optional(),status:le(["draft","reviewed","action_plan","closed"]).optional()}),ha={draft:"secondary",reviewed:"warning",action_plan:"warning",closed:"success"},pa={draft:"Draft",reviewed:"Reviewed",action_plan:"Action Plan",closed:"Closed"},xa={green:"success",yellow:"warning",red:"destructive"},ja={green:"Low",yellow:"Medium",red:"High"};function br(){const[a,t]=j.useState(!1),[n,x]=j.useState(null),[i,y]=j.useState(null),[g,D]=j.useState(""),[S,W]=j.useState(""),{hasPermission:w}=Oe(),K=w("compliance","pay_equity","create"),{pagination:Y,setPagination:H,sorting:Q,setSorting:z,globalFilter:L,setGlobalFilter:ee,queryParams:q}=de(),G={...q,...g&&{risk_level:g},...S&&{status:S}},{data:h,isLoading:v}=dn(G),J=un(),B=mn(),Z=hn(),l=Fe({resolver:Ae(ma),defaultValues:{company:"",department:"",audit_date:"",overall_gap_pct:"",risk_level:"green",status:"draft"}}),[o,N]=j.useState(""),{data:M}=Qe({search:o||void 0}),[_,ae]=j.useState(""),se=l.watch("company"),{data:X}=Gs({search:_||void 0,...se?{company:se}:{}});function u(){x(null),l.reset({company:"",department:"",audit_date:"",overall_gap_pct:"",risk_level:"green",status:"draft"}),t(!0)}function s(c){x(c),l.reset({company:c.company,department:c.department??"",audit_date:c.audit_date,overall_gap_pct:c.overall_gap_pct,risk_level:c.risk_level,status:c.status}),t(!0)}function k(c){const re={company:c.company,department:c.department||void 0,audit_date:c.audit_date,overall_gap_pct:c.overall_gap_pct||void 0,risk_level:c.risk_level,status:c.status};n?B.mutate({id:n.id,...re},{onSuccess:()=>t(!1)}):J.mutate(re,{onSuccess:()=>t(!1)})}function A(){i&&Z.mutate(i.id,{onSuccess:()=>y(null)})}function d(c){D(c==="__all__"?"":c),H(re=>({...re,pageIndex:0}))}function ie(c){W(c==="__all__"?"":c),H(re=>({...re,pageIndex:0}))}const ze=[{key:"company_name",header:"Company",render:c=>e.jsx("span",{className:"font-medium text-slate-900",children:c.company_name??c.company})},{key:"department_name",header:"Department",render:c=>c.department_name??c.department??"--"},{key:"audit_date",header:"Audit Date",render:c=>new Date(c.audit_date).toLocaleDateString()},{key:"overall_gap_pct",header:"Gap %",render:c=>e.jsxs("span",{className:"font-mono text-[13px] font-medium text-slate-700",children:[Number(c.overall_gap_pct).toFixed(1),"%"]})},{key:"risk_level",header:"Risk Level",render:c=>e.jsx(ne,{variant:xa[c.risk_level],children:ja[c.risk_level]})},{key:"status",header:"Status",render:c=>e.jsx(ne,{variant:ha[c.status],children:pa[c.status]})},{key:"actions",header:"",className:"w-10",render:c=>e.jsxs(ue,{open:(i==null?void 0:i.id)===c.id,onOpenChange:re=>!re&&y(null),children:[e.jsxs(Ee,{children:[e.jsx(Re,{asChild:!0,children:e.jsx(C,{variant:"ghost",size:"icon-sm",children:e.jsx(Le,{className:"h-4 w-4"})})}),e.jsxs(De,{align:"end",children:[K&&e.jsxs(te,{onClick:()=>s(c),children:[e.jsx($e,{className:"mr-2 h-3.5 w-3.5"})," Edit"]}),K&&e.jsx(Te,{asChild:!0,children:e.jsxs(te,{className:"text-red-600",onClick:()=>y(c),children:[e.jsx(Ve,{className:"mr-2 h-3.5 w-3.5"})," Delete"]})})]})]}),e.jsxs(me,{children:[e.jsxs(he,{children:[e.jsx(pe,{children:"Delete pay equity audit?"}),e.jsxs(xe,{children:["This will permanently delete the pay equity audit for"," ",e.jsx("strong",{children:(i==null?void 0:i.company_name)??(i==null?void 0:i.company)})," ","(",i!=null&&i.audit_date?new Date(i.audit_date).toLocaleDateString():"",")."]})]}),e.jsxs(je,{children:[e.jsx(ye,{children:"Cancel"}),e.jsx(ge,{variant:"destructive",onClick:A,children:"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(as,{className:"h-5 w-5 text-primary"})," Pay Equity Audits"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"Monitor gender pay gap and pay equity compliance"})]}),K&&e.jsxs(C,{size:"sm",onClick:u,children:[e.jsx(ke,{className:"mr-1.5 h-3.5 w-3.5"})," Add Audit"]})]}),e.jsx(oe,{columns:ze,data:(h==null?void 0:h.results)??[],isLoading:v,searchPlaceholder:"Search audits...",emptyMessage:"No pay equity audits",emptyDescription:"No pay equity audits have been conducted.",totalCount:(h==null?void 0:h.count)??0,pagination:Y,onPaginationChange:H,sorting:Q,onSortingChange:z,globalFilter:L,onGlobalFilterChange:ee,actions:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs($,{value:g||"__all__",onValueChange:d,children:[e.jsx(O,{className:"w-[140px] h-9",children:e.jsx(I,{placeholder:"All risk levels"})}),e.jsxs(U,{children:[e.jsx(r,{value:"__all__",children:"All Risk Levels"}),e.jsx(r,{value:"green",children:"Low"}),e.jsx(r,{value:"yellow",children:"Medium"}),e.jsx(r,{value:"red",children:"High"})]})]}),e.jsxs($,{value:S||"__all__",onValueChange:ie,children:[e.jsx(O,{className:"w-[140px] h-9",children:e.jsx(I,{placeholder:"All statuses"})}),e.jsxs(U,{children:[e.jsx(r,{value:"__all__",children:"All Statuses"}),e.jsx(r,{value:"draft",children:"Draft"}),e.jsx(r,{value:"reviewed",children:"Reviewed"}),e.jsx(r,{value:"action_plan",children:"Action Plan"}),e.jsx(r,{value:"closed",children:"Closed"})]})]})]})}),e.jsx(ve,{open:a,onOpenChange:t,children:e.jsxs(fe,{size:"lg",children:[e.jsxs(Se,{children:[e.jsx(Ne,{children:n?"Edit Pay Equity Audit":"Add Pay Equity Audit"}),e.jsx(Ce,{children:n?"Update the pay equity audit details.":"Create a new pay equity audit."})]}),e.jsxs("form",{onSubmit:l.handleSubmit(k),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(m,{children:"Company *"}),e.jsx(_e,{value:l.watch("company")??null,onValueChange:c=>{l.setValue("company",c,{shouldValidate:!0}),l.setValue("department","",{shouldValidate:!0})},onSearch:N,selectedLabel:(n==null?void 0:n.company_name)??void 0,options:((M==null?void 0:M.results)??[]).map(c=>({value:c.id,label:c.name,hint:c.code})),placeholder:"Select company",searchPlaceholder:"Search companies...",className:"mt-1.5"}),l.formState.errors.company&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:l.formState.errors.company.message})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Department"}),e.jsx(_e,{value:l.watch("department")??null,onValueChange:c=>l.setValue("department",c,{shouldValidate:!0}),onSearch:ae,selectedLabel:(n==null?void 0:n.department_name)??void 0,options:((X==null?void 0:X.results)??[]).map(c=>({value:c.id,label:c.name,hint:c.code})),placeholder:se?"Select department (optional)":"Select company first",searchPlaceholder:"Search departments...",disabled:!se,className:"mt-1.5"})]})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Audit Date *"}),e.jsx(F,{...l.register("audit_date"),type:"date",className:"mt-1.5"}),l.formState.errors.audit_date&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:l.formState.errors.audit_date.message})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Overall Gap %"}),e.jsx(F,{...l.register("overall_gap_pct"),type:"number",step:"0.01",className:"mt-1.5",placeholder:"0.00"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(m,{children:"Risk Level"}),e.jsxs($,{value:l.watch("risk_level")??"green",onValueChange:c=>l.setValue("risk_level",c),children:[e.jsx(O,{className:"mt-1.5",children:e.jsx(I,{})}),e.jsxs(U,{children:[e.jsx(r,{value:"green",children:"Low (Green)"}),e.jsx(r,{value:"yellow",children:"Medium (Yellow)"}),e.jsx(r,{value:"red",children:"High (Red)"})]})]})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Status"}),e.jsxs($,{value:l.watch("status")??"draft",onValueChange:c=>l.setValue("status",c),children:[e.jsx(O,{className:"mt-1.5",children:e.jsx(I,{})}),e.jsxs(U,{children:[e.jsx(r,{value:"draft",children:"Draft"}),e.jsx(r,{value:"reviewed",children:"Reviewed"}),e.jsx(r,{value:"action_plan",children:"Action Plan"}),e.jsx(r,{value:"closed",children:"Closed"})]})]})]})]})]}),e.jsxs(be,{children:[e.jsx(C,{variant:"outline",onClick:()=>t(!1),children:"Cancel"}),e.jsx(C,{onClick:l.handleSubmit(k),disabled:J.isPending||B.isPending,children:n?"Save Changes":"Add Audit"})]})]})})]})}function ya(a){const t=parseFloat(a);return t>=80?"success":t>=60?"warning":"destructive"}function kr(){const{pagination:a,setPagination:t,sorting:n,setSorting:x,globalFilter:i,setGlobalFilter:y,queryParams:g}=de(),{data:D,isLoading:S}=pn(g),W=[{key:"company_name",header:"Company",render:w=>e.jsx("span",{className:"font-medium text-slate-900",children:w.company_name??w.company.substring(0,8)})},{key:"branch_name",header:"Branch",render:w=>w.branch_name??"--"},{key:"score_date",header:"Date",render:w=>new Date(w.score_date).toLocaleDateString()},{key:"overall_score",header:"Score",render:w=>e.jsxs(ne,{variant:ya(w.overall_score),children:[w.overall_score,"%"]})},{key:"filings_on_time_pct",header:"On-Time %",render:w=>`${w.filings_on_time_pct}%`},{key:"penalties_ytd",header:"Penalties YTD",render:w=>`₹${Number(w.penalties_ytd).toLocaleString()}`},{key:"open_notices",header:"Open Notices",render:w=>w.open_notices}];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(as,{className:"h-5 w-5 text-primary"})," Compliance Scores"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"Track compliance health scores across establishments"})]})}),e.jsx(oe,{columns:W,data:(D==null?void 0:D.results)??[],isLoading:S,searchPlaceholder:"Search scores...",emptyMessage:"No compliance scores",emptyDescription:"No compliance scores have been recorded yet.",totalCount:(D==null?void 0:D.count)??0,pagination:a,onPaginationChange:t,sorting:n,onSortingChange:x,globalFilter:i,onGlobalFilterChange:y})]})}const ga=we({company:b().min(1,"Company is required"),branch:b().min(1,"Branch is required"),establishment_type:le(["factory","shop","office","warehouse","project_site"]),jurisdiction:b().min(1,"Jurisdiction is required")}),_a={factory:"Factory",shop:"Shop",office:"Office",warehouse:"Warehouse",project_site:"Project Site"};function Fr(){const[a,t]=j.useState(!1),[n,x]=j.useState(null),[i,y]=j.useState(null),{hasPermission:g}=Oe(),D=g("compliance","establishment","update"),{pagination:S,setPagination:W,sorting:w,setSorting:K,globalFilter:Y,setGlobalFilter:H,queryParams:Q}=de(),{data:z,isLoading:L}=xn(Q),ee=jn(),q=yn(),G=gn(),h=Fe({resolver:Ae(ga),defaultValues:{company:"",branch:"",establishment_type:"office",jurisdiction:""}}),[v,J]=j.useState(""),{data:B}=Qe({search:v||void 0}),[Z,l]=j.useState(""),o=h.watch("company"),{data:N}=ds({search:Z||void 0,...o?{company:o}:{}});function M(){x(null),h.reset({company:"",branch:"",establishment_type:"office",jurisdiction:""}),t(!0)}function _(u){x(u),h.reset({company:u.company,branch:u.branch,establishment_type:u.establishment_type,jurisdiction:u.jurisdiction}),t(!0)}function ae(u){const s={...u};n?q.mutate({id:n.id,...s},{onSuccess:()=>t(!1)}):ee.mutate(s,{onSuccess:()=>t(!1)})}function se(){i&&G.mutate(i.id,{onSuccess:()=>y(null)})}const X=[{key:"company_name",header:"Company",render:u=>e.jsx("span",{className:"font-medium text-slate-900",children:u.company_name??u.company.substring(0,8)})},{key:"branch_name",header:"Branch",render:u=>u.branch_name??u.branch.substring(0,8)},{key:"establishment_type",header:"Type",render:u=>e.jsx(ne,{variant:"secondary",children:_a[u.establishment_type]})},{key:"jurisdiction",header:"Jurisdiction",render:u=>u.jurisdiction},{key:"registrations",header:"Registrations",render:u=>u.registrations.length},{key:"applicable_laws",header:"Laws",render:u=>u.applicable_laws.length},{key:"compliance_officer_display",header:"Officer",render:u=>u.compliance_officer_display??"--"},{key:"actions",header:"",className:"w-10",render:u=>e.jsxs(ue,{open:(i==null?void 0:i.id)===u.id,onOpenChange:s=>!s&&y(null),children:[e.jsxs(Ee,{children:[e.jsx(Re,{asChild:!0,children:e.jsx(C,{variant:"ghost",size:"icon-sm",children:e.jsx(Le,{className:"h-4 w-4"})})}),e.jsxs(De,{align:"end",children:[D&&e.jsxs(te,{onClick:()=>_(u),children:[e.jsx($e,{className:"mr-2 h-3.5 w-3.5"})," Edit"]}),D&&e.jsx(Te,{asChild:!0,children:e.jsxs(te,{className:"text-red-600",onClick:()=>y(u),children:[e.jsx(Ve,{className:"mr-2 h-3.5 w-3.5"})," Delete"]})})]})]}),e.jsxs(me,{children:[e.jsxs(he,{children:[e.jsx(pe,{children:"Delete establishment?"}),e.jsx(xe,{children:"This action cannot be undone."})]}),e.jsxs(je,{children:[e.jsx(ye,{children:"Cancel"}),e.jsx(ge,{variant:"destructive",onClick:se,children:"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(Ns,{className:"h-5 w-5 text-primary"})," Establishments"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"Multi-establishment compliance tracking"})]}),D&&e.jsxs(C,{size:"sm",onClick:M,children:[e.jsx(ke,{className:"mr-1.5 h-3.5 w-3.5"})," New Establishment"]})]}),e.jsx(oe,{columns:X,data:(z==null?void 0:z.results)??[],isLoading:L,searchPlaceholder:"Search establishments...",emptyMessage:"No establishments",emptyDescription:"Add your first establishment.",totalCount:(z==null?void 0:z.count)??0,pagination:S,onPaginationChange:W,sorting:w,onSortingChange:K,globalFilter:Y,onGlobalFilterChange:H}),e.jsx(ve,{open:a,onOpenChange:t,children:e.jsxs(fe,{size:"lg",children:[e.jsxs(Se,{children:[e.jsx(Ne,{children:n?"Edit Establishment":"New Establishment"}),e.jsx(Ce,{children:n?"Update establishment details.":"Register a new establishment for compliance tracking."})]}),e.jsxs("form",{onSubmit:h.handleSubmit(ae),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(m,{children:"Company *"}),e.jsx(_e,{value:h.watch("company")??null,onValueChange:u=>{h.setValue("company",u,{shouldValidate:!0}),h.setValue("branch","",{shouldValidate:!0})},onSearch:J,selectedLabel:(n==null?void 0:n.company_name)??void 0,options:((B==null?void 0:B.results)??[]).map(u=>({value:u.id,label:u.name,hint:u.code})),placeholder:"Select company",searchPlaceholder:"Search companies...",className:"mt-1.5"}),h.formState.errors.company&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:h.formState.errors.company.message})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Branch *"}),e.jsx(_e,{value:h.watch("branch")??null,onValueChange:u=>h.setValue("branch",u,{shouldValidate:!0}),onSearch:l,selectedLabel:(n==null?void 0:n.branch_name)??void 0,options:((N==null?void 0:N.results)??[]).map(u=>({value:u.id,label:u.name,hint:u.code})),placeholder:o?"Select branch":"Select company first",searchPlaceholder:"Search branches...",disabled:!o,className:"mt-1.5"}),h.formState.errors.branch&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:h.formState.errors.branch.message})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(m,{children:"Establishment Type *"}),e.jsxs($,{value:h.watch("establishment_type"),onValueChange:u=>h.setValue("establishment_type",u),children:[e.jsx(O,{className:"mt-1.5",children:e.jsx(I,{})}),e.jsxs(U,{children:[e.jsx(r,{value:"factory",children:"Factory"}),e.jsx(r,{value:"shop",children:"Shop"}),e.jsx(r,{value:"office",children:"Office"}),e.jsx(r,{value:"warehouse",children:"Warehouse"}),e.jsx(r,{value:"project_site",children:"Project Site"})]})]})]}),e.jsxs("div",{children:[e.jsx(m,{children:"Jurisdiction *"}),e.jsx(F,{...h.register("jurisdiction"),className:"mt-1.5",placeholder:"e.g. Maharashtra"}),h.formState.errors.jurisdiction&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:h.formState.errors.jurisdiction.message})]})]})]}),e.jsxs(be,{children:[e.jsx(C,{variant:"outline",onClick:()=>t(!1),children:"Cancel"}),e.jsx(C,{onClick:h.handleSubmit(ae),disabled:ee.isPending||q.isPending,children:n?"Save Changes":"Create Establishment"})]})]})})]})}const va={draft:"secondary",generated:"warning",issued:"success"},fa={draft:"Draft",generated:"Generated",issued:"Issued"};function Ar(){const[a,t]=j.useState(!1),[n,x]=j.useState(""),[i,y]=j.useState(""),[g,D]=j.useState(""),{pagination:S,setPagination:W,sorting:w,setSorting:K,globalFilter:Y,setGlobalFilter:H,queryParams:Q}=de(),z={...Q,...n&&{financial_year:n},...i&&{status:i}},{data:L,isLoading:ee}=fn(z),q=Sn(),G=Nn();function h(){g&&q.mutate({financial_year:g},{onSuccess:()=>{t(!1),D("")}})}function v(l){G.mutate(l.id,{onSuccess:o=>{const N=window.URL.createObjectURL(o),M=document.createElement("a");M.href=N,M.download=`Form16_${l.employee_name??l.employee}_${l.financial_year}.pdf`,M.click(),window.URL.revokeObjectURL(N)}})}function J(l){x(l==="__all__"?"":l),W(o=>({...o,pageIndex:0}))}function B(l){y(l==="__all__"?"":l),W(o=>({...o,pageIndex:0}))}const Z=[{key:"employee_name",header:"Employee",render:l=>e.jsx("span",{className:"font-medium text-slate-900",children:l.employee_name??l.employee.substring(0,8)})},{key:"financial_year",header:"Financial Year",render:l=>l.financial_year},{key:"total_income",header:"Total Income",render:l=>e.jsxs("span",{className:"font-mono text-[13px]",children:["Rs. ",Number(l.total_income).toLocaleString("en-IN")]})},{key:"total_deductions",header:"Total Deductions",render:l=>e.jsxs("span",{className:"font-mono text-[13px]",children:["Rs. ",Number(l.total_deductions).toLocaleString("en-IN")]})},{key:"total_tax",header:"Total Tax",render:l=>e.jsxs("span",{className:"font-mono text-[13px]",children:["Rs. ",Number(l.total_tax).toLocaleString("en-IN")]})},{key:"status",header:"Status",render:l=>e.jsx(ne,{variant:va[l.status],children:fa[l.status]})},{key:"issued_at",header:"Issued At",render:l=>l.issued_at?new Date(l.issued_at).toLocaleDateString():"--"},{key:"actions",header:"",className:"w-10",render:l=>e.jsx(C,{variant:"ghost",size:"icon-sm",disabled:l.status==="draft"||G.isPending,onClick:()=>v(l),title:"Download Form 16",children:G.isPending?e.jsx(Ds,{className:"h-4 w-4 animate-spin"}):e.jsx(_s,{className:"h-4 w-4"})})}];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(is,{className:"h-5 w-5 text-primary"})," Form 16"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"Manage and download Form 16 certificates for employees"})]}),e.jsxs(C,{size:"sm",onClick:()=>t(!0),children:[e.jsx(is,{className:"mr-1.5 h-3.5 w-3.5"})," Generate Batch"]})]}),e.jsx(oe,{columns:Z,data:(L==null?void 0:L.results)??[],isLoading:ee,searchPlaceholder:"Search by employee...",emptyMessage:"No Form 16 records",emptyDescription:"Generate Form 16 certificates for a financial year.",totalCount:(L==null?void 0:L.count)??0,pagination:S,onPaginationChange:W,sorting:w,onSortingChange:K,globalFilter:Y,onGlobalFilterChange:H,actions:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs($,{value:n||"__all__",onValueChange:J,children:[e.jsx(O,{className:"w-[150px] h-9",children:e.jsx(I,{placeholder:"All FYs"})}),e.jsxs(U,{children:[e.jsx(r,{value:"__all__",children:"All FYs"}),e.jsx(r,{value:"2025-2026",children:"2025-2026"}),e.jsx(r,{value:"2024-2025",children:"2024-2025"}),e.jsx(r,{value:"2023-2024",children:"2023-2024"})]})]}),e.jsxs($,{value:i||"__all__",onValueChange:B,children:[e.jsx(O,{className:"w-[140px] h-9",children:e.jsx(I,{placeholder:"All statuses"})}),e.jsxs(U,{children:[e.jsx(r,{value:"__all__",children:"All Statuses"}),e.jsx(r,{value:"draft",children:"Draft"}),e.jsx(r,{value:"generated",children:"Generated"}),e.jsx(r,{value:"issued",children:"Issued"})]})]})]})}),e.jsx(ve,{open:a,onOpenChange:t,children:e.jsxs(fe,{size:"md",children:[e.jsxs(Se,{children:[e.jsx(Ne,{children:"Generate Form 16 Batch"}),e.jsx(Ce,{children:"Generate Form 16 certificates for all employees in the selected financial year."})]}),e.jsx("div",{className:"flex-1 overflow-y-auto px-6 py-5 space-y-4",children:e.jsxs("div",{children:[e.jsx(m,{children:"Financial Year *"}),e.jsx(F,{value:g,onChange:l=>D(l.target.value),className:"mt-1.5",placeholder:"e.g. 2025-2026"})]})}),e.jsxs(be,{children:[e.jsx(C,{variant:"outline",onClick:()=>t(!1),children:"Cancel"}),e.jsx(C,{onClick:h,disabled:!g||q.isPending,children:q.isPending?"Generating...":"Generate Batch"})]})]})})]})}const Sa=[{id:"filing-summary",icon:ns,title:"Filing Summary",description:"Recent filing status across all statutory types including PF, ESI, PT, and TDS.",color:"bg-primary",reportType:"filing_summary"},{id:"penalty-summary",icon:es,title:"Penalty Summary",description:"Open penalties, total amounts, and breakdown by penalty type for current year.",color:"bg-red-500",reportType:"penalty_summary"},{id:"calendar-status",icon:ls,title:"Calendar Status",description:"Upcoming compliance deadlines and overdue items requiring immediate attention.",color:"bg-amber-500",reportType:"calendar_status"},{id:"contractor-compliance",icon:ss,title:"Contractor Compliance",description:"Contractor wage audit results, document compliance, and worker status overview.",color:"bg-emerald-500",reportType:"contractor_compliance"},{id:"audit-trail",icon:Ts,title:"Audit Trail",description:"Full compliance audit log including amendments, correspondence, and status changes.",color:"bg-violet-500",reportType:"audit_trail"},{id:"export-reports",icon:_s,title:"Export Reports",description:"Download compliance data as CSV or Excel for external reporting and analysis.",color:"bg-slate-600",reportType:"export"}];function wr(){const a=vn();function t(n){n==="export"&&a.refetch()}return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-6",children:[e.jsxs("h2",{className:"text-[16px] font-semibold text-slate-900 flex items-center gap-2",children:[e.jsx(Ss,{className:"h-5 w-5 text-primary"})," Compliance Reports"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"Generate and view compliance reports across all statutory categories"})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:Sa.map(n=>{const x=n.icon;return e.jsxs(Ge,{className:"flex flex-col",children:[e.jsx(Je,{className:"pb-3",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:`flex h-10 w-10 shrink-0 items-center justify-center rounded-xl ${n.color}`,children:e.jsx(x,{className:"h-5 w-5 text-white"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx(Ze,{className:"text-[14px]",children:n.title}),e.jsx(Vs,{className:"mt-1 text-[12px]",children:n.description})]})]})}),e.jsx(Be,{className:"mt-auto pt-0",children:e.jsx(C,{variant:"outline",size:"sm",className:"w-full",onClick:()=>t(n.reportType),children:n.reportType==="export"?"Export Data":"View Report"})})]},n.id)})})]})}const Na={high:"destructive",medium:"warning",low:"secondary"},Ca={high:"High",medium:"Medium",low:"Low"},ba={wage_code:"Wage Code",social_security:"Social Security",industrial_relations:"Industrial Relations",occupational_safety:"Occupational Safety"};function rs({icon:a,label:t,value:n,color:x,loading:i}){return e.jsx(Ge,{children:e.jsxs(Be,{className:"flex items-center gap-4 p-5",children:[e.jsx("div",{className:`flex h-10 w-10 shrink-0 items-center justify-center rounded-xl ${x}`,children:e.jsx(a,{className:"h-5 w-5 text-white"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-[12px] font-medium text-slate-400",children:t}),i?e.jsx(Ue,{className:"mt-1 h-6 w-16"}):e.jsx("p",{className:"text-xl font-bold text-slate-900",children:n})]})]})})}function qr(){const{pagination:a,setPagination:t,sorting:n,setSorting:x,globalFilter:i,setGlobalFilter:y}=de(),g=!1,D=[{key:"area",header:"Area",render:S=>e.jsx(ne,{variant:"outline",children:ba[S.area]})},{key:"current_status",header:"Current Status",render:S=>e.jsx("span",{className:"text-[13px] text-slate-700",children:S.current_status})},{key:"required_change",header:"Required Change",render:S=>e.jsx("span",{className:"text-[13px] text-slate-700",children:S.required_change})},{key:"impact_level",header:"Impact Level",render:S=>e.jsx(ne,{variant:Na[S.impact_level],children:Ca[S.impact_level]})},{key:"action_taken",header:"Action Taken",render:S=>e.jsx(ne,{variant:S.action_taken?"success":"secondary",children:S.action_taken?"Yes":"No"})}];return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-6",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"})," Labour Codes 2025"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"New Labour Code impact assessment and compliance readiness"})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-3 mb-6",children:[e.jsx(rs,{icon:ss,label:"Affected Employees",value:"--",color:"bg-primary",loading:g}),e.jsx(rs,{icon:Ls,label:"Structures Needing Update",value:"--",color:"bg-amber-500",loading:g}),e.jsx(rs,{icon:ks,label:"Current Compliance %",value:"--",color:"bg-emerald-500",loading:g})]}),e.jsx(oe,{columns:D,data:[],isLoading:g,searchPlaceholder:"Search impact areas...",emptyMessage:"No impact assessment data",emptyDescription:"Labour codes impact assessment records will appear here.",totalCount:0,pagination:a,onPaginationChange:t,sorting:n,onSortingChange:x,globalFilter:i,onGlobalFilterChange:y})]})}export{jr as AmendmentsPage,xr as ComplianceCalendarPage,hr as ComplianceDashboardPage,or as ComplianceLayout,wr as ComplianceReportsPage,kr as ComplianceScoresPage,mr as ConsentRecordsPage,fr as ContractWorkersPage,vr as ContractorsPage,gr as CorrespondencePage,dr as DSARRequestsPage,Fr as EstablishmentsPage,_r as FactoryRegistersPage,Ar as Form16Page,qr as LabourCodesPage,Cr as POSHCompliancePage,br as PayEquityPage,yr as PenaltiesPage,ur as RetentionPoliciesPage,pr as StatutoryFilingsPage,Nr as StatutoryUpdatesPage,Sr as WageAuditsPage};
