import{j as e}from"./query-PJ0ZdjbV.js";import{f as Rs,a as p,O as Ts,k as Gs}from"./vendor-CWhr2lg4.js";import{a2 as Xe,b0 as Fe,bg as es,bf as Is,ap as Qe,bh as He,B as C,P as _e,s as ae,t as te,v as ne,w as ie,x as T,aa as oe,ab as de,ac as me,ad as he,ae as ue,q as g,I as x,r as Be,af as xe,Q as Oe,ag as Ne,ah as Ce,ai as Se,aj as se,b5 as Ee,y as Me,V as Le,W as qe,Y as Ve,Z as ze,_ as Re,$ as Te,a0 as Ge,N as gs,z as Us,ba as Bs,bb as Hs,bc as hs,bd as us,bi as $e,d as J,e as K,f as Z,g as X,h as W,b as Ys,at as R,bj as _s,bk as Qs,bl as $s,bm as Js,bn as Ws,bo as Ks,bp as Zs,bq as Xs,br as ea,bs as sa,bt as aa,bu as ta,bv as na,bw as ia,bx as la,by as ra,o as ca,a as oa,bz as vs,a7 as da,a5 as ma,U as ha,aM as ua,am as xa,an as pa,ao as ja,L as as}from"./index-BSPIaiZU.js";import{B as bs}from"./building-2-boIK6K2k.js";import{G as ss}from"./git-branch-DrD8zRaR.js";import{M as Ns}from"./map-pin-BhdxZDWP.js";import{N as ls}from"./network-BrXvPFyD.js";import{G as Cs}from"./globe-BTv0oSL0.js";import{C as rs}from"./chart-column-DbfNf7gS.js";import{B as cs}from"./briefcase-ChU_EMgZ.js";import{T as Ss,P as ya}from"./tag-Bm4GEpug.js";import{C as ws}from"./calendar-BZ611BSN.js";import{S as ks,D as ve}from"./data-table-D_-xOEqd.js";import{M as Ds}from"./mail-Bu7DITgC.js";import{L as Ps}from"./layers-DdTlMVfO.js";import{u as je,t as ye,o as fe,s as f,c as Ie,l as As,F as os,b as Ue}from"./date-range-picker-BB0TgAn8.js";import{S as Pe}from"./status-badge-DPaiL_rL.js";import{A as De}from"./async-select-BUbwdJEZ.js";import{u as be}from"./use-data-table-state-CKRg6qY2.js";import{G as ds}from"./geo-select-DH2q7I7V.js";import{u as Je,a as ms,b as fa,c as ga,d as _a,e as va,f as ba,g as Na,h as Ca,i as Sa,j as wa,k as ka,l as Da,m as Pa,n as Aa,o as Fa,p as Oa,q as Ea,r as Fs,s as Ma,t as La,v as qa,w as Va,x as za,y as Ra,z as Ta,A as Ga,B as Os,C as Ia,D as Ua,E as Ba,F as Es,G as Ha,H as Ya,I as Qa,J as $a,K as Ja,L as Wa,M as Ka,N as Za,O as Xa,P as et,Q as st,R as at,S as tt,T as nt,U as it,V as lt,W as rt,X as ct,Y as ot,Z as dt,_ as mt,$ as ht,a0 as ut,a1 as xt,a2 as pt,a3 as jt,a4 as yt}from"./system-admin.api-BT5u-_A_.js";import{E as we}from"./ellipsis-DaNBIBaV.js";import{P as ke}from"./pencil-Dl5fXQYl.js";import{B as ce}from"./badge-C34iUAiA.js";import{E as ft}from"./employee-select-DtUobKxP.js";import{F as Ke}from"./form-date-picker-DpmvXN9z.js";import{w as Ms,i as is}from"./date-validation-D9gNvaP9.js";import{L as xs}from"./list-ordered-Dn0jhaqK.js";import{L as Ls}from"./lock-mVL2BhFn.js";import{A as gt}from"./arrow-left-right-Ds_pa_I7.js";import{P as ps}from"./page-header-D8tSLbK0.js";import{S as _t}from"./skeleton-CfUgaIb_.js";import{R as We}from"./rotate-ccw-u1EtXcFp.js";import{S as Ze}from"./save-DGfbXnAg.js";import{C as vt}from"./circle-alert-9pjtMKqA.js";import{R as bt}from"./refresh-cw-DkxP9YPQ.js";import{L as Nt}from"./layout-dashboard-pgzECxsO.js";import{H as Ct}from"./heart-polFWSKf.js";import{H as St}from"./heart-pulse-B_MXLnGs.js";import{M as wt}from"./message-square-warning-DksdPLDU.js";import{G as kt}from"./gift-DT0Mx4Cc.js";import{T as Dt}from"./trending-up-Cognoqa9.js";import{B as Pt}from"./banknote-r5Yp3Ac5.js";import{C as At}from"./calendar-off-CmZ2XSje.js";import{U as Ft}from"./user-check-B2v_CMeM.js";import{F as Ot}from"./folder-open-BwrzuZcM.js";import{B as Et}from"./brain-CEoL1N-i.js";import{E as Mt}from"./eye-off-D-jqPqD8.js";import{E as Lt}from"./eye-DlIcvqP-.js";import{S as qt}from"./send-hExJQKXK.js";import"./ui-aO-W1bxx.js";import"./chevron-left-DLFf1YD2.js";import"./core-hr.api-MChaGqvv.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 Vt=Xe("ArrowUpDown",[["path",{d:"m21 16-4 4-4-4",key:"f6ql7i"}],["path",{d:"M17 20V4",key:"1ejh1v"}],["path",{d:"m3 8 4-4 4 4",key:"11wl7u"}],["path",{d:"M7 4v16",key:"1glfcx"}]]);/**
 * @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 qs=Xe("Building",[["rect",{width:"16",height:"20",x:"4",y:"2",rx:"2",ry:"2",key:"76otgf"}],["path",{d:"M9 22v-4h6v4",key:"r93iot"}],["path",{d:"M8 6h.01",key:"1dz90k"}],["path",{d:"M16 6h.01",key:"1x0f13"}],["path",{d:"M12 6h.01",key:"1vi96p"}],["path",{d:"M12 10h.01",key:"1nrarc"}],["path",{d:"M12 14h.01",key:"1etili"}],["path",{d:"M16 10h.01",key:"1m94wz"}],["path",{d:"M16 14h.01",key:"1gbofw"}],["path",{d:"M8 10h.01",key:"19clt8"}],["path",{d:"M8 14h.01",key:"6423bh"}]]);/**
 * @license lucide-react v0.469.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Vs=Xe("Coins",[["circle",{cx:"8",cy:"8",r:"6",key:"3yglwk"}],["path",{d:"M18.09 10.37A6 6 0 1 1 10.34 18",key:"t5s6rm"}],["path",{d:"M7 6h1v4",key:"1obek4"}],["path",{d:"m16.71 13.88.7.71-2.82 2.82",key:"1rbuyh"}]]);/**
 * @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 zs=Xe("Map",[["path",{d:"M14.106 5.553a2 2 0 0 0 1.788 0l3.659-1.83A1 1 0 0 1 21 4.619v12.764a1 1 0 0 1-.553.894l-4.553 2.277a2 2 0 0 1-1.788 0l-4.212-2.106a2 2 0 0 0-1.788 0l-3.659 1.83A1 1 0 0 1 3 19.381V6.618a1 1 0 0 1 .553-.894l4.553-2.277a2 2 0 0 1 1.788 0z",key:"169xi5"}],["path",{d:"M15 5.764v15",key:"1pn4in"}],["path",{d:"M9 3.236v15",key:"1uimfh"}]]),zt=[{heading:"Organization",items:[{to:"/system-admin/companies",label:"Companies",description:"Legal entities",icon:bs,permission:["system_admin","company","read"]},{to:"/system-admin/branches",label:"Branches",description:"Offices & locations",icon:ss,permission:["system_admin","branch","read"]},{to:"/system-admin/locations",label:"Locations",description:"Work sites & geofences",icon:Ns,permission:["system_admin","location","read"]},{to:"/system-admin/departments",label:"Departments",description:"Org hierarchy",icon:ls,permission:["system_admin","department","read"]}]},{heading:"Geography",items:[{to:"/system-admin/countries",label:"Countries",description:"Country master",icon:Cs,permission:["system_admin","country","read"]},{to:"/system-admin/states",label:"States",description:"States / provinces",icon:zs,permission:["system_admin","state","read"]},{to:"/system-admin/cities",label:"Cities",description:"City master",icon:qs,permission:["system_admin","city","read"]}]},{heading:"Employee Setup",items:[{to:"/system-admin/grades",label:"Grades",description:"Pay grades & bands",icon:rs,permission:["system_admin","grade","read"]},{to:"/system-admin/designations",label:"Designations",description:"Job titles",icon:cs,permission:["system_admin","designation","read"]},{to:"/system-admin/categories",label:"Categories",description:"Employment types",icon:Ss,permission:["system_admin","category","read"]}]},{heading:"Finance",items:[{to:"/system-admin/fiscal-years",label:"Fiscal Years",description:"Financial periods",icon:ws,permission:["system_admin","fiscal_year","read"]},{to:"/system-admin/currencies",label:"Currencies",description:"Currency & exchange rates",icon:Vs,permission:["system_admin","currency","read"]}]},{heading:"Configuration",items:[{to:"/system-admin/policies",label:"Policies",description:"System parameters",icon:ks,permission:["system_admin","policy","read"]},{to:"/system-admin/email-settings",label:"Email / SMTP",description:"Outgoing mail server",icon:Ds,permission:["system_admin","email_settings","read"]},{to:"/system-admin/modules",label:"Modules",description:"Enable or disable modules",icon:es,permission:["system_admin","modules","read"]},{to:"/system-admin/custom-fields",label:"Custom Fields",description:"Dynamic field definitions",icon:Ps,permission:["system_admin","custom_field","read"]}]}];function Rt({item:b,isActive:r}){const n=b.icon;return e.jsxs(Gs,{to:b.to,className:Qe("group relative flex items-center gap-3 rounded-lg px-3 py-2.5 transition-all duration-150",r?"bg-primary-subtle/70":"hover:bg-slate-50"),children:[r&&e.jsx("span",{className:"absolute left-0 top-2.5 bottom-2.5 w-[3px] rounded-r-full bg-primary"}),e.jsx("div",{className:Qe("flex h-8 w-8 shrink-0 items-center justify-center rounded-lg transition-colors duration-150",r?"bg-primary/10 text-primary":"bg-slate-100 text-slate-400 group-hover:bg-slate-200/70 group-hover:text-slate-500"),children:e.jsx(n,{className:"h-4 w-4"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:Qe("block text-[13px] truncate leading-tight",r?"font-medium text-primary":"font-medium text-slate-700 group-hover:text-slate-900"),children:b.label}),e.jsx("span",{className:Qe("block text-[11px] truncate leading-tight mt-0.5",r?"text-primary/60":"text-slate-400"),children:b.description})]})]})}function Ni(){const b=Rs(),r=p.useRef(null),{hasPermission:n}=Fe();p.useEffect(()=>{var i;(i=r.current)==null||i.scrollTo(0,0)},[b.pathname]);const j=p.useMemo(()=>zt.map(i=>({...i,items:i.items.filter(_=>n(_.permission[0],_.permission[1],_.permission[2]))})).filter(i=>i.items.length>0),[n]);return e.jsxs("div",{className:"-m-6 flex h-[calc(100%+48px)]",children:[e.jsxs("aside",{className:"w-[260px] shrink-0 border-r border-slate-200/60 bg-white flex flex-col",children:[e.jsxs("div",{className:"shrink-0 px-5 pt-6 pb-4 border-b border-slate-100",children:[e.jsx("h1",{className:"text-[15px] font-semibold text-slate-900 tracking-tight",children:"System Administration"}),e.jsx("p",{className:"mt-0.5 text-[11px] text-slate-400",children:"Organization & configuration"})]}),e.jsx("nav",{className:"flex-1 overflow-y-auto px-3 py-3 scrollbar-thin",children:j.map((i,_)=>e.jsxs("div",{className:Qe(_>0&&"mt-6"),children:[e.jsx("p",{className:"mb-2 px-3 text-[11px] font-semibold uppercase tracking-[0.08em] text-slate-400",children:i.heading}),e.jsx("div",{className:"space-y-0.5",children:i.items.map(t=>e.jsx(Rt,{item:t,isActive:Is(b.pathname,t.to)},t.to))})]},i.heading))})]}),e.jsx("main",{ref:r,className:"flex-1 min-w-0 overflow-y-auto bg-background scrollbar-thin",children:e.jsx("div",{className:"px-8 py-6 w-full",children:e.jsx(Ts,{})})})]})}const Tt=fe({name:f().min(1,"Name is required"),code:f().max(50).optional(),registration_number:f().optional(),tax_id:f().optional(),address:f().optional(),city:f().nullable().optional(),state:f().nullable().optional(),country:f().nullable().optional(),timezone:f().optional(),fiscal_year_start_month:Ie.number().min(1).max(12).optional(),default_currency:f().nullable().optional()});function Ci(){var re,h,H,Ae;const[b,r]=p.useState(!1),[n,j]=p.useState(null),[i,_]=p.useState(null),[t,F]=p.useState(""),{hasPermission:y,requirePermission:w}=Fe(),c=He(),o=y("system_admin","company","create"),S=y("system_admin","company","update"),q=y("system_admin","company","delete"),{pagination:s,setPagination:u,sorting:v,setSorting:O,globalFilter:D,setGlobalFilter:B,queryParams:Y}=be(),I={...Y,...t&&{is_active:t}},{data:N,isLoading:M}=Je(I);function $(a){F(a==="__all__"?"":a),u(k=>({...k,pageIndex:0}))}const[A,G]=p.useState(""),{data:z}=ms({search:A||void 0}),U=fa(),L=ga(),E=_a(),P=je({resolver:ye(Tt),defaultValues:{country:null,state:null,city:null,timezone:"Asia/Kolkata",fiscal_year_start_month:4,default_currency:null}});function l(){w("system_admin","company","create")&&(j(null),P.reset({country:null,state:null,city:null,timezone:"Asia/Kolkata",fiscal_year_start_month:4,default_currency:null}),r(!0))}function V(a){w("system_admin","company","update")&&(j(a),P.reset({name:a.name,code:a.code,registration_number:a.registration_number,tax_id:a.tax_id,address:a.address,city:a.city,state:a.state,country:a.country,timezone:a.timezone,fiscal_year_start_month:a.fiscal_year_start_month,default_currency:a.default_currency}),r(!0))}function d(a){const k=a;n?L.mutate({id:n.id,...k},{onSuccess:()=>r(!1)}):U.mutate(k,{onSuccess:()=>r(!1)})}function m(){i&&w("system_admin","company","delete")&&E.mutate(i.id,{onSuccess:()=>_(null)})}const ee=[{key:"name",header:"Company",render:a=>e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-slate-900",children:a.name}),e.jsx("span",{className:"ml-2 text-[11px] text-slate-400",children:a.code})]})},{key:"city",header:"Location",render:a=>a.city_detail?`${a.city_detail.name}${a.state_detail?", "+a.state_detail.name:""}`:"—"},{key:"branch_count",header:"Branches",render:a=>e.jsxs("span",{className:"inline-flex items-center gap-1 text-slate-600",children:[e.jsx(ss,{className:"h-3 w-3"})," ",a.branch_count]})},{key:"department_count",header:"Departments",render:a=>e.jsxs("span",{className:"inline-flex items-center gap-1 text-slate-600",children:[e.jsx(ls,{className:"h-3 w-3"})," ",a.department_count]})},{key:"is_active",header:"Status",render:a=>e.jsx(Pe,{status:a.is_active?"active":"inactive"})},{key:"actions",header:"",className:"w-10",render:a=>e.jsxs(Oe,{open:(i==null?void 0:i.id)===a.id,onOpenChange:k=>!k&&_(null),children:[e.jsxs(Ne,{children:[e.jsx(Ce,{asChild:!0,children:e.jsx(C,{variant:"ghost",size:"icon-sm",children:e.jsx(we,{className:"h-4 w-4"})})}),e.jsxs(Se,{align:"end",children:[e.jsxs(se,{onClick:()=>V(a),disabled:!S,children:[e.jsx(ke,{className:"mr-2 h-3.5 w-3.5"})," Edit"]}),e.jsx(Ee,{asChild:!0,children:e.jsxs(se,{className:"text-red-600",onClick:()=>_(a),disabled:!q,children:[e.jsx(Me,{className:"mr-2 h-3.5 w-3.5"})," Delete"]})})]})]}),e.jsxs(Le,{children:[e.jsxs(qe,{children:[e.jsx(Ve,{children:"Delete company?"}),e.jsxs(ze,{children:["This will permanently delete ",e.jsx("strong",{children:i==null?void 0:i.name})," and all its branches, departments, and related data."]})]}),e.jsxs(Re,{children:[e.jsx(Te,{children:"Cancel"}),e.jsx(Ge,{variant:"destructive",onClick:m,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"})," Companies"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"Legal entities within your organization"})]}),o&&e.jsxs(C,{size:"sm",onClick:l,children:[e.jsx(_e,{className:"mr-1.5 h-3.5 w-3.5"})," Add Company"]})]}),e.jsx(ve,{actions:e.jsxs(ae,{value:t,onValueChange:$,children:[e.jsx(te,{className:"w-[140px] h-9",children:e.jsx(ne,{placeholder:"All statuses"})}),e.jsxs(ie,{children:[e.jsx(T,{value:"__all__",children:"All"}),e.jsx(T,{value:"true",children:"Active"}),e.jsx(T,{value:"false",children:"Inactive"})]})]}),columns:ee,data:(N==null?void 0:N.results)??[],isLoading:M,searchPlaceholder:"Search companies...",emptyMessage:"No companies yet",emptyDescription:"Add your first company to get started.",totalCount:(N==null?void 0:N.count)??0,pagination:s,onPaginationChange:u,sorting:v,onSortingChange:O,globalFilter:D,onGlobalFilterChange:B}),e.jsx(oe,{open:b,onOpenChange:r,children:e.jsxs(de,{size:"lg",children:[e.jsxs(me,{children:[e.jsx(he,{children:n?"Edit Company":"Add Company"}),e.jsx(ue,{children:n?"Update company details.":"Create a new legal entity."})]}),e.jsxs("form",{onSubmit:P.handleSubmit(d),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(g,{children:"Name *"}),e.jsx(x,{...P.register("name"),className:"mt-1.5"}),P.formState.errors.name&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:P.formState.errors.name.message})]}),c==="manual"&&e.jsxs("div",{children:[e.jsx(g,{children:"Code *"}),e.jsx(x,{...P.register("code"),className:"mt-1.5",placeholder:"e.g. ACME"}),P.formState.errors.code&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:P.formState.errors.code.message})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(g,{children:"Registration Number"}),e.jsx(x,{...P.register("registration_number"),className:"mt-1.5"})]}),e.jsxs("div",{children:[e.jsx(g,{children:"Tax ID"}),e.jsx(x,{...P.register("tax_id"),className:"mt-1.5"})]})]}),e.jsxs("div",{children:[e.jsx(g,{children:"Address"}),e.jsx(Be,{...P.register("address"),className:"mt-1.5",rows:3})]}),e.jsx(ds,{value:{country:P.watch("country")??null,state:P.watch("state")??null,city:P.watch("city")??null},onChange:a=>{P.setValue("country",a.country),P.setValue("state",a.state),P.setValue("city",a.city)},initialLabels:n?{country:(re=n.country_detail)==null?void 0:re.name,state:(h=n.state_detail)==null?void 0:h.name,city:(H=n.city_detail)==null?void 0:H.name}:void 0}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsxs("div",{children:[e.jsx(g,{children:"Timezone"}),e.jsx(x,{...P.register("timezone"),className:"mt-1.5"})]}),e.jsxs("div",{children:[e.jsx(g,{children:"FY Start Month"}),e.jsx(x,{...P.register("fiscal_year_start_month"),type:"number",min:1,max:12,className:"mt-1.5"})]}),e.jsxs("div",{children:[e.jsx(g,{children:"Currency"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(De,{value:P.watch("default_currency")??null,onValueChange:a=>P.setValue("default_currency",a),onSearch:G,selectedLabel:(Ae=n==null?void 0:n.default_currency_detail)==null?void 0:Ae.code,options:((z==null?void 0:z.results)??[]).map(a=>({value:a.id,label:a.code,hint:a.name})),placeholder:"Select currency",searchPlaceholder:"Search currencies..."})})]})]})]}),e.jsxs(xe,{children:[e.jsx(C,{variant:"outline",onClick:()=>r(!1),children:"Cancel"}),e.jsx(C,{onClick:P.handleSubmit(d),disabled:U.isPending||L.isPending,children:n?"Save Changes":"Create Company"})]})]})})]})}const Gt=fe({company:f().min(1,"Company is required"),name:f().min(1,"Name is required"),code:f().optional(),address:f().optional(),city:f().nullable().optional(),state:f().nullable().optional(),country:f().nullable().optional(),phone:f().optional(),email:f().email("Invalid email").optional().or(As(""))});function Si(){var h,H,Ae;const[b,r]=p.useState(!1),[n,j]=p.useState(null),[i,_]=p.useState(null),[t,F]=p.useState(""),{hasPermission:y,requirePermission:w}=Fe(),c=He(),o=y("system_admin","branch","create"),S=y("system_admin","branch","update"),q=y("system_admin","branch","delete"),{pagination:s,setPagination:u,sorting:v,setSorting:O,globalFilter:D,setGlobalFilter:B,queryParams:Y}=be(),I={...Y,...t&&{is_active:t}},{data:N,isLoading:M}=va(I);function $(a){F(a==="__all__"?"":a),u(k=>({...k,pageIndex:0}))}const[A,G]=p.useState(""),{data:z}=Je({search:A||void 0}),U=(z==null?void 0:z.results)??[],L=ba(),E=Na(),P=Ca(),l=je({resolver:ye(Gt),defaultValues:{country:null,state:null,city:null}});function V(){w("system_admin","branch","create")&&(j(null),l.reset({company:"",name:"",code:"",country:null,state:null,city:null}),r(!0))}function d(a){w("system_admin","branch","update")&&(j(a),l.reset({company:a.company,name:a.name,code:a.code,address:a.address,city:a.city,state:a.state,country:a.country,phone:a.phone,email:a.email}),r(!0))}function m(a){const k=a;n?E.mutate({id:n.id,...k},{onSuccess:()=>r(!1)}):L.mutate(k,{onSuccess:()=>r(!1)})}function ee(){i&&w("system_admin","branch","delete")&&P.mutate(i.id,{onSuccess:()=>_(null)})}const re=[{key:"name",header:"Branch",render:a=>e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-slate-900",children:a.name}),e.jsx("span",{className:"ml-2 text-[11px] text-slate-400",children:a.code})]})},{key:"company_name",header:"Company"},{key:"city",header:"Location",render:a=>a.city_detail?`${a.city_detail.name}${a.state_detail?", "+a.state_detail.name:""}`:"—"},{key:"phone",header:"Phone",render:a=>a.phone||"—"},{key:"is_active",header:"Status",render:a=>e.jsx(Pe,{status:a.is_active?"active":"inactive"})},{key:"actions",header:"",className:"w-10",render:a=>e.jsxs(Oe,{open:(i==null?void 0:i.id)===a.id,onOpenChange:k=>!k&&_(null),children:[e.jsxs(Ne,{children:[e.jsx(Ce,{asChild:!0,children:e.jsx(C,{variant:"ghost",size:"icon-sm",children:e.jsx(we,{className:"h-4 w-4"})})}),e.jsxs(Se,{align:"end",children:[e.jsxs(se,{onClick:()=>d(a),disabled:!S,children:[e.jsx(ke,{className:"mr-2 h-3.5 w-3.5"})," Edit"]}),e.jsx(Ee,{asChild:!0,children:e.jsxs(se,{className:"text-red-600",onClick:()=>_(a),disabled:!q,children:[e.jsx(Me,{className:"mr-2 h-3.5 w-3.5"})," Delete"]})})]})]}),e.jsxs(Le,{children:[e.jsxs(qe,{children:[e.jsx(Ve,{children:"Delete branch?"}),e.jsxs(ze,{children:["This will permanently delete ",e.jsx("strong",{children:i==null?void 0:i.name}),"."]})]}),e.jsxs(Re,{children:[e.jsx(Te,{children:"Cancel"}),e.jsx(Ge,{variant:"destructive",onClick:ee,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"})," Branches"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"Physical offices and locations"})]}),o&&e.jsxs(C,{size:"sm",onClick:V,children:[e.jsx(_e,{className:"mr-1.5 h-3.5 w-3.5"})," Add Branch"]})]}),e.jsx(ve,{actions:e.jsxs(ae,{value:t,onValueChange:$,children:[e.jsx(te,{className:"w-[140px] h-9",children:e.jsx(ne,{placeholder:"All statuses"})}),e.jsxs(ie,{children:[e.jsx(T,{value:"__all__",children:"All"}),e.jsx(T,{value:"true",children:"Active"}),e.jsx(T,{value:"false",children:"Inactive"})]})]}),columns:re,data:(N==null?void 0:N.results)??[],isLoading:M,searchPlaceholder:"Search branches...",emptyMessage:"No branches yet",emptyDescription:"Add branches for your companies.",totalCount:(N==null?void 0:N.count)??0,pagination:s,onPaginationChange:u,sorting:v,onSortingChange:O,globalFilter:D,onGlobalFilterChange:B}),e.jsx(oe,{open:b,onOpenChange:r,children:e.jsxs(de,{size:"lg",children:[e.jsxs(me,{children:[e.jsx(he,{children:n?"Edit Branch":"Add Branch"}),e.jsx(ue,{children:n?"Update branch details.":"Add a new office location."})]}),e.jsxs("form",{onSubmit:l.handleSubmit(m),className:"flex-1 overflow-y-auto px-6 py-5 space-y-4",children:[e.jsxs("div",{children:[e.jsx(g,{children:"Company *"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(De,{value:l.watch("company")??null,onValueChange:a=>l.setValue("company",a,{shouldValidate:!0}),onSearch:G,selectedLabel:n==null?void 0:n.company_name,options:U.map(a=>({value:a.id,label:a.name,hint:a.code})),placeholder:"Select company",searchPlaceholder:"Search companies..."})}),l.formState.errors.company&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:l.formState.errors.company.message})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(g,{children:"Name *"}),e.jsx(x,{...l.register("name"),className:"mt-1.5"}),l.formState.errors.name&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:l.formState.errors.name.message})]}),c==="manual"&&e.jsxs("div",{children:[e.jsx(g,{children:"Code *"}),e.jsx(x,{...l.register("code"),className:"mt-1.5"}),l.formState.errors.code&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:l.formState.errors.code.message})]})]}),e.jsxs("div",{children:[e.jsx(g,{children:"Address"}),e.jsx(Be,{...l.register("address"),className:"mt-1.5",rows:3})]}),e.jsx(ds,{value:{country:l.watch("country")??null,state:l.watch("state")??null,city:l.watch("city")??null},onChange:a=>{l.setValue("country",a.country),l.setValue("state",a.state),l.setValue("city",a.city)},initialLabels:n?{country:(h=n.country_detail)==null?void 0:h.name,state:(H=n.state_detail)==null?void 0:H.name,city:(Ae=n.city_detail)==null?void 0:Ae.name}:void 0}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(g,{children:"Phone"}),e.jsx(gs,{...l.register("phone"),className:"mt-1.5"})]}),e.jsxs("div",{children:[e.jsx(g,{children:"Email"}),e.jsx(x,{...l.register("email"),type:"email",className:"mt-1.5"}),l.formState.errors.email&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:l.formState.errors.email.message})]})]})]}),e.jsxs(xe,{children:[e.jsx(C,{variant:"outline",onClick:()=>r(!1),children:"Cancel"}),e.jsx(C,{onClick:l.handleSubmit(m),disabled:L.isPending||E.isPending,children:n?"Save Changes":"Create Branch"})]})]})})]})}const It=fe({company:f().min(1,"Company is required"),name:f().min(1,"Name is required"),code:f().optional(),address:f().optional(),city:f().nullable().optional(),state:f().nullable().optional(),country:f().nullable().optional(),pincode:f().optional().refine(b=>!b||/^\d{6}$/.test(b),{message:"PIN code must be exactly 6 digits"}),latitude:f().optional(),longitude:f().optional(),geofence_radius_m:f().optional()});function wi(){var h,H,Ae;const[b,r]=p.useState(!1),[n,j]=p.useState(null),[i,_]=p.useState(null),[t,F]=p.useState(""),{hasPermission:y,requirePermission:w}=Fe(),c=He(),o=y("system_admin","location","create"),S=y("system_admin","location","update"),q=y("system_admin","location","delete"),{pagination:s,setPagination:u,sorting:v,setSorting:O,globalFilter:D,setGlobalFilter:B,queryParams:Y}=be(),I={...Y,...t&&{is_active:t}},{data:N,isLoading:M}=Sa(I);function $(a){F(a==="__all__"?"":a),u(k=>({...k,pageIndex:0}))}const[A,G]=p.useState(""),{data:z}=Je({search:A||void 0}),U=(z==null?void 0:z.results)??[],L=wa(),E=ka(),P=Da(),l=je({resolver:ye(It),defaultValues:{company:"",name:"",code:"",country:null,state:null,city:null}});function V(){w("system_admin","location","create")&&(j(null),l.reset({company:"",name:"",code:"",country:null,state:null,city:null}),r(!0))}function d(a){w("system_admin","location","update")&&(j(a),l.reset({company:a.company,name:a.name,code:a.code,address:a.address,city:a.city,state:a.state,country:a.country,pincode:a.pincode,latitude:a.latitude??"",longitude:a.longitude??"",geofence_radius_m:a.geofence_radius_m?String(a.geofence_radius_m):""}),r(!0))}function m(a){const k={company:a.company,name:a.name,code:a.code,address:a.address,city:a.city||null,state:a.state||null,country:a.country||null,pincode:a.pincode,latitude:a.latitude||null,longitude:a.longitude||null,geofence_radius_m:a.geofence_radius_m?Number(a.geofence_radius_m):0};n?E.mutate({id:n.id,...k},{onSuccess:()=>r(!1)}):L.mutate(k,{onSuccess:()=>r(!1)})}function ee(){i&&w("system_admin","location","delete")&&P.mutate(i.id,{onSuccess:()=>_(null)})}const re=[{key:"name",header:"Location",render:a=>e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-slate-900",children:a.name}),e.jsx("span",{className:"ml-2 text-[11px] text-slate-400",children:a.code})]})},{key:"company_name",header:"Company"},{key:"city",header:"City / State",render:a=>a.city_detail?`${a.city_detail.name}${a.state_detail?", "+a.state_detail.name:""}`:"—"},{key:"pincode",header:"Pincode",render:a=>a.pincode||"—"},{key:"geofence_radius_m",header:"Geofence",render:a=>a.geofence_radius_m?`${a.geofence_radius_m} m`:"—"},{key:"is_active",header:"Status",render:a=>e.jsx(Pe,{status:a.is_active?"active":"inactive"})},{key:"actions",header:"",className:"w-10",render:a=>e.jsxs(Oe,{open:(i==null?void 0:i.id)===a.id,onOpenChange:k=>!k&&_(null),children:[e.jsxs(Ne,{children:[e.jsx(Ce,{asChild:!0,children:e.jsx(C,{variant:"ghost",size:"icon-sm",children:e.jsx(we,{className:"h-4 w-4"})})}),e.jsxs(Se,{align:"end",children:[e.jsxs(se,{onClick:()=>d(a),disabled:!S,children:[e.jsx(ke,{className:"mr-2 h-3.5 w-3.5"})," Edit"]}),e.jsx(Ee,{asChild:!0,children:e.jsxs(se,{className:"text-red-600",onClick:()=>_(a),disabled:!q,children:[e.jsx(Me,{className:"mr-2 h-3.5 w-3.5"})," Delete"]})})]})]}),e.jsxs(Le,{children:[e.jsxs(qe,{children:[e.jsx(Ve,{children:"Delete location?"}),e.jsxs(ze,{children:["This will permanently delete ",e.jsx("strong",{children:i==null?void 0:i.name}),"."]})]}),e.jsxs(Re,{children:[e.jsx(Te,{children:"Cancel"}),e.jsx(Ge,{variant:"destructive",onClick:ee,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"})," Locations"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"Work sites & geofenced office locations"})]}),o&&e.jsxs(C,{size:"sm",onClick:V,children:[e.jsx(_e,{className:"mr-1.5 h-3.5 w-3.5"})," Add Location"]})]}),e.jsx(ve,{actions:e.jsxs(ae,{value:t,onValueChange:$,children:[e.jsx(te,{className:"w-[140px] h-9",children:e.jsx(ne,{placeholder:"All statuses"})}),e.jsxs(ie,{children:[e.jsx(T,{value:"__all__",children:"All"}),e.jsx(T,{value:"true",children:"Active"}),e.jsx(T,{value:"false",children:"Inactive"})]})]}),columns:re,data:(N==null?void 0:N.results)??[],isLoading:M,searchPlaceholder:"Search locations...",emptyMessage:"No locations yet",emptyDescription:"Add work locations for your companies.",totalCount:(N==null?void 0:N.count)??0,pagination:s,onPaginationChange:u,sorting:v,onSortingChange:O,globalFilter:D,onGlobalFilterChange:B}),e.jsx(oe,{open:b,onOpenChange:r,children:e.jsxs(de,{size:"lg",children:[e.jsxs(me,{children:[e.jsx(he,{children:n?"Edit Location":"Add Location"}),e.jsx(ue,{children:n?"Update location details.":"Add a new work site."})]}),e.jsxs("form",{onSubmit:l.handleSubmit(m),className:"flex-1 overflow-y-auto px-6 py-5 space-y-4",children:[e.jsxs("div",{children:[e.jsx(g,{children:"Company *"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(De,{value:l.watch("company")??null,onValueChange:a=>l.setValue("company",a,{shouldValidate:!0}),onSearch:G,selectedLabel:n==null?void 0:n.company_name,options:U.map(a=>({value:a.id,label:a.name,hint:a.code})),placeholder:"Select company",searchPlaceholder:"Search companies..."})}),l.formState.errors.company&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:l.formState.errors.company.message})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(g,{children:"Name *"}),e.jsx(x,{...l.register("name"),className:"mt-1.5"}),l.formState.errors.name&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:l.formState.errors.name.message})]}),c==="manual"&&e.jsxs("div",{children:[e.jsx(g,{children:"Code *"}),e.jsx(x,{...l.register("code"),className:"mt-1.5"}),l.formState.errors.code&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:l.formState.errors.code.message})]})]}),e.jsxs("div",{children:[e.jsx(g,{children:"Address"}),e.jsx(Be,{...l.register("address"),className:"mt-1.5",rows:3})]}),e.jsx(ds,{value:{country:l.watch("country")??null,state:l.watch("state")??null,city:l.watch("city")??null},onChange:a=>{l.setValue("country",a.country),l.setValue("state",a.state),l.setValue("city",a.city)},initialLabels:n?{country:(h=n.country_detail)==null?void 0:h.name,state:(H=n.state_detail)==null?void 0:H.name,city:(Ae=n.city_detail)==null?void 0:Ae.name}:void 0}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(g,{children:"Pincode"}),e.jsx(x,{...l.register("pincode"),className:"mt-1.5",maxLength:6,inputMode:"numeric"})]}),e.jsxs("div",{children:[e.jsx(g,{children:"Geofence Radius (m)"}),e.jsx(gs,{...l.register("geofence_radius_m"),className:"mt-1.5",placeholder:"0 = no geofence"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(g,{children:"Latitude"}),e.jsx(x,{...l.register("latitude"),className:"mt-1.5",placeholder:"e.g. 12.971599"})]}),e.jsxs("div",{children:[e.jsx(g,{children:"Longitude"}),e.jsx(x,{...l.register("longitude"),className:"mt-1.5",placeholder:"e.g. 77.594566"})]})]})]}),e.jsxs(xe,{children:[e.jsx(C,{variant:"outline",onClick:()=>r(!1),children:"Cancel"}),e.jsx(C,{onClick:l.handleSubmit(m),disabled:L.isPending||E.isPending,children:n?"Save Changes":"Create Location"})]})]})})]})}const Ut=fe({name:f().min(1,"Name is required"),code:f().min(1,"Code is required"),phone_code:f().optional()});function ki(){const[b,r]=p.useState(!1),[n,j]=p.useState(null),[i,_]=p.useState(null),{hasPermission:t,requirePermission:F}=Fe(),y=t("system_admin","country","create"),w=t("system_admin","country","update"),c=t("system_admin","country","delete"),{pagination:o,setPagination:S,sorting:q,setSorting:s,globalFilter:u,setGlobalFilter:v,queryParams:O}=be(),{data:D,isLoading:B}=Pa(O),Y=Aa(),I=Fa(),N=Oa(),M=je({resolver:ye(Ut)});function $(){F("system_admin","country","create")&&(j(null),M.reset({name:"",code:"",phone_code:""}),r(!0))}function A(L){F("system_admin","country","update")&&(j(L),M.reset({name:L.name,code:L.code,phone_code:L.phone_code??""}),r(!0))}function G(L){const E=L;n?I.mutate({id:n.id,...E},{onSuccess:()=>r(!1)}):Y.mutate(E,{onSuccess:()=>r(!1)})}function z(){i&&F("system_admin","country","delete")&&N.mutate(i.id,{onSuccess:()=>_(null)})}const U=[{key:"name",header:"Country",render:L=>e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-slate-900",children:L.name}),e.jsx("span",{className:"ml-2 text-[11px] text-slate-400",children:L.code})]})},{key:"is_active",header:"Status",render:L=>e.jsx(Pe,{status:L.is_active?"active":"inactive"})},{key:"actions",header:"",className:"w-10",render:L=>e.jsxs(Oe,{open:(i==null?void 0:i.id)===L.id,onOpenChange:E=>!E&&_(null),children:[e.jsxs(Ne,{children:[e.jsx(Ce,{asChild:!0,children:e.jsx(C,{variant:"ghost",size:"icon-sm",children:e.jsx(we,{className:"h-4 w-4"})})}),e.jsxs(Se,{align:"end",children:[e.jsxs(se,{onClick:()=>A(L),disabled:!w,children:[e.jsx(ke,{className:"mr-2 h-3.5 w-3.5"})," Edit"]}),e.jsx(Ee,{asChild:!0,children:e.jsxs(se,{className:"text-red-600",onClick:()=>_(L),disabled:!c,children:[e.jsx(Me,{className:"mr-2 h-3.5 w-3.5"})," Delete"]})})]})]}),e.jsxs(Le,{children:[e.jsxs(qe,{children:[e.jsx(Ve,{children:"Delete country?"}),e.jsxs(ze,{children:["This will permanently delete ",e.jsx("strong",{children:i==null?void 0:i.name}),"."]})]}),e.jsxs(Re,{children:[e.jsx(Te,{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(Cs,{className:"h-5 w-5 text-primary"})," Countries"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"Country master (used by address & location pickers)"})]}),y&&e.jsxs(C,{size:"sm",onClick:$,children:[e.jsx(_e,{className:"mr-1.5 h-3.5 w-3.5"})," Add Country"]})]}),e.jsx(ve,{columns:U,data:(D==null?void 0:D.results)??[],isLoading:B,searchPlaceholder:"Search countries...",emptyMessage:"No countries yet",emptyDescription:"Seed via seed_location_currency, or add one.",totalCount:(D==null?void 0:D.count)??0,pagination:o,onPaginationChange:S,sorting:q,onSortingChange:s,globalFilter:u,onGlobalFilterChange:v}),e.jsx(oe,{open:b,onOpenChange:r,children:e.jsxs(de,{size:"lg",children:[e.jsxs(me,{children:[e.jsx(he,{children:n?"Edit Country":"Add Country"}),e.jsx(ue,{children:n?"Update country details.":"Add a new country."})]}),e.jsxs("form",{onSubmit:M.handleSubmit(G),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(g,{children:"Name *"}),e.jsx(x,{...M.register("name"),className:"mt-1.5"}),M.formState.errors.name&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:M.formState.errors.name.message})]}),e.jsxs("div",{children:[e.jsx(g,{children:"Code *"}),e.jsx(x,{...M.register("code"),className:"mt-1.5",placeholder:"e.g. IN"}),M.formState.errors.code&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:M.formState.errors.code.message})]})]}),e.jsxs("div",{children:[e.jsx(g,{children:"Phone Code"}),e.jsx(x,{...M.register("phone_code"),className:"mt-1.5",placeholder:"e.g. +91"})]})]}),e.jsxs(xe,{children:[e.jsx(C,{variant:"outline",onClick:()=>r(!1),children:"Cancel"}),e.jsx(C,{onClick:M.handleSubmit(G),disabled:Y.isPending||I.isPending,children:n?"Save Changes":"Create Country"})]})]})})]})}const Bt=fe({name:f().min(1,"Name is required"),code:f().min(1,"Code is required"),country:f().min(1,"Country is required")});function Di(){const[b,r]=p.useState(!1),[n,j]=p.useState(null),[i,_]=p.useState(null),{hasPermission:t,requirePermission:F}=Fe(),y=t("system_admin","state","create"),w=t("system_admin","state","update"),c=t("system_admin","state","delete"),{pagination:o,setPagination:S,sorting:q,setSorting:s,globalFilter:u,setGlobalFilter:v,queryParams:O}=be(),{data:D,isLoading:B}=Ea(O),[Y,I]=p.useState(""),{data:N}=Fs(Y),M=Ma(),$=La(),A=qa(),G=je({resolver:ye(Bt)});function z(){F("system_admin","state","create")&&(j(null),G.reset({name:"",code:"",country:""}),r(!0))}function U(l){F("system_admin","state","update")&&(j(l),G.reset({name:l.name,code:l.code,country:l.country}),r(!0))}function L(l){const V=l;n?$.mutate({id:n.id,...V},{onSuccess:()=>r(!1)}):M.mutate(V,{onSuccess:()=>r(!1)})}function E(){i&&F("system_admin","state","delete")&&A.mutate(i.id,{onSuccess:()=>_(null)})}const P=[{key:"name",header:"State",render:l=>e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-slate-900",children:l.name}),e.jsx("span",{className:"ml-2 text-[11px] text-slate-400",children:l.code})]})},{key:"country_name",header:"Country"},{key:"is_active",header:"Status",render:l=>e.jsx(Pe,{status:l.is_active?"active":"inactive"})},{key:"actions",header:"",className:"w-10",render:l=>e.jsxs(Oe,{open:(i==null?void 0:i.id)===l.id,onOpenChange:V=>!V&&_(null),children:[e.jsxs(Ne,{children:[e.jsx(Ce,{asChild:!0,children:e.jsx(C,{variant:"ghost",size:"icon-sm",children:e.jsx(we,{className:"h-4 w-4"})})}),e.jsxs(Se,{align:"end",children:[e.jsxs(se,{onClick:()=>U(l),disabled:!w,children:[e.jsx(ke,{className:"mr-2 h-3.5 w-3.5"})," Edit"]}),e.jsx(Ee,{asChild:!0,children:e.jsxs(se,{className:"text-red-600",onClick:()=>_(l),disabled:!c,children:[e.jsx(Me,{className:"mr-2 h-3.5 w-3.5"})," Delete"]})})]})]}),e.jsxs(Le,{children:[e.jsxs(qe,{children:[e.jsx(Ve,{children:"Delete state?"}),e.jsxs(ze,{children:["This will permanently delete ",e.jsx("strong",{children:i==null?void 0:i.name}),"."]})]}),e.jsxs(Re,{children:[e.jsx(Te,{children:"Cancel"}),e.jsx(Ge,{variant:"destructive",onClick:E,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(zs,{className:"h-5 w-5 text-primary"})," States"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"State / province master under each country"})]}),y&&e.jsxs(C,{size:"sm",onClick:z,children:[e.jsx(_e,{className:"mr-1.5 h-3.5 w-3.5"})," Add State"]})]}),e.jsx(ve,{columns:P,data:(D==null?void 0:D.results)??[],isLoading:B,searchPlaceholder:"Search states...",emptyMessage:"No states yet",emptyDescription:"Add states under a country.",totalCount:(D==null?void 0:D.count)??0,pagination:o,onPaginationChange:S,sorting:q,onSortingChange:s,globalFilter:u,onGlobalFilterChange:v}),e.jsx(oe,{open:b,onOpenChange:r,children:e.jsxs(de,{size:"lg",children:[e.jsxs(me,{children:[e.jsx(he,{children:n?"Edit State":"Add State"}),e.jsx(ue,{children:n?"Update state details.":"Add a new state under a country."})]}),e.jsxs("form",{onSubmit:G.handleSubmit(L),className:"flex-1 overflow-y-auto px-6 py-5 space-y-4",children:[e.jsxs("div",{children:[e.jsx(g,{children:"Country *"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(De,{value:G.watch("country"),onValueChange:l=>G.setValue("country",l,{shouldValidate:!0}),onSearch:I,options:((N==null?void 0:N.results)??[]).map(l=>({value:l.id,label:l.name,hint:l.code})),placeholder:"Select country",searchPlaceholder:"Search countries..."})}),G.formState.errors.country&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:G.formState.errors.country.message})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(g,{children:"Name *"}),e.jsx(x,{...G.register("name"),className:"mt-1.5"}),G.formState.errors.name&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:G.formState.errors.name.message})]}),e.jsxs("div",{children:[e.jsx(g,{children:"Code *"}),e.jsx(x,{...G.register("code"),className:"mt-1.5",placeholder:"e.g. KA"}),G.formState.errors.code&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:G.formState.errors.code.message})]})]})]}),e.jsxs(xe,{children:[e.jsx(C,{variant:"outline",onClick:()=>r(!1),children:"Cancel"}),e.jsx(C,{onClick:G.handleSubmit(L),disabled:M.isPending||$.isPending,children:n?"Save Changes":"Create State"})]})]})})]})}const Ht=fe({name:f().min(1,"Name is required"),state:f().min(1,"State is required")});function Pi(){const[b,r]=p.useState(!1),[n,j]=p.useState(null),[i,_]=p.useState(null),[t,F]=p.useState(null),{hasPermission:y,requirePermission:w}=Fe(),c=y("system_admin","city","create"),o=y("system_admin","city","update"),S=y("system_admin","city","delete"),{pagination:q,setPagination:s,sorting:u,setSorting:v,globalFilter:O,setGlobalFilter:D,queryParams:B}=be(),{data:Y,isLoading:I}=Va(B),[N,M]=p.useState(""),[$,A]=p.useState(""),{data:G}=Fs(N),{data:z,isLoading:U}=za(t,$),L=Ra(),E=Ta(),P=Ga(),l=je({resolver:ye(Ht)});function V(){w("system_admin","city","create")&&(j(null),F(null),l.reset({name:"",state:""}),r(!0))}function d(h){w("system_admin","city","update")&&(j(h),F(h.country),l.reset({name:h.name,state:h.state}),r(!0))}function m(h){const H=h;n?E.mutate({id:n.id,...H},{onSuccess:()=>r(!1)}):L.mutate(H,{onSuccess:()=>r(!1)})}function ee(){i&&w("system_admin","city","delete")&&P.mutate(i.id,{onSuccess:()=>_(null)})}const re=[{key:"name",header:"City",render:h=>e.jsx("span",{className:"font-medium text-slate-900",children:h.name})},{key:"state_name",header:"State"},{key:"country_name",header:"Country"},{key:"is_active",header:"Status",render:h=>e.jsx(Pe,{status:h.is_active?"active":"inactive"})},{key:"actions",header:"",className:"w-10",render:h=>e.jsxs(Oe,{open:(i==null?void 0:i.id)===h.id,onOpenChange:H=>!H&&_(null),children:[e.jsxs(Ne,{children:[e.jsx(Ce,{asChild:!0,children:e.jsx(C,{variant:"ghost",size:"icon-sm",children:e.jsx(we,{className:"h-4 w-4"})})}),e.jsxs(Se,{align:"end",children:[e.jsxs(se,{onClick:()=>d(h),disabled:!o,children:[e.jsx(ke,{className:"mr-2 h-3.5 w-3.5"})," Edit"]}),e.jsx(Ee,{asChild:!0,children:e.jsxs(se,{className:"text-red-600",onClick:()=>_(h),disabled:!S,children:[e.jsx(Me,{className:"mr-2 h-3.5 w-3.5"})," Delete"]})})]})]}),e.jsxs(Le,{children:[e.jsxs(qe,{children:[e.jsx(Ve,{children:"Delete city?"}),e.jsxs(ze,{children:["This will permanently delete ",e.jsx("strong",{children:i==null?void 0:i.name}),"."]})]}),e.jsxs(Re,{children:[e.jsx(Te,{children:"Cancel"}),e.jsx(Ge,{variant:"destructive",onClick:ee,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(qs,{className:"h-5 w-5 text-primary"})," Cities"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"City master under each state"})]}),c&&e.jsxs(C,{size:"sm",onClick:V,children:[e.jsx(_e,{className:"mr-1.5 h-3.5 w-3.5"})," Add City"]})]}),e.jsx(ve,{columns:re,data:(Y==null?void 0:Y.results)??[],isLoading:I,searchPlaceholder:"Search cities...",emptyMessage:"No cities yet",emptyDescription:"Add cities under a state.",totalCount:(Y==null?void 0:Y.count)??0,pagination:q,onPaginationChange:s,sorting:u,onSortingChange:v,globalFilter:O,onGlobalFilterChange:D}),e.jsx(oe,{open:b,onOpenChange:r,children:e.jsxs(de,{size:"lg",children:[e.jsxs(me,{children:[e.jsx(he,{children:n?"Edit City":"Add City"}),e.jsx(ue,{children:n?"Update city details.":"Add a new city. Pick a country to filter states."})]}),e.jsxs("form",{onSubmit:l.handleSubmit(m),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(g,{children:"Country"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(De,{value:t,onValueChange:h=>{F(h),l.setValue("state","")},onSearch:M,options:((G==null?void 0:G.results)??[]).map(h=>({value:h.id,label:h.name,hint:h.code})),placeholder:"Select country",searchPlaceholder:"Search countries..."})})]}),e.jsxs("div",{children:[e.jsx(g,{children:"State *"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(De,{value:l.watch("state"),onValueChange:h=>l.setValue("state",h,{shouldValidate:!0}),onSearch:A,isLoading:U,options:((z==null?void 0:z.results)??[]).map(h=>({value:h.id,label:h.name,hint:h.code})),placeholder:t?"Select state":"Select country first",searchPlaceholder:"Search states...",disabled:!t})}),l.formState.errors.state&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:l.formState.errors.state.message})]})]}),e.jsxs("div",{children:[e.jsx(g,{children:"City Name *"}),e.jsx(x,{...l.register("name"),className:"mt-1.5"}),l.formState.errors.name&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:l.formState.errors.name.message})]})]}),e.jsxs(xe,{children:[e.jsx(C,{variant:"outline",onClick:()=>r(!1),children:"Cancel"}),e.jsx(C,{onClick:l.handleSubmit(m),disabled:L.isPending||E.isPending,children:n?"Save Changes":"Create City"})]})]})})]})}const Yt=fe({company:f().min(1,"Company is required"),name:f().min(1,"Name is required"),code:f().optional(),parent:f().nullable().optional(),head:f().nullable().optional()});function Ai(){const[b,r]=p.useState(!1),[n,j]=p.useState(null),[i,_]=p.useState(null),[t,F]=p.useState(""),{hasPermission:y,requirePermission:w}=Fe(),c=He(),o=y("system_admin","department","create"),S=y("system_admin","department","update"),q=y("system_admin","department","delete"),{pagination:s,setPagination:u,sorting:v,setSorting:O,globalFilter:D,setGlobalFilter:B,queryParams:Y}=be(),I={...Y,...t&&{is_active:t}},{data:N,isLoading:M}=Os(I);function $(a){F(a==="__all__"?"":a),u(k=>({...k,pageIndex:0}))}const A=(N==null?void 0:N.results)??[],[G,z]=p.useState(""),{data:U}=Je({search:G||void 0}),L=(U==null?void 0:U.results)??[],E=Ia(),P=Ua(),l=Ba(),V=je({resolver:ye(Yt)});function d(){w("system_admin","department","create")&&(j(null),V.reset({company:"",name:"",code:"",parent:null,head:null}),r(!0))}function m(a){w("system_admin","department","update")&&(j(a),V.reset({company:a.company,name:a.name,code:a.code,parent:a.parent,head:null}),r(!0))}function ee(a){const k={company:a.company,name:a.name,code:a.code,parent:a.parent||null,head:a.head||null};n?P.mutate({id:n.id,...k},{onSuccess:()=>r(!1)}):E.mutate(k,{onSuccess:()=>r(!1)})}function re(){i&&w("system_admin","department","delete")&&l.mutate(i.id,{onSuccess:()=>_(null)})}const h=V.watch("company"),H=A.filter(a=>a.company===h&&a.id!==(n==null?void 0:n.id)),Ae=[{key:"name",header:"Department",render:a=>e.jsxs("div",{className:"flex items-center",children:[a.level>0&&e.jsx("span",{className:"inline-flex items-center text-slate-300 mr-1",children:Array.from({length:a.level}).map((k,Ye)=>e.jsx(Us,{className:"h-3 w-3"},Ye))}),e.jsx("span",{className:"font-medium text-slate-900",children:a.name}),e.jsx("span",{className:"ml-2 text-[11px] text-slate-400",children:a.code})]})},{key:"company_name",header:"Company"},{key:"parent_name",header:"Parent",render:a=>a.parent_name||"—"},{key:"head_display",header:"Head",render:a=>a.head_display||"—"},{key:"children_count",header:"Children",render:a=>a.children_count>0?e.jsx(ce,{variant:"secondary",children:a.children_count}):"—"},{key:"is_active",header:"Status",render:a=>e.jsx(Pe,{status:a.is_active?"active":"inactive"})},{key:"actions",header:"",className:"w-10",render:a=>e.jsxs(Oe,{open:(i==null?void 0:i.id)===a.id,onOpenChange:k=>!k&&_(null),children:[e.jsxs(Ne,{children:[e.jsx(Ce,{asChild:!0,children:e.jsx(C,{variant:"ghost",size:"icon-sm",children:e.jsx(we,{className:"h-4 w-4"})})}),e.jsxs(Se,{align:"end",children:[e.jsxs(se,{onClick:()=>m(a),disabled:!S,children:[e.jsx(ke,{className:"mr-2 h-3.5 w-3.5"})," Edit"]}),e.jsx(Ee,{asChild:!0,children:e.jsxs(se,{className:"text-red-600",onClick:()=>_(a),disabled:!q,children:[e.jsx(Me,{className:"mr-2 h-3.5 w-3.5"})," Delete"]})})]})]}),e.jsxs(Le,{children:[e.jsxs(qe,{children:[e.jsx(Ve,{children:"Delete department?"}),e.jsxs(ze,{children:["This will permanently delete ",e.jsx("strong",{children:i==null?void 0:i.name}),i&&i.children_count>0&&` and its ${i.children_count} sub-departments`,"."]})]}),e.jsxs(Re,{children:[e.jsx(Te,{children:"Cancel"}),e.jsx(Ge,{variant:"destructive",onClick:re,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"})," Departments"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"Organizational hierarchy"})]}),o&&e.jsxs(C,{size:"sm",onClick:d,children:[e.jsx(_e,{className:"mr-1.5 h-3.5 w-3.5"})," Add Department"]})]}),e.jsx(ve,{actions:e.jsxs(ae,{value:t,onValueChange:$,children:[e.jsx(te,{className:"w-[140px] h-9",children:e.jsx(ne,{placeholder:"All statuses"})}),e.jsxs(ie,{children:[e.jsx(T,{value:"__all__",children:"All"}),e.jsx(T,{value:"true",children:"Active"}),e.jsx(T,{value:"false",children:"Inactive"})]})]}),columns:Ae,data:A,isLoading:M,searchPlaceholder:"Search departments...",emptyMessage:"No departments yet",emptyDescription:"Add departments for your companies.",totalCount:(N==null?void 0:N.count)??0,pagination:s,onPaginationChange:u,sorting:v,onSortingChange:O,globalFilter:D,onGlobalFilterChange:B}),e.jsx(oe,{open:b,onOpenChange:r,children:e.jsxs(de,{children:[e.jsxs(me,{children:[e.jsx(he,{children:n?"Edit Department":"Add Department"}),e.jsx(ue,{children:n?"Update department details.":"Create a new department."})]}),e.jsxs("form",{onSubmit:V.handleSubmit(ee),className:"flex-1 overflow-y-auto px-6 py-5 space-y-4",children:[e.jsxs("div",{children:[e.jsx(g,{children:"Company *"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(De,{value:V.watch("company")??null,onValueChange:a=>{V.setValue("company",a,{shouldValidate:!0}),V.setValue("parent",null)},onSearch:z,selectedLabel:n==null?void 0:n.company_name,options:L.map(a=>({value:a.id,label:a.name,hint:a.code})),placeholder:"Select company",searchPlaceholder:"Search companies..."})}),V.formState.errors.company&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:V.formState.errors.company.message})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(g,{children:"Name *"}),e.jsx(x,{...V.register("name"),className:"mt-1.5"}),V.formState.errors.name&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:V.formState.errors.name.message})]}),c==="manual"&&e.jsxs("div",{children:[e.jsx(g,{children:"Code *"}),e.jsx(x,{...V.register("code"),className:"mt-1.5"}),V.formState.errors.code&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:V.formState.errors.code.message})]})]}),e.jsxs("div",{children:[e.jsx(g,{children:"Parent Department"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(De,{value:V.watch("parent")??"__none__",onValueChange:a=>V.setValue("parent",a==="__none__"?null:a),selectedLabel:(n==null?void 0:n.parent_name)??void 0,options:[{value:"__none__",label:"None (root level)"},...H.map(a=>({value:a.id,label:`${"  ".repeat(a.level)}${a.name}`,hint:a.code}))],placeholder:"None (root level)",searchPlaceholder:"Search departments..."})})]}),e.jsxs("div",{children:[e.jsx(g,{children:"Department Head"}),e.jsx(ft,{value:V.watch("head")??"",onValueChange:a=>V.setValue("head",a),userId:n==null?void 0:n.head,placeholder:"Select department head",className:"mt-1.5"})]})]}),e.jsxs(xe,{children:[e.jsx(C,{variant:"outline",onClick:()=>r(!1),children:"Cancel"}),e.jsx(C,{onClick:V.handleSubmit(ee),disabled:E.isPending||P.isPending,children:n?"Save Changes":"Create Department"})]})]})})]})}const Qt=fe({name:f().min(1,"Name is required"),code:f().optional(),level:Ie.number().min(1,"Level must be at least 1"),min_salary:f().optional(),mid_salary:f().optional(),max_salary:f().optional(),currency:f().nullable().optional()});function ts(b,r){const n=parseFloat(b);return n?`${r??""} ${n.toLocaleString()}`.trim():"—"}function Fi(){var re;const[b,r]=p.useState(!1),[n,j]=p.useState(null),[i,_]=p.useState(null),[t,F]=p.useState(""),{hasPermission:y,requirePermission:w}=Fe(),c=He(),o=y("system_admin","grade","create"),S=y("system_admin","grade","update"),q=y("system_admin","grade","delete"),{pagination:s,setPagination:u,sorting:v,setSorting:O,globalFilter:D,setGlobalFilter:B,queryParams:Y}=be(),I={...Y,...t&&{is_active:t}},{data:N,isLoading:M}=Es(I);function $(h){F(h==="__all__"?"":h),u(H=>({...H,pageIndex:0}))}const[A,G]=p.useState(""),{data:z}=ms({search:A||void 0}),U=Ha(),L=Ya(),E=Qa(),P=je({resolver:ye(Qt),defaultValues:{currency:null,min_salary:"0",mid_salary:"0",max_salary:"0"}});function l(){w("system_admin","grade","create")&&(j(null),P.reset({name:"",code:"",level:1,currency:null,min_salary:"0",mid_salary:"0",max_salary:"0"}),r(!0))}function V(h){w("system_admin","grade","update")&&(j(h),P.reset({name:h.name,code:h.code,level:h.level,min_salary:h.min_salary,mid_salary:h.mid_salary,max_salary:h.max_salary,currency:h.currency}),r(!0))}function d(h){const H=h;n?L.mutate({id:n.id,...H},{onSuccess:()=>r(!1)}):U.mutate(H,{onSuccess:()=>r(!1)})}function m(){i&&w("system_admin","grade","delete")&&E.mutate(i.id,{onSuccess:()=>_(null)})}const ee=[{key:"name",header:"Grade",render:h=>e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-slate-900",children:h.name}),e.jsx("span",{className:"ml-2 text-[11px] text-slate-400",children:h.code})]})},{key:"level",header:"Level",render:h=>e.jsxs(ce,{variant:"secondary",children:["L",h.level]})},{key:"min_salary",header:"Min Salary",render:h=>{var H;return e.jsx("span",{className:"tabular-nums",children:ts(h.min_salary,(H=h.currency_detail)==null?void 0:H.code)})}},{key:"mid_salary",header:"Mid Salary",render:h=>{var H;return e.jsx("span",{className:"tabular-nums",children:ts(h.mid_salary,(H=h.currency_detail)==null?void 0:H.code)})}},{key:"max_salary",header:"Max Salary",render:h=>{var H;return e.jsx("span",{className:"tabular-nums",children:ts(h.max_salary,(H=h.currency_detail)==null?void 0:H.code)})}},{key:"designation_count",header:"Designations",render:h=>h.designation_count>0?e.jsx(ce,{variant:"default",children:h.designation_count}):"—"},{key:"is_active",header:"Status",render:h=>e.jsx(Pe,{status:h.is_active?"active":"inactive"})},{key:"actions",header:"",className:"w-10",render:h=>e.jsxs(Oe,{open:(i==null?void 0:i.id)===h.id,onOpenChange:H=>!H&&_(null),children:[e.jsxs(Ne,{children:[e.jsx(Ce,{asChild:!0,children:e.jsx(C,{variant:"ghost",size:"icon-sm",children:e.jsx(we,{className:"h-4 w-4"})})}),e.jsxs(Se,{align:"end",children:[e.jsxs(se,{onClick:()=>V(h),disabled:!S,children:[e.jsx(ke,{className:"mr-2 h-3.5 w-3.5"})," Edit"]}),e.jsx(Ee,{asChild:!0,children:e.jsxs(se,{className:"text-red-600",onClick:()=>_(h),disabled:!q,children:[e.jsx(Me,{className:"mr-2 h-3.5 w-3.5"})," Delete"]})})]})]}),e.jsxs(Le,{children:[e.jsxs(qe,{children:[e.jsx(Ve,{children:"Delete grade?"}),e.jsxs(ze,{children:["This will permanently delete grade ",e.jsx("strong",{children:i==null?void 0:i.name}),"."]})]}),e.jsxs(Re,{children:[e.jsx(Te,{children:"Cancel"}),e.jsx(Ge,{variant:"destructive",onClick:m,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(rs,{className:"h-5 w-5 text-primary"})," Grades"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"Pay grades and salary bands"})]}),o&&e.jsxs(C,{size:"sm",onClick:l,children:[e.jsx(_e,{className:"mr-1.5 h-3.5 w-3.5"})," Add Grade"]})]}),e.jsx(ve,{actions:e.jsxs(ae,{value:t,onValueChange:$,children:[e.jsx(te,{className:"w-[140px] h-9",children:e.jsx(ne,{placeholder:"All statuses"})}),e.jsxs(ie,{children:[e.jsx(T,{value:"__all__",children:"All"}),e.jsx(T,{value:"true",children:"Active"}),e.jsx(T,{value:"false",children:"Inactive"})]})]}),columns:ee,data:(N==null?void 0:N.results)??[],isLoading:M,searchPlaceholder:"Search grades...",emptyMessage:"No grades yet",emptyDescription:"Define pay grades for your organization.",totalCount:(N==null?void 0:N.count)??0,pagination:s,onPaginationChange:u,sorting:v,onSortingChange:O,globalFilter:D,onGlobalFilterChange:B}),e.jsx(oe,{open:b,onOpenChange:r,children:e.jsxs(de,{children:[e.jsxs(me,{children:[e.jsx(he,{children:n?"Edit Grade":"Add Grade"}),e.jsx(ue,{children:n?"Update grade details.":"Create a new pay grade."})]}),e.jsxs("form",{onSubmit:P.handleSubmit(d),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(g,{children:"Name *"}),e.jsx(x,{...P.register("name"),className:"mt-1.5"}),P.formState.errors.name&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:P.formState.errors.name.message})]}),c==="manual"&&e.jsxs("div",{children:[e.jsx(g,{children:"Code *"}),e.jsx(x,{...P.register("code"),className:"mt-1.5",placeholder:"e.g. G1"}),P.formState.errors.code&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:P.formState.errors.code.message})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(g,{children:"Level * (1 = highest)"}),e.jsx(x,{...P.register("level"),type:"number",min:1,className:"mt-1.5"}),P.formState.errors.level&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:P.formState.errors.level.message})]}),e.jsxs("div",{children:[e.jsx(g,{children:"Currency"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(De,{value:P.watch("currency")??null,onValueChange:h=>P.setValue("currency",h),onSearch:G,selectedLabel:(re=n==null?void 0:n.currency_detail)==null?void 0:re.code,options:((z==null?void 0:z.results)??[]).map(h=>({value:h.id,label:h.code,hint:h.name})),placeholder:"Select currency",searchPlaceholder:"Search currencies..."})})]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsxs("div",{children:[e.jsx(g,{children:"Min Salary"}),e.jsx(x,{...P.register("min_salary"),type:"number",step:"0.01",className:"mt-1.5"})]}),e.jsxs("div",{children:[e.jsx(g,{children:"Mid Salary"}),e.jsx(x,{...P.register("mid_salary"),type:"number",step:"0.01",className:"mt-1.5"})]}),e.jsxs("div",{children:[e.jsx(g,{children:"Max Salary"}),e.jsx(x,{...P.register("max_salary"),type:"number",step:"0.01",className:"mt-1.5"})]})]})]}),e.jsxs(xe,{children:[e.jsx(C,{variant:"outline",onClick:()=>r(!1),children:"Cancel"}),e.jsx(C,{onClick:P.handleSubmit(d),disabled:U.isPending||L.isPending,children:n?"Save Changes":"Create Grade"})]})]})})]})}const $t=fe({name:f().min(1,"Name is required"),code:f().optional(),grade:f().nullable().optional(),level:Ie.number().min(0).optional()});function Oi(){const[b,r]=p.useState(!1),[n,j]=p.useState(null),[i,_]=p.useState(null),[t,F]=p.useState(""),{hasPermission:y,requirePermission:w}=Fe(),c=He(),o=y("system_admin","designation","create"),S=y("system_admin","designation","update"),q=y("system_admin","designation","delete"),{pagination:s,setPagination:u,sorting:v,setSorting:O,globalFilter:D,setGlobalFilter:B,queryParams:Y}=be(),I={...Y,...t&&{is_active:t}},{data:N,isLoading:M}=$a(I);function $(h){F(h==="__all__"?"":h),u(H=>({...H,pageIndex:0}))}const[A,G]=p.useState(""),{data:z}=Es({search:A||void 0}),U=(z==null?void 0:z.results)??[],L=Ja(),E=Wa(),P=Ka(),l=je({resolver:ye($t)});function V(){w("system_admin","designation","create")&&(j(null),l.reset({name:"",code:"",grade:null,level:0}),r(!0))}function d(h){w("system_admin","designation","update")&&(j(h),l.reset({name:h.name,code:h.code,grade:h.grade,level:h.level}),r(!0))}function m(h){const H={...h,grade:h.grade||null};n?E.mutate({id:n.id,...H},{onSuccess:()=>r(!1)}):L.mutate(H,{onSuccess:()=>r(!1)})}function ee(){i&&w("system_admin","designation","delete")&&P.mutate(i.id,{onSuccess:()=>_(null)})}const re=[{key:"name",header:"Designation",render:h=>e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-slate-900",children:h.name}),e.jsx("span",{className:"ml-2 text-[11px] text-slate-400",children:h.code})]})},{key:"grade_name",header:"Grade",render:h=>h.grade_name||"—"},{key:"level",header:"Level",render:h=>e.jsx("span",{className:"tabular-nums",children:h.level})},{key:"is_active",header:"Status",render:h=>e.jsx(Pe,{status:h.is_active?"active":"inactive"})},{key:"actions",header:"",className:"w-10",render:h=>e.jsxs(Oe,{open:(i==null?void 0:i.id)===h.id,onOpenChange:H=>!H&&_(null),children:[e.jsxs(Ne,{children:[e.jsx(Ce,{asChild:!0,children:e.jsx(C,{variant:"ghost",size:"icon-sm",children:e.jsx(we,{className:"h-4 w-4"})})}),e.jsxs(Se,{align:"end",children:[e.jsxs(se,{onClick:()=>d(h),disabled:!S,children:[e.jsx(ke,{className:"mr-2 h-3.5 w-3.5"})," Edit"]}),e.jsx(Ee,{asChild:!0,children:e.jsxs(se,{className:"text-red-600",onClick:()=>_(h),disabled:!q,children:[e.jsx(Me,{className:"mr-2 h-3.5 w-3.5"})," Delete"]})})]})]}),e.jsxs(Le,{children:[e.jsxs(qe,{children:[e.jsx(Ve,{children:"Delete designation?"}),e.jsxs(ze,{children:["This will permanently delete ",e.jsx("strong",{children:i==null?void 0:i.name}),"."]})]}),e.jsxs(Re,{children:[e.jsx(Te,{children:"Cancel"}),e.jsx(Ge,{variant:"destructive",onClick:ee,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(cs,{className:"h-5 w-5 text-primary"})," Designations"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"Job titles and designations"})]}),o&&e.jsxs(C,{size:"sm",onClick:V,children:[e.jsx(_e,{className:"mr-1.5 h-3.5 w-3.5"})," Add Designation"]})]}),e.jsx(ve,{actions:e.jsxs(ae,{value:t,onValueChange:$,children:[e.jsx(te,{className:"w-[140px] h-9",children:e.jsx(ne,{placeholder:"All statuses"})}),e.jsxs(ie,{children:[e.jsx(T,{value:"__all__",children:"All"}),e.jsx(T,{value:"true",children:"Active"}),e.jsx(T,{value:"false",children:"Inactive"})]})]}),columns:re,data:(N==null?void 0:N.results)??[],isLoading:M,searchPlaceholder:"Search designations...",emptyMessage:"No designations yet",emptyDescription:"Define job titles for your organization.",totalCount:(N==null?void 0:N.count)??0,pagination:s,onPaginationChange:u,sorting:v,onSortingChange:O,globalFilter:D,onGlobalFilterChange:B}),e.jsx(oe,{open:b,onOpenChange:r,children:e.jsxs(de,{children:[e.jsxs(me,{children:[e.jsx(he,{children:n?"Edit Designation":"Add Designation"}),e.jsx(ue,{children:n?"Update designation details.":"Create a new job title."})]}),e.jsxs("form",{onSubmit:l.handleSubmit(m),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(g,{children:"Name *"}),e.jsx(x,{...l.register("name"),className:"mt-1.5"}),l.formState.errors.name&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:l.formState.errors.name.message})]}),c==="manual"&&e.jsxs("div",{children:[e.jsx(g,{children:"Code *"}),e.jsx(x,{...l.register("code"),className:"mt-1.5"}),l.formState.errors.code&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:l.formState.errors.code.message})]})]}),e.jsxs("div",{children:[e.jsx(g,{children:"Grade"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(De,{value:l.watch("grade")??"__none__",onValueChange:h=>l.setValue("grade",h==="__none__"?null:h),onSearch:G,selectedLabel:(n==null?void 0:n.grade_name)??void 0,options:[{value:"__none__",label:"No grade"},...U.map(h=>({value:h.id,label:`${h.name} (L${h.level})`,hint:h.code}))],placeholder:"No grade linked",searchPlaceholder:"Search grades..."})})]}),e.jsxs("div",{children:[e.jsx(g,{children:"Level"}),e.jsx(x,{...l.register("level"),type:"number",min:0,className:"mt-1.5"})]})]}),e.jsxs(xe,{children:[e.jsx(C,{variant:"outline",onClick:()=>r(!1),children:"Cancel"}),e.jsx(C,{onClick:l.handleSubmit(m),disabled:L.isPending||E.isPending,children:n?"Save Changes":"Create Designation"})]})]})})]})}const Jt=fe({name:f().min(1,"Name is required"),code:f().optional(),description:f().optional(),probation_days:Ie.number().min(0).optional(),notice_period_days:Ie.number().min(0).optional()});function Ei(){const[b,r]=p.useState(!1),[n,j]=p.useState(null),[i,_]=p.useState(null),[t,F]=p.useState(""),{hasPermission:y,requirePermission:w}=Fe(),c=He(),o=y("system_admin","category","create"),S=y("system_admin","category","update"),q=y("system_admin","category","delete"),{pagination:s,setPagination:u,sorting:v,setSorting:O,globalFilter:D,setGlobalFilter:B,queryParams:Y}=be(),I={...Y,...t&&{is_active:t}},{data:N,isLoading:M}=Za(I);function $(d){F(d==="__all__"?"":d),u(m=>({...m,pageIndex:0}))}const A=Xa(),G=et(),z=st(),U=je({resolver:ye(Jt),defaultValues:{probation_days:0,notice_period_days:30}});function L(){w("system_admin","category","create")&&(j(null),U.reset({name:"",code:"",description:"",probation_days:0,notice_period_days:30}),r(!0))}function E(d){w("system_admin","category","update")&&(j(d),U.reset({name:d.name,code:d.code,description:d.description,probation_days:d.probation_days,notice_period_days:d.notice_period_days}),r(!0))}function P(d){const m=d;n?G.mutate({id:n.id,...m},{onSuccess:()=>r(!1)}):A.mutate(m,{onSuccess:()=>r(!1)})}function l(){i&&w("system_admin","category","delete")&&z.mutate(i.id,{onSuccess:()=>_(null)})}const V=[{key:"name",header:"Category",render:d=>e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-slate-900",children:d.name}),e.jsx("span",{className:"ml-2 text-[11px] text-slate-400",children:d.code})]})},{key:"description",header:"Description",render:d=>d.description||"—"},{key:"probation_days",header:"Probation",render:d=>d.probation_days>0?`${d.probation_days} days`:"None"},{key:"notice_period_days",header:"Notice Period",render:d=>`${d.notice_period_days} days`},{key:"is_active",header:"Status",render:d=>e.jsx(Pe,{status:d.is_active?"active":"inactive"})},{key:"actions",header:"",className:"w-10",render:d=>e.jsxs(Oe,{open:(i==null?void 0:i.id)===d.id,onOpenChange:m=>!m&&_(null),children:[e.jsxs(Ne,{children:[e.jsx(Ce,{asChild:!0,children:e.jsx(C,{variant:"ghost",size:"icon-sm",children:e.jsx(we,{className:"h-4 w-4"})})}),e.jsxs(Se,{align:"end",children:[e.jsxs(se,{onClick:()=>E(d),disabled:!S,children:[e.jsx(ke,{className:"mr-2 h-3.5 w-3.5"})," Edit"]}),e.jsx(Ee,{asChild:!0,children:e.jsxs(se,{className:"text-red-600",onClick:()=>_(d),disabled:!q,children:[e.jsx(Me,{className:"mr-2 h-3.5 w-3.5"})," Delete"]})})]})]}),e.jsxs(Le,{children:[e.jsxs(qe,{children:[e.jsx(Ve,{children:"Delete category?"}),e.jsxs(ze,{children:["This will permanently delete ",e.jsx("strong",{children:i==null?void 0:i.name}),"."]})]}),e.jsxs(Re,{children:[e.jsx(Te,{children:"Cancel"}),e.jsx(Ge,{variant:"destructive",onClick:l,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"})," Employee Categories"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"Employment types with probation and notice configurations"})]}),o&&e.jsxs(C,{size:"sm",onClick:L,children:[e.jsx(_e,{className:"mr-1.5 h-3.5 w-3.5"})," Add Category"]})]}),e.jsx(ve,{actions:e.jsxs(ae,{value:t,onValueChange:$,children:[e.jsx(te,{className:"w-[140px] h-9",children:e.jsx(ne,{placeholder:"All statuses"})}),e.jsxs(ie,{children:[e.jsx(T,{value:"__all__",children:"All"}),e.jsx(T,{value:"true",children:"Active"}),e.jsx(T,{value:"false",children:"Inactive"})]})]}),columns:V,data:(N==null?void 0:N.results)??[],isLoading:M,searchPlaceholder:"Search categories...",emptyMessage:"No categories yet",emptyDescription:"Define employment types like Permanent, Contract, Intern.",totalCount:(N==null?void 0:N.count)??0,pagination:s,onPaginationChange:u,sorting:v,onSortingChange:O,globalFilter:D,onGlobalFilterChange:B}),e.jsx(oe,{open:b,onOpenChange:r,children:e.jsxs(de,{children:[e.jsxs(me,{children:[e.jsx(he,{children:n?"Edit Category":"Add Category"}),e.jsx(ue,{children:n?"Update category details.":"Create a new employment category."})]}),e.jsxs("form",{onSubmit:U.handleSubmit(P),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(g,{children:"Name *"}),e.jsx(x,{...U.register("name"),className:"mt-1.5",placeholder:"e.g. Permanent"}),U.formState.errors.name&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:U.formState.errors.name.message})]}),c==="manual"&&e.jsxs("div",{children:[e.jsx(g,{children:"Code *"}),e.jsx(x,{...U.register("code"),className:"mt-1.5",placeholder:"e.g. PERM"}),U.formState.errors.code&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:U.formState.errors.code.message})]})]}),e.jsxs("div",{children:[e.jsx(g,{children:"Description"}),e.jsx(Be,{...U.register("description"),className:"mt-1.5",rows:3})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(g,{children:"Probation Days"}),e.jsx(x,{...U.register("probation_days"),type:"number",min:0,className:"mt-1.5"}),e.jsx("p",{className:"mt-1 text-[11px] text-slate-400",children:"0 = no probation"})]}),e.jsxs("div",{children:[e.jsx(g,{children:"Notice Period (days)"}),e.jsx(x,{...U.register("notice_period_days"),type:"number",min:0,className:"mt-1.5"})]})]})]}),e.jsxs(xe,{children:[e.jsx(C,{variant:"outline",onClick:()=>r(!1),children:"Cancel"}),e.jsx(C,{onClick:U.handleSubmit(P),disabled:A.isPending||G.isPending,children:n?"Save Changes":"Create Category"})]})]})})]})}const Wt=Ms(fe({company:f().min(1,"Company is required"),name:f().min(1,"Name is required"),start_date:is("Start date is required"),end_date:is("End date is required"),is_current:Ue().optional(),is_locked:Ue().optional()}),"start_date","end_date");function Mi(){const[b,r]=p.useState(!1),[n,j]=p.useState(null),[i,_]=p.useState(""),[t,F]=p.useState(null),{pagination:y,setPagination:w,sorting:c,setSorting:o,globalFilter:S,setGlobalFilter:q,queryParams:s}=be(),u={...s,...i&&{is_locked:i}},{data:v,isLoading:O}=at(u);function D(l){_(l==="__all__"?"":l),w(V=>({...V,pageIndex:0}))}const[B,Y]=p.useState(""),{data:I}=Je({search:B||void 0}),N=(I==null?void 0:I.results)??[],M=tt(),$=nt(),{data:A,isLoading:G}=it((t==null?void 0:t.id)??null),z=je({resolver:ye(Wt)});function U(){j(null),z.reset({company:"",name:"",start_date:"",end_date:"",is_current:!1,is_locked:!1}),r(!0)}function L(l){j(l),z.reset({company:l.company,name:l.name,start_date:l.start_date,end_date:l.end_date,is_current:l.is_current,is_locked:l.is_locked}),r(!0)}function E(l){const V=l;n?$.mutate({id:n.id,...V},{onSuccess:()=>r(!1)}):M.mutate(V,{onSuccess:d=>{r(!1),F(d)}})}const P=[{key:"name",header:"Fiscal Year",render:l=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium text-slate-900",children:l.name}),l.is_current&&e.jsx(ce,{variant:"default",children:"Current"}),l.is_locked&&e.jsx(Ls,{className:"h-3 w-3 text-slate-400"})]})},{key:"company_name",header:"Company"},{key:"start_date",header:"Start Date"},{key:"end_date",header:"End Date"},{key:"is_locked",header:"Status",render:l=>e.jsx(ce,{variant:l.is_locked?"secondary":"success",children:l.is_locked?"Locked":"Open"})},{key:"actions",header:"",className:"w-10",render:l=>e.jsxs(Ne,{children:[e.jsx(Ce,{asChild:!0,children:e.jsx(C,{variant:"ghost",size:"icon-sm",children:e.jsx(we,{className:"h-4 w-4"})})}),e.jsxs(Se,{align:"end",children:[e.jsxs(se,{onClick:()=>F(l),children:[e.jsx(xs,{className:"mr-2 h-3.5 w-3.5"})," View Periods"]}),e.jsxs(se,{onClick:()=>L(l),children:[e.jsx(ke,{className:"mr-2 h-3.5 w-3.5"})," Edit"]})]})]})}];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(ws,{className:"h-5 w-5 text-primary"})," Fiscal Years"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"Financial periods for your companies"})]}),e.jsxs(C,{size:"sm",onClick:U,children:[e.jsx(_e,{className:"mr-1.5 h-3.5 w-3.5"})," Add Fiscal Year"]})]}),e.jsx(ve,{actions:e.jsxs(ae,{value:i,onValueChange:D,children:[e.jsx(te,{className:"w-[140px] h-9",children:e.jsx(ne,{placeholder:"All statuses"})}),e.jsxs(ie,{children:[e.jsx(T,{value:"__all__",children:"All"}),e.jsx(T,{value:"false",children:"Open"}),e.jsx(T,{value:"true",children:"Locked"})]})]}),columns:P,data:(v==null?void 0:v.results)??[],isLoading:O,searchPlaceholder:"Search fiscal years...",emptyMessage:"No fiscal years",emptyDescription:"Define financial periods for your companies.",totalCount:(v==null?void 0:v.count)??0,pagination:y,onPaginationChange:w,sorting:c,onSortingChange:o,globalFilter:S,onGlobalFilterChange:q}),e.jsx(oe,{open:b,onOpenChange:r,children:e.jsxs(de,{children:[e.jsxs(me,{children:[e.jsx(he,{children:n?"Edit Fiscal Year":"Add Fiscal Year"}),e.jsx(ue,{children:n?"Update fiscal year details.":"Define a new financial period."})]}),e.jsx("form",{onSubmit:z.handleSubmit(E),className:"flex-1 overflow-y-auto px-6 py-5 space-y-4",children:e.jsxs(os,{...z,children:[e.jsxs("div",{children:[e.jsx(g,{children:"Company *"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(De,{value:z.watch("company")??null,onValueChange:l=>z.setValue("company",l,{shouldValidate:!0}),onSearch:Y,selectedLabel:n==null?void 0:n.company_name,options:N.map(l=>({value:l.id,label:l.name,hint:l.code})),placeholder:"Select company",searchPlaceholder:"Search companies..."})}),z.formState.errors.company&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:z.formState.errors.company.message})]}),e.jsxs("div",{children:[e.jsx(g,{children:"Name *"}),e.jsx(x,{...z.register("name"),className:"mt-1.5",placeholder:"e.g. FY 2025-26"}),z.formState.errors.name&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:z.formState.errors.name.message})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(Ke,{name:"start_date",maxField:"end_date",label:"Start Date",required:!0}),e.jsx(Ke,{name:"end_date",minField:"start_date",label:"End Date",required:!0})]})]})}),e.jsxs(xe,{children:[e.jsx(C,{variant:"outline",onClick:()=>r(!1),children:"Cancel"}),e.jsx(C,{onClick:z.handleSubmit(E),disabled:M.isPending||$.isPending,children:n?"Save Changes":"Create Fiscal Year"})]})]})}),e.jsx(oe,{open:!!t,onOpenChange:l=>{l||F(null)},children:e.jsxs(de,{className:"w-[560px] sm:max-w-[560px]",children:[e.jsxs(me,{children:[e.jsxs(he,{className:"flex items-center gap-2",children:[e.jsx(xs,{className:"h-4 w-4 text-primary"}),t==null?void 0:t.name," — Monthly Periods"]}),e.jsx(ue,{children:"Auto-generated periods based on the fiscal year date range."})]}),e.jsx("div",{className:"flex-1 overflow-y-auto px-6 py-4",children:G?e.jsx("p",{className:"text-[13px] text-slate-400 text-center py-8",children:"Loading periods…"}):e.jsxs("table",{className:"w-full text-[13px]",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b text-slate-500 text-left",children:[e.jsx("th",{className:"pb-2 font-medium w-8",children:"#"}),e.jsx("th",{className:"pb-2 font-medium",children:"Period"}),e.jsx("th",{className:"pb-2 font-medium",children:"Start Date"}),e.jsx("th",{className:"pb-2 font-medium",children:"End Date"})]})}),e.jsx("tbody",{children:((A==null?void 0:A.results)??[]).map(l=>e.jsxs("tr",{className:"border-b last:border-0 hover:bg-slate-50",children:[e.jsx("td",{className:"py-2.5 text-slate-400",children:l.period_number}),e.jsx("td",{className:"py-2.5 font-medium text-slate-900",children:l.name}),e.jsx("td",{className:"py-2.5 text-slate-600",children:l.start_date}),e.jsx("td",{className:"py-2.5 text-slate-600",children:l.end_date})]},l.id))})]})}),e.jsx(xe,{children:e.jsx(C,{variant:"outline",onClick:()=>F(null),children:"Close"})})]})})]})}const Kt=fe({code:f().min(1,"Code is required").max(3),name:f().min(1,"Name is required"),symbol:f().min(1,"Symbol is required"),decimal_places:Ie.number().min(0).max(4).optional()}),Zt=fe({from_currency:f().min(1,"Required"),to_currency:f().min(1,"Required"),rate:f().min(1,"Required"),effective_date:is("Required"),source:f().optional()});function Li(){const[b,r]=p.useState("currencies"),[n,j]=p.useState(!1),[i,_]=p.useState(!1),[t,F]=p.useState(null),[y,w]=p.useState(""),{pagination:c,setPagination:o,sorting:S,setSorting:q,globalFilter:s,setGlobalFilter:u,queryParams:v}=be(),{pagination:O,setPagination:D,sorting:B,setSorting:Y,globalFilter:I,setGlobalFilter:N,queryParams:M}=be(),$={...v,...y&&{is_active:y}},{data:A,isLoading:G}=ms($);function z(k){w(k==="__all__"?"":k),o(Ye=>({...Ye,pageIndex:0}))}const U=(A==null?void 0:A.results)??[],{data:L,isLoading:E}=lt(M),P=rt(),l=ct(),V=ot(),d=je({resolver:ye(Kt),defaultValues:{decimal_places:2}}),m=je({resolver:ye(Zt),defaultValues:{source:"manual"}});function ee(){F(null),d.reset({code:"",name:"",symbol:"",decimal_places:2}),j(!0)}function re(k){F(k),d.reset({code:k.code,name:k.name,symbol:k.symbol,decimal_places:k.decimal_places}),j(!0)}function h(k){const Ye=k;t?l.mutate({id:t.id,...Ye},{onSuccess:()=>j(!1)}):P.mutate(Ye,{onSuccess:()=>j(!1)})}function H(k){V.mutate(k,{onSuccess:()=>_(!1)})}const Ae=[{key:"code",header:"Currency",render:k=>e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-slate-900",children:k.code}),e.jsx("span",{className:"ml-2 text-[13px] text-slate-500",children:k.symbol})]})},{key:"name",header:"Name"},{key:"decimal_places",header:"Decimals",render:k=>e.jsx("span",{className:"tabular-nums",children:k.decimal_places})},{key:"is_active",header:"Status",render:k=>e.jsx(Pe,{status:k.is_active?"active":"inactive"})},{key:"actions",header:"",className:"w-10",render:k=>e.jsxs(Ne,{children:[e.jsx(Ce,{asChild:!0,children:e.jsx(C,{variant:"ghost",size:"icon-sm",children:e.jsx(we,{className:"h-4 w-4"})})}),e.jsx(Se,{align:"end",children:e.jsxs(se,{onClick:()=>re(k),children:[e.jsx(ke,{className:"mr-2 h-3.5 w-3.5"})," Edit"]})})]})}],a=[{key:"from_currency_code",header:"From → To",render:k=>e.jsxs("span",{className:"font-medium text-slate-900",children:[k.from_currency_code," ",e.jsx(gt,{className:"inline h-3 w-3 text-slate-400 mx-1"})," ",k.to_currency_code]})},{key:"rate",header:"Rate",render:k=>e.jsx("span",{className:"tabular-nums font-medium",children:k.rate})},{key:"effective_date",header:"Effective Date"},{key:"source",header:"Source",render:k=>e.jsx(ce,{variant:"secondary",children:k.source})}];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(Vs,{className:"h-5 w-5 text-primary"})," Currencies"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"Currency definitions and exchange rates"})]})}),e.jsxs(Bs,{value:b,onValueChange:r,children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs(Hs,{children:[e.jsx(hs,{value:"currencies",children:"Currencies"}),e.jsx(hs,{value:"rates",children:"Exchange Rates"})]}),b==="currencies"?e.jsxs(C,{size:"sm",onClick:ee,children:[e.jsx(_e,{className:"mr-1.5 h-3.5 w-3.5"})," Add Currency"]}):e.jsxs(C,{size:"sm",onClick:()=>{m.reset({from_currency:"",to_currency:"",rate:"",effective_date:"",source:"manual"}),_(!0)},children:[e.jsx(_e,{className:"mr-1.5 h-3.5 w-3.5"})," Add Rate"]})]}),e.jsx(us,{value:"currencies",children:e.jsx(ve,{actions:e.jsxs(ae,{value:y,onValueChange:z,children:[e.jsx(te,{className:"w-[140px] h-9",children:e.jsx(ne,{placeholder:"All statuses"})}),e.jsxs(ie,{children:[e.jsx(T,{value:"__all__",children:"All"}),e.jsx(T,{value:"true",children:"Active"}),e.jsx(T,{value:"false",children:"Inactive"})]})]}),columns:Ae,data:U,isLoading:G,searchPlaceholder:"Search currencies...",emptyMessage:"No currencies",emptyDescription:"Add your first currency.",totalCount:(A==null?void 0:A.count)??0,pagination:c,onPaginationChange:o,sorting:S,onSortingChange:q,globalFilter:s,onGlobalFilterChange:u})}),e.jsx(us,{value:"rates",children:e.jsx(ve,{columns:a,data:(L==null?void 0:L.results)??[],isLoading:E,searchPlaceholder:"Search rates...",emptyMessage:"No exchange rates",emptyDescription:"Add exchange rates between currencies.",totalCount:(L==null?void 0:L.count)??0,pagination:O,onPaginationChange:D,sorting:B,onSortingChange:Y,globalFilter:I,onGlobalFilterChange:N})})]}),e.jsx(oe,{open:n,onOpenChange:j,children:e.jsxs(de,{children:[e.jsxs(me,{children:[e.jsx(he,{children:t?"Edit Currency":"Add Currency"}),e.jsx(ue,{children:"ISO 4217 currency definition."})]}),e.jsxs("form",{onSubmit:d.handleSubmit(h),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(g,{children:"Code * (3 letters)"}),e.jsx(x,{...d.register("code"),className:"mt-1.5 uppercase",maxLength:3,placeholder:"INR"}),d.formState.errors.code&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:d.formState.errors.code.message})]}),e.jsxs("div",{children:[e.jsx(g,{children:"Symbol *"}),e.jsx(x,{...d.register("symbol"),className:"mt-1.5",placeholder:"₹"}),d.formState.errors.symbol&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:d.formState.errors.symbol.message})]})]}),e.jsxs("div",{children:[e.jsx(g,{children:"Name *"}),e.jsx(x,{...d.register("name"),className:"mt-1.5",placeholder:"Indian Rupee"}),d.formState.errors.name&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:d.formState.errors.name.message})]}),e.jsxs("div",{children:[e.jsx(g,{children:"Decimal Places"}),e.jsx(x,{...d.register("decimal_places"),type:"number",min:0,max:4,className:"mt-1.5"})]})]}),e.jsxs(xe,{children:[e.jsx(C,{variant:"outline",onClick:()=>j(!1),children:"Cancel"}),e.jsx(C,{onClick:d.handleSubmit(h),disabled:P.isPending||l.isPending,children:t?"Save Changes":"Create Currency"})]})]})}),e.jsx(oe,{open:i,onOpenChange:_,children:e.jsxs(de,{children:[e.jsxs(me,{children:[e.jsx(he,{children:"Add Exchange Rate"}),e.jsx(ue,{children:"Define a conversion rate between two currencies."})]}),e.jsx("form",{onSubmit:m.handleSubmit(H),className:"flex-1 overflow-y-auto px-6 py-5 space-y-4",children:e.jsxs(os,{...m,children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(g,{children:"From Currency *"}),e.jsxs(ae,{value:m.watch("from_currency"),onValueChange:k=>m.setValue("from_currency",k),children:[e.jsx(te,{className:"mt-1.5",children:e.jsx(ne,{placeholder:"Select"})}),e.jsx(ie,{children:U.map(k=>e.jsxs(T,{value:k.id,children:[k.code," (",k.symbol,")"]},k.id))})]})]}),e.jsxs("div",{children:[e.jsx(g,{children:"To Currency *"}),e.jsxs(ae,{value:m.watch("to_currency"),onValueChange:k=>m.setValue("to_currency",k),children:[e.jsx(te,{className:"mt-1.5",children:e.jsx(ne,{placeholder:"Select"})}),e.jsx(ie,{children:U.map(k=>e.jsxs(T,{value:k.id,children:[k.code," (",k.symbol,")"]},k.id))})]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(g,{children:"Rate *"}),e.jsx(x,{...m.register("rate"),type:"number",step:"0.000001",className:"mt-1.5"})]}),e.jsx(Ke,{name:"effective_date",label:"Effective Date",required:!0})]}),e.jsxs("div",{children:[e.jsx(g,{children:"Source"}),e.jsx(x,{...m.register("source"),className:"mt-1.5",placeholder:"manual"})]})]})}),e.jsxs(xe,{children:[e.jsx(C,{variant:"outline",onClick:()=>_(!1),children:"Cancel"}),e.jsx(C,{onClick:m.handleSubmit(H),disabled:V.isPending,children:"Create Rate"})]})]})})]})}const js=[{value:"general",label:"General"},{value:"leave",label:"Leave"},{value:"attendance",label:"Attendance"},{value:"payroll",label:"Payroll"},{value:"recruitment",label:"Recruitment"},{value:"performance",label:"Performance"}],Xt=[{value:"string",label:"String"},{value:"integer",label:"Integer"},{value:"decimal",label:"Decimal"},{value:"boolean",label:"Boolean"},{value:"json",label:"JSON"}],en=Ms(fe({code:f().min(1,"Code is required"),name:f().min(1,"Name is required"),description:f().optional(),category:f().min(1,"Category is required"),value_type:f().min(1,"Value type is required"),default_value:f().min(1,"Value is required"),company:f().nullable().optional(),department:f().nullable().optional(),effective_from:f().min(1,"Required"),effective_to:f().nullable().optional()}),"effective_from","effective_to"),sn={global:"default",company:"warning",department:"purple"};function qi(){const[b,r]=p.useState(!1),[n,j]=p.useState(null),[i,_]=p.useState(""),[t,F]=p.useState(""),{pagination:y,setPagination:w,sorting:c,setSorting:o,globalFilter:S,setGlobalFilter:q,queryParams:s}=be(),u={...s,...i&&{is_active:i},...t&&{category:t}},{data:v,isLoading:O}=dt(u);function D(m){_(m==="__all__"?"":m),w(ee=>({...ee,pageIndex:0}))}function B(m){F(m==="__all__"?"":m),w(ee=>({...ee,pageIndex:0}))}const[Y,I]=p.useState(""),{data:N}=Je({search:Y||void 0}),M=(N==null?void 0:N.results)??[],[$,A]=p.useState(""),{data:G}=Os({search:$||void 0}),z=(G==null?void 0:G.results)??[],U=mt(),L=ht(),E=je({resolver:ye(en)});function P(){j(null),E.reset({code:"",name:"",category:"general",value_type:"string",default_value:"",company:null,department:null,effective_from:new Date().toISOString().split("T")[0],effective_to:null}),r(!0)}function l(m){j(m),E.reset({code:m.code,name:m.name,description:m.description,category:m.category,value_type:m.value_type,default_value:m.default_value,company:m.company,department:m.department,effective_from:m.effective_from,effective_to:m.effective_to}),r(!0)}function V(m){const ee={...m,category:m.category,value_type:m.value_type,company:m.company||null,department:m.department||null,effective_to:m.effective_to||null};n?L.mutate({id:n.id,...ee},{onSuccess:()=>r(!1)}):U.mutate(ee,{onSuccess:()=>r(!1)})}const d=[{key:"name",header:"Parameter",render:m=>e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-slate-900",children:m.name}),e.jsx("span",{className:"block text-[11px] text-slate-400 font-mono",children:m.code})]})},{key:"category",header:"Category",render:m=>e.jsx(ce,{variant:"secondary",children:m.category})},{key:"scope",header:"Scope",render:m=>e.jsx(ce,{variant:sn[m.scope]??"default",children:m.scope})},{key:"default_value",header:"Value",render:m=>e.jsx("span",{className:"font-mono text-[12px] text-slate-700 max-w-[200px] truncate block",children:m.default_value})},{key:"value_type",header:"Type",render:m=>e.jsx("span",{className:"text-[12px] text-slate-500",children:m.value_type})},{key:"is_active",header:"Status",render:m=>e.jsx(Pe,{status:m.is_active?"active":"inactive"})},{key:"actions",header:"",className:"w-10",render:m=>e.jsxs(Ne,{children:[e.jsx(Ce,{asChild:!0,children:e.jsx(C,{variant:"ghost",size:"icon-sm",children:e.jsx(we,{className:"h-4 w-4"})})}),e.jsx(Se,{align:"end",children:e.jsxs(se,{onClick:()=>l(m),children:[e.jsx(ke,{className:"mr-2 h-3.5 w-3.5"})," Edit"]})})]})}];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(ks,{className:"h-5 w-5 text-primary"})," Policy Parameters"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"System-wide configurable parameters with hierarchical overrides"})]}),e.jsxs(C,{size:"sm",onClick:P,children:[e.jsx(_e,{className:"mr-1.5 h-3.5 w-3.5"})," Add Parameter"]})]}),e.jsx(ve,{actions:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(ae,{value:t,onValueChange:B,children:[e.jsx(te,{className:"w-[150px] h-9",children:e.jsx(ne,{placeholder:"All categories"})}),e.jsxs(ie,{children:[e.jsx(T,{value:"__all__",children:"All categories"}),js.map(m=>e.jsx(T,{value:m.value,children:m.label},m.value))]})]}),e.jsxs(ae,{value:i,onValueChange:D,children:[e.jsx(te,{className:"w-[140px] h-9",children:e.jsx(ne,{placeholder:"All statuses"})}),e.jsxs(ie,{children:[e.jsx(T,{value:"__all__",children:"All"}),e.jsx(T,{value:"true",children:"Active"}),e.jsx(T,{value:"false",children:"Inactive"})]})]})]}),columns:d,data:(v==null?void 0:v.results)??[],isLoading:O,searchPlaceholder:"Search policies...",emptyMessage:"No policies",emptyDescription:"Define configurable parameters for your organization.",totalCount:(v==null?void 0:v.count)??0,pagination:y,onPaginationChange:w,sorting:c,onSortingChange:o,globalFilter:S,onGlobalFilterChange:q}),e.jsx(oe,{open:b,onOpenChange:r,children:e.jsxs(de,{size:"lg",children:[e.jsxs(me,{children:[e.jsx(he,{children:n?"Edit Policy Parameter":"Add Policy Parameter"}),e.jsx(ue,{children:"Parameters resolve: Department > Company > Global default."})]}),e.jsx("form",{onSubmit:E.handleSubmit(V),className:"flex-1 overflow-y-auto px-6 py-5 space-y-4",children:e.jsxs(os,{...E,children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(g,{children:"Name *"}),e.jsx(x,{...E.register("name"),className:"mt-1.5"}),E.formState.errors.name&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:E.formState.errors.name.message})]}),e.jsxs("div",{children:[e.jsx(g,{children:"Code *"}),e.jsx(x,{...E.register("code"),className:"mt-1.5 font-mono",placeholder:"max_leave_days"}),E.formState.errors.code&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:E.formState.errors.code.message})]})]}),e.jsxs("div",{children:[e.jsx(g,{children:"Description"}),e.jsx(Be,{...E.register("description"),className:"mt-1.5",rows:3})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(g,{children:"Category *"}),e.jsxs(ae,{value:E.watch("category"),onValueChange:m=>E.setValue("category",m),children:[e.jsx(te,{className:"mt-1.5",children:e.jsx(ne,{})}),e.jsx(ie,{children:js.map(m=>e.jsx(T,{value:m.value,children:m.label},m.value))})]})]}),e.jsxs("div",{children:[e.jsx(g,{children:"Value Type *"}),e.jsxs(ae,{value:E.watch("value_type"),onValueChange:m=>E.setValue("value_type",m),children:[e.jsx(te,{className:"mt-1.5",children:e.jsx(ne,{})}),e.jsx(ie,{children:Xt.map(m=>e.jsx(T,{value:m.value,children:m.label},m.value))})]})]})]}),e.jsxs("div",{children:[e.jsx(g,{children:"Value *"}),e.jsx(x,{...E.register("default_value"),className:"mt-1.5 font-mono"}),E.formState.errors.default_value&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:E.formState.errors.default_value.message})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(g,{children:"Company Override"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(De,{value:E.watch("company")??"__none__",onValueChange:m=>E.setValue("company",m==="__none__"?null:m),onSearch:I,selectedLabel:(n==null?void 0:n.company_name)??void 0,options:[{value:"__none__",label:"None (global level)"},...M.map(m=>({value:m.id,label:m.name,hint:m.code}))],placeholder:"None (global level)",searchPlaceholder:"Search companies..."})})]}),e.jsxs("div",{children:[e.jsx(g,{children:"Department Override"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(De,{value:E.watch("department")??"__none__",onValueChange:m=>E.setValue("department",m==="__none__"?null:m),onSearch:A,selectedLabel:(n==null?void 0:n.department_name)??void 0,options:[{value:"__none__",label:"None"},...z.map(m=>({value:m.id,label:m.name,hint:m.code}))],placeholder:"None",searchPlaceholder:"Search departments..."})})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(Ke,{name:"effective_from",maxField:"effective_to",label:"Effective From",required:!0}),e.jsx(Ke,{name:"effective_to",minField:"effective_from",label:"Effective To"})]})]})}),e.jsxs(xe,{children:[e.jsx(C,{variant:"outline",onClick:()=>r(!1),children:"Cancel"}),e.jsx(C,{onClick:E.handleSubmit(V),disabled:U.isPending||L.isPending,children:n?"Save Changes":"Create Parameter"})]})]})})]})}const an=[{value:"draft",label:"Draft"},{value:"computed",label:"Computed"},{value:"approved",label:"Approved"},{value:"processed",label:"Processed"}],tn=[{value:"calendar_days",label:"Calendar Days"},{value:"working_days",label:"Working Days"},{value:"fixed_30",label:"Fixed 30 Days"}];function pe({label:b,description:r,children:n,isDefault:j}){return e.jsxs("div",{className:"flex items-start justify-between gap-4 py-3",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"text-[13px] font-medium text-slate-700",children:b}),!j&&e.jsx(ce,{variant:"outline",className:"text-[9px] px-1.5",children:"Modified"})]}),r&&e.jsx("p",{className:"mt-0.5 text-[11px] text-slate-400",children:r})]}),e.jsx("div",{className:"shrink-0",children:n})]})}function nn({config:b,defaults:r,moduleCode:n}){const j=b,i=r,_=$e(),[t,F]=p.useState(structuredClone(j)),[y,w]=p.useState(!1),c=p.useCallback((u,v,O)=>{F(D=>({...D,[u]:{...D[u],[v]:O}})),w(!0)},[]),o=(u,v)=>{var B,Y;const O=(B=i[u])==null?void 0:B[v],D=(Y=t[u])==null?void 0:Y[v];return JSON.stringify(O)===JSON.stringify(D)},S=()=>{_.mutate({moduleCode:n,config:t},{onSuccess:()=>w(!1)})},q=()=>{F(structuredClone(j)),w(!1)},s=(u,v)=>{const O=[...t.workflow.rerun_allowed_statuses],D=v?[...O,u]:O.filter(B=>B!==u);c("workflow","rerun_allowed_statuses",D)};return e.jsxs("div",{className:"space-y-6",children:[y&&e.jsxs("div",{className:"sticky top-0 z-10 -mx-6 flex items-center justify-between border-b bg-white/95 px-6 py-3 shadow-sm backdrop-blur-sm",children:[e.jsx("p",{className:"text-[13px] text-slate-600",children:"You have unsaved changes"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(C,{variant:"outline",size:"sm",onClick:q,children:[e.jsx(We,{className:"mr-1.5 h-3.5 w-3.5"})," Discard"]}),e.jsxs(C,{size:"sm",onClick:S,disabled:_.isPending,children:[e.jsx(Ze,{className:"mr-1.5 h-3.5 w-3.5"})," Save Changes"]})]})]}),e.jsxs(J,{children:[e.jsxs(K,{className:"pb-2",children:[e.jsx(Z,{className:"text-[14px]",children:"Workflow Rules"}),e.jsx(X,{className:"text-[12px]",children:"Control payroll run statuses and approval requirements."})]}),e.jsxs(W,{className:"space-y-1",children:[e.jsxs("div",{className:"py-3",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("p",{className:"text-[13px] font-medium text-slate-700",children:"Re-run Allowed Statuses"}),!o("workflow","rerun_allowed_statuses")&&e.jsx(ce,{variant:"outline",className:"text-[9px] px-1.5",children:"Modified"})]}),e.jsx("p",{className:"text-[11px] text-slate-400 mb-3",children:"Select which run statuses allow payroll re-computation."}),e.jsx("div",{className:"flex flex-wrap gap-4",children:an.map(u=>e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx(Ys,{checked:t.workflow.rerun_allowed_statuses.includes(u.value),onCheckedChange:v=>s(u.value,!!v)}),e.jsx("span",{className:"text-[13px] text-slate-700",children:u.label})]},u.value))})]}),e.jsx(pe,{label:"Require Approval Before Processing",description:"If enabled, runs must be approved before they can be processed.",isDefault:o("workflow","require_approval_before_processing"),children:e.jsx(R,{checked:t.workflow.require_approval_before_processing,onCheckedChange:u=>c("workflow","require_approval_before_processing",u)})}),e.jsx(pe,{label:"Auto-approve if No Anomalies",description:"Automatically approve computed runs that have zero anomaly flags.",isDefault:o("workflow","auto_approve_if_no_anomalies"),children:e.jsx(R,{checked:t.workflow.auto_approve_if_no_anomalies,onCheckedChange:u=>c("workflow","auto_approve_if_no_anomalies",u)})})]})]}),e.jsxs(J,{children:[e.jsxs(K,{className:"pb-2",children:[e.jsx(Z,{className:"text-[14px]",children:"Anomaly Detection"}),e.jsx(X,{className:"text-[12px]",children:"Variance thresholds for flagging suspicious payroll changes."})]}),e.jsxs(W,{className:"space-y-1",children:[e.jsx(pe,{label:"Anomaly Detection Enabled",description:"Compare payroll runs and flag significant variances.",isDefault:o("anomaly_detection","enabled"),children:e.jsx(R,{checked:t.anomaly_detection.enabled,onCheckedChange:u=>c("anomaly_detection","enabled",u)})}),e.jsx(pe,{label:"Medium Threshold (%)",description:"Flag as medium severity if gross pay changes by more than this percentage.",isDefault:o("anomaly_detection","variance_threshold_medium"),children:e.jsx(x,{type:"number",className:"w-20 text-right",value:t.anomaly_detection.variance_threshold_medium,onChange:u=>c("anomaly_detection","variance_threshold_medium",Number(u.target.value))})}),e.jsx(pe,{label:"High Threshold (%)",description:"Flag as high severity if gross pay changes by more than this percentage.",isDefault:o("anomaly_detection","variance_threshold_high"),children:e.jsx(x,{type:"number",className:"w-20 text-right",value:t.anomaly_detection.variance_threshold_high,onChange:u=>c("anomaly_detection","variance_threshold_high",Number(u.target.value))})})]})]}),e.jsxs(J,{children:[e.jsxs(K,{className:"pb-2",children:[e.jsx(Z,{className:"text-[14px]",children:"Payslip Options"}),e.jsx(X,{className:"text-[12px]",children:"Control what employees see on their payslips."})]}),e.jsxs(W,{className:"space-y-1",children:[e.jsx(pe,{label:"Show Employer Contributions",description:"Display employer PF/ESI contributions on payslips.",isDefault:o("payslip","show_employer_contributions"),children:e.jsx(R,{checked:t.payslip.show_employer_contributions,onCheckedChange:u=>c("payslip","show_employer_contributions",u)})}),e.jsx(pe,{label:"Show YTD Summary",description:"Include year-to-date earnings and deductions summary.",isDefault:o("payslip","show_ytd_summary"),children:e.jsx(R,{checked:t.payslip.show_ytd_summary,onCheckedChange:u=>c("payslip","show_ytd_summary",u)})}),e.jsx(pe,{label:"Auto-send Payslips on Process",description:"Automatically email payslips to employees when a run is processed.",isDefault:o("payslip","auto_send_on_process"),children:e.jsx(R,{checked:t.payslip.auto_send_on_process,onCheckedChange:u=>c("payslip","auto_send_on_process",u)})})]})]}),e.jsxs(J,{children:[e.jsxs(K,{className:"pb-2",children:[e.jsx(Z,{className:"text-[14px]",children:"Computation Rules"}),e.jsx(X,{className:"text-[12px]",children:"Control how payroll amounts are calculated."})]}),e.jsxs(W,{className:"space-y-1",children:[e.jsx(pe,{label:"LOP Calculation Method",description:"How loss-of-pay deduction is calculated.",isDefault:o("computation","lop_calculation"),children:e.jsxs(ae,{value:t.computation.lop_calculation,onValueChange:u=>c("computation","lop_calculation",u),children:[e.jsx(te,{className:"w-[160px]",children:e.jsx(ne,{})}),e.jsx(ie,{children:tn.map(u=>e.jsx(T,{value:u.value,children:u.label},u.value))})]})}),e.jsx(pe,{label:"Default Working Days",description:"Default number of working days per month when attendance is not available.",isDefault:o("computation","default_working_days"),children:e.jsx(x,{type:"number",className:"w-20 text-right",value:t.computation.default_working_days,onChange:u=>c("computation","default_working_days",Number(u.target.value))})}),e.jsx(pe,{label:"Half-day Deduction",description:"Fraction of day deducted for a half-day (e.g., 0.5).",isDefault:o("computation","half_day_deduction"),children:e.jsx(x,{type:"number",step:"0.1",className:"w-20 text-right",value:t.computation.half_day_deduction,onChange:u=>c("computation","half_day_deduction",Number(u.target.value))})}),e.jsx(pe,{label:"Round Net Salary",description:"Round net salary to the nearest whole number.",isDefault:o("computation","round_net_salary"),children:e.jsx(R,{checked:t.computation.round_net_salary,onCheckedChange:u=>c("computation","round_net_salary",u)})})]})]}),e.jsxs(J,{children:[e.jsxs(K,{className:"pb-2",children:[e.jsx(Z,{className:"text-[14px]",children:"Notifications"}),e.jsx(X,{className:"text-[12px]",children:"Control when notifications are sent during the payroll lifecycle."})]}),e.jsxs(W,{className:"space-y-1",children:[e.jsx(pe,{label:"Notify on Compute",description:"Send notification when payroll computation completes.",isDefault:o("notifications","notify_on_compute"),children:e.jsx(R,{checked:t.notifications.notify_on_compute,onCheckedChange:u=>c("notifications","notify_on_compute",u)})}),e.jsx(pe,{label:"Notify on Approve",description:"Send notification when a payroll run is approved.",isDefault:o("notifications","notify_on_approve"),children:e.jsx(R,{checked:t.notifications.notify_on_approve,onCheckedChange:u=>c("notifications","notify_on_approve",u)})}),e.jsx(pe,{label:"Notify on Process",description:"Send notification when a payroll run is processed.",isDefault:o("notifications","notify_on_process"),children:e.jsx(R,{checked:t.notifications.notify_on_process,onCheckedChange:u=>c("notifications","notify_on_process",u)})}),e.jsx(pe,{label:"Notify Employee on Payslip",description:"Send individual notification to each employee when payslip is available.",isDefault:o("notifications","notify_employee_on_payslip"),children:e.jsx(R,{checked:t.notifications.notify_employee_on_payslip,onCheckedChange:u=>c("notifications","notify_employee_on_payslip",u)})})]})]})]})}function ge({label:b,description:r,children:n,isDefault:j}){return e.jsxs("div",{className:"flex items-start justify-between gap-4 py-3",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"text-[13px] font-medium text-slate-700",children:b}),!j&&e.jsx(ce,{variant:"outline",className:"text-[9px] px-1.5",children:"Modified"})]}),r&&e.jsx("p",{className:"mt-0.5 text-[11px] text-slate-400",children:r})]}),e.jsx("div",{className:"shrink-0",children:n})]})}function ln({config:b,defaults:r,moduleCode:n}){const j=b,i=r,_=$e(),[t,F]=p.useState(structuredClone(j)),[y,w]=p.useState(!1),c=p.useCallback((s,u,v)=>{F(O=>({...O,[s]:{...O[s],[u]:v}})),w(!0)},[]),o=(s,u)=>{var D,B;const v=(D=i[s])==null?void 0:D[u],O=(B=t[s])==null?void 0:B[u];return JSON.stringify(v)===JSON.stringify(O)},S=()=>{_.mutate({moduleCode:n,config:t},{onSuccess:()=>w(!1)})},q=()=>{F(structuredClone(j)),w(!1)};return e.jsxs("div",{className:"space-y-6",children:[y&&e.jsxs("div",{className:"sticky top-0 z-10 -mx-6 flex items-center justify-between border-b bg-white/95 px-6 py-3 shadow-sm backdrop-blur-sm",children:[e.jsx("p",{className:"text-[13px] text-slate-600",children:"You have unsaved changes"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(C,{variant:"outline",size:"sm",onClick:q,children:[e.jsx(We,{className:"mr-1.5 h-3.5 w-3.5"})," Discard"]}),e.jsxs(C,{size:"sm",onClick:S,disabled:_.isPending,children:[e.jsx(Ze,{className:"mr-1.5 h-3.5 w-3.5"})," Save Changes"]})]})]}),e.jsxs(J,{children:[e.jsxs(K,{className:"pb-2",children:[e.jsx(Z,{className:"text-[14px]",children:"Employee Code Generation"}),e.jsx(X,{className:"text-[12px]",children:"Configure how employee IDs are auto-generated."})]}),e.jsxs(W,{className:"space-y-1",children:[e.jsx(ge,{label:"Default Prefix",description:"Fallback prefix when company has no code (e.g. EMP).",isDefault:o("employee_code","prefix"),children:e.jsx(x,{className:"w-24 text-right",value:t.employee_code.prefix,onChange:s=>c("employee_code","prefix",s.target.value)})}),e.jsx(ge,{label:"Separator",description:"Character between prefix and number (e.g. - or /).",isDefault:o("employee_code","separator"),children:e.jsx(x,{className:"w-16 text-center",value:t.employee_code.separator,onChange:s=>c("employee_code","separator",s.target.value)})}),e.jsx(ge,{label:"Digit Count",description:"Number of zero-padded digits (e.g. 4 = 0001).",isDefault:o("employee_code","digit_count"),children:e.jsx(x,{type:"number",className:"w-20 text-right",min:2,max:8,value:t.employee_code.digit_count,onChange:s=>c("employee_code","digit_count",Number(s.target.value))})}),e.jsx("div",{className:"py-2 px-3 mt-2 rounded-md bg-slate-50 border border-slate-200",children:e.jsxs("p",{className:"text-[11px] text-slate-500",children:["Preview: ",e.jsxs("span",{className:"font-mono font-medium text-slate-700",children:[t.employee_code.prefix,t.employee_code.separator,"0".repeat(Math.max(0,t.employee_code.digit_count-1)),"1"]})]})})]})]}),e.jsxs(J,{children:[e.jsxs(K,{className:"pb-2",children:[e.jsx(Z,{className:"text-[14px]",children:"Onboarding"}),e.jsx(X,{className:"text-[12px]",children:"Control onboarding checklist behavior for new employees."})]}),e.jsxs(W,{className:"space-y-1",children:[e.jsx(ge,{label:"Auto-create Checklist",description:"Automatically create onboarding checklist when employee status is set to 'onboarding'.",isDefault:o("onboarding","auto_create_checklist"),children:e.jsx(R,{checked:t.onboarding.auto_create_checklist,onCheckedChange:s=>c("onboarding","auto_create_checklist",s)})}),e.jsx(ge,{label:"Default Task Deadline (days)",description:"Default number of days for each onboarding task when no template specifies it.",isDefault:o("onboarding","default_deadline_days"),children:e.jsx(x,{type:"number",className:"w-20 text-right",value:t.onboarding.default_deadline_days,onChange:s=>c("onboarding","default_deadline_days",Number(s.target.value))})}),e.jsx(ge,{label:"Auto-complete Checklist",description:"Automatically mark checklist as completed when all tasks are done.",isDefault:o("onboarding","auto_complete_checklist"),children:e.jsx(R,{checked:t.onboarding.auto_complete_checklist,onCheckedChange:s=>c("onboarding","auto_complete_checklist",s)})})]})]}),e.jsxs(J,{children:[e.jsxs(K,{className:"pb-2",children:[e.jsx(Z,{className:"text-[14px]",children:"Probation"}),e.jsx(X,{className:"text-[12px]",children:"Control probation confirmation and extension behavior."})]}),e.jsxs(W,{className:"space-y-1",children:[e.jsx(ge,{label:"Auto-confirm on Positive Review",description:"Automatically set probation status to 'confirmed' when reviewer recommends confirmation.",isDefault:o("probation","auto_confirm_on_review"),children:e.jsx(R,{checked:t.probation.auto_confirm_on_review,onCheckedChange:s=>c("probation","auto_confirm_on_review",s)})}),e.jsx(ge,{label:"Auto-extend on Extension Review",description:"Automatically extend probation end date and increment counter when reviewer recommends extension.",isDefault:o("probation","auto_extend_on_review"),children:e.jsx(R,{checked:t.probation.auto_extend_on_review,onCheckedChange:s=>c("probation","auto_extend_on_review",s)})})]})]}),e.jsxs(J,{children:[e.jsxs(K,{className:"pb-2",children:[e.jsx(Z,{className:"text-[14px]",children:"Separation & Offboarding"}),e.jsx(X,{className:"text-[12px]",children:"Control separation workflow and clearance requirements."})]}),e.jsxs(W,{className:"space-y-1",children:[e.jsx(ge,{label:"Require Workflow Approval",description:"Separations must go through the approval workflow engine.",isDefault:o("separation","require_workflow_approval"),children:e.jsx(R,{checked:t.separation.require_workflow_approval,onCheckedChange:s=>c("separation","require_workflow_approval",s)})}),e.jsx(ge,{label:"Require Clearance",description:"Require clearance items to be completed before processing separation.",isDefault:o("separation","require_clearance"),children:e.jsx(R,{checked:t.separation.require_clearance,onCheckedChange:s=>c("separation","require_clearance",s)})})]})]}),e.jsxs(J,{children:[e.jsxs(K,{className:"pb-2",children:[e.jsx(Z,{className:"text-[14px]",children:"Notifications"}),e.jsx(X,{className:"text-[12px]",children:"Control when notifications are sent for Core HR events."})]}),e.jsxs(W,{className:"space-y-1",children:[e.jsx(ge,{label:"Notify on Transfer",description:"Send notification when an employee transfer is completed.",isDefault:o("notifications","notify_on_transfer"),children:e.jsx(R,{checked:t.notifications.notify_on_transfer,onCheckedChange:s=>c("notifications","notify_on_transfer",s)})}),e.jsx(ge,{label:"Notify on Promotion",description:"Send notification when an employee promotion is approved.",isDefault:o("notifications","notify_on_promotion"),children:e.jsx(R,{checked:t.notifications.notify_on_promotion,onCheckedChange:s=>c("notifications","notify_on_promotion",s)})}),e.jsx(ge,{label:"Notify on Separation",description:"Send notification when a separation is initiated.",isDefault:o("notifications","notify_on_separation"),children:e.jsx(R,{checked:t.notifications.notify_on_separation,onCheckedChange:s=>c("notifications","notify_on_separation",s)})}),e.jsx(ge,{label:"Notify on Probation Confirmed",description:"Notify employee when probation is confirmed.",isDefault:o("notifications","notify_on_probation_confirmed"),children:e.jsx(R,{checked:t.notifications.notify_on_probation_confirmed,onCheckedChange:s=>c("notifications","notify_on_probation_confirmed",s)})}),e.jsx(ge,{label:"Notify on Onboarding Complete",description:"Notify HR when an employee's onboarding checklist is fully completed.",isDefault:o("notifications","notify_on_onboarding_complete"),children:e.jsx(R,{checked:t.notifications.notify_on_onboarding_complete,onCheckedChange:s=>c("notifications","notify_on_onboarding_complete",s)})})]})]})]})}function le({label:b,description:r,children:n,isDefault:j}){return e.jsxs("div",{className:"flex items-start justify-between gap-4 py-3",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"text-[13px] font-medium text-slate-700",children:b}),!j&&e.jsx(ce,{variant:"outline",className:"text-[9px] px-1.5",children:"Modified"})]}),r&&e.jsx("p",{className:"mt-0.5 text-[11px] text-slate-400",children:r})]}),e.jsx("div",{className:"shrink-0",children:n})]})}function rn({config:b,defaults:r,moduleCode:n}){const j=b,i=r,_=$e(),[t,F]=p.useState(structuredClone(j)),[y,w]=p.useState(!1),c=p.useCallback((s,u,v)=>{F(O=>({...O,[s]:{...O[s],[u]:v}})),w(!0)},[]),o=(s,u)=>{var D,B;const v=(D=i[s])==null?void 0:D[u],O=(B=t[s])==null?void 0:B[u];return JSON.stringify(v)===JSON.stringify(O)},S=()=>{_.mutate({moduleCode:n,config:t},{onSuccess:()=>w(!1)})},q=()=>{F(structuredClone(j)),w(!1)};return e.jsxs("div",{className:"space-y-6",children:[y&&e.jsxs("div",{className:"sticky top-0 z-10 -mx-6 flex items-center justify-between border-b bg-white/95 px-6 py-3 shadow-sm backdrop-blur-sm",children:[e.jsx("p",{className:"text-[13px] text-slate-600",children:"You have unsaved changes"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(C,{variant:"outline",size:"sm",onClick:q,children:[e.jsx(We,{className:"mr-1.5 h-3.5 w-3.5"})," Discard"]}),e.jsxs(C,{size:"sm",onClick:S,disabled:_.isPending,children:[e.jsx(Ze,{className:"mr-1.5 h-3.5 w-3.5"})," Save Changes"]})]})]}),e.jsxs(J,{children:[e.jsxs(K,{className:"pb-2",children:[e.jsx(Z,{className:"text-[14px]",children:"Shift Defaults"}),e.jsx(X,{className:"text-[12px]",children:"Fallback values when no shift or policy is assigned to an employee."})]}),e.jsxs(W,{className:"space-y-1",children:[e.jsx(le,{label:"Grace Period (minutes)",description:"Minutes after shift start before marking as late.",isDefault:o("shift_defaults","grace_period_minutes"),children:e.jsx(x,{type:"number",className:"w-20 text-right",value:t.shift_defaults.grace_period_minutes,onChange:s=>c("shift_defaults","grace_period_minutes",Number(s.target.value))})}),e.jsx(le,{label:"Min Hours — Full Day",description:"Minimum working hours to count as a full day.",isDefault:o("shift_defaults","min_hours_full_day"),children:e.jsx(x,{type:"number",step:"0.5",className:"w-20 text-right",value:t.shift_defaults.min_hours_full_day,onChange:s=>c("shift_defaults","min_hours_full_day",Number(s.target.value))})}),e.jsx(le,{label:"Min Hours — Half Day",description:"Minimum working hours for half-day status.",isDefault:o("shift_defaults","min_hours_half_day"),children:e.jsx(x,{type:"number",step:"0.5",className:"w-20 text-right",value:t.shift_defaults.min_hours_half_day,onChange:s=>c("shift_defaults","min_hours_half_day",Number(s.target.value))})}),e.jsx(le,{label:"Break Duration (minutes)",description:"Default break time deducted from working hours.",isDefault:o("shift_defaults","break_duration_minutes"),children:e.jsx(x,{type:"number",className:"w-20 text-right",value:t.shift_defaults.break_duration_minutes,onChange:s=>c("shift_defaults","break_duration_minutes",Number(s.target.value))})})]})]}),e.jsxs(J,{children:[e.jsxs(K,{className:"pb-2",children:[e.jsx(Z,{className:"text-[14px]",children:"Overtime"}),e.jsx(X,{className:"text-[12px]",children:"Default overtime rules when no attendance policy is assigned."})]}),e.jsxs(W,{className:"space-y-1",children:[e.jsx(le,{label:"Overtime Enabled",description:"Enable overtime computation globally.",isDefault:o("overtime","enabled"),children:e.jsx(R,{checked:t.overtime.enabled,onCheckedChange:s=>c("overtime","enabled",s)})}),e.jsx(le,{label:"Minimum OT Minutes",description:"Minimum excess minutes to create an overtime record.",isDefault:o("overtime","min_minutes"),children:e.jsx(x,{type:"number",className:"w-20 text-right",value:t.overtime.min_minutes,onChange:s=>c("overtime","min_minutes",Number(s.target.value))})}),e.jsx(le,{label:"Daily Max OT Minutes",description:"Maximum overtime minutes allowed per day.",isDefault:o("overtime","daily_max_minutes"),children:e.jsx(x,{type:"number",className:"w-20 text-right",value:t.overtime.daily_max_minutes,onChange:s=>c("overtime","daily_max_minutes",Number(s.target.value))})}),e.jsx(le,{label:"Regular Multiplier",description:"Pay multiplier for regular weekday overtime.",isDefault:o("overtime","multiplier_regular"),children:e.jsx(x,{type:"number",step:"0.1",className:"w-20 text-right",value:t.overtime.multiplier_regular,onChange:s=>c("overtime","multiplier_regular",Number(s.target.value))})}),e.jsx(le,{label:"Weekend Multiplier",description:"Pay multiplier for weekend overtime.",isDefault:o("overtime","multiplier_weekend"),children:e.jsx(x,{type:"number",step:"0.1",className:"w-20 text-right",value:t.overtime.multiplier_weekend,onChange:s=>c("overtime","multiplier_weekend",Number(s.target.value))})}),e.jsx(le,{label:"Holiday Multiplier",description:"Pay multiplier for holiday overtime.",isDefault:o("overtime","multiplier_holiday"),children:e.jsx(x,{type:"number",step:"0.1",className:"w-20 text-right",value:t.overtime.multiplier_holiday,onChange:s=>c("overtime","multiplier_holiday",Number(s.target.value))})})]})]}),e.jsxs(J,{children:[e.jsxs(K,{className:"pb-2",children:[e.jsx(Z,{className:"text-[14px]",children:"Compensatory Off"}),e.jsx(X,{className:"text-[12px]",children:"Rules for earning and expiring comp-off days from overtime."})]}),e.jsxs(W,{className:"space-y-1",children:[e.jsx(le,{label:"Hours Per Day",description:"Overtime hours required to earn 1 comp-off day.",isDefault:o("comp_off","hours_per_day"),children:e.jsx(x,{type:"number",className:"w-20 text-right",value:t.comp_off.hours_per_day,onChange:s=>c("comp_off","hours_per_day",Number(s.target.value))})}),e.jsx(le,{label:"Validity Period (days)",description:"Number of days before accrued comp-off expires.",isDefault:o("comp_off","validity_days"),children:e.jsx(x,{type:"number",className:"w-20 text-right",value:t.comp_off.validity_days,onChange:s=>c("comp_off","validity_days",Number(s.target.value))})})]})]}),e.jsxs(J,{children:[e.jsxs(K,{className:"pb-2",children:[e.jsx(Z,{className:"text-[14px]",children:"Anomaly Detection"}),e.jsx(X,{className:"text-[12px]",children:"Thresholds for automatically detecting attendance irregularities."})]}),e.jsxs(W,{className:"space-y-1",children:[e.jsx(le,{label:"Anomaly Detection Enabled",description:"Enable automatic anomaly scanning.",isDefault:o("anomaly_detection","enabled"),children:e.jsx(R,{checked:t.anomaly_detection.enabled,onCheckedChange:s=>c("anomaly_detection","enabled",s)})}),e.jsx(le,{label:"Analysis Period (days)",description:"Number of past days to scan for patterns.",isDefault:o("anomaly_detection","period_days"),children:e.jsx(x,{type:"number",className:"w-20 text-right",value:t.anomaly_detection.period_days,onChange:s=>c("anomaly_detection","period_days",Number(s.target.value))})}),e.jsx(le,{label:"Frequent Late Threshold",description:"Minimum late arrivals within the period to flag.",isDefault:o("anomaly_detection","frequent_late_threshold"),children:e.jsx(x,{type:"number",className:"w-20 text-right",value:t.anomaly_detection.frequent_late_threshold,onChange:s=>c("anomaly_detection","frequent_late_threshold",Number(s.target.value))})}),e.jsx(le,{label:"Consecutive Absence Threshold",description:"Consecutive absent days to flag as anomaly.",isDefault:o("anomaly_detection","consecutive_absence_threshold"),children:e.jsx(x,{type:"number",className:"w-20 text-right",value:t.anomaly_detection.consecutive_absence_threshold,onChange:s=>c("anomaly_detection","consecutive_absence_threshold",Number(s.target.value))})}),e.jsx(le,{label:"Max Hours (minutes)",description:"Working minutes above which to flag as unusual.",isDefault:o("anomaly_detection","unusual_hours_max_minutes"),children:e.jsx(x,{type:"number",className:"w-20 text-right",value:t.anomaly_detection.unusual_hours_max_minutes,onChange:s=>c("anomaly_detection","unusual_hours_max_minutes",Number(s.target.value))})}),e.jsx(le,{label:"Min Hours (minutes)",description:"Working minutes below which to flag as unusual (when present).",isDefault:o("anomaly_detection","unusual_hours_min_minutes"),children:e.jsx(x,{type:"number",className:"w-20 text-right",value:t.anomaly_detection.unusual_hours_min_minutes,onChange:s=>c("anomaly_detection","unusual_hours_min_minutes",Number(s.target.value))})})]})]}),e.jsxs(J,{children:[e.jsxs(K,{className:"pb-2",children:[e.jsx(Z,{className:"text-[14px]",children:"Geofencing"}),e.jsx(X,{className:"text-[12px]",children:"Location-based attendance validation settings."})]}),e.jsxs(W,{className:"space-y-1",children:[e.jsx(le,{label:"Default Radius (meters)",description:"Default geofence radius for new zones.",isDefault:o("geofencing","default_radius_meters"),children:e.jsx(x,{type:"number",className:"w-24 text-right",value:t.geofencing.default_radius_meters,onChange:s=>c("geofencing","default_radius_meters",Number(s.target.value))})}),e.jsx(le,{label:"Tolerance (meters)",description:"Acceptable deviation from geofence boundary.",isDefault:o("geofencing","tolerance_meters"),children:e.jsx(x,{type:"number",className:"w-24 text-right",value:t.geofencing.tolerance_meters,onChange:s=>c("geofencing","tolerance_meters",Number(s.target.value))})})]})]}),e.jsxs(J,{children:[e.jsxs(K,{className:"pb-2",children:[e.jsx(Z,{className:"text-[14px]",children:"Notifications"}),e.jsx(X,{className:"text-[12px]",children:"Control attendance-related notifications."})]}),e.jsxs(W,{className:"space-y-1",children:[e.jsx(le,{label:"Notify on Anomaly",description:"Notify HR when attendance anomalies are detected.",isDefault:o("notifications","notify_on_anomaly"),children:e.jsx(R,{checked:t.notifications.notify_on_anomaly,onCheckedChange:s=>c("notifications","notify_on_anomaly",s)})}),e.jsx(le,{label:"Notify on Regularization",description:"Notify manager when regularization is requested.",isDefault:o("notifications","notify_on_regularization"),children:e.jsx(R,{checked:t.notifications.notify_on_regularization,onCheckedChange:s=>c("notifications","notify_on_regularization",s)})}),e.jsx(le,{label:"Notify Employee on Late",description:"Send notification to employee when marked late.",isDefault:o("notifications","notify_employee_on_late"),children:e.jsx(R,{checked:t.notifications.notify_employee_on_late,onCheckedChange:s=>c("notifications","notify_employee_on_late",s)})})]})]})]})}const cn=[{value:"sat_sun",label:"Saturday & Sunday"},{value:"rotating",label:"Rotating"},{value:"floating",label:"Floating"}],on=[{value:"round_up",label:"Round Up"},{value:"round_down",label:"Round Down"},{value:"round_half",label:"Round to Nearest Half"}],dn=[{value:"0.25",label:"0.25 days"},{value:"0.5",label:"0.5 days"},{value:"1",label:"1 day"}],mn=[{value:"fifo",label:"FIFO (First In, First Out)"},{value:"lifo",label:"LIFO (Last In, First Out)"}],hn=Array.from({length:12},(b,r)=>({value:String(r+1),label:["January","February","March","April","May","June","July","August","September","October","November","December"][r]}));function Q({label:b,description:r,children:n,isDefault:j}){return e.jsxs("div",{className:"flex items-start justify-between gap-4 py-3",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"text-[13px] font-medium text-slate-700",children:b}),!j&&e.jsx(ce,{variant:"outline",className:"text-[9px] px-1.5",children:"Modified"})]}),r&&e.jsx("p",{className:"mt-0.5 text-[11px] text-slate-400",children:r})]}),e.jsx("div",{className:"shrink-0",children:n})]})}function un({config:b,defaults:r,moduleCode:n}){const j=b,i=r,_=$e(),[t,F]=p.useState(structuredClone(j)),[y,w]=p.useState(!1),c=p.useCallback((s,u,v)=>{F(O=>({...O,[s]:{...O[s],[u]:v}})),w(!0)},[]),o=(s,u)=>{var D,B;const v=(D=i[s])==null?void 0:D[u],O=(B=t[s])==null?void 0:B[u];return JSON.stringify(v)===JSON.stringify(O)},S=()=>{_.mutate({moduleCode:n,config:t},{onSuccess:()=>w(!1)})},q=()=>{F(structuredClone(j)),w(!1)};return e.jsxs("div",{className:"space-y-6",children:[y&&e.jsxs("div",{className:"sticky top-0 z-10 -mx-6 flex items-center justify-between border-b bg-white/95 px-6 py-3 shadow-sm backdrop-blur-sm",children:[e.jsx("p",{className:"text-[13px] text-slate-600",children:"You have unsaved changes"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(C,{variant:"outline",size:"sm",onClick:q,children:[e.jsx(We,{className:"mr-1.5 h-3.5 w-3.5"})," Discard"]}),e.jsxs(C,{size:"sm",onClick:S,disabled:_.isPending,children:[e.jsx(Ze,{className:"mr-1.5 h-3.5 w-3.5"})," Save Changes"]})]})]}),e.jsxs(J,{children:[e.jsxs(K,{className:"pb-2",children:[e.jsx(Z,{className:"text-[14px]",children:"General"}),e.jsx(X,{className:"text-[12px]",children:"Core leave management rules and calendar settings."})]}),e.jsxs(W,{className:"space-y-1",children:[e.jsx(Q,{label:"Financial Year Start Month",description:"Month when the leave year begins (e.g. April for India).",isDefault:o("general","financial_year_start_month"),children:e.jsxs(ae,{value:String(t.general.financial_year_start_month),onValueChange:s=>c("general","financial_year_start_month",Number(s)),children:[e.jsx(te,{className:"w-[140px]",children:e.jsx(ne,{})}),e.jsx(ie,{children:hn.map(s=>e.jsx(T,{value:s.value,children:s.label},s.value))})]})}),e.jsx(Q,{label:"Default Weekend Type",description:"Default weekend pattern for new leave policies.",isDefault:o("general","default_weekend_type"),children:e.jsxs(ae,{value:t.general.default_weekend_type,onValueChange:s=>c("general","default_weekend_type",s),children:[e.jsx(te,{className:"w-[160px]",children:e.jsx(ne,{})}),e.jsx(ie,{children:cn.map(s=>e.jsx(T,{value:s.value,children:s.label},s.value))})]})}),e.jsx(Q,{label:"Negative Balance Allowed",description:"Allow employees to apply for leave beyond their available balance.",isDefault:o("general","negative_balance_allowed"),children:e.jsx(R,{checked:t.general.negative_balance_allowed,onCheckedChange:s=>c("general","negative_balance_allowed",s)})}),e.jsx(Q,{label:"Sandwich Rule",description:"Count intervening weekends/holidays between leave days as leave.",isDefault:o("general","sandwich_rule_default"),children:e.jsx(R,{checked:t.general.sandwich_rule_default,onCheckedChange:s=>c("general","sandwich_rule_default",s)})})]})]}),e.jsxs(J,{children:[e.jsxs(K,{className:"pb-2",children:[e.jsx(Z,{className:"text-[14px]",children:"Reminders"}),e.jsx(X,{className:"text-[12px]",children:"Thresholds for leave balance and expiry reminders."})]}),e.jsxs(W,{className:"space-y-1",children:[e.jsx(Q,{label:"Low Balance Threshold (days)",description:"Send reminder when balance falls to this many days or below.",isDefault:o("reminders","low_balance_threshold"),children:e.jsx(x,{type:"number",className:"w-20 text-right",value:t.reminders.low_balance_threshold,onChange:s=>c("reminders","low_balance_threshold",Number(s.target.value))})}),e.jsx(Q,{label:"Carry-forward Expiry Reminder (days)",description:"Days before carry-forward expiry to send reminder.",isDefault:o("reminders","carry_forward_expiry_reminder_days"),children:e.jsx(x,{type:"number",className:"w-20 text-right",value:t.reminders.carry_forward_expiry_reminder_days,onChange:s=>c("reminders","carry_forward_expiry_reminder_days",Number(s.target.value))})})]})]}),e.jsxs(J,{children:[e.jsxs(K,{className:"pb-2",children:[e.jsx(Z,{className:"text-[14px]",children:"Mandatory Leave Enforcement"}),e.jsx(X,{className:"text-[12px]",children:"Rules for enforcing minimum leave utilization before year-end."})]}),e.jsxs(W,{className:"space-y-1",children:[e.jsx(Q,{label:"Enforcement Window (days)",description:"Days before FY end to start enforcement checks.",isDefault:o("mandatory_leave","enforcement_window_days"),children:e.jsx(x,{type:"number",className:"w-20 text-right",value:t.mandatory_leave.enforcement_window_days,onChange:s=>c("mandatory_leave","enforcement_window_days",Number(s.target.value))})}),e.jsx(Q,{label:"Reminder Interval (days)",description:"Frequency of mandatory leave reminders within enforcement window.",isDefault:o("mandatory_leave","reminder_interval_days"),children:e.jsx(x,{type:"number",className:"w-20 text-right",value:t.mandatory_leave.reminder_interval_days,onChange:s=>c("mandatory_leave","reminder_interval_days",Number(s.target.value))})})]})]}),e.jsxs(J,{children:[e.jsxs(K,{className:"pb-2",children:[e.jsx(Z,{className:"text-[14px]",children:"Team Coverage"}),e.jsx(X,{className:"text-[12px]",children:"Minimum team availability requirements for leave approval."})]}),e.jsxs(W,{className:"space-y-1",children:[e.jsx(Q,{label:"Default Min Coverage (%)",description:"Minimum percentage of team that must be present.",isDefault:o("coverage","default_min_coverage_pct"),children:e.jsx(x,{type:"number",className:"w-20 text-right",value:t.coverage.default_min_coverage_pct,onChange:s=>c("coverage","default_min_coverage_pct",Number(s.target.value))})}),e.jsx(Q,{label:"Coverage Check Window (days)",description:"Number of days ahead to check for team coverage.",isDefault:o("coverage","check_window_days"),children:e.jsx(x,{type:"number",className:"w-20 text-right",value:t.coverage.check_window_days,onChange:s=>c("coverage","check_window_days",Number(s.target.value))})})]})]}),e.jsxs(J,{children:[e.jsxs(K,{className:"pb-2",children:[e.jsx(Z,{className:"text-[14px]",children:"Leave Forecasting"}),e.jsx(X,{className:"text-[12px]",children:"AI-driven leave prediction and planning settings."})]}),e.jsxs(W,{className:"space-y-1",children:[e.jsx(Q,{label:"Forecasting Enabled",description:"Enable leave utilization forecasting.",isDefault:o("forecasting","enabled"),children:e.jsx(R,{checked:t.forecasting.enabled,onCheckedChange:s=>c("forecasting","enabled",s)})}),e.jsx(Q,{label:"Historical Period (days)",description:"Days of historical data used for predictions.",isDefault:o("forecasting","history_days"),children:e.jsx(x,{type:"number",className:"w-20 text-right",value:t.forecasting.history_days,onChange:s=>c("forecasting","history_days",Number(s.target.value))})}),e.jsx(Q,{label:"Forecast Window (days)",description:"Number of future days to forecast.",isDefault:o("forecasting","forecast_window_days"),children:e.jsx(x,{type:"number",className:"w-20 text-right",value:t.forecasting.forecast_window_days,onChange:s=>c("forecasting","forecast_window_days",Number(s.target.value))})}),e.jsx(Q,{label:"Max Confidence",description:"Upper cap on forecast confidence score (0-1).",isDefault:o("forecasting","max_confidence"),children:e.jsx(x,{type:"number",step:"0.05",className:"w-20 text-right",value:t.forecasting.max_confidence,onChange:s=>c("forecasting","max_confidence",Number(s.target.value))})})]})]}),e.jsxs(J,{children:[e.jsxs(K,{className:"pb-2",children:[e.jsx(Z,{className:"text-[14px]",children:"Notifications"}),e.jsx(X,{className:"text-[12px]",children:"Control leave-related notifications."})]}),e.jsxs(W,{className:"space-y-1",children:[e.jsx(Q,{label:"Notify on Apply",description:"Notify manager when a leave application is submitted.",isDefault:o("notifications","notify_on_apply"),children:e.jsx(R,{checked:t.notifications.notify_on_apply,onCheckedChange:s=>c("notifications","notify_on_apply",s)})}),e.jsx(Q,{label:"Notify on Approve",description:"Notify employee when leave is approved.",isDefault:o("notifications","notify_on_approve"),children:e.jsx(R,{checked:t.notifications.notify_on_approve,onCheckedChange:s=>c("notifications","notify_on_approve",s)})}),e.jsx(Q,{label:"Notify on Reject",description:"Notify employee when leave is rejected.",isDefault:o("notifications","notify_on_reject"),children:e.jsx(R,{checked:t.notifications.notify_on_reject,onCheckedChange:s=>c("notifications","notify_on_reject",s)})}),e.jsx(Q,{label:"Notify on Cancel",description:"Notify manager when leave is cancelled.",isDefault:o("notifications","notify_on_cancel"),children:e.jsx(R,{checked:t.notifications.notify_on_cancel,onCheckedChange:s=>c("notifications","notify_on_cancel",s)})}),e.jsx(Q,{label:"Notify on Low Balance",description:"Notify employee when leave balance is critically low.",isDefault:o("notifications","notify_on_low_balance"),children:e.jsx(R,{checked:t.notifications.notify_on_low_balance,onCheckedChange:s=>c("notifications","notify_on_low_balance",s)})}),e.jsx(Q,{label:"Notify on Auto-Approve",description:"Notify employee and manager when leave is auto-approved.",isDefault:o("notifications","notify_on_auto_approve"),children:e.jsx(R,{checked:t.notifications.notify_on_auto_approve,onCheckedChange:s=>c("notifications","notify_on_auto_approve",s)})}),e.jsx(Q,{label:"Notify on Amendment",description:"Notify when a leave amendment is requested or processed.",isDefault:o("notifications","notify_on_amendment"),children:e.jsx(R,{checked:t.notifications.notify_on_amendment,onCheckedChange:s=>c("notifications","notify_on_amendment",s)})}),e.jsx(Q,{label:"Notify on Comp-Off",description:"Notify when a comp-off request is approved or rejected.",isDefault:o("notifications","notify_on_comp_off"),children:e.jsx(R,{checked:t.notifications.notify_on_comp_off,onCheckedChange:s=>c("notifications","notify_on_comp_off",s)})}),e.jsx(Q,{label:"Notify on LOP",description:"Notify employee and HR when auto-LOP is triggered.",isDefault:o("notifications","notify_on_lop"),children:e.jsx(R,{checked:t.notifications.notify_on_lop,onCheckedChange:s=>c("notifications","notify_on_lop",s)})})]})]}),e.jsxs(J,{children:[e.jsxs(K,{className:"pb-2",children:[e.jsx(Z,{className:"text-[14px]",children:"Accrual"}),e.jsx(X,{className:"text-[12px]",children:"How leave balances are credited and rounded."})]}),e.jsxs(W,{className:"space-y-1",children:[e.jsx(Q,{label:"Pro-Rata for Mid-Year Joiners",description:"Proportionally reduce accrual for employees who join mid-period.",isDefault:o("accrual","pro_rata_enabled"),children:e.jsx(R,{checked:t.accrual.pro_rata_enabled,onCheckedChange:s=>c("accrual","pro_rata_enabled",s)})}),e.jsx(Q,{label:"Rounding Rule",description:"How fractional accrual amounts are rounded.",isDefault:o("accrual","rounding_rule"),children:e.jsxs(ae,{value:t.accrual.rounding_rule,onValueChange:s=>c("accrual","rounding_rule",s),children:[e.jsx(te,{className:"w-[180px]",children:e.jsx(ne,{})}),e.jsx(ie,{children:on.map(s=>e.jsx(T,{value:s.value,children:s.label},s.value))})]})}),e.jsx(Q,{label:"Rounding Precision",description:"Granularity of rounding (e.g. 0.5 = round to nearest half day).",isDefault:o("accrual","rounding_precision"),children:e.jsxs(ae,{value:String(t.accrual.rounding_precision),onValueChange:s=>c("accrual","rounding_precision",Number(s)),children:[e.jsx(te,{className:"w-[140px]",children:e.jsx(ne,{})}),e.jsx(ie,{children:dn.map(s=>e.jsx(T,{value:s.value,children:s.label},s.value))})]})})]})]}),e.jsxs(J,{children:[e.jsxs(K,{className:"pb-2",children:[e.jsx(Z,{className:"text-[14px]",children:"Auto-Approval"}),e.jsx(X,{className:"text-[12px]",children:"Automatically approve leave applications that meet certain criteria."})]}),e.jsxs(W,{className:"space-y-1",children:[e.jsx(Q,{label:"Enabled",description:"Turn on auto-approval for qualifying leave requests.",isDefault:o("auto_approval","enabled"),children:e.jsx(R,{checked:t.auto_approval.enabled,onCheckedChange:s=>c("auto_approval","enabled",s)})}),e.jsx(Q,{label:"Max Days Threshold",description:"Auto-approve only if the leave is this many days or fewer.",isDefault:o("auto_approval","max_days_threshold"),children:e.jsx(x,{type:"number",className:"w-20 text-right",value:t.auto_approval.max_days_threshold,onChange:s=>c("auto_approval","max_days_threshold",Number(s.target.value))})}),e.jsx(Q,{label:"Require Sufficient Balance",description:"Only auto-approve if the employee has enough leave balance.",isDefault:o("auto_approval","require_sufficient_balance"),children:e.jsx(R,{checked:t.auto_approval.require_sufficient_balance,onCheckedChange:s=>c("auto_approval","require_sufficient_balance",s)})})]})]}),e.jsxs(J,{children:[e.jsxs(K,{className:"pb-2",children:[e.jsx(Z,{className:"text-[14px]",children:"Auto Loss-of-Pay (LOP)"}),e.jsx(X,{className:"text-[12px]",children:"Automatically create LOP entries for unauthorized absences."})]}),e.jsxs(W,{className:"space-y-1",children:[e.jsx(Q,{label:"Enabled",description:"Auto-create LOP when an employee is absent without approved leave.",isDefault:o("auto_lop","enabled"),children:e.jsx(R,{checked:t.auto_lop.enabled,onCheckedChange:s=>c("auto_lop","enabled",s)})}),e.jsx(Q,{label:"Grace Days",description:"Number of unauthorized absence days before triggering auto-LOP.",isDefault:o("auto_lop","grace_days"),children:e.jsx(x,{type:"number",className:"w-20 text-right",value:t.auto_lop.grace_days,onChange:s=>c("auto_lop","grace_days",Number(s.target.value))})}),e.jsx(Q,{label:"Notify Employee",description:"Send notification to the employee when LOP is applied.",isDefault:o("auto_lop","notify_employee"),children:e.jsx(R,{checked:t.auto_lop.notify_employee,onCheckedChange:s=>c("auto_lop","notify_employee",s)})}),e.jsx(Q,{label:"Notify HR",description:"Send notification to HR when LOP is applied.",isDefault:o("auto_lop","notify_hr"),children:e.jsx(R,{checked:t.auto_lop.notify_hr,onCheckedChange:s=>c("auto_lop","notify_hr",s)})})]})]}),e.jsxs(J,{children:[e.jsxs(K,{className:"pb-2",children:[e.jsx(Z,{className:"text-[14px]",children:"Year-End Processing"}),e.jsx(X,{className:"text-[12px]",children:"Carry-forward, lapsing, and fiscal year closure settings."})]}),e.jsxs(W,{className:"space-y-1",children:[e.jsx(Q,{label:"Auto-Process Year-End",description:"Automatically run year-end closing at the fiscal year boundary.",isDefault:o("year_end","auto_process"),children:e.jsx(R,{checked:t.year_end.auto_process,onCheckedChange:s=>c("year_end","auto_process",s)})}),e.jsx(Q,{label:"Dry-Run Notification (days)",description:"Send year-end preview to HR this many days before FY ends.",isDefault:o("year_end","dry_run_notification_days"),children:e.jsx(x,{type:"number",className:"w-20 text-right",value:t.year_end.dry_run_notification_days,onChange:s=>c("year_end","dry_run_notification_days",Number(s.target.value))})}),e.jsx(Q,{label:"CF Consumption Order",description:"When deducting leave, consume carry-forward balance in this order.",isDefault:o("year_end","cf_consumption_order"),children:e.jsxs(ae,{value:t.year_end.cf_consumption_order,onValueChange:s=>c("year_end","cf_consumption_order",s),children:[e.jsx(te,{className:"w-[200px]",children:e.jsx(ne,{})}),e.jsx(ie,{children:mn.map(s=>e.jsx(T,{value:s.value,children:s.label},s.value))})]})})]})]}),e.jsxs(J,{children:[e.jsxs(K,{className:"pb-2",children:[e.jsx(Z,{className:"text-[14px]",children:"Blackout Periods"}),e.jsx(X,{className:"text-[12px]",children:"Control how blackout periods affect leave applications."})]}),e.jsxs(W,{className:"space-y-1",children:[e.jsx(Q,{label:"Enforce on Apply",description:"Block leave applications that fall within blackout periods.",isDefault:o("blackout","enforce_on_apply"),children:e.jsx(R,{checked:t.blackout.enforce_on_apply,onCheckedChange:s=>c("blackout","enforce_on_apply",s)})}),e.jsx(Q,{label:"Allow Override with Approval",description:"Allow leave during blackout periods if a higher-level approver approves.",isDefault:o("blackout","allow_override_with_approval"),children:e.jsx(R,{checked:t.blackout.allow_override_with_approval,onCheckedChange:s=>c("blackout","allow_override_with_approval",s)})})]})]})]})}const ys={company:"Company",branch:"Branch",location:"Location",department:"Department",grade:"Grade",designation:"Designation",employee_category:"Category"};function xn({config:b,defaults:r,moduleCode:n}){const j=b,i=r,_=$e(),[t,F]=p.useState(structuredClone(j)),[y,w]=p.useState(!1),c=p.useCallback((v,O)=>{F(D=>({...D,master_code:{...D.master_code,[v]:O}})),w(!0)},[]),o=p.useCallback((v,O)=>{F(D=>({...D,master_code:{...D.master_code,prefixes:{...D.master_code.prefixes,[v]:O}}})),w(!0)},[]),S=v=>{var O,D;return JSON.stringify((O=i.master_code)==null?void 0:O[v])===JSON.stringify((D=t.master_code)==null?void 0:D[v])},q=()=>{_.mutate({moduleCode:n,config:t},{onSuccess:()=>w(!1)})},s=()=>{F(structuredClone(j)),w(!1)},u=t.master_code.mode==="auto";return e.jsxs("div",{className:"space-y-6",children:[y&&e.jsxs("div",{className:"sticky top-0 z-10 -mx-6 flex items-center justify-between border-b bg-white/95 px-6 py-3 shadow-sm backdrop-blur-sm",children:[e.jsx("p",{className:"text-[13px] text-slate-600",children:"You have unsaved changes"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(C,{variant:"outline",size:"sm",onClick:s,children:[e.jsx(We,{className:"mr-1.5 h-3.5 w-3.5"})," Discard"]}),e.jsxs(C,{size:"sm",onClick:q,disabled:_.isPending,children:[e.jsx(Ze,{className:"mr-1.5 h-3.5 w-3.5"})," Save Changes"]})]})]}),e.jsxs(J,{children:[e.jsxs(K,{className:"pb-2",children:[e.jsxs(Z,{className:"text-[14px] flex items-center gap-2",children:["Master Code Generation",!S("mode")&&e.jsx(ce,{variant:"outline",className:"text-[9px] px-1.5",children:"Modified"})]}),e.jsx(X,{className:"text-[12px]",children:"Controls the Code field on org masters (Company, Branch, Location, Department, Grade, Designation, Category). In Auto mode the Code field is hidden and generated by the system; in Manual mode you type it. Existing records are never changed."})]}),e.jsxs(W,{className:"space-y-4",children:[e.jsx("div",{className:"inline-flex rounded-lg border border-slate-200 p-0.5 bg-slate-50",children:["manual","auto"].map(v=>e.jsx("button",{type:"button",onClick:()=>c("mode",v),className:Qe("px-4 py-1.5 text-[13px] font-medium rounded-md transition-colors capitalize",t.master_code.mode===v?"bg-white text-slate-900 shadow-sm":"text-slate-500 hover:text-slate-700"),children:v},v))}),u&&e.jsxs("div",{className:"space-y-4 pt-2 border-t border-slate-100",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[12px] font-medium text-slate-700 mb-1.5",children:"Separator"}),e.jsx(x,{className:"w-full",value:t.master_code.separator,onChange:v=>c("separator",v.target.value),placeholder:"-"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[12px] font-medium text-slate-700 mb-1.5",children:"Digit Count"}),e.jsx(x,{type:"number",min:2,max:8,className:"w-full",value:t.master_code.digit_count,onChange:v=>c("digit_count",Number(v.target.value))})]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[12px] font-medium text-slate-700 mb-2",children:"Per-master prefix"}),e.jsx("div",{className:"grid grid-cols-2 gap-x-4 gap-y-2",children:Object.keys(ys).map(v=>e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("span",{className:"text-[12px] text-slate-500",children:ys[v]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(x,{className:"w-24 text-right font-mono text-[12px]",value:t.master_code.prefixes[v],onChange:O=>o(v,O.target.value)}),e.jsxs("span",{className:"text-[11px] font-mono text-slate-400 w-20",children:[t.master_code.prefixes[v],t.master_code.separator,"0".repeat(Math.max(0,t.master_code.digit_count-1)),"1"]})]})]},v))})]})]})]})]})]})}const pn={payroll:nn,core_hr:ln,attendance:rn,leave:un,system_admin:xn};function jn({open:b,onOpenChange:r,moduleCode:n}){const{data:j,isLoading:i}=_s(n??""),_=Qs(),t=n?pn[n]:void 0;return e.jsx(oe,{open:b,onOpenChange:r,children:e.jsxs(de,{size:"xl",children:[e.jsxs(me,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(he,{children:i?"Module Settings":`${(j==null?void 0:j.module_name)??n} Settings`}),(j==null?void 0:j.has_overrides)&&e.jsx(ce,{variant:"secondary",className:"text-[10px]",children:"Customized"})]}),e.jsx(ue,{children:"Configure module behavior for your organization."})]}),e.jsx("div",{className:"flex-1 overflow-y-auto px-6 py-5",children:i?e.jsx("div",{className:"space-y-4",children:[1,2,3,4].map(F=>e.jsx(_t,{className:"h-[160px] rounded-lg"},F))}):t&&j?e.jsx(t,{config:j.config,defaults:j.defaults,moduleCode:n}):e.jsx("p",{className:"text-[13px] text-slate-500",children:"No settings available for this module."})}),e.jsxs(xe,{children:[e.jsxs(C,{variant:"outline",size:"sm",disabled:!(j!=null&&j.has_overrides)||_.isPending,onClick:()=>n&&_.mutate(n),children:[e.jsx(We,{className:"mr-1.5 h-3.5 w-3.5"})," Reset to Defaults"]}),e.jsx(C,{variant:"outline",size:"sm",onClick:()=>r(!1),children:"Close"})]})]})})}const yn={Users:ha,Bell:ma,ArrowUpDown:Vt,Brain:Et,ScrollText:da,FolderOpen:Ot,Settings:vs,GitBranch:ss,UserCheck:Ft,Clock:oa,CalendarOff:At,Banknote:Pt,ShieldCheck:ca,CircleUser:ra,UserCog:la,Briefcase:cs,TrendingUp:Dt,GraduationCap:ia,Gift:kt,Plane:na,Package:ya,MessageSquareWarning:wt,HeartPulse:St,FileSignature:ta,BarChart3:rs,Crown:aa,Heart:Ct,LayoutDashboard:Nt,LayoutGrid:es},fn={common:"Common Modules",infrastructure:"Infrastructure",core_ops:"Core Operations",self_service:"Self Service",talent:"Talent & Growth",operations:"Operations",strategic:"Strategic"};function gn(b,r,n){const j=n.find(_=>_.module_code===b.code);if(b.is_base)return{label:"Base module",variant:"default",isEnabled:!0};if(j)return{label:j.is_enabled?"Override: enabled":"Override: disabled",variant:j.is_enabled?"default":"outline",isEnabled:j.is_enabled,overrideId:j.id};const i=r.includes(b.code);return{label:i?"Enabled":"Disabled",variant:i?"secondary":"outline",isEnabled:i}}function _n({mod:b,status:r,onToggle:n,isToggling:j,hasSettings:i,onSettings:_}){const t=yn[b.icon]||es;return e.jsx(J,{className:"relative overflow-hidden transition-shadow hover:shadow-md",children:e.jsxs(W,{className:"p-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex items-start gap-3 min-w-0 flex-1",children:[e.jsx("div",{className:`flex h-10 w-10 shrink-0 items-center justify-center rounded-xl ${r.isEnabled?"bg-primary/10":"bg-slate-100"}`,children:e.jsx(t,{className:`h-5 w-5 ${r.isEnabled?"text-primary":"text-slate-400"}`})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-[13px] font-semibold text-slate-900 truncate",children:b.name}),e.jsx("p",{className:"mt-0.5 text-[11px] text-slate-500 line-clamp-2 leading-relaxed",children:b.description})]})]}),b.is_base?e.jsx(ua,{children:e.jsxs(xa,{children:[e.jsx(pa,{asChild:!0,children:e.jsx("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-slate-50",children:e.jsx(Ls,{className:"h-3.5 w-3.5 text-slate-400"})})}),e.jsx(ja,{children:"Base modules cannot be disabled"})]})}):e.jsx(R,{checked:r.isEnabled,onCheckedChange:()=>n(b,r.isEnabled,r.overrideId),disabled:j})]}),e.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[e.jsx(ce,{variant:r.variant,className:"text-[10px]",children:r.label}),b.depends_on_codes.length>0&&e.jsxs("span",{className:"text-[10px] text-slate-400",children:["Requires: ",b.depends_on_codes.join(", ")]}),i&&r.isEnabled&&e.jsx(C,{variant:"ghost",size:"icon-sm",className:"ml-auto h-7 w-7",onClick:F=>{F.stopPropagation(),_()},children:e.jsx(vs,{className:"h-3.5 w-3.5 text-slate-400 hover:text-primary"})})]})]})})}function Vi(){const[b,r]=p.useState(null),[n,j]=p.useState(!1),{data:i,isLoading:_,isError:t,refetch:F}=$s(),{data:y}=Js(),{data:w=[]}=Ws(),{data:c}=Ks(),o=Zs(),S=Xs(),q=ea(),{setEntitlements:s}=sa(),u=p.useMemo(()=>new Set((c==null?void 0:c.map(I=>I.module_code))??[]),[c]),v=p.useMemo(()=>(y==null?void 0:y.enabled_modules)??[],[y]),O=p.useMemo(()=>{if(!i)return{};const I={};for(const N of i){const M=N.category;I[M]||(I[M]=[]),I[M].push(N)}return I},[i]),D=p.useMemo(()=>(y==null?void 0:y.enabled_modules.length)??0,[y]),B=p.useCallback((I,N,M)=>{M?N?S.mutate({id:M,is_enabled:!1},{onSuccess:()=>{if(y){const $=y.enabled_modules.filter(A=>A!==I.code);s($)}}}):q.mutate(M):o.mutate({module:I.id,is_enabled:!N,reason:N?"Disabled via Module Control":"Enabled via Module Control"})},[o,S,q,y,s]),Y=o.isPending||S.isPending||q.isPending;return t?e.jsxs("div",{className:"space-y-5",children:[e.jsx(ps,{title:"Module Control",description:"Manage which HCM modules are enabled for your organization."}),e.jsxs("div",{className:"flex flex-col items-center justify-center py-20 text-center",children:[e.jsx("div",{className:"mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-red-50",children:e.jsx(vt,{className:"h-5 w-5 text-red-500"})}),e.jsx("p",{className:"text-[13px] font-medium text-slate-600",children:"Failed to load modules"}),e.jsxs(C,{variant:"outline",size:"sm",className:"mt-4 gap-1.5",onClick:()=>F(),children:[e.jsx(bt,{className:"h-3.5 w-3.5"})," Retry"]})]})]}):e.jsxs("div",{className:"space-y-5",children:[e.jsx(ps,{title:"Module Control",description:"Manage which HCM modules are enabled for your organization."}),y&&e.jsx(J,{children:e.jsx(W,{className:"flex items-center justify-between p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-xl bg-primary/10",children:e.jsx(es,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[14px] font-semibold text-slate-900",children:"Enabled Modules"}),e.jsxs("p",{className:"text-[12px] text-slate-500",children:[D," of ",(i==null?void 0:i.length)??"..."," modules enabled"]})]})]})})}),_?e.jsx("div",{className:"space-y-6",children:[1,2,3].map(I=>e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"h-4 w-40 rounded skeleton-shimmer"}),e.jsx("div",{className:"grid gap-3 sm:grid-cols-2 lg:grid-cols-3",children:[1,2,3].map(N=>e.jsx("div",{className:"h-[120px] rounded-lg skeleton-shimmer"},N))})]},I))}):e.jsx("div",{className:"space-y-6",children:Object.entries(O).map(([I,N])=>e.jsxs("div",{children:[e.jsx("h3",{className:"mb-3 text-[12px] font-semibold uppercase tracking-[0.08em] text-slate-500",children:fn[I]??I}),e.jsx("div",{className:"grid gap-3 sm:grid-cols-2 lg:grid-cols-3",children:N.map(M=>{const $=gn(M,v,w);return e.jsx(_n,{mod:M,status:$,onToggle:B,isToggling:Y,hasSettings:u.has(M.code),onSettings:()=>{r(M.code),j(!0)}},M.id)})})]},I))}),e.jsx(jn,{open:n,onOpenChange:j,moduleCode:b})]})}const ns=[{value:"text",label:"Text"},{value:"number",label:"Number"},{value:"date",label:"Date"},{value:"boolean",label:"Boolean"},{value:"select",label:"Select"},{value:"multiselect",label:"Multi-Select"},{value:"textarea",label:"Textarea"},{value:"email",label:"Email"},{value:"url",label:"URL"},{value:"phone",label:"Phone"}],vn=fe({name:f().min(1,"Name is required"),field_key:f().min(1,"Field key is required").regex(/^[a-z][a-z0-9_]*$/,"Lowercase letters, digits, and underscores only"),field_type:f().min(1,"Type is required"),target_model:f().default("employee"),section:f().optional(),is_required:Ue().default(!1),is_active:Ue().default(!0),display_order:Ie.number().min(0).default(0),placeholder:f().optional(),help_text:f().optional(),options_text:f().optional()});function zi(){const[b,r]=p.useState(!1),[n,j]=p.useState(null),[i,_]=p.useState(null),[t,F]=p.useState(""),[y,w]=p.useState(""),{pagination:c,setPagination:o,sorting:S,setSorting:q,globalFilter:s,setGlobalFilter:u,queryParams:v}=be(),O={...v,...t&&{field_type:t},...y&&{is_active:y}},{data:D,isLoading:B}=ut(O);function Y(d){F(d==="__all__"?"":d),o(m=>({...m,pageIndex:0}))}function I(d){w(d==="__all__"?"":d),o(m=>({...m,pageIndex:0}))}const N=xt(),M=pt(),$=jt(),A=je({resolver:ye(vn),defaultValues:{name:"",field_key:"",field_type:"text",target_model:"employee",section:"",is_required:!1,is_active:!0,display_order:0,placeholder:"",help_text:"",options_text:""}}),G=A.watch("field_type"),z=G==="select"||G==="multiselect";function U(){j(null),A.reset({name:"",field_key:"",field_type:"text",target_model:"employee",section:"",is_required:!1,is_active:!0,display_order:0,placeholder:"",help_text:"",options_text:""}),r(!0)}function L(d){j(d),A.reset({name:d.name,field_key:d.field_key,field_type:d.field_type,target_model:d.target_model,section:d.section||"",is_required:d.is_required,is_active:d.is_active,display_order:d.display_order,placeholder:d.placeholder||"",help_text:d.help_text||"",options_text:(d.options??[]).join(`
`)}),r(!0)}function E(d){const{options_text:m,...ee}=d,re={...ee,options:z&&m?m.split(`
`).map(h=>h.trim()).filter(Boolean):[]};n?M.mutate({id:n.id,...re},{onSuccess:()=>r(!1)}):N.mutate(re,{onSuccess:()=>r(!1)})}function P(){i&&$.mutate(i.id,{onSuccess:()=>_(null)})}function l(d){const m=ns.find(ee=>ee.value===d);return m?m.label:d}const V=[{key:"name",header:"Name",render:d=>e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-slate-900",children:d.name}),e.jsx("br",{}),e.jsx("code",{className:"text-[11px] font-mono text-slate-400",children:d.field_key})]})},{key:"field_type",header:"Type",render:d=>e.jsx(ce,{variant:"outline",children:l(d.field_type)})},{key:"section",header:"Section",render:d=>d.section||e.jsx("span",{className:"text-slate-300",children:"—"})},{key:"is_required",header:"Required",render:d=>e.jsx(ce,{variant:d.is_required?"warning":"secondary",children:d.is_required?"Required":"Optional"})},{key:"is_active",header:"Status",render:d=>e.jsx(Pe,{status:d.is_active?"active":"inactive"})},{key:"display_order",header:"Order",render:d=>e.jsx("span",{className:"text-slate-600",children:d.display_order})},{key:"actions",header:"",className:"w-10",render:d=>e.jsxs(Oe,{open:(i==null?void 0:i.id)===d.id,onOpenChange:m=>!m&&_(null),children:[e.jsxs(Ne,{children:[e.jsx(Ce,{asChild:!0,children:e.jsx(C,{variant:"ghost",size:"icon-sm",children:e.jsx(we,{className:"h-4 w-4"})})}),e.jsxs(Se,{align:"end",children:[e.jsxs(se,{onClick:()=>L(d),children:[e.jsx(ke,{className:"mr-2 h-3.5 w-3.5"})," Edit"]}),e.jsx(Ee,{asChild:!0,children:e.jsxs(se,{className:"text-red-600",onClick:()=>_(d),children:[e.jsx(Me,{className:"mr-2 h-3.5 w-3.5"})," Delete"]})})]})]}),e.jsxs(Le,{children:[e.jsxs(qe,{children:[e.jsx(Ve,{children:"Delete custom field?"}),e.jsxs(ze,{children:["This will permanently delete ",e.jsx("strong",{children:i==null?void 0:i.name})," and remove it from all employee profiles that use it."]})]}),e.jsxs(Re,{children:[e.jsx(Te,{children:"Cancel"}),e.jsx(Ge,{variant:"destructive",onClick:P,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(Ps,{className:"h-5 w-5 text-primary"})," Custom Fields"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"Define dynamic fields to extend employee profiles"})]}),e.jsxs(C,{size:"sm",onClick:U,children:[e.jsx(_e,{className:"mr-1.5 h-3.5 w-3.5"})," Add Field"]})]}),e.jsx(ve,{actions:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(ae,{value:t||"__all__",onValueChange:Y,children:[e.jsx(te,{className:"w-[140px] h-9",children:e.jsx(ne,{placeholder:"All types"})}),e.jsxs(ie,{children:[e.jsx(T,{value:"__all__",children:"All Types"}),ns.map(d=>e.jsx(T,{value:d.value,children:d.label},d.value))]})]}),e.jsxs(ae,{value:y||"__all__",onValueChange:I,children:[e.jsx(te,{className:"w-[140px] h-9",children:e.jsx(ne,{placeholder:"All statuses"})}),e.jsxs(ie,{children:[e.jsx(T,{value:"__all__",children:"All"}),e.jsx(T,{value:"true",children:"Active"}),e.jsx(T,{value:"false",children:"Inactive"})]})]})]}),columns:V,data:(D==null?void 0:D.results)??[],isLoading:B,searchPlaceholder:"Search custom fields...",emptyMessage:"No custom fields yet",emptyDescription:"Define your first custom field to extend employee profiles.",totalCount:(D==null?void 0:D.count)??0,pagination:c,onPaginationChange:o,sorting:S,onSortingChange:q,globalFilter:s,onGlobalFilterChange:u}),e.jsx(oe,{open:b,onOpenChange:r,children:e.jsxs(de,{size:"lg",children:[e.jsxs(me,{children:[e.jsx(he,{children:n?"Edit Custom Field":"Add Custom Field"}),e.jsx(ue,{children:n?"Update field definition.":"Define a new dynamic field for employee profiles."})]}),e.jsxs("form",{onSubmit:A.handleSubmit(E),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(g,{children:"Name *"}),e.jsx(x,{...A.register("name"),className:"mt-1.5",placeholder:"e.g. Tax ID"}),A.formState.errors.name&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:A.formState.errors.name.message})]}),e.jsxs("div",{children:[e.jsx(g,{children:"Field Key *"}),e.jsx(x,{...A.register("field_key"),className:"mt-1.5",placeholder:"lowercase_with_underscores"}),A.formState.errors.field_key&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:A.formState.errors.field_key.message})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(g,{children:"Field Type *"}),e.jsxs(ae,{value:A.watch("field_type"),onValueChange:d=>A.setValue("field_type",d),children:[e.jsx(te,{className:"mt-1.5",children:e.jsx(ne,{placeholder:"Select type"})}),e.jsx(ie,{children:ns.map(d=>e.jsx(T,{value:d.value,children:d.label},d.value))})]}),A.formState.errors.field_type&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:A.formState.errors.field_type.message})]}),e.jsxs("div",{children:[e.jsx(g,{children:"Target Model"}),e.jsxs(ae,{value:A.watch("target_model"),onValueChange:d=>A.setValue("target_model",d),children:[e.jsx(te,{className:"mt-1.5",children:e.jsx(ne,{placeholder:"Select model"})}),e.jsx(ie,{children:e.jsx(T,{value:"employee",children:"Employee"})})]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(g,{children:"Section"}),e.jsx(x,{...A.register("section"),className:"mt-1.5",placeholder:"e.g. Personal Info, Employment"})]}),e.jsxs("div",{children:[e.jsx(g,{children:"Display Order"}),e.jsx(x,{...A.register("display_order"),type:"number",min:0,className:"mt-1.5"}),A.formState.errors.display_order&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:A.formState.errors.display_order.message})]})]}),e.jsxs("div",{children:[e.jsx(g,{children:"Placeholder"}),e.jsx(x,{...A.register("placeholder"),className:"mt-1.5",placeholder:"Placeholder text shown in the field"})]}),e.jsxs("div",{children:[e.jsx(g,{children:"Help Text"}),e.jsx(Be,{...A.register("help_text"),className:"mt-1.5",rows:2,placeholder:"Additional guidance for users filling this field"})]}),z&&e.jsxs("div",{children:[e.jsx(g,{children:"Options (one per line)"}),e.jsx(Be,{...A.register("options_text"),className:"mt-1.5 font-mono text-[13px]",rows:5,placeholder:`Option A
Option B
Option C`}),e.jsx("p",{className:"mt-1 text-[11px] text-slate-400",children:"Enter each option on a separate line."})]}),e.jsxs("div",{className:"flex items-center gap-6 pt-2",children:[e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx(R,{checked:A.watch("is_required"),onCheckedChange:d=>A.setValue("is_required",!!d)}),e.jsx("span",{className:"text-[13px] text-slate-700",children:"Required"})]}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx(R,{checked:A.watch("is_active"),onCheckedChange:d=>A.setValue("is_active",!!d)}),e.jsx("span",{className:"text-[13px] text-slate-700",children:"Active"})]})]})]}),e.jsxs(xe,{children:[e.jsx(C,{variant:"outline",onClick:()=>r(!1),children:"Cancel"}),e.jsx(C,{onClick:A.handleSubmit(E),disabled:N.isPending||M.isPending,children:n?"Save Changes":"Create Field"})]})]})})]})}const fs="email",bn=fe({host:f().min(1,"SMTP host is required"),port:Ie.number().int().min(1).max(65535),username:f().optional(),password:f().optional(),from_email:f().email("Enter a valid email").or(As("")),from_name:f().optional(),use_tls:Ue(),use_ssl:Ue(),timeout:Ie.number().int().min(5).max(120),is_active:Ue()}),Nn=[{label:"Gmail",host:"smtp.gmail.com",port:587},{label:"Outlook / Office 365",host:"smtp.office365.com",port:587},{label:"SendGrid",host:"smtp.sendgrid.net",port:587},{label:"Mailgun",host:"smtp.mailgun.org",port:587},{label:"Amazon SES",host:"email-smtp.us-east-1.amazonaws.com",port:587}];function Ri(){const[b,r]=p.useState(!1),[n,j]=p.useState(""),{data:i,isLoading:_}=_s(fs),t=$e(),F=yt(),y=je({resolver:ye(bn),defaultValues:{host:"",port:587,username:"",password:"",from_email:"",from_name:"",use_tls:!0,use_ssl:!1,timeout:30,is_active:!1}});p.useEffect(()=>{if(!i)return;const S=i.config,q=(S==null?void 0:S.smtp)??{},s=(S==null?void 0:S.sender)??{};y.reset({host:q.host??"",port:q.port??587,username:q.username??"",password:"",from_email:s.from_email??"",from_name:s.from_name??"",use_tls:q.use_tls??!0,use_ssl:q.use_ssl??!1,timeout:q.timeout??30,is_active:(S==null?void 0:S.is_active)??!1})},[i]);function w(S,q){y.setValue("host",S),y.setValue("port",q),y.setValue("use_tls",!0),y.setValue("use_ssl",!1)}function c(S){const q={is_active:S.is_active,smtp:{host:S.host,port:S.port,username:S.username??"",use_tls:S.use_tls,use_ssl:S.use_ssl,timeout:S.timeout,...S.password?{password:S.password}:{}},sender:{from_email:S.from_email??"",from_name:S.from_name??""}};t.mutate({moduleCode:fs,config:q})}const o=(i==null?void 0:i.has_overrides)??!1;return e.jsxs("div",{className:"max-w-2xl",children:[e.jsx("div",{className:"flex items-center justify-between mb-6",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-lg bg-primary/10",children:e.jsx(Ds,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{children:[e.jsxs("h2",{className:"text-[16px] font-semibold text-slate-900 flex items-center gap-2",children:["Email / SMTP Configuration",o&&e.jsx(ce,{variant:"outline",className:"text-[10px]",children:"Customized"})]}),e.jsx("p",{className:"text-[13px] text-slate-400",children:"Configure the outgoing mail server for all system emails"})]})]})}),_?e.jsxs("div",{className:"flex items-center justify-center gap-2 text-slate-400 text-[13px] py-16",children:[e.jsx(as,{className:"h-4 w-4 animate-spin"})," Loading…"]}):e.jsxs("form",{onSubmit:y.handleSubmit(c),className:"space-y-5",children:[e.jsxs("div",{className:"rounded-lg border border-slate-200 p-5 space-y-3",children:[e.jsx("p",{className:"text-[12px] font-semibold text-slate-600 uppercase tracking-wide",children:"Quick Presets"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:Nn.map(S=>e.jsx("button",{type:"button",onClick:()=>w(S.host,S.port),className:"text-[12px] px-3 py-1.5 rounded-md border border-slate-200 bg-white hover:bg-slate-50 text-slate-600 transition-colors",children:S.label},S.label))})]}),e.jsxs("div",{className:"rounded-lg border border-slate-200 p-5 space-y-4",children:[e.jsx("p",{className:"text-[12px] font-semibold text-slate-600 uppercase tracking-wide",children:"Connection"}),e.jsxs("div",{className:"grid grid-cols-[1fr_120px] gap-3",children:[e.jsxs("div",{children:[e.jsx(g,{className:"text-[12px] font-medium text-slate-500",children:"SMTP Host *"}),e.jsx(x,{...y.register("host"),className:"mt-1.5",placeholder:"smtp.example.com"}),y.formState.errors.host&&e.jsx("p",{className:"text-[11px] text-red-500 mt-1",children:y.formState.errors.host.message})]}),e.jsxs("div",{children:[e.jsx(g,{className:"text-[12px] font-medium text-slate-500",children:"Port"}),e.jsx(x,{...y.register("port"),type:"number",className:"mt-1.5"})]})]}),e.jsxs("div",{className:"flex gap-6",children:[e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer select-none",children:[e.jsx("input",{type:"checkbox",...y.register("use_tls"),className:"h-4 w-4 rounded border-slate-300 text-primary"}),e.jsx("span",{className:"text-[13px] text-slate-700",children:"Use TLS (STARTTLS)"})]}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer select-none",children:[e.jsx("input",{type:"checkbox",...y.register("use_ssl"),className:"h-4 w-4 rounded border-slate-300 text-primary"}),e.jsx("span",{className:"text-[13px] text-slate-700",children:"Use SSL"})]})]})]}),e.jsxs("div",{className:"rounded-lg border border-slate-200 p-5 space-y-4",children:[e.jsx("p",{className:"text-[12px] font-semibold text-slate-600 uppercase tracking-wide",children:"Authentication"}),e.jsxs("div",{children:[e.jsx(g,{className:"text-[12px] font-medium text-slate-500",children:"Username / Email"}),e.jsx(x,{...y.register("username"),className:"mt-1.5",placeholder:"you@example.com",autoComplete:"off"})]}),e.jsxs("div",{children:[e.jsx(g,{className:"text-[12px] font-medium text-slate-500",children:"Password"}),e.jsxs("div",{className:"relative mt-1.5",children:[e.jsx(x,{...y.register("password"),type:b?"text":"password",className:"pr-9",placeholder:"Leave blank to keep existing",autoComplete:"new-password"}),e.jsx("button",{type:"button",className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-slate-400 hover:text-slate-600",onClick:()=>r(S=>!S),children:b?e.jsx(Mt,{className:"h-4 w-4"}):e.jsx(Lt,{className:"h-4 w-4"})})]})]})]}),e.jsxs("div",{className:"rounded-lg border border-slate-200 p-5 space-y-4",children:[e.jsx("p",{className:"text-[12px] font-semibold text-slate-600 uppercase tracking-wide",children:"Sender Details"}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(g,{className:"text-[12px] font-medium text-slate-500",children:"From Email"}),e.jsx(x,{...y.register("from_email"),className:"mt-1.5",placeholder:"noreply@yourcompany.com"}),y.formState.errors.from_email&&e.jsx("p",{className:"text-[11px] text-red-500 mt-1",children:y.formState.errors.from_email.message})]}),e.jsxs("div",{children:[e.jsx(g,{className:"text-[12px] font-medium text-slate-500",children:"From Name"}),e.jsx(x,{...y.register("from_name"),className:"mt-1.5",placeholder:"PeoplePin"})]})]}),e.jsxs("div",{className:"w-36",children:[e.jsx(g,{className:"text-[12px] font-medium text-slate-500",children:"Timeout (seconds)"}),e.jsx(x,{...y.register("timeout"),type:"number",className:"mt-1.5"})]})]}),e.jsxs("div",{className:"flex items-center justify-between rounded-lg border border-slate-200 px-5 py-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[13px] font-medium text-slate-700",children:"Use this configuration"}),e.jsx("p",{className:"text-[12px] text-slate-400 mt-0.5",children:"All system emails will use these SMTP settings when enabled"})]}),e.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[e.jsx("input",{type:"checkbox",...y.register("is_active"),className:"sr-only peer"}),e.jsx("div",{className:"w-11 h-6 bg-slate-200 rounded-full peer peer-checked:bg-primary peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border after:border-slate-300 after:rounded-full after:h-5 after:w-5 after:transition-all"})]})]}),e.jsxs("div",{className:"flex items-center gap-3 pt-1",children:[e.jsxs(C,{type:"submit",disabled:t.isPending,children:[t.isPending&&e.jsx(as,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}),"Save Configuration"]}),e.jsxs("div",{className:"flex items-center gap-2 ml-auto",children:[e.jsx(x,{value:n,onChange:S=>j(S.target.value),placeholder:"test@example.com",type:"email",className:"w-48 h-9 text-[13px]"}),e.jsxs(C,{type:"button",variant:"outline",disabled:F.isPending||!n,onClick:()=>F.mutate(n),children:[F.isPending?e.jsx(as,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}):e.jsx(qt,{className:"mr-1.5 h-3.5 w-3.5"}),"Send Test"]})]})]})]})]})}export{Si as BranchesPage,Ei as CategoriesPage,Pi as CitiesPage,Ci as CompaniesPage,ki as CountriesPage,Li as CurrenciesPage,zi as CustomFieldsPage,Ai as DepartmentsPage,Oi as DesignationsPage,Ri as EmailSettingsPage,Mi as FiscalYearsPage,Fi as GradesPage,wi as LocationsPage,Vi as ModulesPage,qi as PoliciesPage,Di as StatesPage,Ni as SystemAdminLayout};
