import{j as e}from"./query-PJ0ZdjbV.js";import{a as b,N as lt,f as ct,O as ot,k as dt,u as wa,L as Ke,l as Cs}from"./vendor-CWhr2lg4.js";import{a2 as as,aU as xa,ap as Pe,aT as mt,r as ps,b as ts,s as le,t as ce,v as oe,w as de,x as T,at as Ge,I as M,q as h,b0 as je,U as Rs,bU as xt,o as qs,bf as ht,B as C,P as se,Q as Ie,V as Le,W as Me,Y as Oe,Z as Re,_ as qe,$ as ze,a0 as Ue,ag as ns,ah as rs,ai as is,aj as $e,y as De,bV as Ks,bW as ea,bX as sa,d as G,h as Q,L as aa,aa as fe,ab as ve,ac as ye,ad as be,ae as Ne,N as Qe,af as Ae,a8 as pt,a4 as Fs,l as Hs,al as bs,bw as Ws,ba as ha,bb as pa,bY as Ns,bc as ua,bd as ja,T as ut,bZ as jt,b_ as Pa,b5 as Aa,b$ as gt,aL as _t,e as ms,f as xs,G as ft,H as vt,J as ga,K as js,O as yt,a1 as gs,av as bt,ax as Nt,ay as Ct,az as St,aA as kt,au as Is,ak as wt,c0 as Pt}from"./index-BSPIaiZU.js";import{B as Ss}from"./briefcase-ChU_EMgZ.js";import{C as Ta}from"./clipboard-list-DCTO70_z.js";import{L as Ea}from"./list-checks-DgCazpHc.js";import{T as Da}from"./trending-up-Cognoqa9.js";import{U as Fa}from"./user-check-B2v_CMeM.js";import{B}from"./badge-C34iUAiA.js";import{D as es,S as ks}from"./data-table-D_-xOEqd.js";import{u as ls}from"./use-data-table-state-CKRg6qY2.js";import{u as At,a as Xe,b as Ia,c as zs,d as La,e as Ma,f as Tt,g as Oa,h as Ra,i as Et,j as Dt,k as Ft,l as It,m as Lt,n as Mt,o as Ot,p as Rt,q as qt,r as zt,s as Ut,t as Vt,v as $t,w as Bt,x as Gt,y as Qt,z as Ht,A as Wt,B as Zt,C as Xt,D as Yt,E as Jt,F as Kt,G as en,H as sn,I as an,J as tn,K as nn,L as rn,M as qa,N as ln,O as cn,P as on,Q as dn,R as mn,S as xn,T as za,U as hn,V as pn,W as un,X as Ua,Y as jn,Z as gn,_ as _n,$ as Va,a0 as fn,a1 as vn,a2 as yn,a3 as bn,a4 as Nn,a5 as Cn,a6 as Sn,a7 as kn,a8 as wn,a9 as Pn,aa as An,ab as Tn,ac as En,ad as Dn,ae as Fn,af as In,ag as Ln,ah as Mn,ai as On,aj as Rn,ak as qn,al as zn,am as $a,an as Un,ao as Vn,ap as $n,aq as Bn}from"./core-hr.api-MChaGqvv.js";import{M as Ba}from"./mail-Bu7DITgC.js";import{P as Ga}from"./phone-BsfOydnt.js";import{C as Gn}from"./calendar-BZ611BSN.js";import{f as me}from"./format-Bw_hER4B.js";import{p as ie}from"./parseISO-CsaAlwIQ.js";import{E as vs}from"./ellipsis-DaNBIBaV.js";import{E as Us}from"./eye-DlIcvqP-.js";import{P as ke}from"./pencil-Dl5fXQYl.js";import{u as Te,t as Ee,o as ue,b as Fe,s as v,e as hs,l as Qn,Z as We,d as us,f as Qa,g as Zs,r as Hn,h as Wn,F as fs,p as Zn,n as Xn,c as _a}from"./date-range-picker-BB0TgAn8.js";import{G as Ha}from"./geo-select-DH2q7I7V.js";import{M as ws}from"./map-pin-BhdxZDWP.js";import{C as Wa}from"./copy-Bt5x5xC5.js";import{L as Vs,d as Yn}from"./differenceInDays-DAUcN-BF.js";import{H as Za}from"./heart-pulse-B_MXLnGs.js";import{C as Xa}from"./circle-check-Dgh1V3VA.js";import{C as Jn}from"./circle-alert-9pjtMKqA.js";import{a as Ls,w as Ms,b as Kn,i as ss}from"./date-validation-D9gNvaP9.js";import{F as Os}from"./file-text-BeBoTfpI.js";import{E as er}from"./external-link-B0k2fwUi.js";import{A as K}from"./async-select-BUbwdJEZ.js";import{x as Ps,u as ta,e as na,i as sr,B as ys,J as $s,F as Bs,N as ra,r as ia,a5 as la}from"./system-admin.api-BT5u-_A_.js";import{u as Ya,a as Ja,b as Ka}from"./payroll.api-CdAqb0T2.js";import{S as Xs}from"./shield-7SCLx_iT.js";import{H as et}from"./history-BtMjBzl1.js";import{A as Ys}from"./arrow-left-CtkbIigo.js";import{F as Ze}from"./form-date-picker-DpmvXN9z.js";import{E as ar}from"./employee-select-DtUobKxP.js";import{B as tr}from"./building-2-boIK6K2k.js";import{A as ca}from"./arrow-right-Bmt6JCm_.js";import{S as st}from"./status-badge-DPaiL_rL.js";import{S as nr}from"./square-check-big-BcV2kv-K.js";import{B as Js}from"./ban-B36B5PRf.js";import{Z as at}from"./zap-DzbXsdut.js";import{A as oa,D as _e}from"./approval-detail-layout-CcJbUOlS.js";import{L as rr}from"./laptop-BvdVHGpX.js";import"./ui-aO-W1bxx.js";import"./chevron-left-DLFf1YD2.js";import"./page-header-D8tSLbK0.js";import"./skeleton-CfUgaIb_.js";import"./circle-x-C0sF-Oht.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 tt=as("ArrowRightLeft",[["path",{d:"m16 3 4 4-4 4",key:"1x1c3m"}],["path",{d:"M20 7H4",key:"zbl0bi"}],["path",{d:"m8 21-4-4 4-4",key:"h9nckh"}],["path",{d:"M4 17h16",key:"g4d7ey"}]]);/**
 * @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 da=as("Camera",[["path",{d:"M14.5 4h-5L7 7H4a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-3l-2.5-3z",key:"1tc9qg"}],["circle",{cx:"12",cy:"13",r:"3",key:"1vg3eu"}]]);/**
 * @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 nt=as("Contact",[["path",{d:"M16 2v2",key:"scm5qe"}],["path",{d:"M7 22v-2a2 2 0 0 1 2-2h6a2 2 0 0 1 2 2v2",key:"1waht3"}],["path",{d:"M8 2v2",key:"pbkmx"}],["circle",{cx:"12",cy:"11",r:"3",key:"itu57m"}],["rect",{x:"3",y:"4",width:"18",height:"18",rx:"2",key:"12vinp"}]]);/**
 * @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 ir=as("DoorOpen",[["path",{d:"M13 4h3a2 2 0 0 1 2 2v14",key:"hrm0s9"}],["path",{d:"M2 20h3",key:"1gaodv"}],["path",{d:"M13 20h9",key:"s90cdi"}],["path",{d:"M10 12v.01",key:"vx6srw"}],["path",{d:"M13 4.562v16.157a1 1 0 0 1-1.242.97L5 20V5.562a2 2 0 0 1 1.515-1.94l4-1A2 2 0 0 1 13 4.561Z",key:"199qr4"}]]);/**
 * @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 lr=as("File",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}]]);/**
 * @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 cr=as("MessageSquarePlus",[["path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z",key:"1lielz"}],["path",{d:"M12 7v6",key:"lw1j43"}],["path",{d:"M9 10h6",key:"9gxzsh"}]]);/**
 * @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 ma=as("Paperclip",[["path",{d:"M13.234 20.252 21 12.3",key:"1cbrk9"}],["path",{d:"m16 6-8.414 8.586a2 2 0 0 0 0 2.828 2 2 0 0 0 2.828 0l8.414-8.586a4 4 0 0 0 0-5.656 4 4 0 0 0-5.656 0l-8.415 8.585a6 6 0 1 0 8.486 8.486",key:"1pkts6"}]]);/**
 * @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 or=as("Square",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]]);function Gs(s){return s<1024?`${s} B`:s<1024*1024?`${(s/1024).toFixed(1)} KB`:`${(s/(1024*1024)).toFixed(1)} MB`}function dr({onUpload:s,accept:a,maxSize:r=10*1024*1024,multiple:t=!1,disabled:n=!1,className:m}){const[l,i]=b.useState(!1),[x,g]=b.useState([]),p=b.useRef(null);function F(w){if(!w)return;const _=[];for(const o of Array.from(w)){const u=o.size>r;_.push({id:`${o.name}-${Date.now()}-${Math.random()}`,file:o,status:u?"error":"pending",progress:0,errorMessage:u?`File exceeds ${Gs(r)} limit`:void 0})}g(o=>t?[...o,..._]:_)}function y(w){g(_=>_.filter(o=>o.id!==w))}async function D(){const w=x.filter(_=>_.status==="pending");if(w.length!==0){g(_=>_.map(o=>o.status==="pending"?{...o,status:"uploading"}:o));try{await s(w.map(_=>_.file)),g(_=>_.map(o=>o.status==="uploading"?{...o,status:"done",progress:100}:o))}catch{g(_=>_.map(o=>o.status==="uploading"?{...o,status:"error",errorMessage:"Upload failed"}:o))}}}const c=x.some(w=>w.status==="pending");return e.jsxs("div",{className:Pe("space-y-3",m),children:[e.jsxs("div",{role:"button",tabIndex:n?-1:0,"aria-label":"Upload files",onKeyDown:w=>{var _;(w.key==="Enter"||w.key===" ")&&((_=p.current)==null||_.click())},onClick:()=>{var w;return!n&&((w=p.current)==null?void 0:w.click())},onDragOver:w=>{w.preventDefault(),n||i(!0)},onDragLeave:()=>i(!1),onDrop:w=>{w.preventDefault(),i(!1),n||F(w.dataTransfer.files)},className:Pe("relative flex flex-col items-center justify-center rounded-lg border-2 border-dashed","px-6 py-10 text-center cursor-pointer transition-colors",l?"border-blue-400 bg-blue-50/60":"border-slate-200 bg-slate-50/40 hover:border-slate-300 hover:bg-slate-50",n&&"pointer-events-none opacity-50"),children:[e.jsx("div",{className:"mb-3 flex h-10 w-10 items-center justify-center rounded-full bg-slate-100",children:e.jsx(xa,{className:"h-5 w-5 text-slate-400"})}),e.jsx("p",{className:"text-[13px] font-medium text-slate-700",children:l?"Drop files here":"Drop files here or click to browse"}),e.jsxs("p",{className:"mt-1 text-[12px] text-slate-400",children:[a?`Accepted: ${a} · `:"","Max ",Gs(r)]}),e.jsx("input",{ref:p,type:"file",accept:a,multiple:t,className:"sr-only",onChange:w=>F(w.target.files)})]}),x.length>0&&e.jsx("ul",{className:"space-y-2",children:x.map(w=>e.jsxs("li",{className:"flex items-center gap-3 rounded-lg border border-slate-200 bg-white px-3 py-2.5",children:[e.jsx("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded bg-slate-100",children:w.status==="done"?e.jsx(Xa,{className:"h-4 w-4 text-emerald-500"}):w.status==="error"?e.jsx(Jn,{className:"h-4 w-4 text-red-500"}):e.jsx(lr,{className:"h-4 w-4 text-slate-400"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-[13px] font-medium text-slate-700",children:w.file.name}),e.jsx("p",{className:"text-[11px] text-slate-400",children:w.errorMessage??Gs(w.file.size)}),w.status==="uploading"&&e.jsx("div",{className:"mt-1 h-1 w-full overflow-hidden rounded-full bg-slate-100",children:e.jsx("div",{className:"h-full rounded-full bg-blue-500 transition-all",style:{width:`${w.progress}%`}})})]}),w.status!=="uploading"&&e.jsx("button",{onClick:_=>{_.stopPropagation(),y(w.id)},className:"shrink-0 rounded p-1 text-slate-400 hover:bg-slate-100 hover:text-slate-600 transition-colors",children:e.jsx(mt,{className:"h-3.5 w-3.5"})})]},w.id))}),c&&e.jsxs("button",{onClick:D,className:Pe("flex h-9 w-full items-center justify-center gap-2 rounded-md","bg-blue-600 text-[13px] font-medium text-white","hover:bg-blue-700 transition-colors"),children:[e.jsx(xa,{className:"h-4 w-4"}),"Upload ",x.filter(w=>w.status==="pending").length," file",x.filter(w=>w.status==="pending").length!==1?"s":""]})]})}const fa="Additional Information";function rt(s,a){if(a==null||a==="")return"—";switch(s.field_type){case"boolean":return a?"Yes":"No";case"multiselect":return Array.isArray(a)&&a.length>0?a.join(", "):"—";default:return String(a)}}function mr(s){var m;const a=s.filter(l=>l.is_active),r=new Map;for(const l of a){const i=((m=l.section)==null?void 0:m.trim())||fa,x=r.get(i);x?x.push(l):r.set(i,[l])}const t=[];for(const[l,i]of r)i.sort((x,g)=>x.display_order-g.display_order),t.push({section:l,fields:i});const n=t.findIndex(l=>l.section===fa);if(n>-1&&n!==t.length-1){const l=t.splice(n,1);l[0]&&t.push(l[0])}return t}function _s({definition:s,value:a,onChange:r,error:t}){const m={text:"text",number:"number",date:"date",email:"email",url:"url",phone:"tel"}[s.field_type]??"text";return e.jsxs("div",{children:[e.jsx(As,{definition:s}),e.jsx(M,{type:m,className:Pe("mt-1.5",t&&"border-red-400 focus-visible:ring-red-500/30"),placeholder:s.placeholder,value:a!=null?String(a):"",onChange:l=>{const i=l.target.value;s.field_type==="number"?r(s.field_key,i===""?"":Number(i)):r(s.field_key,i)}}),e.jsx(Ts,{text:s.help_text}),e.jsx(Es,{text:t})]})}function xr({definition:s,value:a,onChange:r,error:t}){return e.jsxs("div",{children:[e.jsx(As,{definition:s}),e.jsx("div",{className:"mt-1.5",children:e.jsx(Ge,{checked:!!a,onCheckedChange:n=>r(s.field_key,n)})}),e.jsx(Ts,{text:s.help_text}),e.jsx(Es,{text:t})]})}function hr({definition:s,value:a,onChange:r,error:t}){return e.jsxs("div",{children:[e.jsx(As,{definition:s}),e.jsxs(le,{value:a!=null?String(a):"",onValueChange:n=>r(s.field_key,n),children:[e.jsx(ce,{className:Pe("mt-1.5",t&&"border-red-400 focus:ring-red-500/30"),children:e.jsx(oe,{placeholder:s.placeholder||"Select..."})}),e.jsx(de,{children:s.options.map(n=>e.jsx(T,{value:n,children:n},n))})]}),e.jsx(Ts,{text:s.help_text}),e.jsx(Es,{text:t})]})}function pr({definition:s,value:a,onChange:r,error:t}){const n=Array.isArray(a)?a:[];function m(l){const i=n.includes(l)?n.filter(x=>x!==l):[...n,l];r(s.field_key,i)}return e.jsxs("div",{children:[e.jsx(As,{definition:s}),e.jsx("div",{className:"mt-1.5 flex flex-wrap gap-3",children:s.options.map(l=>e.jsxs("label",{className:"flex items-center gap-1.5 cursor-pointer text-[13px] text-slate-600",children:[e.jsx(ts,{checked:n.includes(l),onCheckedChange:()=>m(l)}),l]},l))}),e.jsx(Ts,{text:s.help_text}),e.jsx(Es,{text:t})]})}function ur({definition:s,value:a,onChange:r,error:t}){return e.jsxs("div",{className:"col-span-2",children:[e.jsx(As,{definition:s}),e.jsx(ps,{className:Pe("mt-1.5",t&&"border-red-400 focus-visible:ring-red-500/30"),placeholder:s.placeholder,value:a!=null?String(a):"",onChange:n=>r(s.field_key,n.target.value)}),e.jsx(Ts,{text:s.help_text}),e.jsx(Es,{text:t})]})}function As({definition:s}){return e.jsxs(h,{className:"text-[13px]",children:[s.name,s.is_required&&e.jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]})}function Ts({text:s}){return s?e.jsx("p",{className:"mt-1 text-[11px] text-slate-400",children:s}):null}function Es({text:s}){return s?e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:s}):null}const jr={text:_s,number:_s,date:_s,email:_s,url:_s,phone:_s,boolean:xr,select:hr,multiselect:pr,textarea:ur};function gr({definitions:s,values:a,onChange:r,errors:t}){const n=b.useMemo(()=>mr(s),[s]);return n.length===0?null:e.jsx("div",{children:n.map((m,l)=>e.jsxs("div",{className:Pe(l>0&&"border-t border-slate-100 pt-4 mt-4"),children:[e.jsx("h4",{className:"text-[13px] font-semibold text-slate-700 mb-3",children:m.section}),e.jsx("div",{className:"grid grid-cols-2 gap-4",children:m.fields.map(i=>{const x=jr[i.field_type];return x?e.jsx(x,{definition:i,value:a[i.field_key],onChange:r,error:t==null?void 0:t[i.field_key]},i.id):null})})]},m.section))})}const it=[{heading:"People",items:[{to:"/core-hr/employees",label:"Employees",description:"Employee directory",icon:Rs,permission:["core_hr","employee","read"]},{to:"/core-hr/positions",label:"Positions",description:"Org positions",icon:Ss,permission:["core_hr","position","read"]}]},{heading:"Onboarding",items:[{to:"/core-hr/onboarding-templates",label:"Templates",description:"Onboarding templates",icon:Ta,permission:["core_hr","onboarding_template","read"]},{to:"/core-hr/onboarding",label:"Checklists",description:"Active onboarding",icon:Ea,permission:["core_hr","onboarding","read"]}]},{heading:"Lifecycle",items:[{to:"/core-hr/transfers",label:"Transfers",description:"Transfer requests",icon:tt,permission:["core_hr","transfer","read"]},{to:"/core-hr/promotions",label:"Promotions",description:"Grade & designation changes",icon:Da,permission:["core_hr","promotion","read"]},{to:"/core-hr/probations",label:"Probations",description:"Probation tracking",icon:Fa,permission:["core_hr","probation","read"]},{to:"/core-hr/separations",label:"Separations",description:"Exit & offboarding",icon:xt,permission:["core_hr","separation","read"]},{to:"/core-hr/exit-clearance",label:"Exit Clearance",description:"Clearance departments",icon:qs,permission:["core_hr","clearance_department","read"]}]}];function Bl(){const{hasPermission:s}=je(),a=it.flatMap(r=>r.items).find(r=>s(r.permission[0],r.permission[1],r.permission[2]));return e.jsx(lt,{to:(a==null?void 0:a.to)??"/",replace:!0})}function _r({item:s,isActive:a}){const r=s.icon;return e.jsxs(dt,{to:s.to,className:Pe("group relative flex items-center gap-3 rounded-lg px-3 py-2.5 transition-all duration-150",a?"bg-primary-subtle/70":"hover:bg-slate-50"),children:[a&&e.jsx("span",{className:"absolute left-0 top-2.5 bottom-2.5 w-[3px] rounded-r-full bg-primary"}),e.jsx("div",{className:Pe("flex h-8 w-8 shrink-0 items-center justify-center rounded-lg transition-colors duration-150",a?"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(r,{className:"h-4 w-4"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:Pe("block text-[13px] truncate leading-tight",a?"font-medium text-primary":"font-medium text-slate-700 group-hover:text-slate-900"),children:s.label}),e.jsx("span",{className:Pe("block text-[11px] truncate leading-tight mt-0.5",a?"text-primary/60":"text-slate-400"),children:s.description})]})]})}function Gl(){const s=ct(),a=b.useRef(null),{hasPermission:r}=je();b.useEffect(()=>{var m;(m=a.current)==null||m.scrollTo(0,0)},[s.pathname]);const t=b.useMemo(()=>it.map(m=>({...m,items:m.items.filter(l=>r(l.permission[0],l.permission[1],l.permission[2]))})).filter(m=>m.items.length>0),[r]),n=/^\/core-hr\/employees\/[^/]+/.test(s.pathname);return e.jsxs("div",{className:"-m-6 flex h-[calc(100%+48px)]",children:[!n&&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:"Core HR"}),e.jsx("p",{className:"mt-0.5 text-[11px] text-slate-400",children:"People & lifecycle management"})]}),e.jsx("nav",{className:"flex-1 overflow-y-auto px-3 py-3 scrollbar-thin",children:t.map((m,l)=>e.jsxs("div",{className:Pe(l>0&&"mt-6"),children:[e.jsx("p",{className:"mb-2 px-3 text-[11px] font-semibold uppercase tracking-[0.08em] text-slate-400",children:m.heading}),e.jsx("div",{className:"space-y-0.5",children:m.items.map(i=>e.jsx(_r,{item:i,isActive:ht(s.pathname,i.to)},i.to))})]},m.heading))})]}),e.jsx("main",{ref:a,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(ot,{})})})]})}const fr={draft:"secondary",onboarding:"default",active:"success",on_notice:"warning",separated:"destructive"},vr={draft:"Draft",onboarding:"Onboarding",active:"Active",on_notice:"On Notice",separated:"Separated"};function Ql(){const s=wa(),[a,r]=b.useState(""),{hasPermission:t}=je(),n=t("core_hr","employee","read"),m=t("core_hr","employee","create"),l=t("core_hr","employee","update"),i=t("core_hr","employee","delete"),[x,g]=b.useState(null),p=At();function F(){x&&p.mutate(x.id,{onSuccess:()=>g(null)})}const{pagination:y,setPagination:D,sorting:c,setSorting:w,globalFilter:_,setGlobalFilter:o,queryParams:u}=ls(),O={...u,...a&&{status:a}},{data:z,isLoading:I}=Xe(O),j=(z==null?void 0:z.results)??[];function S(P){r(P==="__all__"?"":P),D(L=>({...L,pageIndex:0}))}const N=[{key:"name",header:"Employee",render:P=>e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-primary/10 text-primary text-[11px] font-semibold",children:[P.first_name[0],P.last_name[0]]}),e.jsxs("div",{children:[e.jsxs(Ke,{to:`/core-hr/employees/${P.id}`,className:"font-medium text-slate-900 hover:text-primary hover:underline transition-colors",children:[P.first_name," ",P.last_name]}),e.jsx("span",{className:"ml-2 text-[11px] text-slate-400",children:P.employee_id})]})]})},{key:"department",header:"Department",render:P=>P.department_name??"—"},{key:"designation",header:"Designation",render:P=>P.designation_name??"—"},{key:"category",header:"Category",render:P=>e.jsx("span",{className:"text-[12px] text-slate-500",children:P.category_name??"—"})},{key:"email",header:"Contact",render:P=>e.jsxs("div",{className:"space-y-0.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-slate-600 text-[12px]",children:[e.jsx(Ba,{className:"h-3 w-3"})," ",P.email]}),P.phone&&e.jsxs("div",{className:"flex items-center gap-1.5 text-slate-400 text-[11px]",children:[e.jsx(Ga,{className:"h-3 w-3"})," ",P.phone]})]})},{key:"date_of_joining",header:"Joined",render:P=>e.jsxs("span",{className:"flex items-center gap-1.5 text-slate-600 text-[12px]",children:[e.jsx(Gn,{className:"h-3 w-3"}),me(ie(P.date_of_joining),"dd MMM yyyy")]})},{key:"status",header:"Status",render:P=>e.jsx(B,{variant:fr[P.status],children:vr[P.status]})},{key:"actions",header:"",className:"w-10",render:P=>e.jsxs(ns,{children:[e.jsx(rs,{asChild:!0,children:e.jsx(C,{variant:"ghost",size:"icon-sm",children:e.jsx(vs,{className:"h-4 w-4"})})}),e.jsxs(is,{align:"end",children:[n&&e.jsxs($e,{onClick:()=>s(`/core-hr/employees/${P.id}`),children:[e.jsx(Us,{className:"mr-2 h-3.5 w-3.5"})," View"]}),l&&e.jsxs($e,{onClick:()=>s(`/core-hr/employees/${P.id}/edit`),children:[e.jsx(ke,{className:"mr-2 h-3.5 w-3.5"})," Edit"]}),i&&e.jsxs($e,{className:"text-red-600 focus:text-red-600",onClick:()=>g(P),children:[e.jsx(De,{className:"mr-2 h-3.5 w-3.5"})," Delete"]})]})]})}];return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"text-[16px] font-semibold text-slate-900 flex items-center gap-2",children:[e.jsx(Rs,{className:"h-5 w-5 text-primary"})," Employees"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"Employee directory and management"})]}),m&&e.jsxs(C,{size:"sm",onClick:()=>s("/core-hr/employees/new"),children:[e.jsx(se,{className:"mr-1.5 h-3.5 w-3.5"})," Add Employee"]})]}),e.jsx(es,{actions:e.jsx("div",{className:"flex gap-2",children:e.jsxs(le,{value:a,onValueChange:S,children:[e.jsx(ce,{className:"w-[140px] h-9",children:e.jsx(oe,{placeholder:"All statuses"})}),e.jsxs(de,{children:[e.jsx(T,{value:"__all__",children:"All"}),e.jsx(T,{value:"draft",children:"Draft"}),e.jsx(T,{value:"onboarding",children:"Onboarding"}),e.jsx(T,{value:"active",children:"Active"}),e.jsx(T,{value:"on_notice",children:"On Notice"}),e.jsx(T,{value:"separated",children:"Separated"})]})]})}),columns:N,data:j,isLoading:I,searchPlaceholder:"Search employees...",emptyMessage:"No employees yet",emptyDescription:"Add your first employee to get started.",totalCount:(z==null?void 0:z.count)??0,pagination:y,onPaginationChange:D,sorting:c,onSortingChange:w,globalFilter:_,onGlobalFilterChange:o}),e.jsx(Ie,{open:!!x,onOpenChange:P=>!P&&g(null),children:e.jsxs(Le,{children:[e.jsxs(Me,{children:[e.jsx(Oe,{children:"Delete employee?"}),e.jsx(Re,{children:x?`This removes ${x.first_name} ${x.last_name} (${x.employee_id}) from the directory. This can be undone by an administrator.`:""})]}),e.jsxs(qe,{children:[e.jsx(ze,{children:"Cancel"}),e.jsx(Ue,{className:"bg-red-600 hover:bg-red-700",onClick:F,disabled:p.isPending,children:p.isPending?"Deleting…":"Delete"})]})]})})]})}const yr={draft:"secondary",onboarding:"default",active:"success",on_notice:"warning",separated:"destructive"},br={draft:"Draft",onboarding:"Onboarding",active:"Active",on_notice:"On Notice",separated:"Separated"};function Nr({employee:s}){const a=b.useRef(null),r=Ia();function t(m){var i;const l=(i=m.target.files)==null?void 0:i[0];l&&r.mutate({employeeId:s.id,photo:l})}const n=`${s.first_name[0]??""}${s.last_name[0]??""}`.toUpperCase();return e.jsx("div",{className:"rounded-xl border border-slate-200 bg-white p-6",children:e.jsxs("div",{className:"flex items-start gap-5",children:[e.jsxs("div",{className:"relative group",children:[e.jsxs(Ks,{className:"h-20 w-20 text-lg",children:[s.photo&&e.jsx(ea,{src:s.photo,alt:`${s.first_name} ${s.last_name}`}),e.jsx(sa,{className:"bg-primary/10 text-primary font-semibold text-[18px]",children:n})]}),e.jsx("button",{type:"button",onClick:()=>{var m;return(m=a.current)==null?void 0:m.click()},className:"absolute inset-0 flex items-center justify-center rounded-full bg-black/40 opacity-0 group-hover:opacity-100 transition-opacity cursor-pointer",children:e.jsx(da,{className:"h-5 w-5 text-white"})}),e.jsx("input",{ref:a,type:"file",accept:"image/*",className:"hidden",onChange:t})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("h1",{className:"text-[20px] font-semibold text-slate-900",children:[s.first_name," ",s.last_name]}),e.jsx(B,{variant:"outline",className:"font-mono text-[11px]",children:s.employee_id}),e.jsx(B,{variant:yr[s.status],children:br[s.status]})]}),e.jsxs("div",{className:"mt-3 grid grid-cols-2 md:grid-cols-4 gap-x-8 gap-y-2 text-[13px]",children:[e.jsx(Ye,{label:"Company",value:s.company_name}),e.jsx(Ye,{label:"Department",value:s.department_name}),e.jsx(Ye,{label:"Designation",value:s.designation_name}),e.jsx(Ye,{label:"Grade",value:s.grade_name}),e.jsx(Ye,{label:"Branch",value:s.branch_name}),e.jsx(Ye,{label:"Work Location",value:s.work_location_name}),e.jsx(Ye,{label:"Joined",value:s.date_of_joining}),e.jsx(Ye,{label:"Manager",value:s.reporting_manager_name}),e.jsx(Ye,{label:"Category",value:s.category_name})]})]})]})})}function Ye({label:s,value:a}){return e.jsxs("div",{children:[e.jsx("span",{className:"text-slate-400 text-[11px]",children:s}),e.jsx("p",{className:"text-slate-700 font-medium truncate",children:a??"—"})]})}function Cr({employee:s}){const{hasPermission:a}=je(),r=a("core_hr","employee","update");return e.jsxs(e.Fragment,{children:[r&&e.jsx("div",{className:"flex justify-end mb-4",children:e.jsx(C,{asChild:!0,size:"sm",variant:"outline",children:e.jsxs(Ke,{to:`/core-hr/employees/${s.id}/edit`,children:[e.jsx(ke,{className:"mr-1.5 h-3.5 w-3.5"})," Edit"]})})}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(G,{children:e.jsxs(Q,{className:"p-5 space-y-3",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.08em] text-slate-400 mb-2",children:"Personal Information"}),e.jsx(we,{label:"Full Name",value:`${s.first_name} ${s.last_name}`}),e.jsx(we,{label:"Email",value:s.email}),e.jsx(we,{label:"Phone",value:s.phone}),e.jsx(we,{label:"Date of Birth",value:s.date_of_birth}),e.jsx(we,{label:"Gender",value:s.gender}),e.jsx(we,{label:"Marital Status",value:s.marital_status}),e.jsx(we,{label:"Blood Group",value:s.blood_group}),e.jsx(we,{label:"Nationality",value:s.nationality})]})}),e.jsx(G,{children:e.jsxs(Q,{className:"p-5 space-y-3",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.08em] text-slate-400 mb-2",children:"Organization"}),e.jsx(we,{label:"Company",value:s.company_name}),e.jsx(we,{label:"Branch",value:s.branch_name}),e.jsx(we,{label:"Department",value:s.department_name}),e.jsx(we,{label:"Designation",value:s.designation_name}),e.jsx(we,{label:"Grade",value:s.grade_name}),e.jsx(we,{label:"Category",value:s.category_name}),e.jsx(we,{label:"Reporting Manager",value:s.reporting_manager_name}),e.jsx(we,{label:"Date of Joining",value:s.date_of_joining}),e.jsx(we,{label:"Confirmation",value:Sr[s.confirmation_status]}),s.confirmation_date&&e.jsx(we,{label:"Confirmation Date",value:s.confirmation_date})]})})]})]})}const Sr={not_applicable:"—",in_probation:"In Probation",confirmed:"Confirmed",extended:"Probation Extended",terminated:"Probation Terminated"};function we({label:s,value:a}){return e.jsxs("div",{className:"flex justify-between items-baseline",children:[e.jsx("span",{className:"text-[12px] text-slate-400",children:s}),e.jsx("span",{className:"text-[13px] text-slate-700 font-medium text-right",children:a||"—"})]})}const va="Additional Information";function kr({employee:s}){const{hasPermission:a}=je(),r=a("core_hr","employee","update"),{data:t,isLoading:n}=zs(),m=b.useMemo(()=>{var F;const i=(t??[]).filter(y=>y.is_active),x=new Map;for(const y of i){const D=((F=y.section)==null?void 0:F.trim())||va,c=x.get(D);c?c.push(y):x.set(D,[y])}const g=[...x.entries()].map(([y,D])=>({section:y,fields:[...D].sort((c,w)=>c.display_order-w.display_order)})),p=g.findIndex(y=>y.section===va);return p>-1&&p!==g.length-1&&g.push(...g.splice(p,1)),g},[t]);if(n)return e.jsx("div",{className:"flex items-center justify-center py-16 text-slate-400",children:e.jsx(aa,{className:"h-5 w-5 animate-spin"})});if(m.length===0)return e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-center",children:[e.jsx("div",{className:"flex h-11 w-11 items-center justify-center rounded-full bg-slate-100",children:e.jsx(ks,{className:"h-5 w-5 text-slate-400"})}),e.jsx("p",{className:"mt-3 text-[13px] font-medium text-slate-700",children:"No custom fields configured"}),e.jsxs("p",{className:"mt-1 text-[12px] text-slate-400 max-w-sm",children:["An administrator can add organisation-specific fields under"," ","System Admin → Custom Fields."]})]});const l=s.custom_fields??{};return e.jsxs(e.Fragment,{children:[r&&e.jsx("div",{className:"flex justify-end mb-4",children:e.jsx(C,{asChild:!0,size:"sm",variant:"outline",children:e.jsxs(Ke,{to:`/core-hr/employees/${s.id}/edit`,children:[e.jsx(ke,{className:"mr-1.5 h-3.5 w-3.5"})," Edit"]})})}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:m.map(i=>e.jsx(G,{children:e.jsxs(Q,{className:"p-5 space-y-3",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.08em] text-slate-400 mb-2",children:i.section}),i.fields.map(x=>e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsx("span",{className:"text-[12px] text-slate-500 shrink-0",children:x.name}),e.jsx("span",{className:"text-[13px] text-slate-900 text-right break-words",children:rt(x,l[x.field_key])})]},x.id))]})},i.section))})]})}const wr=ue({address_type:hs(["current","permanent"]),line_1:v().min(1,"Address line 1 is required"),line_2:v().optional(),country:v().min(1,"Country is required"),state:v().min(1,"State is required"),city:v().min(1,"City is required"),postal_code:v().min(1,"Postal code is required").refine(s=>/^\d{6}$/.test(s),{message:"PIN code must be exactly 6 digits"}),is_primary:Fe().optional()});function Pr({employeeId:s,addresses:a}){var S,N,P;const[r,t]=b.useState(!1),[n,m]=b.useState(null),[l,i]=b.useState(null),{hasPermission:x,requirePermission:g}=je(),p=x("core_hr","employee","create"),F=x("core_hr","employee","update"),y=x("core_hr","employee","delete"),D=La(),c=Ma(),w=Tt(),_=Te({resolver:Ee(wr),defaultValues:{address_type:"current",is_primary:!1}});function o(){g("core_hr","employee","create")&&(m(null),_.reset({address_type:"current",is_primary:!1}),t(!0))}function u(L){g("core_hr","employee","update")&&(m(L),_.reset({address_type:L.address_type,line_1:L.line_1,line_2:L.line_2,city:L.city??"",state:L.state??"",country:L.country??"",postal_code:L.postal_code,is_primary:L.is_primary}),t(!0))}function O(L){const ae={...L};n?c.mutate({employeeId:s,addressId:n.id,...ae},{onSuccess:()=>t(!1)}):D.mutate({employeeId:s,employee:s,...ae},{onSuccess:()=>t(!1)})}function z(){g("core_hr","employee","delete")&&l&&w.mutate({employeeId:s,addressId:l.id},{onSuccess:()=>i(null)})}const I=a.find(L=>L.address_type==="current");function j(){I&&(_.setValue("line_1",I.line_1,{shouldValidate:!0}),_.setValue("line_2",I.line_2,{shouldValidate:!0}),_.setValue("city",I.city??"",{shouldValidate:!0}),_.setValue("state",I.state??"",{shouldValidate:!0}),_.setValue("country",I.country??"",{shouldValidate:!0}),_.setValue("postal_code",I.postal_code,{shouldValidate:!0}))}return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex justify-end mb-4",children:p&&e.jsxs(C,{size:"sm",onClick:o,children:[e.jsx(se,{className:"mr-1.5 h-3.5 w-3.5"})," Add Address"]})}),a.length===0?e.jsx(G,{children:e.jsxs(Q,{className:"p-12 text-center",children:[e.jsx("div",{className:"mx-auto flex h-12 w-12 items-center justify-center rounded-xl bg-slate-100 text-slate-400",children:e.jsx(ws,{className:"h-6 w-6"})}),e.jsx("h3",{className:"mt-4 text-[14px] font-medium text-slate-700",children:"No addresses added"}),e.jsx("p",{className:"mt-1 text-[13px] text-slate-400",children:"Add current or permanent address details."}),p&&e.jsxs(C,{size:"sm",className:"mt-4",onClick:o,children:[e.jsx(se,{className:"mr-1.5 h-3.5 w-3.5"})," Add Address"]})]})}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:a.map(L=>{var ae,te;return e.jsx(G,{className:"hover:border-primary/20 transition-colors",children:e.jsxs(Q,{className:"p-5",children:[e.jsxs("div",{className:"flex items-start justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(B,{variant:L.address_type==="current"?"default":"secondary",children:L.address_type==="current"?"Current":"Permanent"}),L.is_primary&&e.jsx(B,{variant:"success",children:"Primary"})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[F&&e.jsx(C,{variant:"ghost",size:"icon-sm",onClick:()=>u(L),children:e.jsx(ke,{className:"h-3.5 w-3.5"})}),y&&e.jsx(C,{variant:"ghost",size:"icon-sm",className:"text-red-500",onClick:()=>i(L),children:e.jsx(De,{className:"h-3.5 w-3.5"})})]})]}),e.jsxs("div",{className:"text-[13px] text-slate-700 space-y-0.5",children:[e.jsx("p",{children:L.line_1}),L.line_2&&e.jsx("p",{children:L.line_2}),e.jsxs("p",{children:[(ae=L.city_detail)==null?void 0:ae.name,L.state_detail?`, ${L.state_detail.name}`:""," ",L.postal_code]}),e.jsx("p",{children:(te=L.country_detail)==null?void 0:te.name})]})]})},L.id)})}),e.jsx(fe,{open:r,onOpenChange:t,children:e.jsxs(ve,{size:"lg",children:[e.jsxs(ye,{children:[e.jsx(be,{children:n?"Edit Address":"Add Address"}),e.jsx(Ne,{children:n?"Update address details.":"Add a new address for this employee."})]}),e.jsxs("form",{onSubmit:_.handleSubmit(O),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(h,{children:"Address Type *"}),e.jsxs(le,{value:_.watch("address_type"),onValueChange:L=>_.setValue("address_type",L),children:[e.jsx(ce,{className:"mt-1.5",children:e.jsx(oe,{})}),e.jsxs(de,{children:[e.jsx(T,{value:"current",children:"Current"}),e.jsx(T,{value:"permanent",children:"Permanent"})]})]})]}),e.jsx("div",{className:"flex items-end pb-1",children:e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx(ts,{checked:_.watch("is_primary")??!1,onCheckedChange:L=>_.setValue("is_primary",L===!0)}),e.jsx("span",{className:"text-[13px] text-slate-700",children:"Primary address"})]})})]}),_.watch("address_type")==="permanent"&&I&&I.id!==(n==null?void 0:n.id)&&e.jsxs(C,{type:"button",variant:"outline",size:"sm",onClick:j,children:[e.jsx(Wa,{className:"mr-1.5 h-3.5 w-3.5"})," Copy from Current Address"]}),e.jsxs("div",{children:[e.jsx(h,{children:"Address Line 1 *"}),e.jsx(M,{..._.register("line_1"),className:"mt-1.5"}),_.formState.errors.line_1&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:_.formState.errors.line_1.message})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Address Line 2"}),e.jsx(M,{..._.register("line_2"),className:"mt-1.5"})]}),e.jsx(Ha,{required:!0,value:{country:_.watch("country")||null,state:_.watch("state")||null,city:_.watch("city")||null},onChange:L=>{_.setValue("country",L.country??"",{shouldValidate:!0}),_.setValue("state",L.state??"",{shouldValidate:!0}),_.setValue("city",L.city??"",{shouldValidate:!0})},initialLabels:n?{country:(S=n.country_detail)==null?void 0:S.name,state:(N=n.state_detail)==null?void 0:N.name,city:(P=n.city_detail)==null?void 0:P.name}:void 0}),(_.formState.errors.country||_.formState.errors.state||_.formState.errors.city)&&e.jsx("p",{className:"text-[12px] text-red-500",children:"Country, state and city are required."}),e.jsxs("div",{children:[e.jsx(h,{children:"Postal Code *"}),e.jsx(Qe,{..._.register("postal_code"),className:"mt-1.5",maxLength:6})]})]}),e.jsxs(Ae,{children:[e.jsx(C,{variant:"outline",onClick:()=>t(!1),children:"Cancel"}),e.jsx(C,{onClick:_.handleSubmit(O),disabled:D.isPending||c.isPending,children:D.isPending||c.isPending?"Saving...":n?"Save Changes":"Add Address"})]})]})}),e.jsx(Ie,{open:!!l,onOpenChange:L=>!L&&i(null),children:e.jsxs(Le,{children:[e.jsxs(Me,{children:[e.jsx(Oe,{children:"Delete address?"}),e.jsxs(Re,{children:["This will permanently delete the ",e.jsx("strong",{children:l==null?void 0:l.address_type})," address."]})]}),e.jsxs(qe,{children:[e.jsx(ze,{children:"Cancel"}),e.jsx(Ue,{variant:"destructive",onClick:z,children:"Delete"})]})]})})]})}const Ar=ue({bank_name:v().min(1,"Bank name is required"),branch_name:v().optional(),account_number:v().refine(s=>s===""||/^\d{9,18}$/.test(s),{message:"Account number must be 9–18 digits (numbers only)"}),ifsc_code:v().min(1,"IFSC code is required"),account_type:hs(["savings","current"]),is_primary:Fe().optional()});function Tr({employeeId:s,bankAccounts:a}){const[r,t]=b.useState(!1),[n,m]=b.useState(null),[l,i]=b.useState(null),[x,g]=b.useState(null),{hasPermission:p,requirePermission:F}=je(),y=p("core_hr","employee","create"),D=p("core_hr","employee","update"),c=p("core_hr","employee","delete"),w=Oa(),_=Ra(),o=Et(),u=Te({resolver:Ee(Ar),defaultValues:{account_type:"savings",is_primary:!1}});function O(){F("core_hr","employee","create")&&(m(null),g(null),u.reset({account_type:"savings",is_primary:!1}),t(!0))}function z(S){F("core_hr","employee","update")&&(m(S),g(null),u.reset({bank_name:S.bank_name,branch_name:S.branch_name,account_number:"",ifsc_code:S.ifsc_code,account_type:S.account_type,is_primary:S.is_primary}),t(!0))}function I(S){n?_.mutate({employeeId:s,accountId:n.id,...S,document:x},{onSuccess:()=>t(!1)}):w.mutate({employeeId:s,...S,document:x},{onSuccess:()=>t(!1)})}function j(){F("core_hr","employee","delete")&&l&&o.mutate({employeeId:s,accountId:l.id},{onSuccess:()=>i(null)})}return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex justify-end mb-4",children:y&&e.jsxs(C,{size:"sm",onClick:O,children:[e.jsx(se,{className:"mr-1.5 h-3.5 w-3.5"})," Add Bank Account"]})}),a.length===0?e.jsx(G,{children:e.jsxs(Q,{className:"p-12 text-center",children:[e.jsx("div",{className:"mx-auto flex h-12 w-12 items-center justify-center rounded-xl bg-slate-100 text-slate-400",children:e.jsx(Vs,{className:"h-6 w-6"})}),e.jsx("h3",{className:"mt-4 text-[14px] font-medium text-slate-700",children:"No bank accounts added"}),e.jsx("p",{className:"mt-1 text-[13px] text-slate-400",children:"Add bank account details for salary payments."}),y&&e.jsxs(C,{size:"sm",className:"mt-4",onClick:O,children:[e.jsx(se,{className:"mr-1.5 h-3.5 w-3.5"})," Add Bank Account"]})]})}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:a.map(S=>e.jsx(G,{className:"hover:border-primary/20 transition-colors",children:e.jsxs(Q,{className:"p-5",children:[e.jsxs("div",{className:"flex items-start justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[14px] font-semibold text-slate-900",children:S.bank_name}),S.is_primary&&e.jsx(B,{variant:"success",children:"Primary"}),e.jsx(B,{variant:"secondary",children:S.account_type})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[D&&e.jsx(C,{variant:"ghost",size:"icon-sm",onClick:()=>z(S),children:e.jsx(ke,{className:"h-3.5 w-3.5"})}),c&&e.jsx(C,{variant:"ghost",size:"icon-sm",className:"text-red-500",onClick:()=>i(S),children:e.jsx(De,{className:"h-3.5 w-3.5"})})]})]}),e.jsxs("div",{className:"space-y-1.5 text-[12px] text-slate-500",children:[S.branch_name&&e.jsxs("p",{children:["Branch: ",S.branch_name]}),e.jsxs("p",{children:["A/C: ",e.jsx("span",{className:"font-mono",children:S.masked_account})]}),e.jsxs("p",{children:["IFSC: ",e.jsx("span",{className:"font-mono",children:S.ifsc_code})]}),S.document_url&&e.jsxs("a",{href:S.document_url,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 pt-0.5 text-[12px] text-primary hover:underline",children:[e.jsx(ma,{className:"h-3 w-3"})," Cancelled cheque"]})]})]})},S.id))}),e.jsx(fe,{open:r,onOpenChange:t,children:e.jsxs(ve,{size:"lg",children:[e.jsxs(ye,{children:[e.jsx(be,{children:n?"Edit Bank Account":"Add Bank Account"}),e.jsx(Ne,{children:n?"Update bank account details.":"Add a new bank account for salary disbursements."})]}),e.jsxs("form",{onSubmit:u.handleSubmit(I),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(h,{children:"Bank Name *"}),e.jsx(M,{...u.register("bank_name"),className:"mt-1.5",placeholder:"e.g. State Bank of India"}),u.formState.errors.bank_name&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:u.formState.errors.bank_name.message})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Branch Name"}),e.jsx(M,{...u.register("branch_name"),className:"mt-1.5",placeholder:"e.g. MG Road"})]})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Account Number *"}),e.jsx(Qe,{...u.register("account_number"),className:"mt-1.5 font-mono",maxLength:18,placeholder:n?"(enter new to update)":"Account number"}),u.formState.errors.account_number&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:u.formState.errors.account_number.message})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(h,{children:"IFSC Code *"}),e.jsx(M,{...u.register("ifsc_code"),className:"mt-1.5 font-mono uppercase",placeholder:"e.g. SBIN0001234"}),u.formState.errors.ifsc_code&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:u.formState.errors.ifsc_code.message})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Account Type"}),e.jsxs(le,{value:u.watch("account_type"),onValueChange:S=>u.setValue("account_type",S),children:[e.jsx(ce,{className:"mt-1.5",children:e.jsx(oe,{})}),e.jsxs(de,{children:[e.jsx(T,{value:"savings",children:"Savings"}),e.jsx(T,{value:"current",children:"Current"})]})]})]})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Cancelled Cheque / Passbook Copy"}),e.jsx(M,{type:"file",accept:".pdf,.jpg,.jpeg,.png",className:"mt-1.5",onChange:S=>{var N;return g(((N=S.target.files)==null?void 0:N[0])??null)}}),(n==null?void 0:n.document_url)&&!x&&e.jsxs("p",{className:"mt-1 text-[11px] text-slate-400",children:["Current:"," ",e.jsx("a",{href:n.document_url,target:"_blank",rel:"noreferrer",className:"text-primary hover:underline",children:"View attachment"})," ","— choosing a file replaces it."]})]}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx(ts,{checked:u.watch("is_primary")??!1,onCheckedChange:S=>u.setValue("is_primary",S===!0)}),e.jsx("span",{className:"text-[13px] text-slate-700",children:"Primary account (for salary credits)"})]})]}),e.jsxs(Ae,{children:[e.jsx(C,{variant:"outline",onClick:()=>t(!1),children:"Cancel"}),e.jsx(C,{onClick:u.handleSubmit(I),disabled:w.isPending||_.isPending,children:w.isPending||_.isPending?"Saving...":n?"Save Changes":"Add Account"})]})]})}),e.jsx(Ie,{open:!!l,onOpenChange:S=>!S&&i(null),children:e.jsxs(Le,{children:[e.jsxs(Me,{children:[e.jsx(Oe,{children:"Delete bank account?"}),e.jsxs(Re,{children:["This will permanently delete the ",e.jsx("strong",{children:l==null?void 0:l.bank_name})," account (",l==null?void 0:l.masked_account,")."]})]}),e.jsxs(qe,{children:[e.jsx(ze,{children:"Cancel"}),e.jsx(Ue,{variant:"destructive",onClick:j,children:"Delete"})]})]})})]})}const Er=ue({name:v().min(1,"Name is required"),relationship:v().min(1,"Relationship is required"),phone:v().regex(/^[6-9]\d{9}$/,"Enter a valid 10-digit mobile number"),email:v().email().optional().or(Qn("")),is_primary:Fe().optional()});function Dr({employeeId:s,contacts:a}){const[r,t]=b.useState(!1),[n,m]=b.useState(null),[l,i]=b.useState(null),{hasPermission:x,requirePermission:g}=je(),p=x("core_hr","employee","create"),F=x("core_hr","employee","update"),y=x("core_hr","employee","delete"),D=Dt(),c=Ft(),w=It(),_=Te({resolver:Ee(Er),defaultValues:{is_primary:!1}});function o(){g("core_hr","employee","create")&&(m(null),_.reset({is_primary:!1}),t(!0))}function u(I){g("core_hr","employee","update")&&(m(I),_.reset({name:I.name,relationship:I.relationship,phone:I.phone,email:I.email,is_primary:I.is_primary}),t(!0))}function O(I){n?c.mutate({employeeId:s,contactId:n.id,...I},{onSuccess:()=>t(!1)}):D.mutate({employeeId:s,employee:s,id:"",...I},{onSuccess:()=>t(!1)})}function z(){g("core_hr","employee","delete")&&l&&w.mutate({employeeId:s,contactId:l.id},{onSuccess:()=>i(null)})}return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex justify-end mb-4",children:p&&e.jsxs(C,{size:"sm",onClick:o,children:[e.jsx(se,{className:"mr-1.5 h-3.5 w-3.5"})," Add Contact"]})}),a.length===0?e.jsx(G,{children:e.jsxs(Q,{className:"p-12 text-center",children:[e.jsx("div",{className:"mx-auto flex h-12 w-12 items-center justify-center rounded-xl bg-slate-100 text-slate-400",children:e.jsx(Za,{className:"h-6 w-6"})}),e.jsx("h3",{className:"mt-4 text-[14px] font-medium text-slate-700",children:"No emergency contacts"}),e.jsx("p",{className:"mt-1 text-[13px] text-slate-400",children:"Add emergency contact details for this employee."}),p&&e.jsxs(C,{size:"sm",className:"mt-4",onClick:o,children:[e.jsx(se,{className:"mr-1.5 h-3.5 w-3.5"})," Add Contact"]})]})}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:a.map(I=>e.jsx(G,{className:"hover:border-primary/20 transition-colors",children:e.jsxs(Q,{className:"p-5",children:[e.jsxs("div",{className:"flex items-start justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[14px] font-semibold text-slate-900",children:I.name}),e.jsx(B,{variant:"secondary",children:I.relationship}),I.is_primary&&e.jsx(B,{variant:"success",children:"Primary"})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[F&&e.jsx(C,{variant:"ghost",size:"icon-sm",onClick:()=>u(I),children:e.jsx(ke,{className:"h-3.5 w-3.5"})}),y&&e.jsx(C,{variant:"ghost",size:"icon-sm",className:"text-red-500",onClick:()=>i(I),children:e.jsx(De,{className:"h-3.5 w-3.5"})})]})]}),e.jsxs("div",{className:"space-y-1 text-[12px] text-slate-500",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Ga,{className:"h-3 w-3"})," ",I.phone]}),I.email&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Ba,{className:"h-3 w-3"})," ",I.email]})]})]})},I.id))}),e.jsx(fe,{open:r,onOpenChange:t,children:e.jsxs(ve,{size:"md",children:[e.jsxs(ye,{children:[e.jsx(be,{children:n?"Edit Emergency Contact":"Add Emergency Contact"}),e.jsx(Ne,{children:n?"Update emergency contact details.":"Add a new emergency contact."})]}),e.jsxs("form",{onSubmit:_.handleSubmit(O),className:"flex-1 overflow-y-auto px-6 py-5 space-y-4",children:[e.jsxs("div",{children:[e.jsx(h,{children:"Full Name *"}),e.jsx(M,{..._.register("name"),className:"mt-1.5"}),_.formState.errors.name&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:_.formState.errors.name.message})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Relationship *"}),e.jsx(M,{..._.register("relationship"),className:"mt-1.5",placeholder:"e.g. Spouse, Parent, Sibling"}),_.formState.errors.relationship&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:_.formState.errors.relationship.message})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Phone *"}),e.jsx(Qe,{..._.register("phone"),className:"mt-1.5",placeholder:"10-digit mobile",maxLength:10}),_.formState.errors.phone&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:_.formState.errors.phone.message})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Email"}),e.jsx(M,{type:"email",..._.register("email"),className:"mt-1.5"})]}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx(ts,{checked:_.watch("is_primary")??!1,onCheckedChange:I=>_.setValue("is_primary",I===!0)}),e.jsx("span",{className:"text-[13px] text-slate-700",children:"Primary emergency contact"})]})]}),e.jsxs(Ae,{children:[e.jsx(C,{variant:"outline",onClick:()=>t(!1),children:"Cancel"}),e.jsx(C,{onClick:_.handleSubmit(O),disabled:D.isPending||c.isPending,children:D.isPending||c.isPending?"Saving...":n?"Save Changes":"Add Contact"})]})]})}),e.jsx(Ie,{open:!!l,onOpenChange:I=>!I&&i(null),children:e.jsxs(Le,{children:[e.jsxs(Me,{children:[e.jsx(Oe,{children:"Delete emergency contact?"}),e.jsxs(Re,{children:["This will permanently delete ",e.jsx("strong",{children:l==null?void 0:l.name})," from the emergency contacts list."]})]}),e.jsxs(qe,{children:[e.jsx(ze,{children:"Cancel"}),e.jsx(Ue,{variant:"destructive",onClick:z,children:"Delete"})]})]})})]})}const ya=[{value:"id",label:"Identity"},{value:"educational",label:"Educational"},{value:"employment",label:"Employment"},{value:"legal",label:"Legal"},{value:"medical",label:"Medical"}],Fr={active:"success",expired:"destructive",superseded:"secondary"},Ir=ue({category:v().min(1,"Category is required"),document_type:v().min(1,"Document type is required"),expiry_date:Ls()});function Lr({employeeId:s}){const[a,r]=b.useState(!1),[t,n]=b.useState([]),[m,l]=b.useState(null),{hasPermission:i,requirePermission:x}=je(),g=i("core_hr","employee","create"),p=i("core_hr","employee","delete"),{data:F,isLoading:y}=Lt(s),D=(F==null?void 0:F.results)??[],c=Mt(),w=Ot();async function _(j,S){try{const N=await Rt(s,j.id),P=URL.createObjectURL(N),L=document.createElement("a");L.href=P,L.rel="noopener noreferrer",S?L.download=j.file_name||"document":L.target="_blank",document.body.appendChild(L),L.click(),L.remove(),setTimeout(()=>URL.revokeObjectURL(P),1e4)}catch(N){Fs.error(Hs(N,"Could not open document"))}}const o=Te({resolver:Ee(Ir),defaultValues:{category:"id"}});function u(){x("core_hr","employee","create")&&(n([]),o.reset({category:"id",document_type:"",expiry_date:""}),r(!0))}function O(j){n(j)}function z(j){if(t.length===0)return;const S=new FormData;S.append("category",j.category),S.append("document_type",j.document_type),j.expiry_date&&S.append("expiry_date",j.expiry_date),t.forEach(N=>S.append("file",N)),c.mutate({employeeId:s,data:S},{onSuccess:()=>r(!1)})}function I(){x("core_hr","employee","delete")&&m&&w.mutate({employeeId:s,documentId:m.id},{onSuccess:()=>l(null)})}return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex justify-end mb-4",children:g&&e.jsxs(C,{size:"sm",onClick:u,children:[e.jsx(se,{className:"mr-1.5 h-3.5 w-3.5"})," Upload Document"]})}),y?e.jsx("div",{className:"space-y-3",children:[1,2,3].map(j=>e.jsx(G,{children:e.jsx(Q,{className:"p-4",children:e.jsxs("div",{className:"animate-pulse flex items-center gap-3",children:[e.jsx("div",{className:"h-10 w-10 rounded-lg bg-slate-200"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx("div",{className:"h-3 w-48 rounded bg-slate-200"}),e.jsx("div",{className:"h-2.5 w-32 rounded bg-slate-100"})]})]})})},j))}):D.length===0?e.jsx(G,{children:e.jsxs(Q,{className:"p-12 text-center",children:[e.jsx("div",{className:"mx-auto flex h-12 w-12 items-center justify-center rounded-xl bg-slate-100 text-slate-400",children:e.jsx(Os,{className:"h-6 w-6"})}),e.jsx("h3",{className:"mt-4 text-[14px] font-medium text-slate-700",children:"No documents uploaded"}),e.jsx("p",{className:"mt-1 text-[13px] text-slate-400",children:"Upload ID proofs, certificates, and other documents."}),g&&e.jsxs(C,{size:"sm",className:"mt-4",onClick:u,children:[e.jsx(se,{className:"mr-1.5 h-3.5 w-3.5"})," Upload Document"]})]})}):e.jsx("div",{className:"space-y-3",children:D.map(j=>{var S;return e.jsx(G,{className:"hover:border-primary/20 transition-colors",children:e.jsx(Q,{className:"p-4",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-lg bg-blue-50 text-blue-600",children:e.jsx(Os,{className:"h-5 w-5"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[13px] font-semibold text-slate-900 truncate",children:j.file_name||j.document_type}),e.jsx(B,{variant:Fr[j.status]??"secondary",children:j.status}),e.jsx(B,{variant:"secondary",children:((S=ya.find(N=>N.value===j.category))==null?void 0:S.label)??j.category})]}),e.jsxs("div",{className:"mt-0.5 flex items-center gap-4 text-[11px] text-slate-400",children:[e.jsxs("span",{children:["Type: ",j.document_type]}),e.jsxs("span",{children:["v",j.version]}),j.expiry_date&&e.jsxs("span",{children:["Expires: ",me(ie(j.expiry_date),"dd MMM yyyy")]}),e.jsxs("span",{children:["Uploaded: ",me(ie(j.created_at),"dd MMM yyyy")]})]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[j.file_url&&e.jsxs(e.Fragment,{children:[e.jsx(C,{variant:"ghost",size:"icon-sm",title:"View",onClick:()=>_(j,!1),children:e.jsx(er,{className:"h-3.5 w-3.5"})}),e.jsx(C,{variant:"ghost",size:"icon-sm",title:"Download",onClick:()=>_(j,!0),children:e.jsx(pt,{className:"h-3.5 w-3.5"})})]}),p&&e.jsx(C,{variant:"ghost",size:"icon-sm",className:"text-red-500",onClick:()=>l(j),children:e.jsx(De,{className:"h-3.5 w-3.5"})})]})]})})},j.id)})}),e.jsx(fe,{open:a,onOpenChange:r,children:e.jsxs(ve,{size:"lg",children:[e.jsxs(ye,{children:[e.jsx(be,{children:"Upload Document"}),e.jsx(Ne,{children:"Attach identity proofs, certificates, or employment documents."})]}),e.jsxs("form",{onSubmit:o.handleSubmit(z),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(h,{children:"Category *"}),e.jsxs(le,{value:o.watch("category"),onValueChange:j=>o.setValue("category",j),children:[e.jsx(ce,{className:"mt-1.5",children:e.jsx(oe,{})}),e.jsx(de,{children:ya.map(j=>e.jsx(T,{value:j.value,children:j.label},j.value))})]})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Document Type *"}),e.jsx(M,{...o.register("document_type"),className:"mt-1.5",placeholder:"e.g. Aadhaar Card, Degree Certificate"}),o.formState.errors.document_type&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:o.formState.errors.document_type.message})]})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Expiry Date"}),e.jsx(M,{type:"date",...o.register("expiry_date"),className:"mt-1.5"})]}),e.jsxs("div",{children:[e.jsx(h,{className:"mb-2 block",children:"File *"}),e.jsx(dr,{onUpload:O,accept:".pdf,.jpg,.jpeg,.png,.doc,.docx",maxSize:10*1024*1024}),t.length>0&&e.jsxs("p",{className:"mt-1.5 text-[12px] text-emerald-600",children:[t.length," file(s) selected"]})]})]}),e.jsxs(Ae,{children:[e.jsx(C,{variant:"outline",onClick:()=>r(!1),children:"Cancel"}),e.jsx(C,{onClick:o.handleSubmit(z),disabled:c.isPending||t.length===0,children:c.isPending?"Uploading...":"Upload Document"})]})]})}),e.jsx(Ie,{open:!!m,onOpenChange:j=>!j&&l(null),children:e.jsxs(Le,{children:[e.jsxs(Me,{children:[e.jsx(Oe,{children:"Delete document?"}),e.jsxs(Re,{children:["This will permanently delete ",e.jsx("strong",{children:(m==null?void 0:m.file_name)||(m==null?void 0:m.document_type)}),". This action cannot be undone."]})]}),e.jsxs(qe,{children:[e.jsx(ze,{children:"Cancel"}),e.jsx(Ue,{variant:"destructive",onClick:I,children:"Delete"})]})]})})]})}const Mr=ue({pf_account_number:v().optional().refine(s=>!s||/^\d{12}$/.test(s),{message:"UAN must be exactly 12 digits"}),pf_member_id:v().optional().refine(s=>!s||/^[A-Z]{2}\/[A-Z]{3}\/\d{7}\/\d{3}$/.test(s),{message:"Invalid PF Member ID (e.g. MH/BOM/1234567/001)"}),esi_number:v().optional().refine(s=>!s||/^\d{10}$/.test(s),{message:"ESI/IP number must be exactly 10 digits"}),pan:v().optional().refine(s=>!s||/^[A-Z]{3}[ABCFGHJLPT][A-Z][0-9]{4}[A-Z]$/.test(s),{message:"Invalid PAN format (e.g. ABCPE1234F)"}),aadhaar:v().optional().refine(s=>!s||/^\d{12}$/.test(s),{message:"Aadhaar must be 12 digits"}),passport_number:v().optional().refine(s=>!s||/^[A-Za-z0-9]{8}$/.test(s),{message:"Passport number must be 8 alphanumeric characters"}),voter_id:v().optional().refine(s=>!s||/^[A-Z]{3}[0-9]{7}$/.test(s),{message:"Voter ID must be 3 letters followed by 7 digits (e.g. ABC1234567)"}),driving_license:v().optional().refine(s=>!s||s.length<=20,{message:"Driving licence cannot exceed 20 characters"}),ration_card_number:v().optional().refine(s=>!s||s.length<=15,{message:"Ration card number cannot exceed 15 characters"}),professional_tax_number:v().optional(),state:v().nullable().optional(),tax_regime:v().optional(),pf_opt_out:Fe().optional(),esi_opt_out:Fe().optional(),pt_opt_out:Fe().optional(),tds_opt_out:Fe().optional()}).superRefine((s,a)=>{var r,t,n;s.pf_opt_out&&!((r=s.pf_account_number)!=null&&r.trim())&&a.addIssue({code:We.custom,message:"PF Account Number (UAN) is required when PF is applicable",path:["pf_account_number"]}),s.esi_opt_out&&!((t=s.esi_number)!=null&&t.trim())&&a.addIssue({code:We.custom,message:"ESI Number is required when ESI is applicable",path:["esi_number"]}),s.pt_opt_out&&((n=s.professional_tax_number)!=null&&n.trim()||a.addIssue({code:We.custom,message:"Professional Tax Number is required when PT is applicable",path:["professional_tax_number"]}),s.state||a.addIssue({code:We.custom,message:"State is required when PT is applicable",path:["state"]})),s.tds_opt_out&&!s.tax_regime&&a.addIssue({code:We.custom,message:"Tax Regime is required when TDS is applicable",path:["tax_regime"]})});function Or(s){return!s||s.length<4?"—":`XXXX XXXX ${s.slice(-4)}`}function Rr({employeeId:s}){var o;const[a,r]=b.useState(!1),{hasPermission:t,requirePermission:n}=je(),m=t("payroll","statutory_info","update"),{data:l}=Ya({employee:s}),i=((o=l==null?void 0:l.results)==null?void 0:o[0])??null,[x,g]=b.useState(""),{data:p,isLoading:F}=Ps("all",x),y=Ja(),D=Ka(),c=Te({resolver:Ee(Mr),defaultValues:{pf_opt_out:!1,esi_opt_out:!1,pt_opt_out:!1,tds_opt_out:!1,tax_regime:"new"}});b.useEffect(()=>{i&&c.reset({pf_account_number:i.pf_account_number,pf_member_id:i.pf_member_id,esi_number:i.esi_number,pan:i.pan,aadhaar:i.aadhaar,passport_number:i.passport_number,voter_id:i.voter_id,driving_license:i.driving_license,ration_card_number:i.ration_card_number,professional_tax_number:i.professional_tax_number,state:i.state,tax_regime:i.tax_regime||"new",pf_opt_out:i.pf_opt_out,esi_opt_out:i.esi_opt_out,pt_opt_out:i.pt_opt_out,tds_opt_out:i.tds_opt_out})},[i,c]);function w(){n("payroll","statutory_info","update")&&(i?c.reset({pf_account_number:i.pf_account_number,pf_member_id:i.pf_member_id,esi_number:i.esi_number,pan:i.pan,aadhaar:i.aadhaar,passport_number:i.passport_number,voter_id:i.voter_id,driving_license:i.driving_license,ration_card_number:i.ration_card_number,professional_tax_number:i.professional_tax_number,state:i.state,tax_regime:i.tax_regime||"new",pf_opt_out:i.pf_opt_out,esi_opt_out:i.esi_opt_out,pt_opt_out:i.pt_opt_out,tds_opt_out:i.tds_opt_out}):c.reset({pf_opt_out:!1,esi_opt_out:!1,pt_opt_out:!1,tds_opt_out:!1,tax_regime:"new"}),r(!0))}function _(u){const O={employee:s,...u};i?D.mutate({id:i.id,...O},{onSuccess:()=>r(!1)}):y.mutate(O,{onSuccess:()=>r(!1)})}return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex justify-end mb-4",children:m&&e.jsxs(C,{size:"sm",variant:"outline",onClick:w,children:[i?e.jsx(ke,{className:"mr-1.5 h-3.5 w-3.5"}):e.jsx(se,{className:"mr-1.5 h-3.5 w-3.5"}),i?"Edit":"Add Statutory Info"]})}),i?e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(G,{children:e.jsxs(Q,{className:"p-5 space-y-3",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.08em] text-slate-400 mb-2",children:"Provident Fund"}),e.jsx(Ve,{label:"PF Account Number",value:i.pf_account_number}),e.jsx(Ve,{label:"PF Member ID",value:i.pf_member_id}),e.jsx(Ve,{label:"PF Applicable",value:i.pf_opt_out?"Yes":"No"})]})}),e.jsx(G,{children:e.jsxs(Q,{className:"p-5 space-y-3",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.08em] text-slate-400 mb-2",children:"ESI & Professional Tax"}),e.jsx(Ve,{label:"ESI Number",value:i.esi_number}),e.jsx(Ve,{label:"ESI Applicable",value:i.esi_opt_out?"Yes":"No"}),e.jsx(Ve,{label:"Professional Tax No.",value:i.professional_tax_number}),e.jsx(Ve,{label:"PT Applicable",value:i.pt_opt_out?"Yes":"No"}),e.jsx(Ve,{label:"State",value:i.state_name})]})}),e.jsx(G,{children:e.jsxs(Q,{className:"p-5 space-y-3",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.08em] text-slate-400 mb-2",children:"Identity & Tax"}),e.jsx(Ve,{label:"PAN",value:i.pan}),e.jsx(Ve,{label:"Aadhaar",value:Or(i.aadhaar)}),e.jsx(Ve,{label:"Tax Regime",value:i.tax_regime==="new"?"New Regime":i.tax_regime==="old"?"Old Regime":i.tax_regime}),e.jsx(Ve,{label:"TDS Applicable",value:i.tds_opt_out?"Yes":"No"})]})}),e.jsx(G,{children:e.jsxs(Q,{className:"p-5 space-y-3",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.08em] text-slate-400 mb-2",children:"Other Government IDs"}),e.jsx(Ve,{label:"Passport Number",value:i.passport_number}),e.jsx(Ve,{label:"Voter ID",value:i.voter_id}),e.jsx(Ve,{label:"Driving License",value:i.driving_license}),e.jsx(Ve,{label:"Ration Card No.",value:i.ration_card_number})]})})]}):e.jsx(G,{children:e.jsxs(Q,{className:"p-12 text-center",children:[e.jsx("div",{className:"mx-auto flex h-12 w-12 items-center justify-center rounded-xl bg-slate-100 text-slate-400",children:e.jsx(Xs,{className:"h-6 w-6"})}),e.jsx("h3",{className:"mt-4 text-[14px] font-medium text-slate-700",children:"No statutory information"}),e.jsx("p",{className:"mt-1 text-[13px] text-slate-400",children:"Add PF, ESI, PAN, and other statutory details."}),m&&e.jsxs(C,{size:"sm",className:"mt-4",onClick:w,children:[e.jsx(se,{className:"mr-1.5 h-3.5 w-3.5"})," Add Statutory Info"]})]})}),e.jsx(fe,{open:a,onOpenChange:r,children:e.jsxs(ve,{size:"lg",children:[e.jsxs(ye,{children:[e.jsx(be,{children:i?"Edit Statutory Information":"Add Statutory Information"}),e.jsx(Ne,{children:"PF, ESI, PAN, Aadhaar, and tax regime details."})]}),e.jsxs("form",{onSubmit:c.handleSubmit(_),className:"flex-1 overflow-y-auto px-6 py-5 space-y-4",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.08em] text-slate-400 mb-1",children:"Provident Fund"}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Ge,{checked:c.watch("pf_opt_out")??!1,onCheckedChange:u=>c.setValue("pf_opt_out",u)}),e.jsx(h,{className:"mb-0",children:"PF Applicable"})]}),c.watch("pf_opt_out")&&e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(h,{children:"PF Account Number (UAN) *"}),e.jsx(Qe,{...c.register("pf_account_number"),className:"mt-1.5 font-mono text-[12px]",placeholder:"e.g. 100123456789",maxLength:12}),c.formState.errors.pf_account_number&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:c.formState.errors.pf_account_number.message})]}),e.jsxs("div",{children:[e.jsx(h,{children:"PF Member ID"}),e.jsx(M,{...c.register("pf_member_id"),className:"mt-1.5 font-mono uppercase text-[12px]",placeholder:"e.g. MH/BOM/1234567/001",maxLength:22}),c.formState.errors.pf_member_id&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:c.formState.errors.pf_member_id.message})]})]}),e.jsx(bs,{}),e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.08em] text-slate-400 mb-1",children:"ESI & Professional Tax"}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Ge,{checked:c.watch("esi_opt_out")??!1,onCheckedChange:u=>c.setValue("esi_opt_out",u)}),e.jsx(h,{className:"mb-0",children:"ESI Applicable"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Ge,{checked:c.watch("pt_opt_out")??!1,onCheckedChange:u=>c.setValue("pt_opt_out",u)}),e.jsx(h,{className:"mb-0",children:"PT Applicable"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[c.watch("esi_opt_out")&&e.jsxs("div",{children:[e.jsx(h,{children:"ESI Number *"}),e.jsx(Qe,{...c.register("esi_number"),className:"mt-1.5 font-mono text-[12px]",placeholder:"10-digit IP number",maxLength:10}),c.formState.errors.esi_number&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:c.formState.errors.esi_number.message})]}),c.watch("pt_opt_out")&&e.jsxs("div",{children:[e.jsx(h,{children:"Professional Tax Number *"}),e.jsx(M,{...c.register("professional_tax_number"),className:"mt-1.5 font-mono text-[12px]"}),c.formState.errors.professional_tax_number&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:c.formState.errors.professional_tax_number.message})]}),c.watch("pt_opt_out")&&e.jsxs("div",{children:[e.jsx(h,{children:"State *"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(K,{value:c.watch("state")??null,onValueChange:u=>c.setValue("state",u,{shouldValidate:!0}),onSearch:g,isLoading:F,options:((p==null?void 0:p.results)??[]).map(u=>({value:u.id,label:u.name,hint:u.code})),placeholder:"Select state",searchPlaceholder:"Search states..."})}),c.formState.errors.state?e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:c.formState.errors.state.message}):e.jsx("p",{className:"mt-1 text-[11px] text-slate-400",children:"Used for Professional Tax slab lookup."})]})]}),e.jsx(bs,{}),e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.08em] text-slate-400 mb-1",children:"Identity & Tax"}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(h,{children:"PAN"}),e.jsx(M,{...c.register("pan"),className:"mt-1.5 font-mono uppercase text-[12px]",placeholder:"ABCPE1234F",maxLength:10,onChange:u=>c.setValue("pan",u.target.value.toUpperCase(),{shouldValidate:!0})}),c.formState.errors.pan&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:c.formState.errors.pan.message})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Aadhaar"}),e.jsx(Qe,{...c.register("aadhaar"),className:"mt-1.5 font-mono text-[12px]",placeholder:"12-digit number",maxLength:12}),c.formState.errors.aadhaar&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:c.formState.errors.aadhaar.message})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(h,{children:"Passport Number"}),e.jsx(M,{...c.register("passport_number"),className:"mt-1.5 font-mono uppercase text-[12px]",placeholder:"e.g. M1234567",maxLength:8,onChange:u=>c.setValue("passport_number",u.target.value.toUpperCase(),{shouldValidate:!0})}),c.formState.errors.passport_number&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:c.formState.errors.passport_number.message})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Voter ID"}),e.jsx(M,{...c.register("voter_id"),className:"mt-1.5 font-mono uppercase text-[12px]",placeholder:"e.g. ABC1234567",maxLength:10,onChange:u=>c.setValue("voter_id",u.target.value.toUpperCase(),{shouldValidate:!0})}),c.formState.errors.voter_id&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:c.formState.errors.voter_id.message})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(h,{children:"Driving License"}),e.jsx(M,{...c.register("driving_license"),className:"mt-1.5 font-mono uppercase text-[12px]",placeholder:"e.g. DL-0420110012345",maxLength:20,onChange:u=>c.setValue("driving_license",u.target.value.toUpperCase(),{shouldValidate:!0})}),c.formState.errors.driving_license&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:c.formState.errors.driving_license.message})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Ration Card No."}),e.jsx(M,{...c.register("ration_card_number"),className:"mt-1.5 font-mono text-[12px]",placeholder:"Ration card number",maxLength:15}),c.formState.errors.ration_card_number&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:c.formState.errors.ration_card_number.message})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Ge,{checked:c.watch("tds_opt_out")??!1,onCheckedChange:u=>c.setValue("tds_opt_out",u,{shouldValidate:!0})}),e.jsx(h,{className:"mb-0",children:"TDS Applicable"})]}),c.watch("tds_opt_out")&&e.jsxs("div",{children:[e.jsx(h,{children:"Tax Regime *"}),e.jsxs(le,{value:c.watch("tax_regime")??"new",onValueChange:u=>c.setValue("tax_regime",u,{shouldValidate:!0}),children:[e.jsx(ce,{className:"mt-1.5",children:e.jsx(oe,{})}),e.jsxs(de,{children:[e.jsx(T,{value:"new",children:"New Regime"}),e.jsx(T,{value:"old",children:"Old Regime"})]})]}),c.formState.errors.tax_regime&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:c.formState.errors.tax_regime.message})]})]}),e.jsxs(Ae,{children:[e.jsx(C,{variant:"outline",onClick:()=>r(!1),children:"Cancel"}),e.jsx(C,{onClick:c.handleSubmit(_),disabled:y.isPending||D.isPending,children:y.isPending||D.isPending?"Saving...":i?"Save Changes":"Add Statutory Info"})]})]})})]})}function Ve({label:s,value:a}){return e.jsxs("div",{className:"flex justify-between items-baseline",children:[e.jsx("span",{className:"text-[12px] text-slate-400",children:s}),e.jsx("span",{className:"text-[13px] text-slate-700 font-medium text-right",children:a||"—"})]})}const qr={creation:"Initial Creation",company_transfer:"Company Transfer",manual:"Manual Change"},zr={creation:"secondary",company_transfer:"default",manual:"warning"};function Ur({employeeId:s}){const{data:a,isLoading:r}=qt(s);return r?e.jsx("div",{className:"space-y-3",children:[1,2].map(t=>e.jsx("div",{className:"h-20 rounded-lg bg-slate-100 animate-pulse"},t))}):!a||a.length===0?e.jsx(G,{children:e.jsxs(Q,{className:"p-12 text-center",children:[e.jsx("div",{className:"mx-auto flex h-12 w-12 items-center justify-center rounded-xl bg-slate-100 text-slate-400",children:e.jsx(et,{className:"h-6 w-6"})}),e.jsx("h3",{className:"mt-4 text-[14px] font-medium text-slate-700",children:"No code history"}),e.jsx("p",{className:"mt-1 text-[13px] text-slate-400",children:"Employee code change history will appear here."})]})}):e.jsx("div",{className:"space-y-3",children:a.map((t,n)=>e.jsx(G,{children:e.jsxs(Q,{className:"p-4 flex items-start gap-4",children:[e.jsxs("div",{className:"flex flex-col items-center pt-1",children:[e.jsx("div",{className:`h-3 w-3 rounded-full border-2 ${n===0?"border-primary bg-primary/20":"border-slate-300 bg-slate-100"}`}),n<a.length-1&&e.jsx("div",{className:"w-px flex-1 bg-slate-200 mt-1"})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"font-mono text-[13px] font-semibold text-slate-900",children:t.employee_code}),e.jsx(B,{variant:zr[t.reason],children:qr[t.reason]}),n===0&&e.jsx(B,{variant:"success",className:"text-[10px]",children:"Current"})]}),e.jsxs("div",{className:"mt-1.5 flex items-center gap-4 text-[12px] text-slate-500",children:[t.company_name&&e.jsxs("span",{children:["Company: ",e.jsx("span",{className:"font-medium text-slate-600",children:t.company_name})]}),e.jsxs("span",{children:["From: ",e.jsx("span",{className:"font-medium text-slate-600",children:me(ie(t.effective_from),"dd MMM yyyy")})]}),t.effective_to&&e.jsxs("span",{children:["To: ",e.jsx("span",{className:"font-medium text-slate-600",children:me(ie(t.effective_to),"dd MMM yyyy")})]})]}),t.notes&&e.jsx("p",{className:"mt-1 text-[12px] text-slate-400",children:t.notes})]}),e.jsx("span",{className:"text-[11px] text-slate-400 whitespace-nowrap",children:me(ie(t.created_at),"dd MMM yyyy")})]})},t.id))})}const Vr=ue({name:v().min(1,"Name is required"),relationship:hs(["spouse","father","mother","son","daughter","brother","sister","other"]),date_of_birth:v().optional(),gender:hs(["","male","female","other"]).optional(),occupation:v().optional(),phone:v().optional(),is_dependent:Fe().optional()}),$r=[{value:"spouse",label:"Spouse"},{value:"father",label:"Father"},{value:"mother",label:"Mother"},{value:"son",label:"Son"},{value:"daughter",label:"Daughter"},{value:"brother",label:"Brother"},{value:"sister",label:"Sister"},{value:"other",label:"Other"}];function Br({employeeId:s}){const[a,r]=b.useState(!1),[t,n]=b.useState(null),[m,l]=b.useState(null),{hasPermission:i,requirePermission:x}=je(),g=i("core_hr","employee","create"),p=i("core_hr","employee","update"),F=i("core_hr","employee","delete"),{data:y=[],isLoading:D}=zt(s),c=Ut(),w=Vt(),_=$t(),o=Te({resolver:Ee(Vr),defaultValues:{name:"",relationship:"spouse",date_of_birth:"",gender:"",occupation:"",phone:"",is_dependent:!1}});function u(){x("core_hr","employee","create")&&(n(null),o.reset({name:"",relationship:"spouse",date_of_birth:"",gender:"",occupation:"",phone:"",is_dependent:!1}),r(!0))}function O(j){x("core_hr","employee","update")&&(n(j),o.reset({name:j.name,relationship:j.relationship,date_of_birth:j.date_of_birth??"",gender:j.gender??"",occupation:j.occupation??"",phone:j.phone??"",is_dependent:j.is_dependent}),r(!0))}function z(j){const S={name:j.name,relationship:j.relationship,date_of_birth:j.date_of_birth||null,gender:j.gender??"",occupation:j.occupation??"",phone:j.phone??"",is_dependent:j.is_dependent??!1};t?w.mutate({employeeId:s,id:t.id,...S},{onSuccess:()=>r(!1)}):c.mutate({employeeId:s,...S},{onSuccess:()=>r(!1)})}function I(){x("core_hr","employee","delete")&&m&&_.mutate({employeeId:s,id:m.id},{onSuccess:()=>l(null)})}return D?e.jsx("div",{className:"p-12 text-center text-[13px] text-slate-400",children:"Loading..."}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex justify-end mb-4",children:g&&e.jsxs(C,{size:"sm",onClick:u,children:[e.jsx(se,{className:"mr-1.5 h-3.5 w-3.5"})," Add Family Member"]})}),y.length===0?e.jsx(G,{children:e.jsxs(Q,{className:"p-12 text-center",children:[e.jsx("div",{className:"mx-auto flex h-12 w-12 items-center justify-center rounded-xl bg-slate-100 text-slate-400",children:e.jsx(Rs,{className:"h-6 w-6"})}),e.jsx("h3",{className:"mt-4 text-[14px] font-medium text-slate-700",children:"No family members added"}),e.jsx("p",{className:"mt-1 text-[13px] text-slate-400",children:"Add family member and dependent details."}),g&&e.jsxs(C,{size:"sm",className:"mt-4",onClick:u,children:[e.jsx(se,{className:"mr-1.5 h-3.5 w-3.5"})," Add Family Member"]})]})}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:y.map(j=>e.jsx(G,{className:"hover:border-primary/20 transition-colors",children:e.jsxs(Q,{className:"p-5",children:[e.jsxs("div",{className:"flex items-start justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(B,{variant:"secondary",children:j.relationship_display??j.relationship}),j.is_dependent&&e.jsx(B,{variant:"success",children:"Dependent"})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[p&&e.jsx(C,{variant:"ghost",size:"icon-sm",onClick:()=>O(j),children:e.jsx(ke,{className:"h-3.5 w-3.5"})}),F&&e.jsx(C,{variant:"ghost",size:"icon-sm",className:"text-red-500",onClick:()=>l(j),children:e.jsx(De,{className:"h-3.5 w-3.5"})})]})]}),e.jsxs("div",{className:"text-[13px] text-slate-700 space-y-0.5",children:[e.jsx("p",{className:"font-medium",children:j.name}),j.occupation&&e.jsx("p",{className:"text-slate-500",children:j.occupation}),j.phone&&e.jsx("p",{className:"text-slate-500",children:j.phone}),j.date_of_birth&&e.jsx("p",{className:"text-slate-400",children:j.date_of_birth})]})]})},j.id))}),e.jsx(fe,{open:a,onOpenChange:r,children:e.jsxs(ve,{size:"lg",children:[e.jsxs(ye,{children:[e.jsx(be,{children:t?"Edit Family Member":"Add Family Member"}),e.jsx(Ne,{children:t?"Update family member details.":"Add a new family member for this employee."})]}),e.jsxs("form",{onSubmit:o.handleSubmit(z),className:"flex-1 overflow-y-auto px-6 py-5 space-y-4",children:[e.jsxs("div",{children:[e.jsx(h,{children:"Name *"}),e.jsx(M,{...o.register("name"),className:"mt-1.5"}),o.formState.errors.name&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:o.formState.errors.name.message})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(h,{children:"Relationship *"}),e.jsxs(le,{value:o.watch("relationship"),onValueChange:j=>o.setValue("relationship",j),children:[e.jsx(ce,{className:"mt-1.5",children:e.jsx(oe,{})}),e.jsx(de,{children:$r.map(j=>e.jsx(T,{value:j.value,children:j.label},j.value))})]})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Gender"}),e.jsxs(le,{value:o.watch("gender")||void 0,onValueChange:j=>o.setValue("gender",j),children:[e.jsx(ce,{className:"mt-1.5",children:e.jsx(oe,{placeholder:"Select gender"})}),e.jsxs(de,{children:[e.jsx(T,{value:"male",children:"Male"}),e.jsx(T,{value:"female",children:"Female"}),e.jsx(T,{value:"other",children:"Other"})]})]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(h,{children:"Date of Birth"}),e.jsx(M,{type:"date",...o.register("date_of_birth"),className:"mt-1.5"})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Phone"}),e.jsx(M,{...o.register("phone"),className:"mt-1.5"})]})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Occupation"}),e.jsx(M,{...o.register("occupation"),className:"mt-1.5"})]}),e.jsx("div",{children:e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx(ts,{checked:o.watch("is_dependent")??!1,onCheckedChange:j=>o.setValue("is_dependent",j===!0)}),e.jsx("span",{className:"text-[13px] text-slate-700",children:"Dependent"})]})})]}),e.jsxs(Ae,{children:[e.jsx(C,{variant:"outline",onClick:()=>r(!1),children:"Cancel"}),e.jsx(C,{onClick:o.handleSubmit(z),disabled:c.isPending||w.isPending,children:c.isPending||w.isPending?"Saving...":t?"Save Changes":"Add Family Member"})]})]})}),e.jsx(Ie,{open:!!m,onOpenChange:j=>!j&&l(null),children:e.jsxs(Le,{children:[e.jsxs(Me,{children:[e.jsx(Oe,{children:"Delete family member?"}),e.jsxs(Re,{children:["This will permanently delete ",e.jsx("strong",{children:m==null?void 0:m.name}),"."]})]}),e.jsxs(qe,{children:[e.jsx(ze,{children:"Cancel"}),e.jsx(Ue,{variant:"destructive",onClick:I,children:"Delete"})]})]})})]})}const Gr=ue({name:v().min(1,"Name is required"),relationship:v().min(1,"Relationship is required"),date_of_birth:v().optional(),share_percentage:v().optional(),address:v().optional(),is_minor:Fe().optional(),guardian_name:v().optional()});function Qr({employeeId:s}){const{data:a=[],isLoading:r}=Bt(s),{hasPermission:t,requirePermission:n}=je(),m=t("core_hr","employee","create"),l=t("core_hr","employee","update"),i=t("core_hr","employee","delete"),[x,g]=b.useState(!1),[p,F]=b.useState(null),[y,D]=b.useState(null),c=Gt(),w=Qt(),_=Ht(),o=Te({resolver:Ee(Gr),defaultValues:{name:"",relationship:"",is_minor:!1}});function u(){n("core_hr","employee","create")&&(F(null),o.reset({name:"",relationship:"",is_minor:!1}),g(!0))}function O(S){n("core_hr","employee","update")&&(F(S),o.reset({name:S.name,relationship:S.relationship,date_of_birth:S.date_of_birth??"",share_percentage:S.share_percentage??"",address:S.address??"",is_minor:S.is_minor,guardian_name:S.guardian_name??""}),g(!0))}function z(S){const N={...S};p?w.mutate({employeeId:s,id:p.id,...N},{onSuccess:()=>g(!1)}):c.mutate({employeeId:s,...N},{onSuccess:()=>g(!1)})}function I(){n("core_hr","employee","delete")&&y&&_.mutate({employeeId:s,id:y.id},{onSuccess:()=>D(null)})}const j=o.watch("is_minor")??!1;return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex justify-end mb-4",children:m&&e.jsxs(C,{size:"sm",onClick:u,children:[e.jsx(se,{className:"mr-1.5 h-3.5 w-3.5"})," Add Nominee"]})}),r?e.jsx("div",{className:"p-12 text-center text-[13px] text-slate-400",children:"Loading..."}):a.length===0?e.jsx(G,{children:e.jsxs(Q,{className:"p-12 text-center",children:[e.jsx("div",{className:"mx-auto flex h-12 w-12 items-center justify-center rounded-xl bg-slate-100 text-slate-400",children:e.jsx(qs,{className:"h-6 w-6"})}),e.jsx("h3",{className:"mt-4 text-[14px] font-medium text-slate-700",children:"No PF nominees added"}),e.jsx("p",{className:"mt-1 text-[13px] text-slate-400",children:"Add provident fund nominee details."}),m&&e.jsxs(C,{size:"sm",className:"mt-4",onClick:u,children:[e.jsx(se,{className:"mr-1.5 h-3.5 w-3.5"})," Add Nominee"]})]})}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:a.map(S=>e.jsx(G,{className:"hover:border-primary/20 transition-colors",children:e.jsxs(Q,{className:"p-5",children:[e.jsxs("div",{className:"flex items-start justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(B,{variant:"default",children:S.relationship}),S.share_percentage&&e.jsxs(B,{variant:"secondary",children:[S.share_percentage,"%"]}),S.is_minor&&e.jsx(B,{variant:"warning",children:"Minor"})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[l&&e.jsx(C,{variant:"ghost",size:"icon-sm",onClick:()=>O(S),children:e.jsx(ke,{className:"h-3.5 w-3.5"})}),i&&e.jsx(C,{variant:"ghost",size:"icon-sm",className:"text-red-500",onClick:()=>D(S),children:e.jsx(De,{className:"h-3.5 w-3.5"})})]})]}),e.jsxs("div",{className:"text-[13px] text-slate-700 space-y-0.5",children:[e.jsx("p",{className:"font-medium",children:S.name}),S.date_of_birth&&e.jsxs("p",{children:["DOB: ",S.date_of_birth]}),S.address&&e.jsx("p",{children:S.address}),S.is_minor&&S.guardian_name&&e.jsxs("p",{children:["Guardian: ",S.guardian_name]})]})]})},S.id))}),e.jsx(fe,{open:x,onOpenChange:g,children:e.jsxs(ve,{size:"lg",children:[e.jsxs(ye,{children:[e.jsx(be,{children:p?"Edit Nominee":"Add Nominee"}),e.jsx(Ne,{children:p?"Update PF nominee details.":"Add a new PF nominee for this employee."})]}),e.jsxs("form",{onSubmit:o.handleSubmit(z),className:"flex-1 overflow-y-auto px-6 py-5 space-y-4",children:[e.jsxs("div",{children:[e.jsx(h,{children:"Name *"}),e.jsx(M,{...o.register("name"),className:"mt-1.5"}),o.formState.errors.name&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:o.formState.errors.name.message})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Relationship *"}),e.jsx(M,{...o.register("relationship"),className:"mt-1.5",placeholder:"e.g. Spouse, Son"}),o.formState.errors.relationship&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:o.formState.errors.relationship.message})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(h,{children:"Date of Birth"}),e.jsx(M,{type:"date",...o.register("date_of_birth"),className:"mt-1.5"})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Share Percentage"}),e.jsx(M,{...o.register("share_percentage"),className:"mt-1.5",placeholder:"e.g. 50.00"}),e.jsx("p",{className:"mt-1 text-[12px] text-slate-400",children:"Percentage of PF share (%)."})]})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Address"}),e.jsx(ps,{...o.register("address"),className:"mt-1.5"})]}),e.jsx("div",{className:"flex items-center pb-1",children:e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx(ts,{checked:o.watch("is_minor")??!1,onCheckedChange:S=>o.setValue("is_minor",S===!0)}),e.jsx("span",{className:"text-[13px] text-slate-700",children:"Nominee is a minor"})]})}),j&&e.jsxs("div",{children:[e.jsx(h,{children:"Guardian Name"}),e.jsx(M,{...o.register("guardian_name"),className:"mt-1.5"})]})]}),e.jsxs(Ae,{children:[e.jsx(C,{variant:"outline",onClick:()=>g(!1),children:"Cancel"}),e.jsx(C,{onClick:o.handleSubmit(z),disabled:c.isPending||w.isPending,children:c.isPending||w.isPending?"Saving...":p?"Save Changes":"Add Nominee"})]})]})}),e.jsx(Ie,{open:!!y,onOpenChange:S=>!S&&D(null),children:e.jsxs(Le,{children:[e.jsxs(Me,{children:[e.jsx(Oe,{children:"Delete nominee?"}),e.jsxs(Re,{children:["This will permanently delete the nominee ",e.jsx("strong",{children:y==null?void 0:y.name}),"."]})]}),e.jsxs(qe,{children:[e.jsx(ze,{children:"Cancel"}),e.jsx(Ue,{variant:"destructive",onClick:I,children:"Delete"})]})]})})]})}const Hr=[{value:"10th",label:"10th"},{value:"12th",label:"12th"},{value:"diploma",label:"Diploma"},{value:"graduate",label:"Graduate"},{value:"post_graduate",label:"Post Graduate"},{value:"doctorate",label:"Doctorate"},{value:"certification",label:"Certification"},{value:"other",label:"Other"}],Wr=ue({qualification:hs(["10th","12th","diploma","graduate","post_graduate","doctorate","certification","other"]),specialization:v().optional(),institution:v().min(1,"Institution is required"),university_board:v().optional(),year_of_passing:v().optional(),grade_or_percentage:v().optional()});function Zr({employeeId:s}){const{data:a=[],isLoading:r}=Wt(s),{hasPermission:t,requirePermission:n}=je(),m=t("core_hr","employee","create"),l=t("core_hr","employee","update"),i=t("core_hr","employee","delete"),[x,g]=b.useState(!1),[p,F]=b.useState(null),[y,D]=b.useState(null),[c,w]=b.useState(null),_=Zt(),o=Xt(),u=Yt(),O=Te({resolver:Ee(Wr),defaultValues:{qualification:"graduate"}});function z(){n("core_hr","employee","create")&&(F(null),w(null),O.reset({qualification:"graduate"}),g(!0))}function I(N){n("core_hr","employee","update")&&(F(N),w(null),O.reset({qualification:N.qualification,specialization:N.specialization??"",institution:N.institution,university_board:N.university_board??"",year_of_passing:N.year_of_passing!=null?String(N.year_of_passing):"",grade_or_percentage:N.grade_or_percentage??""}),g(!0))}function j(N){const P={qualification:N.qualification,specialization:N.specialization,institution:N.institution,university_board:N.university_board,year_of_passing:N.year_of_passing?Number(N.year_of_passing):void 0,grade_or_percentage:N.grade_or_percentage,document:c};p?o.mutate({employeeId:s,id:p.id,...P},{onSuccess:()=>g(!1)}):_.mutate({employeeId:s,...P},{onSuccess:()=>g(!1)})}function S(){n("core_hr","employee","delete")&&y&&u.mutate({employeeId:s,id:y.id},{onSuccess:()=>D(null)})}return r?e.jsx("div",{className:"p-12 text-center text-[13px] text-slate-400",children:"Loading..."}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex justify-end mb-4",children:m&&e.jsxs(C,{size:"sm",onClick:z,children:[e.jsx(se,{className:"mr-1.5 h-3.5 w-3.5"})," Add Education"]})}),a.length===0?e.jsx(G,{children:e.jsxs(Q,{className:"p-12 text-center",children:[e.jsx("div",{className:"mx-auto flex h-12 w-12 items-center justify-center rounded-xl bg-slate-100 text-slate-400",children:e.jsx(Ws,{className:"h-6 w-6"})}),e.jsx("h3",{className:"mt-4 text-[14px] font-medium text-slate-700",children:"No education records added"}),e.jsx("p",{className:"mt-1 text-[13px] text-slate-400",children:"Add qualification and institution details."}),m&&e.jsxs(C,{size:"sm",className:"mt-4",onClick:z,children:[e.jsx(se,{className:"mr-1.5 h-3.5 w-3.5"})," Add Education"]})]})}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:a.map(N=>e.jsx(G,{className:"hover:border-primary/20 transition-colors",children:e.jsxs(Q,{className:"p-5",children:[e.jsxs("div",{className:"flex items-start justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(B,{variant:"default",children:N.qualification_display??N.qualification}),N.year_of_passing!=null&&e.jsx(B,{variant:"secondary",children:N.year_of_passing})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[l&&e.jsx(C,{variant:"ghost",size:"icon-sm",onClick:()=>I(N),children:e.jsx(ke,{className:"h-3.5 w-3.5"})}),i&&e.jsx(C,{variant:"ghost",size:"icon-sm",className:"text-red-500",onClick:()=>D(N),children:e.jsx(De,{className:"h-3.5 w-3.5"})})]})]}),e.jsxs("div",{className:"text-[13px] text-slate-700 space-y-0.5",children:[e.jsx("p",{className:"font-medium",children:N.institution}),N.specialization&&e.jsx("p",{children:N.specialization}),N.university_board&&e.jsx("p",{className:"text-slate-400",children:N.university_board}),N.grade_or_percentage&&e.jsxs("p",{className:"text-slate-400",children:["Grade: ",N.grade_or_percentage]}),N.document_url&&e.jsxs("a",{href:N.document_url,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 pt-1 text-[12px] text-primary hover:underline",children:[e.jsx(ma,{className:"h-3 w-3"})," Certificate"]})]})]})},N.id))}),e.jsx(fe,{open:x,onOpenChange:g,children:e.jsxs(ve,{size:"lg",children:[e.jsxs(ye,{children:[e.jsx(be,{children:p?"Edit Education":"Add Education"}),e.jsx(Ne,{children:p?"Update education details.":"Add a new education record for this employee."})]}),e.jsxs("form",{onSubmit:O.handleSubmit(j),className:"flex-1 overflow-y-auto px-6 py-5 space-y-4",children:[e.jsxs("div",{children:[e.jsx(h,{children:"Qualification *"}),e.jsxs(le,{value:O.watch("qualification"),onValueChange:N=>O.setValue("qualification",N),children:[e.jsx(ce,{className:"mt-1.5",children:e.jsx(oe,{})}),e.jsx(de,{children:Hr.map(N=>e.jsx(T,{value:N.value,children:N.label},N.value))})]})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Specialization"}),e.jsx(M,{...O.register("specialization"),className:"mt-1.5"})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Institution *"}),e.jsx(M,{...O.register("institution"),className:"mt-1.5"}),O.formState.errors.institution&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:O.formState.errors.institution.message})]}),e.jsxs("div",{children:[e.jsx(h,{children:"University / Board"}),e.jsx(M,{...O.register("university_board"),className:"mt-1.5"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(h,{children:"Year of Passing"}),e.jsx(M,{type:"number",...O.register("year_of_passing"),className:"mt-1.5"})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Grade / Percentage"}),e.jsx(M,{...O.register("grade_or_percentage"),className:"mt-1.5"})]})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Certificate"}),e.jsx(M,{type:"file",accept:".pdf,.jpg,.jpeg,.png",className:"mt-1.5",onChange:N=>{var P;return w(((P=N.target.files)==null?void 0:P[0])??null)}}),(p==null?void 0:p.document_url)&&!c&&e.jsxs("p",{className:"mt-1 text-[11px] text-slate-400",children:["Current:"," ",e.jsx("a",{href:p.document_url,target:"_blank",rel:"noreferrer",className:"text-primary hover:underline",children:"View attachment"})," ","— choosing a file replaces it."]})]})]}),e.jsxs(Ae,{children:[e.jsx(C,{variant:"outline",onClick:()=>g(!1),children:"Cancel"}),e.jsx(C,{onClick:O.handleSubmit(j),disabled:_.isPending||o.isPending,children:_.isPending||o.isPending?"Saving...":p?"Save Changes":"Add Education"})]})]})}),e.jsx(Ie,{open:!!y,onOpenChange:N=>!N&&D(null),children:e.jsxs(Le,{children:[e.jsxs(Me,{children:[e.jsx(Oe,{children:"Delete education record?"}),e.jsxs(Re,{children:["This will permanently delete the ",e.jsx("strong",{children:(y==null?void 0:y.qualification_display)??(y==null?void 0:y.qualification)})," record."]})]}),e.jsxs(qe,{children:[e.jsx(ze,{children:"Cancel"}),e.jsx(Ue,{variant:"destructive",onClick:S,children:"Delete"})]})]})})]})}const Xr=Ms(ue({employer_name:v().min(1,"Employer name is required"),designation:v().optional(),from_date:Ls(),to_date:Ls(),last_ctc:v().optional(),reason_for_leaving:v().optional()}),"from_date","to_date");function ba(s){if(!s)return null;const a=new Date(s);return Number.isNaN(a.getTime())?s:a.toLocaleDateString(void 0,{year:"numeric",month:"short"})}function Yr(s,a){const r=ba(s),t=ba(a);return r&&t?`${r} → ${t}`:r?`${r} → Present`:t?`Until ${t}`:"Dates not specified"}function Jr({employeeId:s}){const[a,r]=b.useState(!1),[t,n]=b.useState(null),[m,l]=b.useState(null),[i,x]=b.useState(null),{hasPermission:g,requirePermission:p}=je(),F=g("core_hr","employee","create"),y=g("core_hr","employee","update"),D=g("core_hr","employee","delete"),{data:c=[],isLoading:w}=Jt(s),_=Kt(),o=en(),u=sn(),O=Te({resolver:Ee(Xr),defaultValues:{employer_name:""}});function z(){p("core_hr","employee","create")&&(n(null),x(null),O.reset({employer_name:"",designation:"",from_date:"",to_date:"",last_ctc:"",reason_for_leaving:""}),r(!0))}function I(N){p("core_hr","employee","update")&&(n(N),x(null),O.reset({employer_name:N.employer_name,designation:N.designation??"",from_date:N.from_date??"",to_date:N.to_date??"",last_ctc:N.last_ctc??"",reason_for_leaving:N.reason_for_leaving??""}),r(!0))}function j(N){const P={employer_name:N.employer_name,designation:N.designation||void 0,from_date:N.from_date||null,to_date:N.to_date||null,last_ctc:N.last_ctc||void 0,reason_for_leaving:N.reason_for_leaving||void 0,document:i};t?o.mutate({employeeId:s,id:t.id,...P},{onSuccess:()=>r(!1)}):_.mutate({employeeId:s,...P},{onSuccess:()=>r(!1)})}function S(){p("core_hr","employee","delete")&&m&&u.mutate({employeeId:s,id:m.id},{onSuccess:()=>l(null)})}return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex justify-end mb-4",children:F&&e.jsxs(C,{size:"sm",onClick:z,children:[e.jsx(se,{className:"mr-1.5 h-3.5 w-3.5"})," Add Experience"]})}),w?e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[1,2].map(N=>e.jsx(G,{children:e.jsx(Q,{className:"p-5",children:e.jsxs("div",{className:"animate-pulse space-y-3",children:[e.jsx("div",{className:"h-4 w-40 rounded bg-slate-200"}),e.jsx("div",{className:"h-3 w-28 rounded bg-slate-100"}),e.jsx("div",{className:"h-3 w-32 rounded bg-slate-100"})]})})},N))}):c.length===0?e.jsx(G,{children:e.jsxs(Q,{className:"p-12 text-center",children:[e.jsx("div",{className:"mx-auto flex h-12 w-12 items-center justify-center rounded-xl bg-slate-100 text-slate-400",children:e.jsx(Ss,{className:"h-6 w-6"})}),e.jsx("h3",{className:"mt-4 text-[14px] font-medium text-slate-700",children:"No work experience added"}),e.jsx("p",{className:"mt-1 text-[13px] text-slate-400",children:"Add previous employment details."}),F&&e.jsxs(C,{size:"sm",className:"mt-4",onClick:z,children:[e.jsx(se,{className:"mr-1.5 h-3.5 w-3.5"})," Add Experience"]})]})}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:c.map(N=>e.jsx(G,{className:"hover:border-primary/20 transition-colors",children:e.jsxs(Q,{className:"p-5",children:[e.jsxs("div",{className:"flex items-start justify-between mb-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h4",{className:"text-[14px] font-medium text-slate-800 truncate",children:N.employer_name}),N.designation&&e.jsx("p",{className:"text-[13px] text-slate-500 truncate",children:N.designation})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[y&&e.jsx(C,{variant:"ghost",size:"icon-sm",onClick:()=>I(N),children:e.jsx(ke,{className:"h-3.5 w-3.5"})}),D&&e.jsx(C,{variant:"ghost",size:"icon-sm",className:"text-red-500",onClick:()=>l(N),children:e.jsx(De,{className:"h-3.5 w-3.5"})})]})]}),e.jsx("div",{className:"flex items-center gap-2 mb-2",children:e.jsx(B,{variant:"secondary",children:Yr(N.from_date,N.to_date)})}),e.jsxs("div",{className:"text-[13px] text-slate-700 space-y-0.5",children:[N.last_ctc&&e.jsxs("p",{children:[e.jsx("span",{className:"text-slate-400",children:"Last CTC:"})," ",N.last_ctc]}),N.reason_for_leaving&&e.jsxs("p",{children:[e.jsx("span",{className:"text-slate-400",children:"Reason for leaving:"})," ",N.reason_for_leaving]}),N.document_url&&e.jsxs("a",{href:N.document_url,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 pt-1 text-[12px] text-primary hover:underline",children:[e.jsx(ma,{className:"h-3 w-3"})," Relieving letter"]})]})]})},N.id))}),e.jsx(fe,{open:a,onOpenChange:r,children:e.jsxs(ve,{size:"lg",children:[e.jsxs(ye,{children:[e.jsx(be,{children:t?"Edit Experience":"Add Experience"}),e.jsx(Ne,{children:t?"Update work experience details.":"Add a previous employment record for this employee."})]}),e.jsxs("form",{onSubmit:O.handleSubmit(j),className:"flex-1 overflow-y-auto px-6 py-5 space-y-4",children:[e.jsxs("div",{children:[e.jsx(h,{children:"Employer Name *"}),e.jsx(M,{...O.register("employer_name"),className:"mt-1.5"}),O.formState.errors.employer_name&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:O.formState.errors.employer_name.message})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Designation"}),e.jsx(M,{...O.register("designation"),className:"mt-1.5"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(h,{children:"From Date"}),e.jsx(M,{type:"date",...O.register("from_date"),className:"mt-1.5",max:O.watch("to_date")||void 0})]}),e.jsxs("div",{children:[e.jsx(h,{children:"To Date"}),e.jsx(M,{type:"date",...O.register("to_date"),className:"mt-1.5",min:O.watch("from_date")||void 0})]})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Last CTC"}),e.jsx(M,{...O.register("last_ctc"),className:"mt-1.5"})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Reason for Leaving"}),e.jsx(M,{...O.register("reason_for_leaving"),className:"mt-1.5"})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Relieving Letter / Experience Certificate"}),e.jsx(M,{type:"file",accept:".pdf,.jpg,.jpeg,.png",className:"mt-1.5",onChange:N=>{var P;return x(((P=N.target.files)==null?void 0:P[0])??null)}}),(t==null?void 0:t.document_url)&&!i&&e.jsxs("p",{className:"mt-1 text-[11px] text-slate-400",children:["Current:"," ",e.jsx("a",{href:t.document_url,target:"_blank",rel:"noreferrer",className:"text-primary hover:underline",children:"View attachment"})," ","— choosing a file replaces it."]})]})]}),e.jsxs(Ae,{children:[e.jsx(C,{variant:"outline",onClick:()=>r(!1),children:"Cancel"}),e.jsx(C,{onClick:O.handleSubmit(j),disabled:_.isPending||o.isPending,children:_.isPending||o.isPending?"Saving...":t?"Save Changes":"Add Experience"})]})]})}),e.jsx(Ie,{open:!!m,onOpenChange:N=>!N&&l(null),children:e.jsxs(Le,{children:[e.jsxs(Me,{children:[e.jsx(Oe,{children:"Delete experience?"}),e.jsxs(Re,{children:["This will permanently delete the experience at ",e.jsx("strong",{children:m==null?void 0:m.employer_name}),"."]})]}),e.jsxs(qe,{children:[e.jsx(ze,{children:"Cancel"}),e.jsx(Ue,{variant:"destructive",onClick:S,children:"Delete"})]})]})})]})}const Kr=ue({name:v().min(1,"Name is required"),designation:v().optional(),company:v().optional(),relationship:v().optional(),email:v().optional(),phone:v().optional()});function ei({employeeId:s}){const{data:a=[],isLoading:r}=an(s),{hasPermission:t,requirePermission:n}=je(),m=t("core_hr","employee","create"),l=t("core_hr","employee","update"),i=t("core_hr","employee","delete"),[x,g]=b.useState(!1),[p,F]=b.useState(null),[y,D]=b.useState(null),c=tn(),w=nn(),_=rn(),o=Te({resolver:Ee(Kr),defaultValues:{name:"",designation:"",company:"",relationship:"",email:"",phone:""}});function u(){n("core_hr","employee","create")&&(F(null),o.reset({name:"",designation:"",company:"",relationship:"",email:"",phone:""}),g(!0))}function O(j){n("core_hr","employee","update")&&(F(j),o.reset({name:j.name,designation:j.designation??"",company:j.company??"",relationship:j.relationship??"",email:j.email??"",phone:j.phone??""}),g(!0))}function z(j){const S={...j};p?w.mutate({employeeId:s,id:p.id,...S},{onSuccess:()=>g(!1)}):c.mutate({employeeId:s,...S},{onSuccess:()=>g(!1)})}function I(){n("core_hr","employee","delete")&&y&&_.mutate({employeeId:s,id:y.id},{onSuccess:()=>D(null)})}return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex justify-end mb-4",children:m&&e.jsxs(C,{size:"sm",onClick:u,children:[e.jsx(se,{className:"mr-1.5 h-3.5 w-3.5"})," Add Reference"]})}),r?e.jsx("div",{className:"p-12 text-center text-[13px] text-slate-400",children:"Loading..."}):a.length===0?e.jsx(G,{children:e.jsxs(Q,{className:"p-12 text-center",children:[e.jsx("div",{className:"mx-auto flex h-12 w-12 items-center justify-center rounded-xl bg-slate-100 text-slate-400",children:e.jsx(nt,{className:"h-6 w-6"})}),e.jsx("h3",{className:"mt-4 text-[14px] font-medium text-slate-700",children:"No references added"}),e.jsx("p",{className:"mt-1 text-[13px] text-slate-400",children:"Add professional or personal references for this employee."}),m&&e.jsxs(C,{size:"sm",className:"mt-4",onClick:u,children:[e.jsx(se,{className:"mr-1.5 h-3.5 w-3.5"})," Add Reference"]})]})}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:a.map(j=>e.jsx(G,{className:"hover:border-primary/20 transition-colors",children:e.jsxs(Q,{className:"p-5",children:[e.jsxs("div",{className:"flex items-start justify-between mb-3",children:[e.jsx("div",{className:"flex items-center gap-2",children:j.relationship&&e.jsx(B,{variant:"secondary",children:j.relationship})}),e.jsxs("div",{className:"flex items-center gap-1",children:[l&&e.jsx(C,{variant:"ghost",size:"icon-sm",onClick:()=>O(j),children:e.jsx(ke,{className:"h-3.5 w-3.5"})}),i&&e.jsx(C,{variant:"ghost",size:"icon-sm",className:"text-red-500",onClick:()=>D(j),children:e.jsx(De,{className:"h-3.5 w-3.5"})})]})]}),e.jsxs("div",{className:"text-[13px] text-slate-700 space-y-0.5",children:[e.jsx("p",{className:"font-medium",children:j.name}),(j.designation||j.company)&&e.jsxs("p",{className:"text-slate-500",children:[j.designation,j.designation&&j.company?" · ":"",j.company]}),j.email&&e.jsx("p",{children:j.email}),j.phone&&e.jsx("p",{children:j.phone})]})]})},j.id))}),e.jsx(fe,{open:x,onOpenChange:g,children:e.jsxs(ve,{size:"lg",children:[e.jsxs(ye,{children:[e.jsx(be,{children:p?"Edit Reference":"Add Reference"}),e.jsx(Ne,{children:p?"Update reference details.":"Add a new reference for this employee."})]}),e.jsxs("form",{onSubmit:o.handleSubmit(z),className:"flex-1 overflow-y-auto px-6 py-5 space-y-4",children:[e.jsxs("div",{children:[e.jsx(h,{children:"Name *"}),e.jsx(M,{...o.register("name"),className:"mt-1.5"}),o.formState.errors.name&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:o.formState.errors.name.message})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(h,{children:"Designation"}),e.jsx(M,{...o.register("designation"),className:"mt-1.5"})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Company"}),e.jsx(M,{...o.register("company"),className:"mt-1.5"})]})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Relationship"}),e.jsx(M,{...o.register("relationship"),className:"mt-1.5",placeholder:"How they know the employee"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(h,{children:"Email"}),e.jsx(M,{type:"email",...o.register("email"),className:"mt-1.5"})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Phone"}),e.jsx(M,{...o.register("phone"),className:"mt-1.5"})]})]})]}),e.jsxs(Ae,{children:[e.jsx(C,{variant:"outline",onClick:()=>g(!1),children:"Cancel"}),e.jsx(C,{onClick:o.handleSubmit(z),disabled:c.isPending||w.isPending,children:c.isPending||w.isPending?"Saving...":p?"Save Changes":"Add Reference"})]})]})}),e.jsx(Ie,{open:!!y,onOpenChange:j=>!j&&D(null),children:e.jsxs(Le,{children:[e.jsxs(Me,{children:[e.jsx(Oe,{children:"Delete reference?"}),e.jsxs(Re,{children:["This will permanently delete the reference ",e.jsx("strong",{children:y==null?void 0:y.name}),"."]})]}),e.jsxs(qe,{children:[e.jsx(ze,{children:"Cancel"}),e.jsx(Ue,{variant:"destructive",onClick:I,children:"Delete"})]})]})})]})}function Hl(){const{id:s}=Cs(),{data:a,isLoading:r}=qa(s),{hasPermission:t}=je(),n=t("core_hr","employee","update");return r?e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"h-9 w-32 rounded bg-slate-200 animate-pulse"}),e.jsx("div",{className:"rounded-xl border border-slate-200 bg-white p-6",children:e.jsxs("div",{className:"flex items-start gap-5",children:[e.jsx("div",{className:"h-20 w-20 rounded-full bg-slate-200 animate-pulse"}),e.jsxs("div",{className:"flex-1 space-y-3",children:[e.jsx("div",{className:"h-6 w-64 rounded bg-slate-200 animate-pulse"}),e.jsx("div",{className:"h-4 w-96 rounded bg-slate-100 animate-pulse"}),e.jsx("div",{className:"grid grid-cols-4 gap-4",children:[1,2,3,4].map(m=>e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("div",{className:"h-3 w-16 rounded bg-slate-100 animate-pulse"}),e.jsx("div",{className:"h-4 w-24 rounded bg-slate-200 animate-pulse"})]},m))})]})]})}),e.jsx("div",{className:"h-10 w-full rounded bg-slate-100 animate-pulse"}),e.jsx("div",{className:"h-64 rounded-lg bg-slate-50 animate-pulse"})]}):a?e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(C,{asChild:!0,variant:"ghost",size:"sm",className:"text-slate-500",children:e.jsxs(Ke,{to:"/core-hr/employees",children:[e.jsx(Ys,{className:"mr-1.5 h-4 w-4"})," Back to Employees"]})}),n&&e.jsx(C,{asChild:!0,size:"sm",variant:"outline",children:e.jsxs(Ke,{to:`/core-hr/employees/${a.id}/edit`,children:[e.jsx(ke,{className:"mr-1.5 h-3.5 w-3.5"})," Edit Employee"]})})]}),e.jsx(Nr,{employee:a}),e.jsxs(ha,{defaultValue:"personal",className:"w-full",children:[e.jsx(pa,{className:"w-full justify-start border-b rounded-none bg-transparent p-0 h-auto",children:Na.map(m=>{const l=m.icon;return e.jsxs(ua,{value:m.value,className:"gap-1.5 rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:shadow-none",children:[e.jsx(l,{className:"h-3.5 w-3.5"})," ",m.label]},m.value)})}),e.jsx("div",{className:"mt-6",children:Na.map(m=>{const l=m.subTabs[0];return l?e.jsx(ja,{value:m.value,children:m.subTabs.length===1?Ca(l.value,a):e.jsxs(ha,{defaultValue:l.value,className:"w-full",children:[e.jsx(pa,{className:"justify-start bg-slate-50/80 rounded-lg p-1 h-auto gap-1",children:m.subTabs.map(i=>{const x=i.icon;return e.jsxs(ua,{value:i.value,className:"gap-1.5 rounded-md text-[13px] data-[state=active]:bg-white data-[state=active]:shadow-sm",children:[e.jsx(x,{className:"h-3.5 w-3.5"})," ",i.label]},i.value)})}),e.jsx("div",{className:"mt-5",children:m.subTabs.map(i=>e.jsx(ja,{value:i.value,children:Ca(i.value,a)},i.value))})]})},m.value):null})})]})]}):e.jsxs("div",{className:"text-center py-20",children:[e.jsx("h2",{className:"text-[16px] font-semibold text-slate-700",children:"Employee not found"}),e.jsx("p",{className:"mt-1 text-[13px] text-slate-400",children:"The requested employee record does not exist."}),e.jsx(C,{asChild:!0,size:"sm",className:"mt-4",children:e.jsx(Ke,{to:"/core-hr/employees",children:"Back to Employees"})})]})}const Na=[{value:"personal",label:"Personal",icon:Ns,subTabs:[{value:"personal-info",label:"Personal Info",icon:Ns},{value:"addresses",label:"Addresses",icon:ws},{value:"family",label:"Family",icon:Rs},{value:"emergency",label:"Emergency Contacts",icon:Za},{value:"custom-fields",label:"Custom Fields",icon:ks}]},{value:"employment",label:"Employment",icon:Xs,subTabs:[{value:"statutory",label:"Statutory",icon:Xs},{value:"bank",label:"Bank Accounts",icon:Vs},{value:"nominees",label:"PF Nominees",icon:qs}]},{value:"background",label:"Background",icon:Ws,subTabs:[{value:"education",label:"Education",icon:Ws},{value:"experience",label:"Work Experience",icon:Ss},{value:"references",label:"References",icon:nt}]},{value:"records",label:"Documents & History",icon:Os,subTabs:[{value:"documents",label:"Documents",icon:Os},{value:"code-history",label:"Code History",icon:et}]}];function Ca(s,a){switch(s){case"personal-info":return e.jsx(Cr,{employee:a});case"addresses":return e.jsx(Pr,{employeeId:a.id,addresses:a.addresses});case"family":return e.jsx(Br,{employeeId:a.id});case"emergency":return e.jsx(Dr,{employeeId:a.id,contacts:a.emergency_contacts});case"custom-fields":return e.jsx(kr,{employee:a});case"statutory":return e.jsx(Rr,{employeeId:a.id});case"bank":return e.jsx(Tr,{employeeId:a.id,bankAccounts:a.bank_accounts});case"nominees":return e.jsx(Qr,{employeeId:a.id});case"education":return e.jsx(Zr,{employeeId:a.id});case"experience":return e.jsx(Jr,{employeeId:a.id});case"references":return e.jsx(ei,{employeeId:a.id});case"documents":return e.jsx(Lr,{employeeId:a.id});case"code-history":return e.jsx(Ur,{employeeId:a.id});default:return null}}function si({photo:s,onPhotoChange:a,existingPhotoUrl:r}){const{register:t,watch:n,setValue:m,formState:{errors:l}}=us(),i=b.useRef(null),x=s?URL.createObjectURL(s):r??null,g=n("first_name")??"",p=n("last_name")??"",F=`${g[0]??""}${p[0]??""}`.toUpperCase(),D=n("marital_status")==="married";return e.jsxs("div",{className:"space-y-5",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.08em] text-slate-400 mb-2",children:"Personal Information"}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsxs(h,{children:["First Name ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx(M,{...t("first_name"),className:"mt-1.5",placeholder:"First name"}),l.first_name&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:l.first_name.message})]}),e.jsxs("div",{children:[e.jsxs(h,{children:["Last Name ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx(M,{...t("last_name"),className:"mt-1.5",placeholder:"Last name"}),l.last_name&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:l.last_name.message})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsxs(h,{children:["Email ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx(M,{type:"email",...t("email"),className:"mt-1.5",placeholder:"employee@company.com"}),l.email&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:l.email.message})]}),e.jsxs("div",{children:[e.jsxs(h,{children:["Mobile Number ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx(Qe,{...t("phone"),className:"mt-1.5",placeholder:"10-digit mobile",maxLength:10}),l.phone&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:l.phone.message})]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsx(Ze,{name:"date_of_birth",label:"Date of Birth"}),e.jsxs("div",{children:[e.jsx(h,{children:"Gender"}),e.jsxs(le,{value:n("gender")??"",onValueChange:c=>m("gender",c),children:[e.jsx(ce,{className:"mt-1.5",children:e.jsx(oe,{placeholder:"Select"})}),e.jsxs(de,{children:[e.jsx(T,{value:"male",children:"Male"}),e.jsx(T,{value:"female",children:"Female"}),e.jsx(T,{value:"other",children:"Other"})]})]})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Marital Status"}),e.jsxs(le,{value:n("marital_status")??"",onValueChange:c=>{m("marital_status",c),c!=="married"&&m("spouse_name","")},children:[e.jsx(ce,{className:"mt-1.5",children:e.jsx(oe,{placeholder:"Select"})}),e.jsxs(de,{children:[e.jsx(T,{value:"single",children:"Single"}),e.jsx(T,{value:"married",children:"Married"}),e.jsx(T,{value:"divorced",children:"Divorced"}),e.jsx(T,{value:"widowed",children:"Widowed"})]})]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(h,{children:"Blood Group"}),e.jsx(M,{...t("blood_group"),className:"mt-1.5",placeholder:"e.g. O+"})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Nationality"}),e.jsx(M,{...t("nationality"),className:"mt-1.5",placeholder:"e.g. Indian"})]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsxs("div",{children:[e.jsxs(h,{children:["Father's Name ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx(M,{...t("father_name"),className:"mt-1.5",placeholder:"Father's full name"}),l.father_name&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:l.father_name.message})]}),e.jsxs("div",{children:[e.jsxs(h,{children:["Mother's Name ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx(M,{...t("mother_name"),className:"mt-1.5",placeholder:"Mother's full name"}),l.mother_name&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:l.mother_name.message})]}),D&&e.jsxs("div",{children:[e.jsxs(h,{children:["Spouse's Name ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx(M,{...t("spouse_name"),className:"mt-1.5",placeholder:"Spouse's full name"}),l.spouse_name&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:l.spouse_name.message})]})]}),e.jsx("div",{className:"h-px bg-slate-100 my-2"}),e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.08em] text-slate-400 mb-2",children:"Photo"}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"relative group cursor-pointer",onClick:()=>{var c;return(c=i.current)==null?void 0:c.click()},children:[e.jsxs(Ks,{className:"h-16 w-16",children:[x&&e.jsx(ea,{src:x}),e.jsx(sa,{className:"bg-primary/10 text-primary font-semibold",children:F||e.jsx(Ns,{className:"h-5 w-5"})})]}),e.jsx("div",{className:"absolute inset-0 flex items-center justify-center rounded-full bg-black/40 opacity-0 group-hover:opacity-100 transition-opacity",children:e.jsx(da,{className:"h-4 w-4 text-white"})})]}),e.jsxs("div",{children:[e.jsx("button",{type:"button",onClick:()=>{var c;return(c=i.current)==null?void 0:c.click()},className:"text-[13px] font-medium text-primary hover:underline",children:s?"Change photo":"Upload photo"}),e.jsx("p",{className:"text-[11px] text-slate-400 mt-0.5",children:"JPG, PNG. Max 5 MB."}),s&&e.jsx("button",{type:"button",onClick:()=>a(null),className:"text-[11px] text-red-500 hover:underline mt-0.5",children:"Remove"})]}),e.jsx("input",{ref:i,type:"file",accept:"image/*",className:"hidden",onChange:c=>{var _;const w=((_=c.target.files)==null?void 0:_[0])??null;a(w)}})]})]})}const ds=(s=[])=>s.map(a=>({value:a.id,label:a.name,hint:a.code}));function ai(){const{watch:s,setValue:a,formState:{errors:r}}=us(),[t,n]=b.useState(""),[m,l]=b.useState(""),[i,x]=b.useState(""),[g,p]=b.useState(""),[F,y]=b.useState(""),[D,c]=b.useState(""),[w,_]=b.useState(""),o=s("company"),{data:u,isLoading:O}=ta({search:t||void 0}),{data:z,isLoading:I}=na({search:m||void 0,...o?{company:o}:{}}),{data:j,isLoading:S}=sr({search:i||void 0,...o?{company:o}:{}}),{data:N,isLoading:P}=ys({search:g||void 0,...o?{company:o}:{}}),{data:L,isLoading:ae}=$s({search:F||void 0}),{data:te,isLoading:ne}=Bs({search:D||void 0}),{data:W,isLoading:he}=ra({search:w||void 0});return e.jsxs("div",{className:"space-y-5",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.08em] text-slate-400 mb-2",children:"Organization"}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsxs(h,{children:["Company ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("div",{className:"mt-1.5",children:e.jsx(K,{value:s("company"),onValueChange:U=>{a("company",U,{shouldValidate:!0}),a("branch",null),a("work_location",null),a("department",null)},onSearch:n,isLoading:O,options:ds(u==null?void 0:u.results),placeholder:"Select company",searchPlaceholder:"Search companies..."})}),r.company&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:r.company.message})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Branch"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(K,{value:s("branch"),onValueChange:U=>a("branch",U||null),onSearch:l,isLoading:I,options:ds(z==null?void 0:z.results),placeholder:"Select branch",searchPlaceholder:"Search branches..."})})]})]}),e.jsx("div",{className:"grid grid-cols-2 gap-4",children:e.jsxs("div",{children:[e.jsx(h,{children:"Work Location"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(K,{value:s("work_location"),onValueChange:U=>a("work_location",U||null),onSearch:x,isLoading:S,options:ds(j==null?void 0:j.results),placeholder:"Select work location",searchPlaceholder:"Search locations..."})}),e.jsx("p",{className:"mt-1 text-[11px] text-slate-400",children:"Where this employee physically works."})]})}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(h,{children:"Department"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(K,{value:s("department"),onValueChange:U=>a("department",U||null),onSearch:p,isLoading:P,options:ds(N==null?void 0:N.results),placeholder:"Select department",searchPlaceholder:"Search departments..."})})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Designation"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(K,{value:s("designation"),onValueChange:U=>a("designation",U||null),onSearch:y,isLoading:ae,options:ds(L==null?void 0:L.results),placeholder:"Select designation",searchPlaceholder:"Search designations..."})})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(h,{children:"Grade"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(K,{value:s("grade"),onValueChange:U=>a("grade",U||null),onSearch:c,isLoading:ne,options:ds(te==null?void 0:te.results),placeholder:"Select grade",searchPlaceholder:"Search grades..."})})]}),e.jsxs("div",{children:[e.jsxs(h,{children:["Category ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("div",{className:"mt-1.5",children:e.jsx(K,{value:s("category"),onValueChange:U=>a("category",U,{shouldValidate:!0}),onSearch:_,isLoading:he,options:ds(W==null?void 0:W.results),placeholder:"Select category",searchPlaceholder:"Search categories..."})}),r.category&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:r.category.message})]})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Reporting Manager"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(ar,{value:s("reporting_manager")??"",onValueChange:U=>a("reporting_manager",U||null),placeholder:"Select reporting manager"})})]})]})}function ti({isEditMode:s}={}){const{register:a,watch:r,setValue:t,formState:{errors:n}}=us(),[m,l]=b.useState(""),{data:i,isLoading:x}=Ps("all",m);return e.jsxs("div",{className:"space-y-5",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.08em] text-slate-400 mb-2",children:"Employment"}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(Ze,{name:"date_of_joining",label:"Date of Joining",required:!0}),e.jsxs("div",{children:[e.jsx(h,{children:"Status"}),e.jsxs(le,{value:r("status")??"draft",onValueChange:g=>t("status",g),children:[e.jsx(ce,{className:"mt-1.5",children:e.jsx(oe,{})}),e.jsxs(de,{children:[e.jsx(T,{value:"draft",children:"Draft"}),e.jsx(T,{value:"onboarding",children:"Onboarding"}),e.jsx(T,{value:"active",children:"Active"}),s&&e.jsx(T,{value:"on_notice",children:"On Notice"}),s&&e.jsx(T,{value:"separated",children:"Separated"})]})]})]})]}),e.jsx(bs,{}),e.jsxs("p",{className:"text-[11px] font-semibold uppercase tracking-[0.08em] text-slate-400 mb-2",children:["Statutory Details ",e.jsx("span",{className:"normal-case font-normal",children:"(fields below become required once their toggle is on)"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-x-6 gap-y-3 rounded-lg border border-slate-200 bg-slate-50/50 p-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Ge,{checked:r("pf_opt_out")??!1,onCheckedChange:g=>t("pf_opt_out",g,{shouldValidate:!0})}),e.jsx(h,{className:"mb-0",children:"PF Applicable"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Ge,{checked:r("esi_opt_out")??!1,onCheckedChange:g=>t("esi_opt_out",g,{shouldValidate:!0})}),e.jsx(h,{className:"mb-0",children:"ESI Applicable"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Ge,{checked:r("pt_opt_out")??!1,onCheckedChange:g=>t("pt_opt_out",g,{shouldValidate:!0})}),e.jsx(h,{className:"mb-0",children:"PT Applicable"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Ge,{checked:r("tds_opt_out")??!1,onCheckedChange:g=>t("tds_opt_out",g,{shouldValidate:!0})}),e.jsx(h,{className:"mb-0",children:"TDS Applicable"})]})]}),(r("pf_opt_out")||r("esi_opt_out"))&&e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[r("pf_opt_out")&&e.jsxs("div",{children:[e.jsx(h,{children:"PF Account Number (UAN) *"}),e.jsx(Qe,{...a("pf_account_number"),className:"mt-1.5 font-mono text-[12px]",placeholder:"e.g. 100123456789",maxLength:12}),n.pf_account_number&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:n.pf_account_number.message})]}),r("esi_opt_out")&&e.jsxs("div",{children:[e.jsx(h,{children:"ESI Number *"}),e.jsx(Qe,{...a("esi_number"),className:"mt-1.5 font-mono text-[12px]",placeholder:"10-digit IP number",maxLength:10}),n.esi_number&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:n.esi_number.message})]})]}),r("pt_opt_out")&&e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(h,{children:"Professional Tax Number *"}),e.jsx(M,{...a("professional_tax_number"),className:"mt-1.5 font-mono text-[12px]",placeholder:"Professional tax registration number"}),n.professional_tax_number&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:n.professional_tax_number.message})]}),e.jsxs("div",{children:[e.jsx(h,{children:"State *"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(K,{value:r("state")??null,onValueChange:g=>t("state",g,{shouldValidate:!0}),onSearch:l,isLoading:x,options:((i==null?void 0:i.results)??[]).map(g=>({value:g.id,label:g.name,hint:g.code})),placeholder:"Select state",searchPlaceholder:"Search states..."})}),n.state?e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:n.state.message}):e.jsx("p",{className:"mt-1 text-[11px] text-slate-400",children:"Used for Professional Tax slab lookup."})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(h,{children:"PAN"}),e.jsx(M,{...a("pan",{onChange:g=>{g.target.value=g.target.value.toUpperCase()}}),className:"mt-1.5 font-mono uppercase text-[12px]",placeholder:"ABCPE1234F",maxLength:10}),n.pan&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:n.pan.message})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Aadhaar"}),e.jsx(Qe,{...a("aadhaar"),className:"mt-1.5 font-mono text-[12px]",placeholder:"12-digit number",maxLength:12}),n.aadhaar&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:n.aadhaar.message})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(h,{children:"Passport Number"}),e.jsx(M,{...a("passport_number",{onChange:g=>{g.target.value=g.target.value.toUpperCase()}}),className:"mt-1.5 font-mono text-[12px] uppercase",placeholder:"e.g. M1234567",maxLength:8})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Voter ID"}),e.jsx(M,{...a("voter_id",{onChange:g=>{g.target.value=g.target.value.toUpperCase()}}),className:"mt-1.5 font-mono text-[12px] uppercase",placeholder:"e.g. ABC1234567",maxLength:10})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(h,{children:"Driving License"}),e.jsx(M,{...a("driving_license",{onChange:g=>{g.target.value=g.target.value.toUpperCase()}}),className:"mt-1.5 font-mono text-[12px] uppercase",placeholder:"e.g. DL-0420110012345",maxLength:20})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Ration Card Number"}),e.jsx(M,{...a("ration_card_number"),className:"mt-1.5 font-mono text-[12px]",placeholder:"Ration card number",maxLength:15})]})]})]})}function ni(){return e.jsxs("div",{className:"space-y-8",children:[e.jsx(ri,{}),e.jsx(bs,{}),e.jsx(ci,{})]})}function ri(){const{control:s}=us(),{fields:a,append:r,update:t,remove:n}=Qa({control:s,name:"addresses"}),[m,l]=b.useState(!1),[i,x]=b.useState(null);function g(y){i!==null?(t(i,y),x(null)):r(y),l(!1)}function p(y){x(y),l(!0)}function F(){l(!1),x(null)}return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.08em] text-slate-400",children:"Addresses"}),e.jsx("p",{className:"text-[12px] text-slate-400 mt-0.5",children:"Add current or permanent address details (optional)"})]}),!m&&e.jsxs(C,{size:"sm",variant:"outline",onClick:()=>{x(null),l(!0)},children:[e.jsx(se,{className:"mr-1.5 h-3.5 w-3.5"})," Add Address"]})]}),a.length>0&&!m&&e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3 mb-4",children:a.map((y,D)=>e.jsx(ii,{field:y,onEdit:()=>p(D),onRemove:()=>n(D)},y.id))}),m&&e.jsx(li,{defaultValues:i!==null?a[i]:void 0,currentAddress:a.find(y=>y.address_type==="current"),onSave:g,onCancel:F}),a.length===0&&!m&&e.jsx(G,{children:e.jsxs(Q,{className:"p-8 text-center",children:[e.jsx(ws,{className:"h-8 w-8 text-slate-300 mx-auto"}),e.jsx("p",{className:"mt-2 text-[13px] text-slate-400",children:"No addresses added. You can add them later."})]})})]})}function ii({field:s,onEdit:a,onRemove:r}){var g,p,F;const{data:t}=ia(),{data:n}=Ps(s.country),{data:m}=la(s.state),l=((g=t==null?void 0:t.results.find(y=>y.id===s.country))==null?void 0:g.name)??s.country,i=((p=n==null?void 0:n.results.find(y=>y.id===s.state))==null?void 0:p.name)??s.state,x=((F=m==null?void 0:m.results.find(y=>y.id===s.city))==null?void 0:F.name)??s.city;return e.jsx(G,{className:"hover:border-primary/20 transition-colors",children:e.jsxs(Q,{className:"p-4",children:[e.jsxs("div",{className:"flex items-start justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(B,{variant:s.address_type==="current"?"default":"secondary",children:s.address_type==="current"?"Current":"Permanent"}),s.is_primary&&e.jsx(B,{variant:"success",children:"Primary"}),s._existingId&&e.jsx(B,{variant:"outline",children:"Saved"})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(C,{variant:"ghost",size:"icon-sm",onClick:a,children:e.jsx(ke,{className:"h-3.5 w-3.5"})}),e.jsx(C,{variant:"ghost",size:"icon-sm",className:"text-red-500",onClick:r,children:e.jsx(De,{className:"h-3.5 w-3.5"})})]})]}),e.jsxs("div",{className:"text-[12px] text-slate-600 space-y-0.5",children:[e.jsx("p",{children:s.line_1}),s.line_2&&e.jsx("p",{children:s.line_2}),e.jsxs("p",{children:[x,", ",i," ",s.postal_code]}),e.jsx("p",{children:l})]})]})})}function li({defaultValues:s,currentAddress:a,onSave:r,onCancel:t}){var w,_,o;const[n,m]=b.useState({_existingId:s==null?void 0:s._existingId,address_type:(s==null?void 0:s.address_type)??"current",line_1:(s==null?void 0:s.line_1)??"",line_2:(s==null?void 0:s.line_2)??"",city:(s==null?void 0:s.city)??"",state:(s==null?void 0:s.state)??"",country:(s==null?void 0:s.country)??"",postal_code:(s==null?void 0:s.postal_code)??"",is_primary:(s==null?void 0:s.is_primary)??!1}),{data:l}=ia(),{data:i}=Ps(s==null?void 0:s.country),{data:x}=la(s==null?void 0:s.state),g=s?{country:(w=l==null?void 0:l.results.find(u=>u.id===s.country))==null?void 0:w.name,state:(_=i==null?void 0:i.results.find(u=>u.id===s.state))==null?void 0:_.name,city:(o=x==null?void 0:x.results.find(u=>u.id===s.city))==null?void 0:o.name}:void 0,[p,F]=b.useState({});function y(){const u={};return n.line_1||(u.line_1="Required"),n.city||(u.city="Required"),n.state||(u.state="Required"),n.country||(u.country="Required"),n.postal_code?/^\d{6}$/.test(n.postal_code)||(u.postal_code="PIN code must be exactly 6 digits"):u.postal_code="Required",F(u),Object.keys(u).length===0}function D(){y()&&r(n)}function c(){a&&(m({...n,line_1:a.line_1,line_2:a.line_2??"",city:a.city,state:a.state,country:a.country,postal_code:a.postal_code}),F({}))}return e.jsx(G,{className:"border-primary/30 bg-primary/[0.02]",children:e.jsxs(Q,{className:"p-5 space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(h,{children:"Address Type"}),e.jsxs(le,{value:n.address_type,onValueChange:u=>m({...n,address_type:u}),children:[e.jsx(ce,{className:"mt-1.5",children:e.jsx(oe,{})}),e.jsxs(de,{children:[e.jsx(T,{value:"current",children:"Current"}),e.jsx(T,{value:"permanent",children:"Permanent"})]})]})]}),e.jsx("div",{className:"flex items-end pb-1",children:e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx(ts,{checked:n.is_primary,onCheckedChange:u=>m({...n,is_primary:u===!0})}),e.jsx("span",{className:"text-[13px] text-slate-700",children:"Primary address"})]})})]}),n.address_type==="permanent"&&a&&e.jsxs(C,{type:"button",variant:"outline",size:"sm",onClick:c,children:[e.jsx(Wa,{className:"mr-1.5 h-3.5 w-3.5"})," Copy from Current Address"]}),e.jsxs("div",{children:[e.jsxs(h,{children:["Address Line 1 ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx(M,{value:n.line_1,onChange:u=>m({...n,line_1:u.target.value}),className:"mt-1.5"}),p.line_1&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:p.line_1})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Address Line 2"}),e.jsx(M,{value:n.line_2,onChange:u=>m({...n,line_2:u.target.value}),className:"mt-1.5"})]}),e.jsx(Ha,{required:!0,value:{country:n.country||null,state:n.state||null,city:n.city||null},onChange:u=>m({...n,country:u.country??"",state:u.state??"",city:u.city??""}),initialLabels:g}),(p.city||p.state||p.country)&&e.jsx("p",{className:"text-[12px] text-red-500",children:"Country, state, and city are required"}),e.jsxs("div",{children:[e.jsxs(h,{children:["Postal Code ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx(Qe,{value:n.postal_code,onChange:u=>m({...n,postal_code:u.target.value}),className:"mt-1.5",maxLength:6}),p.postal_code&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:p.postal_code})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx(C,{variant:"outline",size:"sm",onClick:t,children:"Cancel"}),e.jsx(C,{size:"sm",onClick:D,children:s?"Update Address":"Add Address"})]})]})})}function ci(){const{control:s}=us(),{fields:a,append:r,update:t,remove:n}=Qa({control:s,name:"bank_accounts"}),[m,l]=b.useState(!1),[i,x]=b.useState(null);function g(y){i!==null?(t(i,y),x(null)):r(y),l(!1)}function p(y){x(y),l(!0)}function F(){l(!1),x(null)}return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.08em] text-slate-400",children:"Bank Accounts"}),e.jsx("p",{className:"text-[12px] text-slate-400 mt-0.5",children:"Add bank account details for salary disbursement (optional)"})]}),!m&&e.jsxs(C,{size:"sm",variant:"outline",onClick:()=>{x(null),l(!0)},children:[e.jsx(se,{className:"mr-1.5 h-3.5 w-3.5"})," Add Bank Account"]})]}),a.length>0&&!m&&e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3 mb-4",children:a.map((y,D)=>e.jsx(G,{className:"hover:border-primary/20 transition-colors",children:e.jsxs(Q,{className:"p-4",children:[e.jsxs("div",{className:"flex items-start justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[13px] font-semibold text-slate-900",children:y.bank_name}),e.jsx(B,{variant:"secondary",children:y.account_type}),y.is_primary&&e.jsx(B,{variant:"success",children:"Primary"})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(C,{variant:"ghost",size:"icon-sm",onClick:()=>p(D),children:e.jsx(ke,{className:"h-3.5 w-3.5"})}),e.jsx(C,{variant:"ghost",size:"icon-sm",className:"text-red-500",onClick:()=>n(D),children:e.jsx(De,{className:"h-3.5 w-3.5"})})]})]}),e.jsxs("div",{className:"space-y-0.5 text-[12px] text-slate-500",children:[y.branch_name&&e.jsxs("p",{children:["Branch: ",y.branch_name]}),y.masked_account&&e.jsxs("p",{children:["A/C: ",e.jsx("span",{className:"font-mono",children:y.masked_account})]}),e.jsxs("p",{children:["IFSC: ",e.jsx("span",{className:"font-mono",children:y.ifsc_code})]})]})]})},y.id))}),m&&e.jsx(oi,{defaultValues:i!==null?a[i]:void 0,onSave:g,onCancel:F}),a.length===0&&!m&&e.jsx(G,{children:e.jsxs(Q,{className:"p-8 text-center",children:[e.jsx(Vs,{className:"h-8 w-8 text-slate-300 mx-auto"}),e.jsx("p",{className:"mt-2 text-[13px] text-slate-400",children:"No bank accounts added. You can add them later."})]})})]})}function oi({defaultValues:s,onSave:a,onCancel:r}){const t=!!(s!=null&&s._existingId),[n,m]=b.useState({_existingId:s==null?void 0:s._existingId,bank_name:(s==null?void 0:s.bank_name)??"",branch_name:(s==null?void 0:s.branch_name)??"",account_number:(s==null?void 0:s.account_number)??"",ifsc_code:(s==null?void 0:s.ifsc_code)??"",account_type:(s==null?void 0:s.account_type)??"savings",is_primary:(s==null?void 0:s.is_primary)??!1,masked_account:s==null?void 0:s.masked_account}),[l,i]=b.useState({});function x(){const p={};return n.bank_name||(p.bank_name="Required"),!t&&!n.account_number&&(p.account_number="Required"),n.account_number&&!/^\d{9,18}$/.test(n.account_number)&&(p.account_number="Account number must be 9–18 digits (numbers only)"),n.ifsc_code||(p.ifsc_code="Required"),i(p),Object.keys(p).length===0}function g(){x()&&a(n)}return e.jsx(G,{className:"border-primary/30 bg-primary/[0.02]",children:e.jsxs(Q,{className:"p-5 space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsxs(h,{children:["Bank Name ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx(M,{value:n.bank_name,onChange:p=>m({...n,bank_name:p.target.value}),className:"mt-1.5",placeholder:"e.g. State Bank of India"}),l.bank_name&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:l.bank_name})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Branch Name"}),e.jsx(M,{value:n.branch_name,onChange:p=>m({...n,branch_name:p.target.value}),className:"mt-1.5"})]})]}),e.jsxs("div",{children:[e.jsxs(h,{children:["Account Number ",!t&&e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx(Qe,{value:n.account_number,onChange:p=>m({...n,account_number:p.target.value}),className:"mt-1.5 font-mono",maxLength:18,placeholder:t?"(enter new to update)":"Digits only"}),l.account_number&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:l.account_number})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsxs(h,{children:["IFSC Code ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx(M,{value:n.ifsc_code,onChange:p=>m({...n,ifsc_code:p.target.value}),className:"mt-1.5 font-mono uppercase",placeholder:"e.g. SBIN0001234"}),l.ifsc_code&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:l.ifsc_code})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Account Type"}),e.jsxs(le,{value:n.account_type,onValueChange:p=>m({...n,account_type:p}),children:[e.jsx(ce,{className:"mt-1.5",children:e.jsx(oe,{})}),e.jsxs(de,{children:[e.jsx(T,{value:"savings",children:"Savings"}),e.jsx(T,{value:"current",children:"Current"})]})]})]})]}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx(ts,{checked:n.is_primary,onCheckedChange:p=>m({...n,is_primary:p===!0})}),e.jsx("span",{className:"text-[13px] text-slate-700",children:"Primary account"})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx(C,{variant:"outline",size:"sm",onClick:r,children:"Cancel"}),e.jsx(C,{size:"sm",onClick:g,children:s?"Update Account":"Add Account"})]})]})})}function di(s,a){const r={};for(const t of s){if(!t.is_active||!t.is_required)continue;const n=a==null?void 0:a[t.field_key];(n==null||n===""||Array.isArray(n)&&n.length===0)&&(r[t.field_key]=`${t.name} is required`)}return r}function mi({errors:s}){const a=us(),{data:r,isLoading:t}=zs(),n=a.watch("custom_fields")??{};function m(i,x){a.setValue("custom_fields",{...n,[i]:x},{shouldDirty:!0})}if(t)return e.jsx("div",{className:"flex items-center justify-center py-16 text-slate-400",children:e.jsx(aa,{className:"h-5 w-5 animate-spin"})});const l=(r??[]).filter(i=>i.is_active);return l.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-center",children:[e.jsx("div",{className:"flex h-11 w-11 items-center justify-center rounded-full bg-slate-100",children:e.jsx(ks,{className:"h-5 w-5 text-slate-400"})}),e.jsx("p",{className:"mt-3 text-[13px] font-medium text-slate-700",children:"No custom fields configured"}),e.jsxs("p",{className:"mt-1 text-[12px] text-slate-400 max-w-sm",children:["An administrator can add organisation-specific fields under"," ","System Admin → Custom Fields. They will appear here automatically."]})]}):e.jsx(gr,{definitions:l,values:n,onChange:m,errors:s})}function Je(s,a){if(!a)return"—";const r=s==null?void 0:s.find(t=>t.id===a);return(r==null?void 0:r.name)??a}function xi({photo:s,existingPhotoUrl:a}){var U,Y;const{getValues:r}=us(),t=r(),{data:n}=ta(),m=(n==null?void 0:n.results)??[],{data:l}=na(),i=(l==null?void 0:l.results)??[],{data:x}=ys(),g=(x==null?void 0:x.results)??[],{data:p}=$s(),F=(p==null?void 0:p.results)??[],{data:y}=Bs(),D=(y==null?void 0:y.results)??[],{data:c}=ra(),w=(c==null?void 0:c.results)??[],{data:_}=Xe(),o=(_==null?void 0:_.results)??[],{data:u}=zs(),O=Je(m,t.company),z=Je(i,t.branch),I=Je(g,t.department),j=Je(F,t.designation),S=Je(D,t.grade),N=Je(w,t.category),P=t.reporting_manager?o.find(k=>k.id===t.reporting_manager)?`${o.find(k=>k.id===t.reporting_manager).first_name} ${o.find(k=>k.id===t.reporting_manager).last_name}`:t.reporting_manager:"—",L=s?URL.createObjectURL(s):a??null,ae=`${((U=t.first_name)==null?void 0:U[0])??""}${((Y=t.last_name)==null?void 0:Y[0])??""}`.toUpperCase(),te=t.addresses??[],ne=t.bank_accounts??[],W=t.custom_fields??{},he=(u??[]).filter(k=>k.is_active);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-3 rounded-lg border border-amber-200 bg-amber-50 px-4 py-3",children:[e.jsx(ut,{className:"h-4 w-4 text-amber-600 shrink-0"}),e.jsx("p",{className:"text-[13px] text-amber-800",children:"Review all details before submitting. You can go back to any step to make changes."})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs(Ks,{className:"h-14 w-14",children:[L?e.jsx(ea,{src:L}):null,e.jsx(sa,{className:"bg-primary/10 text-primary font-semibold text-lg",children:ae||e.jsx(da,{className:"h-5 w-5"})})]}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-[15px] font-semibold text-slate-900",children:[t.first_name," ",t.last_name]}),e.jsx("p",{className:"text-[13px] text-slate-500",children:t.email})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(G,{children:e.jsxs(Q,{className:"p-5",children:[e.jsxs("p",{className:"text-[11px] font-semibold uppercase tracking-[0.08em] text-slate-400 mb-3",children:[e.jsx(Ns,{className:"inline h-3.5 w-3.5 mr-1 -mt-0.5"}),"Personal Information"]}),e.jsxs("dl",{className:"space-y-2 text-[13px]",children:[e.jsx(Se,{label:"Phone",value:t.phone||"—"}),e.jsx(Se,{label:"Date of Birth",value:t.date_of_birth||"—"}),e.jsx(Se,{label:"Gender",value:Qs(t.gender)||"—"}),e.jsx(Se,{label:"Marital Status",value:Qs(t.marital_status)||"—"}),e.jsx(Se,{label:"Blood Group",value:t.blood_group||"—"}),e.jsx(Se,{label:"Nationality",value:t.nationality||"—"})]})]})}),e.jsx(G,{children:e.jsxs(Q,{className:"p-5",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.08em] text-slate-400 mb-3",children:"Organization"}),e.jsxs("dl",{className:"space-y-2 text-[13px]",children:[e.jsx(Se,{label:"Company",value:O}),e.jsx(Se,{label:"Branch",value:z}),e.jsx(Se,{label:"Department",value:I}),e.jsx(Se,{label:"Designation",value:j}),e.jsx(Se,{label:"Grade",value:S}),e.jsx(Se,{label:"Category",value:N}),e.jsx(Se,{label:"Reporting Manager",value:P})]})]})}),e.jsx(G,{children:e.jsxs(Q,{className:"p-5",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.08em] text-slate-400 mb-3",children:"Employment & Statutory"}),e.jsxs("dl",{className:"space-y-2 text-[13px]",children:[e.jsx(Se,{label:"Date of Joining",value:t.date_of_joining||"—"}),e.jsx(Se,{label:"Status",value:Qs(t.status)||"Draft"}),e.jsx(Se,{label:"PF Account No.",value:t.pf_account_number||"—"}),e.jsx(Se,{label:"ESI Number",value:t.esi_number||"—"}),e.jsx(Se,{label:"PAN",value:t.pan||"—"}),e.jsx(Se,{label:"Aadhaar",value:t.aadhaar?`XXXX XXXX ${t.aadhaar.slice(-4)}`:"—"})]})]})}),e.jsx(G,{children:e.jsxs(Q,{className:"p-5",children:[e.jsxs("p",{className:"text-[11px] font-semibold uppercase tracking-[0.08em] text-slate-400 mb-3",children:[e.jsx(ws,{className:"inline h-3.5 w-3.5 mr-1 -mt-0.5"}),"Addresses (",te.length,")"]}),te.length===0?e.jsx("p",{className:"text-[12px] text-slate-400 italic",children:"No addresses added"}):e.jsx("div",{className:"space-y-2",children:te.map((k,ee)=>e.jsx(hi,{address:k},ee))}),e.jsx("div",{className:"h-px bg-slate-100 my-3"}),e.jsxs("p",{className:"text-[11px] font-semibold uppercase tracking-[0.08em] text-slate-400 mb-3",children:[e.jsx(Vs,{className:"inline h-3.5 w-3.5 mr-1 -mt-0.5"}),"Bank Accounts (",ne.length,")"]}),ne.length===0?e.jsx("p",{className:"text-[12px] text-slate-400 italic",children:"No bank accounts added"}):e.jsx("div",{className:"space-y-2",children:ne.map((k,ee)=>e.jsxs("div",{className:"text-[12px] text-slate-600 border-l-2 border-slate-200 pl-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-0.5",children:[e.jsx("span",{className:"font-medium text-slate-900",children:k.bank_name}),e.jsx(B,{variant:"secondary",className:"text-[10px] px-1.5 py-0",children:k.account_type}),k.is_primary&&e.jsx(B,{variant:"success",className:"text-[10px] px-1.5 py-0",children:"Primary"})]}),k.branch_name&&e.jsxs("p",{children:["Branch: ",k.branch_name]}),e.jsxs("p",{children:["IFSC: ",e.jsx("span",{className:"font-mono",children:k.ifsc_code})]})]},ee))})]})}),he.length>0&&e.jsx(G,{className:"md:col-span-2",children:e.jsxs(Q,{className:"p-5",children:[e.jsxs("p",{className:"text-[11px] font-semibold uppercase tracking-[0.08em] text-slate-400 mb-3",children:[e.jsx(ks,{className:"inline h-3.5 w-3.5 mr-1 -mt-0.5"}),"Custom Fields"]}),e.jsx("dl",{className:"grid grid-cols-1 md:grid-cols-2 gap-x-8 gap-y-1.5 text-[12px]",children:he.map(k=>e.jsx(Se,{label:k.name,value:rt(k,W[k.field_key])},k.id))})]})})]})]})}function hi({address:s}){const{data:a}=ia(),{data:r}=Ps(s.country),{data:t}=la(s.state),n=Je(a==null?void 0:a.results,s.country),m=Je(r==null?void 0:r.results,s.state),l=Je(t==null?void 0:t.results,s.city);return e.jsxs("div",{className:"text-[12px] text-slate-600 border-l-2 border-slate-200 pl-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-0.5",children:[e.jsx(B,{variant:s.address_type==="current"?"default":"secondary",className:"text-[10px] px-1.5 py-0",children:s.address_type==="current"?"Current":"Permanent"}),s.is_primary&&e.jsx(B,{variant:"success",className:"text-[10px] px-1.5 py-0",children:"Primary"})]}),e.jsxs("p",{children:[s.line_1,s.line_2?`, ${s.line_2}`:""]}),e.jsxs("p",{children:[l,", ",m," ",s.postal_code,", ",n]})]})}function Se({label:s,value:a}){return e.jsxs("div",{className:"flex justify-between",children:[e.jsx("dt",{className:"text-slate-400",children:s}),e.jsx("dd",{className:"text-slate-700 font-medium text-right",children:a})]})}function Qs(s){return s?s.charAt(0).toUpperCase()+s.slice(1).replace(/_/g," "):""}const pi=ue({first_name:v().min(1,"First name is required"),last_name:v().min(1,"Last name is required"),email:v().email("Valid email required"),phone:v().min(1,"Mobile number is required").regex(/^[6-9]\d{9}$/,"Enter a valid 10-digit mobile number"),date_of_birth:Kn(),gender:v().optional(),marital_status:v().optional(),blood_group:v().optional(),nationality:v().optional(),father_name:v().min(1,"Father's name is required"),mother_name:v().min(1,"Mother's name is required"),spouse_name:v().optional()}),ui=ue({company:v().min(1,"Company is required"),branch:v().optional().nullable(),work_location:v().optional().nullable(),department:v().optional().nullable(),designation:v().optional().nullable(),grade:v().optional().nullable(),category:v().min(1,"Category is required"),reporting_manager:v().optional().nullable()}),ji=ue({date_of_joining:ss("Joining date is required"),status:v().optional(),pf_account_number:v().optional().refine(s=>!s||/^\d{12}$/.test(s),{message:"UAN must be exactly 12 digits"}),esi_number:v().optional().refine(s=>!s||/^\d{10}$/.test(s),{message:"ESI/IP number must be exactly 10 digits"}),pan:v().optional().refine(s=>!s||/^[A-Z]{3}[ABCFGHJLPT][A-Z][0-9]{4}[A-Z]$/.test(s),{message:"Invalid PAN format (e.g. ABCPE1234F)"}),aadhaar:v().optional().refine(s=>!s||/^\d{12}$/.test(s),{message:"Aadhaar must be 12 digits"}),passport_number:v().optional().refine(s=>!s||/^[A-Za-z0-9]{8}$/.test(s),{message:"Passport number must be 8 alphanumeric characters"}),voter_id:v().optional().refine(s=>!s||/^[A-Z]{3}[0-9]{7}$/.test(s),{message:"Voter ID must be 3 letters followed by 7 digits (e.g. ABC1234567)"}),driving_license:v().optional().refine(s=>!s||s.length<=20,{message:"Driving licence cannot exceed 20 characters"}),ration_card_number:v().optional().refine(s=>!s||s.length<=15,{message:"Ration card number cannot exceed 15 characters"}),professional_tax_number:v().optional(),state:v().nullable().optional(),pf_opt_out:Fe().optional().default(!1),esi_opt_out:Fe().optional().default(!1),pt_opt_out:Fe().optional().default(!1),tds_opt_out:Fe().optional().default(!1)}),gi=ue({_existingId:v().optional(),address_type:hs(["current","permanent"]),line_1:v().min(1,"Address line 1 is required"),line_2:v().optional().default(""),city:v().min(1,"City is required"),state:v().min(1,"State is required"),country:v().min(1,"Country is required"),postal_code:v().min(1,"Postal code is required").refine(s=>/^\d{6}$/.test(s),{message:"PIN code must be exactly 6 digits"}),is_primary:Fe().optional().default(!1)}),_i=ue({_existingId:v().optional(),bank_name:v().min(1,"Bank name is required"),branch_name:v().optional().default(""),account_number:v().default("").refine(s=>s===""||/^\d{9,18}$/.test(s),{message:"Account number must be 9–18 digits (numbers only)"}),ifsc_code:v().min(1,"IFSC code is required"),account_type:hs(["savings","current"]),is_primary:Fe().optional().default(!1),masked_account:v().optional()}),fi=ue({addresses:Zs(gi).optional().default([]),bank_accounts:Zs(_i).optional().default([])}),vi=ue({custom_fields:Hn(v(),Wn()).optional().default({})}),yi=pi.merge(ui).merge(ji).merge(fi).merge(vi).superRefine((s,a)=>{var r,t,n,m;s.marital_status==="married"&&!((r=s.spouse_name)!=null&&r.trim())&&a.addIssue({code:We.custom,message:"Spouse's name is required when married",path:["spouse_name"]}),s.pf_opt_out&&!((t=s.pf_account_number)!=null&&t.trim())&&a.addIssue({code:We.custom,message:"PF Account Number (UAN) is required when PF is applicable",path:["pf_account_number"]}),s.esi_opt_out&&!((n=s.esi_number)!=null&&n.trim())&&a.addIssue({code:We.custom,message:"ESI Number is required when ESI is applicable",path:["esi_number"]}),s.pt_opt_out&&((m=s.professional_tax_number)!=null&&m.trim()||a.addIssue({code:We.custom,message:"Professional Tax Number is required when PT is applicable",path:["professional_tax_number"]}),s.state||a.addIssue({code:We.custom,message:"State is required when PT is applicable",path:["state"]}))}),bi=[["first_name","last_name","email","phone","date_of_birth","gender","marital_status","blood_group","nationality","father_name","mother_name","spouse_name"],["company","branch","work_location","department","designation","grade","category","reporting_manager"],["date_of_joining","status","pf_account_number","esi_number","professional_tax_number","state","pan","aadhaar","pf_opt_out","esi_opt_out","pt_opt_out","tds_opt_out"],["addresses","bank_accounts"],[],[]],Ds=[{label:"Personal",description:"Basic details",icon:Ns},{label:"Organization",description:"Company & team",icon:tr},{label:"Employment",description:"Joining & statutory",icon:Ss},{label:"Address & Bank",description:"Optional info",icon:ws},{label:"Custom Fields",description:"Organisation-specific",icon:ks},{label:"Review",description:"Confirm & save",icon:Pa}],Ni=4;function Wl(){var Y;const s=wa(),{id:a}=Cs(),r=!!a,[t,n]=b.useState(0),[m,l]=b.useState(null),[i,x]=b.useState(!1),[g,p]=b.useState(!r),[F,y]=b.useState({}),{data:D}=zs(),{data:c}=qa(a??""),{data:w,isLoading:_}=Ya(r?{employee:a}:void 0),o=((Y=w==null?void 0:w.results)==null?void 0:Y[0])??null,u=Te({resolver:Ee(yi),defaultValues:{first_name:"",last_name:"",email:"",phone:"",date_of_birth:"",gender:"",marital_status:"",blood_group:"",nationality:"",father_name:"",mother_name:"",spouse_name:"",company:"",branch:null,work_location:null,department:null,designation:null,grade:null,category:"",reporting_manager:null,date_of_joining:"",status:"draft",pf_account_number:"",esi_number:"",pan:"",aadhaar:"",passport_number:"",voter_id:"",driving_license:"",ration_card_number:"",addresses:[],bank_accounts:[],custom_fields:{}},mode:"onTouched"});b.useEffect(()=>{r&&c&&!_&&!g&&(u.reset({first_name:c.first_name,last_name:c.last_name,email:c.email,phone:c.phone??"",date_of_birth:c.date_of_birth??"",gender:c.gender??"",marital_status:c.marital_status??"",blood_group:c.blood_group??"",nationality:c.nationality??"",father_name:c.father_name??"",mother_name:c.mother_name??"",spouse_name:c.spouse_name??"",company:c.company,branch:c.branch,work_location:c.work_location,department:c.department,designation:c.designation,grade:c.grade,category:c.category??"",reporting_manager:c.reporting_manager,date_of_joining:c.date_of_joining,status:c.status??"draft",pf_account_number:(o==null?void 0:o.pf_account_number)??"",esi_number:(o==null?void 0:o.esi_number)??"",pan:(o==null?void 0:o.pan)??"",aadhaar:(o==null?void 0:o.aadhaar)??"",passport_number:(o==null?void 0:o.passport_number)??"",voter_id:(o==null?void 0:o.voter_id)??"",driving_license:(o==null?void 0:o.driving_license)??"",ration_card_number:(o==null?void 0:o.ration_card_number)??"",professional_tax_number:(o==null?void 0:o.professional_tax_number)??"",state:(o==null?void 0:o.state)??null,pf_opt_out:(o==null?void 0:o.pf_opt_out)??!1,esi_opt_out:(o==null?void 0:o.esi_opt_out)??!1,pt_opt_out:(o==null?void 0:o.pt_opt_out)??!1,tds_opt_out:(o==null?void 0:o.tds_opt_out)??!1,addresses:(c.addresses??[]).map(k=>({_existingId:k.id,address_type:k.address_type==="permanent"?"permanent":"current",line_1:k.line_1??"",line_2:k.line_2??"",city:k.city??"",state:k.state??"",country:k.country??"",postal_code:k.postal_code??"",is_primary:k.is_primary??!1})),bank_accounts:(c.bank_accounts??[]).map(k=>({_existingId:k.id,bank_name:k.bank_name??"",branch_name:k.branch_name??"",account_number:"",ifsc_code:k.ifsc_code??"",account_type:k.account_type==="current"?"current":"savings",is_primary:k.is_primary??!1,masked_account:k.masked_account??""})),custom_fields:c.custom_fields??{}}),p(!0))},[r,c,o,_,g,u]);const O=ln(),z=cn(),I=Ia(),j=La(),S=Oa(),N=Ma(),P=Ra(),L=Ja(),ae=Ka();async function te(){const k=bi[t];if(!(k&&k.length>0&&!await u.trigger(k))){if(t===Ni){const ee=u.getValues("custom_fields")??{},$=di(D??[],ee);if(y($),Object.keys($).length>0)return}n(ee=>Math.min(ee+1,Ds.length-1))}}function ne(){n(k=>Math.max(k-1,0))}function W(k){k<t&&n(k)}async function he(){x(!0);const k=u.getValues();try{const ee={first_name:k.first_name,last_name:k.last_name,email:k.email,phone:k.phone||void 0,date_of_birth:k.date_of_birth||void 0,gender:k.gender||void 0,marital_status:k.marital_status||void 0,blood_group:k.blood_group||void 0,nationality:k.nationality||void 0,father_name:k.father_name||void 0,mother_name:k.mother_name||void 0,spouse_name:k.spouse_name||void 0,company:k.company,branch:k.branch||void 0,work_location:k.work_location||void 0,department:k.department||void 0,designation:k.designation||void 0,grade:k.grade||void 0,category:k.category,reporting_manager:k.reporting_manager||void 0,date_of_joining:k.date_of_joining,status:k.status||"draft",custom_fields:k.custom_fields??{}};let $;r?(await z.mutateAsync({id:a,...ee}),$=a):$=(await O.mutateAsync(ee)).id;const Z=[];m&&Z.push(I.mutateAsync({employeeId:$,photo:m}));for(const H of k.addresses??[]){const d=H._existingId,X={address_type:H.address_type,line_1:H.line_1,line_2:H.line_2||"",city:H.city,state:H.state,country:H.country,postal_code:H.postal_code,is_primary:H.is_primary};Z.push(d?N.mutateAsync({employeeId:$,addressId:d,...X}):j.mutateAsync({employeeId:$,...X}))}for(const H of k.bank_accounts??[]){const d=H._existingId;if(d){const X={employeeId:$,accountId:d,bank_name:H.bank_name,branch_name:H.branch_name||"",ifsc_code:H.ifsc_code,account_type:H.account_type,is_primary:H.is_primary};H.account_number&&(X.account_number=H.account_number),Z.push(P.mutateAsync(X))}else Z.push(S.mutateAsync({employeeId:$,bank_name:H.bank_name,branch_name:H.branch_name||void 0,account_number:H.account_number,ifsc_code:H.ifsc_code,account_type:H.account_type,is_primary:H.is_primary}))}const Ce={pf_account_number:k.pf_account_number||void 0,esi_number:k.esi_number||void 0,pan:k.pan||void 0,aadhaar:k.aadhaar||void 0,passport_number:k.passport_number||void 0,voter_id:k.voter_id||void 0,driving_license:k.driving_license||void 0,ration_card_number:k.ration_card_number||void 0,professional_tax_number:k.professional_tax_number||void 0,state:k.state||void 0,pf_opt_out:k.pf_opt_out??!1,esi_opt_out:k.esi_opt_out??!1,pt_opt_out:k.pt_opt_out??!1,tds_opt_out:k.tds_opt_out??!1},pe=k.pf_account_number||k.esi_number||k.pan||k.aadhaar||k.passport_number||k.voter_id||k.driving_license||k.ration_card_number||k.professional_tax_number||k.state||k.pf_opt_out||k.esi_opt_out||k.pt_opt_out||k.tds_opt_out;r&&o?Z.push(ae.mutateAsync({id:o.id,...Ce})):pe&&Z.push(L.mutateAsync({employee:$,...Ce}));const q=(await Promise.allSettled(Z)).find(H=>H.status==="rejected");if(q){Fs.error(Hs(q.reason,"Some details could not be saved")),r||s(`/core-hr/employees/${$}`);return}Fs.success(r?"Employee updated":"Employee created"),s(`/core-hr/employees/${$}`)}catch(ee){Fs.error(Hs(ee,r?"Failed to update employee":"Failed to create employee"))}finally{x(!1)}}const U=t===Ds.length-1;return r&&!g?e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"h-9 w-48 rounded bg-slate-200 animate-pulse"}),e.jsx("div",{className:"h-16 rounded-xl bg-slate-100 animate-pulse"}),e.jsx("div",{className:"h-64 rounded-xl bg-slate-50 animate-pulse"})]}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(C,{variant:"ghost",size:"icon-sm",onClick:()=>s(r?`/core-hr/employees/${a}`:"/core-hr/employees"),children:e.jsx(Ys,{className:"h-4 w-4"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-[16px] font-semibold text-slate-900",children:r?"Edit Employee":"Add Employee"}),e.jsx("p",{className:"text-[13px] text-slate-400",children:r?"Update employee details across all steps":"Complete all steps to create a new employee record"})]})]}),e.jsx(G,{children:e.jsx(Q,{className:"p-6",children:e.jsx(jt,{steps:Ds,currentStep:t,onStepClick:W})})}),e.jsx(G,{children:e.jsx(Q,{className:"p-6",children:e.jsx(fs,{...u,children:e.jsxs("form",{onSubmit:k=>k.preventDefault(),children:[t===0&&e.jsx(si,{photo:m,onPhotoChange:l,existingPhotoUrl:r?(c==null?void 0:c.photo)??null:null}),t===1&&e.jsx(ai,{}),t===2&&e.jsx(ti,{isEditMode:r}),t===3&&e.jsx(ni,{}),t===4&&e.jsx(mi,{errors:F}),t===5&&e.jsx(xi,{photo:m,existingPhotoUrl:r?(c==null?void 0:c.photo)??null:null})]})})})}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(C,{variant:"outline",onClick:ne,disabled:t===0,children:[e.jsx(Ys,{className:"mr-1.5 h-3.5 w-3.5"})," Back"]}),e.jsxs("div",{className:"text-[12px] text-slate-400",children:["Step ",t+1," of ",Ds.length]}),U?e.jsxs(C,{onClick:he,disabled:i,children:[i&&e.jsx(aa,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}),r?"Save Changes":"Create Employee"]}):e.jsxs(C,{onClick:te,children:["Continue ",e.jsx(ca,{className:"ml-1.5 h-3.5 w-3.5"})]})]})]})}const Ci=ue({title:v().min(1,"Title is required"),code:v().min(1,"Code is required"),department:v().min(1,"Department is required"),grade:v().optional().nullable(),reporting_position:v().optional().nullable(),incumbent:v().optional().nullable(),status:v().optional()}),Si={active:"success",vacant:"warning",frozen:"secondary"};function Zl(){const[s,a]=b.useState(!1),[r,t]=b.useState(null),[n,m]=b.useState(null),[l,i]=b.useState(""),{hasPermission:x,requirePermission:g}=je(),p=x("core_hr","position","create"),F=x("core_hr","position","update"),y=x("core_hr","position","delete"),{pagination:D,setPagination:c,sorting:w,setSorting:_,globalFilter:o,setGlobalFilter:u,queryParams:O}=ls(),z={...O,...l&&{status:l}},{data:I,isLoading:j}=on(z),S=(I==null?void 0:I.results)??[],N=dn(),P=mn(),L=xn(),{data:ae}=ys(),te=(ae==null?void 0:ae.results)??[],{data:ne}=Bs(),W=(ne==null?void 0:ne.results)??[],[he,U]=b.useState(""),{data:Y,isLoading:k}=Xe({search:he||void 0}),ee=(Y==null?void 0:Y.results)??[],$=Te({resolver:Ee(Ci),defaultValues:{status:"vacant"}});function Z(d){i(d==="__all__"?"":d),c(X=>({...X,pageIndex:0}))}function Ce(){g("core_hr","position","create")&&(t(null),$.reset({status:"vacant"}),a(!0))}function pe(d){g("core_hr","position","update")&&(t(d),$.reset({title:d.title,code:d.code,department:d.department??"",grade:d.grade,reporting_position:d.reporting_position,incumbent:d.incumbent,status:d.status}),a(!0))}function V(d){const X={...d,department:d.department,grade:d.grade||null,reporting_position:d.reporting_position||null,incumbent:d.incumbent||null,status:d.status||"vacant"};r?P.mutate({id:r.id,...X},{onSuccess:()=>a(!1)}):N.mutate(X,{onSuccess:()=>a(!1)})}function q(){g("core_hr","position","delete")&&n&&L.mutate(n.id,{onSuccess:()=>m(null)})}const H=[{key:"title",header:"Position",render:d=>e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-slate-900",children:d.title}),e.jsx("span",{className:"ml-2 text-[11px] text-slate-400",children:d.code})]})},{key:"department_name",header:"Department",render:d=>d.department_name??"—"},{key:"grade_name",header:"Grade",render:d=>d.grade_name??"—"},{key:"incumbent_name",header:"Incumbent",render:d=>d.incumbent_name??e.jsx("span",{className:"text-slate-400 italic",children:"Vacant"})},{key:"status",header:"Status",render:d=>e.jsx(B,{variant:Si[d.status],children:d.status})},{key:"actions",header:"",className:"w-10",render:d=>e.jsxs(Ie,{open:(n==null?void 0:n.id)===d.id,onOpenChange:X=>!X&&m(null),children:[e.jsxs(ns,{children:[e.jsx(rs,{asChild:!0,children:e.jsx(C,{variant:"ghost",size:"icon-sm",children:e.jsx(vs,{className:"h-4 w-4"})})}),e.jsxs(is,{align:"end",children:[F&&e.jsxs($e,{onClick:()=>pe(d),children:[e.jsx(ke,{className:"mr-2 h-3.5 w-3.5"})," Edit"]}),y&&e.jsx(Aa,{asChild:!0,children:e.jsxs($e,{className:"text-red-600",onClick:()=>m(d),children:[e.jsx(De,{className:"mr-2 h-3.5 w-3.5"})," Delete"]})})]})]}),e.jsxs(Le,{children:[e.jsxs(Me,{children:[e.jsx(Oe,{children:"Delete position?"}),e.jsxs(Re,{children:["This will permanently delete ",e.jsx("strong",{children:n==null?void 0:n.title}),"."]})]}),e.jsxs(qe,{children:[e.jsx(ze,{children:"Cancel"}),e.jsx(Ue,{variant:"destructive",onClick:q,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"})," Positions"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"Organizational positions and incumbents"})]}),p&&e.jsxs(C,{size:"sm",onClick:Ce,children:[e.jsx(se,{className:"mr-1.5 h-3.5 w-3.5"})," Add Position"]})]}),e.jsx(es,{actions:e.jsx("div",{className:"flex gap-2",children:e.jsxs(le,{value:l,onValueChange:Z,children:[e.jsx(ce,{className:"w-[140px] h-9",children:e.jsx(oe,{placeholder:"All statuses"})}),e.jsxs(de,{children:[e.jsx(T,{value:"__all__",children:"All"}),e.jsx(T,{value:"active",children:"Active"}),e.jsx(T,{value:"vacant",children:"Vacant"}),e.jsx(T,{value:"frozen",children:"Frozen"})]})]})}),columns:H,data:S,isLoading:j,searchPlaceholder:"Search positions...",emptyMessage:"No positions yet",emptyDescription:"Define positions for your organization.",totalCount:(I==null?void 0:I.count)??0,pagination:D,onPaginationChange:c,sorting:w,onSortingChange:_,globalFilter:o,onGlobalFilterChange:u}),e.jsx(fe,{open:s,onOpenChange:a,children:e.jsxs(ve,{size:"lg",children:[e.jsxs(ye,{children:[e.jsx(be,{children:r?"Edit Position":"Add Position"}),e.jsx(Ne,{children:r?"Update position details.":"Create a new organizational position."})]}),e.jsxs("form",{onSubmit:$.handleSubmit(V),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(h,{children:"Title *"}),e.jsx(M,{...$.register("title"),className:"mt-1.5"}),$.formState.errors.title&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:$.formState.errors.title.message})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Code *"}),e.jsx(M,{...$.register("code"),className:"mt-1.5",placeholder:"e.g. POS-001"}),$.formState.errors.code&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:$.formState.errors.code.message})]})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Department *"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(K,{value:$.watch("department")??null,onValueChange:d=>$.setValue("department",d,{shouldValidate:!0}),options:te.map(d=>({value:d.id,label:d.name})),selectedLabel:(r==null?void 0:r.department_name)??void 0,placeholder:"Select department",searchPlaceholder:"Search departments..."})}),$.formState.errors.department&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:$.formState.errors.department.message})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(h,{children:"Grade"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(K,{value:$.watch("grade")??null,onValueChange:d=>$.setValue("grade",d||null),options:W.map(d=>({value:d.id,label:d.name})),selectedLabel:(r==null?void 0:r.grade_name)??void 0,placeholder:"Select grade",searchPlaceholder:"Search grades..."})})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Status"}),e.jsxs(le,{value:$.watch("status")??"vacant",onValueChange:d=>$.setValue("status",d),children:[e.jsx(ce,{className:"mt-1.5",children:e.jsx(oe,{})}),e.jsxs(de,{children:[e.jsx(T,{value:"active",children:"Active"}),e.jsx(T,{value:"vacant",children:"Vacant"}),e.jsx(T,{value:"frozen",children:"Frozen"})]})]})]})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Reporting Position"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(K,{value:$.watch("reporting_position")??null,onValueChange:d=>$.setValue("reporting_position",d||null),options:S.filter(d=>d.id!==(r==null?void 0:r.id)).map(d=>({value:d.id,label:d.title,hint:d.code})),placeholder:"Select position",searchPlaceholder:"Search positions..."})})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Incumbent"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(K,{value:$.watch("incumbent")??null,onValueChange:d=>$.setValue("incumbent",d||null),onSearch:U,isLoading:k,options:ee.map(d=>({value:d.id,label:`${d.first_name} ${d.last_name}`,hint:d.employee_id})),selectedLabel:(r==null?void 0:r.incumbent_name)??void 0,placeholder:"Select employee",searchPlaceholder:"Search employees..."})})]})]}),e.jsxs(Ae,{children:[e.jsx(C,{variant:"outline",onClick:()=>a(!1),children:"Cancel"}),e.jsx(C,{onClick:$.handleSubmit(V),disabled:N.isPending||P.isPending,children:r?"Save Changes":"Create Position"})]})]})})]})}function Xl(){const[s,a]=b.useState(!1),[r,t]=b.useState(null),[n,m]=b.useState(null),[l,i]=b.useState(""),[x,g]=b.useState(""),{hasPermission:p,requirePermission:F}=je(),y=p("core_hr","clearance_department","create"),D=p("core_hr","clearance_department","update"),c=p("core_hr","clearance_department","delete"),{data:w,isLoading:_}=za({page_size:200}),o=(w==null?void 0:w.results)??[],{data:u,isLoading:O}=ys({is_active:!0,search:l||void 0,page_size:200}),{data:z,isLoading:I}=Xe({search:x||void 0}),j=hn(),S=pn(),N=un(),P=new Set(o.map(W=>W.department)),L=((u==null?void 0:u.results)??[]).filter(W=>!P.has(W.id));function ae(){F("core_hr","clearance_department","create")&&(t(null),m(null),a(!0))}function te(){r&&j.mutate({department:r,default_owner:n},{onSuccess:()=>a(!1)})}const ne=[{key:"department_name",header:"Department",render:W=>e.jsx("span",{className:"font-medium text-slate-900",children:W.department_name})},{key:"default_owner_display",header:"Clearance Manager",render:W=>W.default_owner_display??e.jsx("span",{className:"text-[12px] text-amber-600",children:"Unassigned"})},{key:"is_active",header:"Status",render:W=>e.jsx(B,{variant:W.is_active?"success":"secondary",children:W.is_active?"Active":"Inactive"})},{key:"actions",header:"",render:W=>e.jsxs("div",{className:"flex items-center justify-end gap-3",children:[D&&e.jsx(Ge,{checked:W.is_active,onCheckedChange:he=>S.mutate({id:W.id,data:{is_active:he}})}),c&&e.jsx(C,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0 text-slate-400 hover:text-red-500",onClick:()=>N.mutate(W.id),children:e.jsx(De,{className:"h-3.5 w-3.5"})})]})}];return e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"flex items-center gap-2 text-[17px] font-semibold text-slate-900",children:[e.jsx(qs,{className:"h-4 w-4 text-slate-400"}),"Exit Clearance"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"Departments that sign off on every exit, and who owns each."})]}),y&&e.jsxs(C,{onClick:ae,children:[e.jsx(se,{className:"mr-1.5 h-3.5 w-3.5"}),"Add Department"]})]}),!_&&o.length===0&&e.jsxs("div",{className:"rounded-lg border border-amber-200 bg-amber-50/50 px-4 py-3",children:[e.jsx("p",{className:"text-[13px] text-amber-800",children:"No clearance departments configured yet."}),e.jsx("p",{className:"mt-0.5 text-[12px] text-amber-700",children:"Until at least one is added, a separation cannot generate its exit checklist and will have to have its departments chosen by hand."})]}),e.jsx(es,{columns:ne,data:o,isLoading:_}),e.jsx(fe,{open:s,onOpenChange:a,children:e.jsxs(ve,{size:"lg",children:[e.jsxs(ye,{children:[e.jsx(be,{children:"Add Clearance Department"}),e.jsx(Ne,{children:"This department will be added to every new exit checklist."})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-6 py-5 space-y-4",children:[e.jsxs("div",{children:[e.jsx(h,{children:"Department *"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(K,{value:r,onValueChange:t,onSearch:i,options:L.map(W=>({value:W.id,label:W.name})),isLoading:O,placeholder:"Select department…"})})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Clearance Manager"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(K,{value:n,onValueChange:m,onSearch:g,options:((z==null?void 0:z.results)??[]).map(W=>({value:W.id,label:`${W.first_name} ${W.last_name}`,hint:W.employee_id})),isLoading:I,placeholder:"Assign owner…"})}),e.jsx("p",{className:"mt-1 text-[11px] text-slate-400",children:"Signs off for this department on every exit. Can be overridden per separation."})]})]}),e.jsxs(Ae,{children:[e.jsx(C,{variant:"outline",onClick:()=>a(!1),children:"Cancel"}),e.jsx(C,{onClick:te,disabled:!r||j.isPending,children:"Add Department"})]})]})})]})}const ki=ue({name:v().min(1,"Name is required"),category:v().optional().nullable(),department:v().optional().nullable(),description:v().optional(),is_default:Fe().optional(),is_active:Fe().optional()}),wi={hr:"HR",it:"IT",manager:"Manager",employee:"Employee"};function Yl(){var V;const[s,a]=b.useState(!1),[r,t]=b.useState(null),[n,m]=b.useState(null),[l,i]=b.useState(""),[x,g]=b.useState(null),{hasPermission:p,requirePermission:F}=je(),y=p("core_hr","onboarding_template","create"),D=p("core_hr","onboarding_template","update"),c=p("core_hr","onboarding_template","delete"),{pagination:w,setPagination:_,sorting:o,setSorting:u,globalFilter:O,setGlobalFilter:z,queryParams:I}=ls(),j={...I,...l&&{is_active:l}},{data:S,isLoading:N}=Ua(j),P=(S==null?void 0:S.results)??[],L=jn(),ae=gn(),te=_n(),{data:ne}=ys(),W=(ne==null?void 0:ne.results)??[],{data:he}=ra(),U=(he==null?void 0:he.results)??[],Y=Te({resolver:Ee(ki),defaultValues:{is_active:!0,is_default:!1}});function k(q){i(q==="__all__"?"":q),_(H=>({...H,pageIndex:0}))}function ee(){F("core_hr","onboarding_template","create")&&(t(null),Y.reset({is_active:!0,is_default:!1}),a(!0))}function $(q){F("core_hr","onboarding_template","update")&&(t(q),Y.reset({name:q.name,category:q.category,department:q.department,description:q.description,is_default:q.is_default,is_active:q.is_active}),a(!0))}function Z(q){const H={...q,category:q.category||null,department:q.department||null};r?ae.mutate({id:r.id,...H},{onSuccess:()=>a(!1)}):L.mutate(H,{onSuccess:()=>a(!1)})}function Ce(){F("core_hr","onboarding_template","delete")&&n&&te.mutate(n.id,{onSuccess:()=>m(null)})}const pe=[{key:"name",header:"Template",render:q=>e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-slate-900",children:q.name}),q.is_default&&e.jsx(B,{variant:"purple",className:"ml-2",children:"Default"})]})},{key:"description",header:"Description",render:q=>e.jsx("span",{className:"text-slate-500 truncate max-w-[200px] inline-block",children:q.description||"—"})},{key:"item_count",header:"Tasks",render:q=>e.jsxs("button",{className:"inline-flex items-center gap-1 text-slate-600 hover:text-primary transition-colors",onClick:()=>g(x===q.id?null:q.id),children:[e.jsx(Xa,{className:"h-3 w-3"})," ",q.item_count,x===q.id?e.jsx(gt,{className:"h-3 w-3"}):e.jsx(_t,{className:"h-3 w-3"})]})},{key:"is_active",header:"Status",render:q=>e.jsx(st,{status:q.is_active?"active":"inactive"})},{key:"actions",header:"",className:"w-10",render:q=>e.jsxs(Ie,{open:(n==null?void 0:n.id)===q.id,onOpenChange:H=>!H&&m(null),children:[e.jsxs(ns,{children:[e.jsx(rs,{asChild:!0,children:e.jsx(C,{variant:"ghost",size:"icon-sm",children:e.jsx(vs,{className:"h-4 w-4"})})}),e.jsxs(is,{align:"end",children:[D&&e.jsxs($e,{onClick:()=>$(q),children:[e.jsx(ke,{className:"mr-2 h-3.5 w-3.5"})," Edit"]}),c&&e.jsx(Aa,{asChild:!0,children:e.jsxs($e,{className:"text-red-600",onClick:()=>m(q),children:[e.jsx(De,{className:"mr-2 h-3.5 w-3.5"})," Delete"]})})]})]}),e.jsxs(Le,{children:[e.jsxs(Me,{children:[e.jsx(Oe,{children:"Delete template?"}),e.jsxs(Re,{children:["This will permanently delete ",e.jsx("strong",{children:n==null?void 0:n.name})," and all its tasks."]})]}),e.jsxs(qe,{children:[e.jsx(ze,{children:"Cancel"}),e.jsx(Ue,{variant:"destructive",onClick:Ce,children:"Delete"})]})]})]})}];return e.jsxs("div",{className:"space-y-4",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(Ta,{className:"h-5 w-5 text-primary"})," Onboarding Templates"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"Define onboarding task templates"})]}),y&&e.jsxs(C,{size:"sm",onClick:ee,children:[e.jsx(se,{className:"mr-1.5 h-3.5 w-3.5"})," Add Template"]})]}),e.jsx(es,{actions:e.jsx("div",{className:"flex gap-2",children:e.jsxs(le,{value:l,onValueChange:k,children:[e.jsx(ce,{className:"w-[140px] h-9",children:e.jsx(oe,{placeholder:"All statuses"})}),e.jsxs(de,{children:[e.jsx(T,{value:"__all__",children:"All"}),e.jsx(T,{value:"true",children:"Active"}),e.jsx(T,{value:"false",children:"Inactive"})]})]})}),columns:pe,data:P,isLoading:N,searchPlaceholder:"Search templates...",emptyMessage:"No templates yet",emptyDescription:"Create your first onboarding template.",totalCount:(S==null?void 0:S.count)??0,pagination:w,onPaginationChange:_,sorting:o,onSortingChange:u,globalFilter:O,onGlobalFilterChange:z}),x&&e.jsx(Pi,{templateId:x,templateName:((V=P.find(q=>q.id===x))==null?void 0:V.name)??""}),e.jsx(fe,{open:s,onOpenChange:a,children:e.jsxs(ve,{size:"lg",children:[e.jsxs(ye,{children:[e.jsx(be,{children:r?"Edit Template":"Add Template"}),e.jsx(Ne,{children:r?"Update template details.":"Create a new onboarding template."})]}),e.jsxs("form",{onSubmit:Y.handleSubmit(Z),className:"flex-1 overflow-y-auto px-6 py-5 space-y-4",children:[e.jsxs("div",{children:[e.jsx(h,{children:"Name *"}),e.jsx(M,{...Y.register("name"),className:"mt-1.5"}),Y.formState.errors.name&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:Y.formState.errors.name.message})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Description"}),e.jsx(ps,{...Y.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(h,{children:"Category"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(K,{value:Y.watch("category")??null,onValueChange:q=>Y.setValue("category",q||null),options:U.map(q=>({value:q.id,label:q.name})),placeholder:"All categories",searchPlaceholder:"Search categories..."})})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Department"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(K,{value:Y.watch("department")??null,onValueChange:q=>Y.setValue("department",q||null),options:W.map(q=>({value:q.id,label:q.name})),placeholder:"All departments",searchPlaceholder:"Search departments..."})})]})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2",children:[e.jsxs("div",{children:[e.jsx(h,{children:"Default Template"}),e.jsx("p",{className:"text-[11px] text-slate-400 mt-0.5",children:"Auto-assign for matching new hires"})]}),e.jsx(Ge,{checked:Y.watch("is_default")??!1,onCheckedChange:q=>Y.setValue("is_default",q)})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(h,{children:"Active"}),e.jsx("p",{className:"text-[11px] text-slate-400 mt-0.5",children:"Available for assignment"})]}),e.jsx(Ge,{checked:Y.watch("is_active")??!0,onCheckedChange:q=>Y.setValue("is_active",q)})]})]}),e.jsxs(Ae,{children:[e.jsx(C,{variant:"outline",onClick:()=>a(!1),children:"Cancel"}),e.jsx(C,{onClick:Y.handleSubmit(Z),disabled:L.isPending||ae.isPending,children:r?"Save Changes":"Create Template"})]})]})})]})}function Pi({templateId:s,templateName:a}){const{data:r,isLoading:t}=Va(s),n=fn(),m=vn(),l=yn(),[i,x]=b.useState(!1),[g,p]=b.useState(null),[F,y]=b.useState(null),{hasPermission:D}=je(),c=D("core_hr","onboarding_template","create"),w=D("core_hr","onboarding_template","update"),_=D("core_hr","onboarding_template","delete"),o=[...r??[]].sort((u,O)=>u.order-O.order);return e.jsxs(G,{children:[e.jsx(ms,{className:"pb-3",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(xs,{className:"text-sm font-medium",children:["Tasks — ",a]}),c&&e.jsxs(C,{size:"sm",variant:"outline",className:"gap-1 h-7 text-xs",onClick:()=>x(!0),children:[e.jsx(se,{className:"h-3 w-3"})," Add Task"]})]})}),e.jsx(Q,{className:"pt-0",children:t?e.jsx("div",{className:"h-16 bg-slate-50 animate-pulse rounded"}):o.length===0?e.jsx("p",{className:"text-xs text-slate-400 py-3 text-center",children:"No tasks yet. Add one above."}):e.jsxs(ft,{children:[e.jsx(vt,{children:e.jsxs(ga,{children:[e.jsx(js,{className:"text-xs w-12",children:"Order"}),e.jsx(js,{className:"text-xs",children:"Task Name"}),e.jsx(js,{className:"text-xs w-24",children:"Role"}),e.jsx(js,{className:"text-xs w-20 text-center",children:"Deadline"}),e.jsx(js,{className:"text-xs w-20 text-center",children:"Mandatory"}),e.jsx(js,{className:"text-xs w-20 text-right",children:"Actions"})]})}),e.jsx(yt,{children:o.map(u=>e.jsxs(ga,{children:[e.jsx(gs,{className:"text-xs",children:u.order}),e.jsxs(gs,{children:[e.jsx("span",{className:"text-sm font-medium",children:u.task_name}),u.description&&e.jsx("p",{className:"text-[11px] text-slate-400 mt-0.5 truncate max-w-[300px]",children:u.description})]}),e.jsx(gs,{children:e.jsx(B,{variant:"outline",className:"text-[10px]",children:wi[u.assigned_role]})}),e.jsx(gs,{className:"text-center",children:e.jsxs("span",{className:"text-xs text-slate-600 tabular-nums",children:[u.deadline_days,u.deadline_days===1?" day":" days"]})}),e.jsx(gs,{className:"text-center",children:u.is_mandatory?e.jsx("span",{className:"text-green-600 text-xs",children:"Yes"}):e.jsx("span",{className:"text-slate-400 text-xs",children:"No"})}),e.jsx(gs,{className:"text-right",children:e.jsxs("div",{className:"flex items-center justify-end gap-0.5",children:[w&&e.jsx(C,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:()=>p(u),"aria-label":`Edit ${u.task_name}`,children:e.jsx(ke,{className:"h-3 w-3"})}),_&&e.jsx(C,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0 text-destructive",onClick:()=>y(u),"aria-label":`Delete ${u.task_name}`,children:e.jsx(De,{className:"h-3 w-3"})})]})})]},u.id))})]})}),i&&e.jsx(Sa,{onClose:()=>x(!1),onSubmit:u=>{n.mutate({templateId:s,...u},{onSuccess:()=>x(!1)})}}),g&&e.jsx(Sa,{item:g,onClose:()=>p(null),onSubmit:u=>{m.mutate({templateId:s,itemId:g.id,...u},{onSuccess:()=>p(null)})}},g.id),e.jsx(Ie,{open:!!F,onOpenChange:u=>!u&&y(null),children:e.jsxs(Le,{children:[e.jsxs(Me,{children:[e.jsx(Oe,{children:"Remove this task?"}),e.jsxs(Re,{children:["“",F==null?void 0:F.task_name,"” will be removed from this template. Checklists already created from it are not affected."]})]}),e.jsxs(qe,{children:[e.jsx(ze,{children:"Cancel"}),e.jsx(Ue,{onClick:()=>{F&&l.mutate({templateId:s,itemId:F.id}),y(null)},children:"Remove"})]})]})})]})}function Sa({item:s,onClose:a,onSubmit:r}){const t=!!s,[n,m]=b.useState((s==null?void 0:s.task_name)??""),[l,i]=b.useState((s==null?void 0:s.description)??""),[x,g]=b.useState((s==null?void 0:s.assigned_role)??"hr"),[p,F]=b.useState(String((s==null?void 0:s.order)??0)),[y,D]=b.useState((s==null?void 0:s.is_mandatory)??!0),[c,w]=b.useState(String((s==null?void 0:s.deadline_days)??7));return e.jsx(bt,{open:!0,onOpenChange:a,children:e.jsxs(Nt,{className:"max-w-md",children:[e.jsx(Ct,{children:e.jsx(St,{children:t?"Edit Task":"Add Task"})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(h,{children:"Task Name *"}),e.jsx(M,{value:n,onChange:_=>m(_.target.value),placeholder:"e.g. Collect ID proof"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(h,{children:"Description"}),e.jsx(ps,{value:l,onChange:_=>i(_.target.value),placeholder:"Optional details...",className:"min-h-[60px] resize-none"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(h,{children:"Assigned Role"}),e.jsxs(le,{value:x,onValueChange:_=>g(_),children:[e.jsx(ce,{children:e.jsx(oe,{})}),e.jsxs(de,{children:[e.jsx(T,{value:"hr",children:"HR"}),e.jsx(T,{value:"it",children:"IT"}),e.jsx(T,{value:"manager",children:"Manager"}),e.jsx(T,{value:"employee",children:"Employee"})]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(h,{children:"Order"}),e.jsx(M,{type:"number",min:"0",value:p,onChange:_=>F(_.target.value)})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(h,{children:"Deadline (days)"}),e.jsx(M,{type:"number",min:"0",value:c,onChange:_=>w(_.target.value)}),e.jsx("p",{className:"text-[11px] text-slate-400",children:"Days after onboarding starts."})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Ge,{checked:y,onCheckedChange:D}),e.jsx(h,{children:"Mandatory"})]})]}),e.jsxs(kt,{children:[e.jsx(C,{variant:"outline",onClick:a,children:"Cancel"}),e.jsx(C,{onClick:()=>r({task_name:n,description:l,assigned_role:x,order:parseInt(p)||0,is_mandatory:y,deadline_days:Math.max(0,parseInt(c)||0)}),disabled:!n.trim(),children:t?"Save Changes":"Add Task"})]})]})})}const Ai={in_progress:"default",completed:"success",overdue:"destructive"},Ti={pending:"secondary",in_progress:"default",completed:"success",skipped:"warning"},Ei={hr:"HR",it:"IT",manager:"Manager",employee:"Employee"};function Jl(){var re,A,xe,f;const[s,a]=b.useState(!1),[r,t]=b.useState(null),[n,m]=b.useState(""),[l,i]=b.useState(""),[x,g]=b.useState(new Set),[p,F]=b.useState(null),[y,D]=b.useState(""),{hasPermission:c}=je(),w=c("core_hr","onboarding","create"),_=c("core_hr","onboarding","update"),o=c("core_hr","onboarding","delete"),{pagination:u,setPagination:O,sorting:z,setSorting:I,globalFilter:j,setGlobalFilter:S,queryParams:N}=ls(),P={...N,...y&&{status:y}},{data:L,isLoading:ae}=bn(P),te=(L==null?void 0:L.results)??[],ne=Nn(),W=Cn(),he=Sn(),{data:U}=kn(r??""),[Y,k]=b.useState(""),{data:ee,isLoading:$}=Xe({search:Y||void 0}),Z=(ee==null?void 0:ee.results)??[],{data:Ce}=Ua(),pe=(Ce==null?void 0:Ce.results)??[],{data:V}=Va(l),q=b.useMemo(()=>(V??[]).sort((E,J)=>E.order-J.order),[V]);function H(E){D(E==="__all__"?"":E),O(J=>({...J,pageIndex:0}))}function d(E){i(E),g(new Set)}function X(E){g(J=>{const Be=new Set(J);return Be.has(E)?Be.delete(E):Be.add(E),Be})}function ge(){x.size===q.length?g(new Set):g(new Set(q.map(E=>E.id)))}function He(){if(!n)return;const E={employee:n};l&&(E.template=l,x.size>0&&x.size<q.length&&(E.item_ids=Array.from(x))),ne.mutate(E,{onSuccess:()=>{a(!1),m(""),i(""),g(new Set)}})}const R=[{key:"employee_name",header:"Employee",render:E=>e.jsx("span",{className:"font-medium text-slate-900",children:E.employee_name??"—"})},{key:"template_name",header:"Template",render:E=>E.template_name??e.jsx("span",{className:"text-slate-400 italic",children:"Custom"})},{key:"progress",header:"Progress",render:E=>{var J,Be;return e.jsxs("div",{className:"flex items-center gap-2 min-w-[140px]",children:[e.jsx(Is,{value:((J=E.progress)==null?void 0:J.percent)??0,className:"flex-1 h-1.5"}),e.jsxs("span",{className:"text-[11px] text-slate-500 tabular-nums w-9 text-right",children:[((Be=E.progress)==null?void 0:Be.percent)??0,"%"]})]})}},{key:"started_at",header:"Started",render:E=>me(ie(E.started_at),"dd MMM yyyy")},{key:"status",header:"Status",render:E=>{const J=E.status??"in_progress";return e.jsx(B,{variant:Ai[J]??"default",children:J.replace("_"," ")})}},{key:"actions",header:"",className:"w-10",render:E=>e.jsxs(Ie,{open:(p==null?void 0:p.id)===E.id,onOpenChange:J=>!J&&F(null),children:[e.jsxs(ns,{children:[e.jsx(rs,{asChild:!0,children:e.jsx(C,{variant:"ghost",size:"icon-sm",children:e.jsx(vs,{className:"h-4 w-4"})})}),e.jsxs(is,{align:"end",children:[e.jsxs($e,{onClick:()=>t(E.id),children:[e.jsx(Us,{className:"mr-2 h-3.5 w-3.5"})," View Tasks"]}),o&&e.jsxs(e.Fragment,{children:[e.jsx(wt,{}),e.jsxs($e,{className:"text-red-600",onClick:()=>F(E),children:[e.jsx(De,{className:"mr-2 h-3.5 w-3.5"})," Delete"]})]})]})]}),e.jsxs(Le,{children:[e.jsxs(Me,{children:[e.jsx(Oe,{children:"Delete checklist?"}),e.jsxs(Re,{children:["This will permanently delete the onboarding checklist for ",e.jsx("strong",{children:(p==null?void 0:p.employee_name)??"this employee"})," and all its tasks."]})]}),e.jsxs(qe,{children:[e.jsx(ze,{children:"Cancel"}),e.jsx(Ue,{variant:"destructive",onClick:()=>{p&&he.mutate(p.id,{onSuccess:()=>F(null)})},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(Ea,{className:"h-5 w-5 text-primary"})," Onboarding Checklists"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"Active onboarding processes"})]}),w&&e.jsxs(C,{size:"sm",onClick:()=>a(!0),children:[e.jsx(se,{className:"mr-1.5 h-3.5 w-3.5"})," Start Onboarding"]})]}),e.jsx(es,{actions:e.jsx("div",{className:"flex gap-2",children:e.jsxs(le,{value:y,onValueChange:H,children:[e.jsx(ce,{className:"w-[140px] h-9",children:e.jsx(oe,{placeholder:"All statuses"})}),e.jsxs(de,{children:[e.jsx(T,{value:"__all__",children:"All"}),e.jsx(T,{value:"in_progress",children:"In Progress"}),e.jsx(T,{value:"completed",children:"Completed"}),e.jsx(T,{value:"overdue",children:"Overdue"})]})]})}),columns:R,data:te,isLoading:ae,searchPlaceholder:"Search checklists...",emptyMessage:"No onboarding in progress",emptyDescription:"Start onboarding for a new employee.",totalCount:(L==null?void 0:L.count)??0,pagination:u,onPaginationChange:O,sorting:z,onSortingChange:I,globalFilter:j,onGlobalFilterChange:S}),e.jsx(fe,{open:s,onOpenChange:a,children:e.jsxs(ve,{size:"lg",children:[e.jsxs(ye,{children:[e.jsx(be,{children:"Start Onboarding"}),e.jsx(Ne,{children:"Select an employee and a template, then choose which tasks to include."})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-6 py-5 space-y-4",children:[e.jsxs("div",{children:[e.jsx(h,{children:"Employee *"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(K,{value:n||null,onValueChange:m,onSearch:k,isLoading:$,options:Z.map(E=>({value:E.id,label:`${E.first_name} ${E.last_name}`,hint:E.employee_id})),placeholder:"Select employee",searchPlaceholder:"Search employees..."})})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Template"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(K,{value:l||null,onValueChange:d,options:pe.map(E=>({value:E.id,label:E.name,hint:`${E.item_count} tasks`})),placeholder:"Select template (optional)",searchPlaceholder:"Search templates..."})})]}),l&&q.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(bs,{}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs(h,{className:"text-xs font-semibold uppercase tracking-wider text-slate-400",children:["Tasks (",x.size,"/",q.length," selected)"]}),e.jsx(C,{size:"sm",variant:"ghost",className:"h-6 text-xs gap-1",onClick:ge,children:x.size===q.length?"Deselect All":"Select All"})]}),e.jsx("div",{className:"space-y-1.5 max-h-[300px] overflow-y-auto",children:q.map(E=>{const J=x.has(E.id);return e.jsxs("button",{type:"button",onClick:()=>X(E.id),className:Pe("w-full flex items-center gap-3 rounded-lg border px-3 py-2.5 text-left transition-colors",J?"bg-primary/5 border-primary/20":"bg-white border-slate-200 hover:bg-slate-50"),children:[J?e.jsx(nr,{className:"h-4 w-4 text-primary shrink-0"}):e.jsx(or,{className:"h-4 w-4 text-slate-300 shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-[13px] font-medium text-slate-900",children:E.task_name}),E.description&&e.jsx("p",{className:"text-[11px] text-slate-400 truncate",children:E.description})]}),e.jsx(B,{variant:"outline",className:"text-[10px] shrink-0",children:Ei[E.assigned_role]})]},E.id)})})]})]})]}),e.jsx("div",{className:"px-6 pb-6",children:e.jsxs(C,{className:"w-full",onClick:He,disabled:!n||ne.isPending,children:["Start Onboarding",l&&x.size>0&&` (${x.size} tasks)`]})})]})}),e.jsx(fe,{open:!!r,onOpenChange:E=>!E&&t(null),children:e.jsxs(ve,{size:"lg",children:[e.jsxs(ye,{children:[e.jsx(be,{children:"Onboarding Tasks"}),e.jsxs(Ne,{children:[U==null?void 0:U.employee_name," — ",(U==null?void 0:U.template_name)??"Custom"]})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-6 py-5 space-y-3",children:[U&&e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx(Is,{value:((re=U.progress)==null?void 0:re.percent)??0,className:"flex-1 h-2"}),e.jsxs("span",{className:"text-[13px] text-slate-600 tabular-nums",children:[((A=U.progress)==null?void 0:A.completed)??0,"/",((xe=U.progress)==null?void 0:xe.total)??0]})]}),(f=U==null?void 0:U.items)==null?void 0:f.map(E=>e.jsxs("div",{className:Pe("flex items-center justify-between rounded-lg border px-4 py-3 transition-colors",E.status==="completed"&&"bg-green-50/50 border-green-100"),children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:Pe("text-[13px] font-medium",E.status==="completed"&&"line-through text-slate-400"),children:E.task_name}),e.jsxs("p",{className:"text-[11px] text-slate-400 mt-0.5",children:[E.assigned_role," · Due ",me(ie(E.due_date),"dd MMM"),E.assigned_to_display&&` · ${E.assigned_to_display}`]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(B,{variant:Ti[E.status]??"secondary",className:"text-[10px]",children:E.status.replace("_"," ")}),_&&E.status!=="completed"&&E.status!=="skipped"&&r&&e.jsx(C,{size:"sm",variant:"outline",className:"text-[11px] h-7",onClick:()=>W.mutate({checklistId:r,taskId:E.id,status:"completed"}),disabled:W.isPending,children:"Complete"})]})]},E.id))]})]})})]})}const Di=ue({employee:v().min(1,"Employee is required"),transfer_type:v().min(1,"Type is required"),from_department:v().optional().nullable(),to_department:v().optional().nullable(),from_branch:v().optional().nullable(),to_branch:v().optional().nullable(),from_designation:v().optional().nullable(),to_designation:v().optional().nullable(),from_company:v().optional().nullable(),to_company:v().optional().nullable(),effective_date:ss("Effective date is required"),reason:v().min(1,"Reason is required")}),Fi={pending:"secondary",approved:"default",rejected:"destructive",completed:"success",cancelled:"warning"},Ii={department:"Department",branch:"Branch",designation:"Designation",company:"Company"};function Kl(){const[s,a]=b.useState(!1),[r,t]=b.useState(""),[n,m]=b.useState(""),[l,i]=b.useState(!1),[x,g]=b.useState(null),[p,F]=b.useState(null),{hasPermission:y,requirePermission:D}=je(),c=y("core_hr","transfer","create"),{pagination:w,setPagination:_,sorting:o,setSorting:u,globalFilter:O,setGlobalFilter:z,queryParams:I}=ls(),j={...I,...r&&{status:r},...n&&{transfer_type:n}},{data:S,isLoading:N}=wn(j),P=(S==null?void 0:S.results)??[],L=Pn(),ae=An(),[te,ne]=b.useState(""),{data:W,isLoading:he}=Xe({search:te||void 0}),U=(W==null?void 0:W.results)??[],{data:Y}=ys(),k=(Y==null?void 0:Y.results)??[],{data:ee}=na(),$=(ee==null?void 0:ee.results)??[],{data:Z}=$s(),Ce=(Z==null?void 0:Z.results)??[],{data:pe}=ta(),V=(pe==null?void 0:pe.results)??[];function q(f){t(f==="__all__"?"":f),_(E=>({...E,pageIndex:0}))}function H(f){m(f==="__all__"?"":f),_(E=>({...E,pageIndex:0}))}const d=Te({resolver:Ee(Di),defaultValues:{transfer_type:"department"}}),X=d.watch("transfer_type");function ge(){D("core_hr","transfer","create")&&(d.reset({transfer_type:"department"}),a(!0))}function He(f){const E={...f,transfer_type:f.transfer_type,from_department:f.from_department||null,to_department:f.to_department||null,from_branch:f.from_branch||null,to_branch:f.to_branch||null,from_designation:f.from_designation||null,to_designation:f.to_designation||null,from_company:f.from_company||null,to_company:f.to_company||null};L.mutate(E,{onSuccess:()=>a(!1)})}function R(f,E,J){g(f),F({status:E,label:J}),i(!0)}function re(){if(!x||!p)return;const f={onSuccess:()=>i(!1)};D("core_hr","transfer","create")&&ae.mutate({id:x.id,status:p.status},f)}const A=(f,E)=>E?f.filter(J=>J.value!==E):f,xe=[{key:"employee_name",header:"Employee",render:f=>e.jsx(Ke,{to:`/core-hr/transfers/${f.id}`,className:"font-medium text-primary hover:underline",children:f.employee_name??"—"})},{key:"transfer_type",header:"Type",render:f=>e.jsx(B,{variant:"secondary",children:Ii[f.transfer_type]})},{key:"details",header:"Transfer Details",render:f=>{let E=null,J=null;if(f.transfer_type==="department")E=f.from_department_name,J=f.to_department_name;else if(f.transfer_type==="branch"){const Be=$.find(os=>os.id===f.from_branch),cs=$.find(os=>os.id===f.to_branch);E=(Be==null?void 0:Be.name)??null,J=(cs==null?void 0:cs.name)??null}else if(f.transfer_type==="designation"){const Be=Ce.find(os=>os.id===f.from_designation),cs=Ce.find(os=>os.id===f.to_designation);E=(Be==null?void 0:Be.name)??null,J=(cs==null?void 0:cs.name)??null}else f.transfer_type==="company"&&(E=f.from_company_name,J=f.to_company_name);return E||J?e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-[12px] text-slate-600",children:[E??"—",e.jsx(ca,{className:"h-3 w-3 text-slate-400"}),J??"—"]}):e.jsx("span",{className:"text-slate-400",children:"—"})}},{key:"effective_date",header:"Effective",render:f=>me(ie(f.effective_date),"dd MMM yyyy")},{key:"status",header:"Status",render:f=>e.jsx(B,{variant:Fi[f.status],children:f.status})},{key:"actions",header:"",render:f=>{const E=[];return f.status==="pending"&&c&&E.push({status:"cancelled",label:"Cancel",icon:Js,className:"text-slate-600"}),f.status==="approved"&&c&&E.push({status:"completed",label:"Complete",icon:at,className:"text-blue-600"}),E.length===0?null:e.jsxs(ns,{children:[e.jsx(rs,{asChild:!0,children:e.jsx(C,{variant:"ghost",size:"icon-sm",children:e.jsx("span",{className:"text-[11px] text-slate-500",children:"Actions"})})}),e.jsx(is,{align:"end",children:E.map(J=>e.jsxs($e,{className:J.className,onClick:()=>R(f,J.status,J.label),children:[e.jsx(J.icon,{className:"mr-2 h-3.5 w-3.5"})," ",J.label]},J.status))})]})}}];return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"text-[16px] font-semibold text-slate-900 flex items-center gap-2",children:[e.jsx(tt,{className:"h-5 w-5 text-primary"})," Transfers"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"Employee transfer requests"})]}),c&&e.jsxs(C,{size:"sm",onClick:ge,children:[e.jsx(se,{className:"mr-1.5 h-3.5 w-3.5"})," New Transfer"]})]}),e.jsx(es,{actions:e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(le,{value:r,onValueChange:q,children:[e.jsx(ce,{className:"w-[140px] h-9",children:e.jsx(oe,{placeholder:"All statuses"})}),e.jsxs(de,{children:[e.jsx(T,{value:"__all__",children:"All"}),e.jsx(T,{value:"pending",children:"Pending"}),e.jsx(T,{value:"approved",children:"Approved"}),e.jsx(T,{value:"rejected",children:"Rejected"}),e.jsx(T,{value:"completed",children:"Completed"}),e.jsx(T,{value:"cancelled",children:"Cancelled"})]})]}),e.jsxs(le,{value:n,onValueChange:H,children:[e.jsx(ce,{className:"w-[140px] h-9",children:e.jsx(oe,{placeholder:"All types"})}),e.jsxs(de,{children:[e.jsx(T,{value:"__all__",children:"All"}),e.jsx(T,{value:"department",children:"Department"}),e.jsx(T,{value:"branch",children:"Branch"}),e.jsx(T,{value:"designation",children:"Designation"}),e.jsx(T,{value:"company",children:"Company"})]})]})]}),columns:xe,data:P,isLoading:N,searchPlaceholder:"Search transfers...",emptyMessage:"No transfers yet",emptyDescription:"Create a transfer request to get started.",totalCount:(S==null?void 0:S.count)??0,pagination:w,onPaginationChange:_,sorting:o,onSortingChange:u,globalFilter:O,onGlobalFilterChange:z}),e.jsx(fe,{open:s,onOpenChange:a,children:e.jsxs(ve,{size:"lg",children:[e.jsxs(ye,{children:[e.jsx(be,{children:"New Transfer Request"}),e.jsx(Ne,{children:"Initiate an employee transfer."})]}),e.jsx("form",{onSubmit:d.handleSubmit(He),className:"flex-1 overflow-y-auto px-6 py-5 space-y-4",children:e.jsxs(fs,{...d,children:[e.jsxs("div",{children:[e.jsx(h,{children:"Employee *"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(K,{value:d.watch("employee")??null,onValueChange:f=>d.setValue("employee",f,{shouldValidate:!0}),onSearch:ne,isLoading:he,options:U.map(f=>({value:f.id,label:`${f.first_name} ${f.last_name}`,hint:f.employee_id})),placeholder:"Select employee",searchPlaceholder:"Search employees..."})}),d.formState.errors.employee&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:d.formState.errors.employee.message})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(h,{children:"Transfer Type *"}),e.jsxs(le,{value:X,onValueChange:f=>d.setValue("transfer_type",f),children:[e.jsx(ce,{className:"mt-1.5",children:e.jsx(oe,{})}),e.jsxs(de,{children:[e.jsx(T,{value:"department",children:"Department"}),e.jsx(T,{value:"branch",children:"Branch"}),e.jsx(T,{value:"designation",children:"Designation"}),e.jsx(T,{value:"company",children:"Company"})]})]})]}),e.jsx(Ze,{name:"effective_date",label:"Effective Date",required:!0})]}),X==="department"&&e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(h,{children:"From Department"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(K,{value:d.watch("from_department")??null,onValueChange:f=>{d.setValue("from_department",f||null),f&&d.getValues("to_department")===f&&d.setValue("to_department",null)},options:k.map(f=>({value:f.id,label:f.name})),placeholder:"Current",searchPlaceholder:"Search departments..."})})]}),e.jsxs("div",{children:[e.jsx(h,{children:"To Department"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(K,{value:d.watch("to_department")??null,onValueChange:f=>d.setValue("to_department",f||null),options:A(k.map(f=>({value:f.id,label:f.name})),d.watch("from_department")??null),placeholder:"New",searchPlaceholder:"Search departments..."})})]})]}),X==="branch"&&e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(h,{children:"From Branch"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(K,{value:d.watch("from_branch")??null,onValueChange:f=>{d.setValue("from_branch",f||null),f&&d.getValues("to_branch")===f&&d.setValue("to_branch",null)},options:$.map(f=>({value:f.id,label:f.name})),placeholder:"Current",searchPlaceholder:"Search branches..."})})]}),e.jsxs("div",{children:[e.jsx(h,{children:"To Branch"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(K,{value:d.watch("to_branch")??null,onValueChange:f=>d.setValue("to_branch",f||null),options:A($.map(f=>({value:f.id,label:f.name})),d.watch("from_branch")??null),placeholder:"New",searchPlaceholder:"Search branches..."})})]})]}),X==="designation"&&e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(h,{children:"From Designation"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(K,{value:d.watch("from_designation")??null,onValueChange:f=>{d.setValue("from_designation",f||null),f&&d.getValues("to_designation")===f&&d.setValue("to_designation",null)},options:Ce.map(f=>({value:f.id,label:f.name})),placeholder:"Current",searchPlaceholder:"Search designations..."})})]}),e.jsxs("div",{children:[e.jsx(h,{children:"To Designation"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(K,{value:d.watch("to_designation")??null,onValueChange:f=>d.setValue("to_designation",f||null),options:A(Ce.map(f=>({value:f.id,label:f.name})),d.watch("from_designation")??null),placeholder:"New",searchPlaceholder:"Search designations..."})})]})]}),X==="company"&&e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(h,{children:"From Company"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(K,{value:d.watch("from_company")??null,onValueChange:f=>{d.setValue("from_company",f||null),f&&d.getValues("to_company")===f&&d.setValue("to_company",null)},options:V.map(f=>({value:f.id,label:f.name,hint:f.code})),placeholder:"Current",searchPlaceholder:"Search companies..."})})]}),e.jsxs("div",{children:[e.jsx(h,{children:"To Company"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(K,{value:d.watch("to_company")??null,onValueChange:f=>d.setValue("to_company",f||null),options:A(V.map(f=>({value:f.id,label:f.name,hint:f.code})),d.watch("from_company")??null),placeholder:"New",searchPlaceholder:"Search companies..."})})]})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Reason *"}),e.jsx(ps,{...d.register("reason"),className:"mt-1.5",rows:3,placeholder:"Reason for transfer"}),d.formState.errors.reason&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:d.formState.errors.reason.message})]})]})}),e.jsxs(Ae,{children:[e.jsx(C,{variant:"outline",onClick:()=>a(!1),children:"Cancel"}),e.jsx(C,{onClick:d.handleSubmit(He),disabled:L.isPending,children:"Submit Transfer"})]})]})}),e.jsx(Ie,{open:l,onOpenChange:i,children:e.jsxs(Le,{children:[e.jsxs(Me,{children:[e.jsxs(Oe,{children:[p==null?void 0:p.label," transfer for ",x==null?void 0:x.employee_name,"?"]}),e.jsxs(Re,{children:[(p==null?void 0:p.status)==="approved"&&"This will approve the transfer. If its effective date has arrived the employee record is updated immediately; otherwise it is applied automatically on the effective date.",(p==null?void 0:p.status)==="rejected"&&"This will reject the transfer request. This action cannot be undone.",(p==null?void 0:p.status)==="cancelled"&&"This will cancel the transfer request. This action cannot be undone.",(p==null?void 0:p.status)==="completed"&&"This will complete the transfer and immediately update the employee record with the new assignment."]})]}),e.jsxs(qe,{children:[e.jsx(ze,{children:"Cancel"}),e.jsx(Ue,{onClick:re,disabled:ae.isPending,children:p==null?void 0:p.label})]})]})})]})}const Li={pending:"warning",approved:"success",rejected:"destructive",completed:"success",cancelled:"secondary"};function ec(){const{id:s}=Cs(),{data:a,isLoading:r,refetch:t}=Tn(s??"");return e.jsx(oa,{recordId:a==null?void 0:a.id,title:a?`Transfer — ${me(ie(a.effective_date),"dd MMM yyyy")}`:"Transfer",subtitle:a==null?void 0:a.employee_name,backTo:"/core-hr/transfers",notFoundText:"Transfer not found.",isLoading:r,found:!!a,onDecided:()=>t(),children:a&&e.jsxs("div",{className:"grid grid-cols-3 gap-6",children:[e.jsx("div",{className:"col-span-2 space-y-4",children:e.jsxs(G,{children:[e.jsx(ms,{className:"pb-3",children:e.jsx(xs,{className:"text-[14px]",children:"Transfer Details"})}),e.jsxs(Q,{className:"grid grid-cols-2 gap-4",children:[e.jsx(_e,{label:"Type",value:a.transfer_type}),e.jsx(_e,{label:"Effective Date",value:me(ie(a.effective_date),"dd MMM yyyy")}),e.jsx(_e,{label:"From Department",value:a.from_department_name}),e.jsx(_e,{label:"To Department",value:a.to_department_name}),e.jsx(_e,{label:"From Company",value:a.from_company_name}),e.jsx(_e,{label:"To Company",value:a.to_company_name}),e.jsx(_e,{label:"Reason",value:a.reason})]})]})}),e.jsx("div",{className:"space-y-4",children:e.jsxs(G,{children:[e.jsx(ms,{className:"pb-3",children:e.jsx(xs,{className:"text-[14px]",children:"Summary"})}),e.jsxs(Q,{className:"space-y-3",children:[e.jsx(_e,{label:"Employee",value:a.employee_name}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wide text-slate-400",children:"Status"}),e.jsx(B,{variant:Li[a.status]??"secondary",className:"mt-1",children:a.status.replace(/_/g," ")})]})]})]})})]})})}const Mi=ue({employee:v().min(1,"Employee is required"),from_grade:v().optional().nullable(),to_grade:v().optional().nullable(),from_designation:v().optional().nullable(),to_designation:v().optional().nullable(),effective_date:ss("Effective date is required"),increment_amount:v().optional(),revised_ctc:v().optional(),reason:v().min(1,"Reason is required")});function sc(){const[s,a]=b.useState(!1),[r,t]=b.useState(""),[n,m]=b.useState(!1),[l,i]=b.useState(null),[x,g]=b.useState(null),{hasPermission:p,requirePermission:F}=je(),y=p("core_hr","promotion","create"),{pagination:D,setPagination:c,sorting:w,setSorting:_,globalFilter:o,setGlobalFilter:u,queryParams:O}=ls(),z={...O,...r&&{status:r}},{data:I,isLoading:j}=En(z),S=(I==null?void 0:I.results)??[],N=Dn(),P=Fn(),L=In(),[ae,te]=b.useState(""),{data:ne,isLoading:W}=Xe({search:ae||void 0}),he=(ne==null?void 0:ne.results)??[],{data:U}=Bs(),Y=(U==null?void 0:U.results)??[],{data:k}=$s(),ee=(k==null?void 0:k.results)??[];function $(d){t(d==="__all__"?"":d),c(X=>({...X,pageIndex:0}))}const Z=Te({resolver:Ee(Mi)});function Ce(){F("core_hr","promotion","create")&&(Z.reset({}),a(!0))}function pe(d,X,ge){i(d),g({status:X,label:ge}),m(!0)}function V(){if(!l||!x)return;const d={onSuccess:()=>m(!1)},ge=x.status==="approved"||x.status==="rejected"?"approve":"create";F("core_hr","promotion",ge)&&(x.status==="approved"?P.mutate({id:l.id,action:"approve"},d):x.status==="rejected"?P.mutate({id:l.id,action:"reject"},d):L.mutate({id:l.id,status:x.status},d))}function q(d){const X={...d,from_grade:d.from_grade||null,to_grade:d.to_grade||null,from_designation:d.from_designation||null,to_designation:d.to_designation||null};N.mutate(X,{onSuccess:()=>a(!1)})}const H=[{key:"employee_name",header:"Employee",render:d=>e.jsx(Ke,{to:`/core-hr/promotions/${d.id}`,className:"font-medium text-primary hover:underline",children:d.employee_name??"—"})},{key:"change",header:"Change",render:d=>{const X=[];return(d.from_grade||d.to_grade)&&X.push({label:"Grade",from:d.from_grade_name??"—",to:d.to_grade_name??"—"}),(d.from_designation||d.to_designation)&&X.push({label:"Designation",from:d.from_designation_name??"—",to:d.to_designation_name??"—"}),X.length===0?e.jsx("span",{className:"text-slate-400",children:"—"}):e.jsx("div",{className:"space-y-0.5",children:X.map(ge=>e.jsxs("div",{className:"flex items-center gap-1.5 text-[12px] text-slate-600",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-wide text-slate-400 w-[68px] shrink-0",children:ge.label}),e.jsx("span",{className:"truncate max-w-[110px]",children:ge.from}),e.jsx(ca,{className:"h-3 w-3 text-slate-400 shrink-0"}),e.jsx("span",{className:"truncate max-w-[110px] font-medium text-slate-800",children:ge.to})]},ge.label))})}},{key:"increment_amount",header:"Increment",render:d=>{const X=parseFloat(d.increment_amount);return X>0?Pt(X):"—"}},{key:"effective_date",header:"Effective",render:d=>me(ie(d.effective_date),"dd MMM yyyy")},{key:"status",header:"Status",render:d=>e.jsx(st,{status:d.status})},{key:"actions",header:"",render:d=>{const X=[];return d.status==="pending"&&y&&X.push({status:"cancelled",label:"Cancel",icon:Js,className:"text-slate-600"}),d.status==="approved"&&y&&(X.push({status:"completed",label:"Complete",icon:at,className:"text-blue-600"}),X.push({status:"cancelled",label:"Cancel",icon:Js,className:"text-slate-600"})),X.length===0?null:e.jsxs(ns,{children:[e.jsx(rs,{asChild:!0,children:e.jsx(C,{variant:"ghost",size:"icon-sm",children:e.jsx("span",{className:"text-[11px] text-slate-500",children:"Actions"})})}),e.jsx(is,{align:"end",children:X.map(ge=>{const He=ge.icon;return e.jsxs($e,{onClick:()=>pe(d,ge.status,ge.label),children:[e.jsx(He,{className:`mr-2 h-3.5 w-3.5 ${ge.className}`}),ge.label]},ge.status)})})]})}}];return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"text-[16px] font-semibold text-slate-900 flex items-center gap-2",children:[e.jsx(Da,{className:"h-5 w-5 text-primary"})," Promotions"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"Employee promotion requests"})]}),y&&e.jsxs(C,{size:"sm",onClick:Ce,children:[e.jsx(se,{className:"mr-1.5 h-3.5 w-3.5"})," New Promotion"]})]}),e.jsx(es,{actions:e.jsx("div",{className:"flex gap-2",children:e.jsxs(le,{value:r,onValueChange:$,children:[e.jsx(ce,{className:"w-[140px] h-9",children:e.jsx(oe,{placeholder:"All statuses"})}),e.jsxs(de,{children:[e.jsx(T,{value:"__all__",children:"All"}),e.jsx(T,{value:"pending",children:"Pending"}),e.jsx(T,{value:"approved",children:"Approved"}),e.jsx(T,{value:"completed",children:"Completed"}),e.jsx(T,{value:"rejected",children:"Rejected"})]})]})}),columns:H,data:S,isLoading:j,searchPlaceholder:"Search promotions...",emptyMessage:"No promotions yet",emptyDescription:"Create a promotion request.",totalCount:(I==null?void 0:I.count)??0,pagination:D,onPaginationChange:c,sorting:w,onSortingChange:_,globalFilter:o,onGlobalFilterChange:u}),e.jsx(fe,{open:s,onOpenChange:a,children:e.jsxs(ve,{size:"lg",children:[e.jsxs(ye,{children:[e.jsx(be,{children:"New Promotion"}),e.jsx(Ne,{children:"Submit a promotion request for an employee."})]}),e.jsx("form",{onSubmit:Z.handleSubmit(q),className:"flex-1 overflow-y-auto px-6 py-5 space-y-4",children:e.jsxs(fs,{...Z,children:[e.jsxs("div",{children:[e.jsx(h,{children:"Employee *"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(K,{value:Z.watch("employee")??null,onValueChange:d=>Z.setValue("employee",d,{shouldValidate:!0}),onSearch:te,isLoading:W,options:he.map(d=>({value:d.id,label:`${d.first_name} ${d.last_name}`,hint:d.employee_id})),placeholder:"Select employee",searchPlaceholder:"Search employees..."})}),Z.formState.errors.employee&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:Z.formState.errors.employee.message})]}),e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.08em] text-slate-400 pt-2",children:"Grade Change"}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(h,{children:"From Grade"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(K,{value:Z.watch("from_grade")??null,onValueChange:d=>Z.setValue("from_grade",d||null),options:Y.map(d=>({value:d.id,label:d.name})),placeholder:"Current",searchPlaceholder:"Search grades..."})})]}),e.jsxs("div",{children:[e.jsx(h,{children:"To Grade"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(K,{value:Z.watch("to_grade")??null,onValueChange:d=>Z.setValue("to_grade",d||null),options:Y.map(d=>({value:d.id,label:d.name})),placeholder:"New",searchPlaceholder:"Search grades..."})})]})]}),e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-[0.08em] text-slate-400 pt-2",children:"Designation Change"}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(h,{children:"From Designation"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(K,{value:Z.watch("from_designation")??null,onValueChange:d=>Z.setValue("from_designation",d||null),options:ee.map(d=>({value:d.id,label:d.name})),placeholder:"Current",searchPlaceholder:"Search designations..."})})]}),e.jsxs("div",{children:[e.jsx(h,{children:"To Designation"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(K,{value:Z.watch("to_designation")??null,onValueChange:d=>Z.setValue("to_designation",d||null),options:ee.map(d=>({value:d.id,label:d.name})),placeholder:"New",searchPlaceholder:"Search designations..."})})]})]}),e.jsx("div",{className:"h-px bg-slate-100 my-2"}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(Ze,{name:"effective_date",label:"Effective Date",required:!0}),e.jsxs("div",{children:[e.jsx(h,{children:"Increment Amount"}),e.jsx(M,{type:"number",step:"0.01",...Z.register("increment_amount"),className:"mt-1.5",placeholder:"0.00"})]})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Revised CTC"}),e.jsx(M,{type:"number",step:"0.01",...Z.register("revised_ctc"),className:"mt-1.5",placeholder:"0.00"})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Reason *"}),e.jsx(ps,{...Z.register("reason"),className:"mt-1.5",rows:3,placeholder:"Reason for promotion"}),Z.formState.errors.reason&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:Z.formState.errors.reason.message})]})]})}),e.jsxs(Ae,{children:[e.jsx(C,{variant:"outline",onClick:()=>a(!1),children:"Cancel"}),e.jsx(C,{onClick:Z.handleSubmit(q),disabled:N.isPending,children:"Submit Promotion"})]})]})}),e.jsx(Ie,{open:n,onOpenChange:m,children:e.jsxs(Le,{children:[e.jsxs(Me,{children:[e.jsxs(Oe,{children:[x==null?void 0:x.label," promotion for ",l==null?void 0:l.employee_name,"?"]}),e.jsxs(Re,{children:[(x==null?void 0:x.status)==="approved"&&"This will approve the promotion. If its effective date has arrived the employee’s grade and designation are updated immediately; otherwise it is applied automatically on the effective date. Where a revised CTC is set, a draft compensation revision is opened for review.",(x==null?void 0:x.status)==="rejected"&&"This will reject the promotion request. This action cannot be undone.",(x==null?void 0:x.status)==="cancelled"&&"This will cancel the promotion request. This action cannot be undone.",(x==null?void 0:x.status)==="completed"&&"This will complete the promotion and immediately update the employee’s grade and designation."]})]}),e.jsxs(qe,{children:[e.jsx(ze,{children:"Cancel"}),e.jsx(Ue,{onClick:V,disabled:P.isPending||L.isPending,children:x==null?void 0:x.label})]})]})})]})}const Oi={pending:"warning",approved:"success",rejected:"destructive",completed:"success"};function ac(){const{id:s}=Cs(),{data:a,isLoading:r,refetch:t}=Ln(s??"");return e.jsx(oa,{recordId:a==null?void 0:a.id,title:a?`Promotion — ${me(ie(a.effective_date),"dd MMM yyyy")}`:"Promotion",subtitle:a==null?void 0:a.employee_name,backTo:"/core-hr/promotions",notFoundText:"Promotion not found.",isLoading:r,found:!!a,onDecided:()=>t(),children:a&&e.jsxs("div",{className:"grid grid-cols-3 gap-6",children:[e.jsx("div",{className:"col-span-2 space-y-4",children:e.jsxs(G,{children:[e.jsx(ms,{className:"pb-3",children:e.jsx(xs,{className:"text-[14px]",children:"Promotion Details"})}),e.jsxs(Q,{className:"grid grid-cols-2 gap-4",children:[e.jsx(_e,{label:"Effective Date",value:me(ie(a.effective_date),"dd MMM yyyy")}),e.jsx(_e,{label:"From Grade",value:a.from_grade_name}),e.jsx(_e,{label:"To Grade",value:a.to_grade_name}),e.jsx(_e,{label:"From Designation",value:a.from_designation_name}),e.jsx(_e,{label:"To Designation",value:a.to_designation_name}),e.jsx(_e,{label:"Increment",value:a.increment_amount}),e.jsx(_e,{label:"Revised CTC",value:a.revised_ctc}),e.jsx(_e,{label:"Reason",value:a.reason})]})]})}),e.jsx("div",{className:"space-y-4",children:e.jsxs(G,{children:[e.jsx(ms,{className:"pb-3",children:e.jsx(xs,{className:"text-[14px]",children:"Summary"})}),e.jsxs(Q,{className:"space-y-3",children:[e.jsx(_e,{label:"Employee",value:a.employee_name}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wide text-slate-400",children:"Status"}),e.jsx(B,{variant:Oi[a.status]??"secondary",className:"mt-1",children:a.status.replace(/_/g," ")})]})]})]})})]})})}const Ri=Ms(Ms(ue({employee:v().min(1,"Employee is required"),start_date:ss("Start date is required"),original_end_date:ss("End date is required"),current_end_date:ss("Current end date is required")}),"start_date","original_end_date","End date cannot be before start date"),"start_date","current_end_date","Current end date cannot be before start date"),qi=ue({review_date:ss("Review date is required"),assessment:v().min(1,"Assessment is required"),recommendation:v().min(1,"Recommendation is required"),extension_days:Zn(s=>s===""||s===void 0||s===null||Number.isNaN(Number(s))?null:Number(s),Xn().int().positive("Must be a positive number").nullable().optional()),extension_reason:v().optional()}).refine(s=>s.recommendation!=="extend"||s.extension_days!=null&&s.extension_days>0,{message:"Extension days are required when extending",path:["extension_days"]}),zi={active:"default",confirmed:"success",extended:"warning",terminated:"destructive"},Ui={confirm:"success",extend:"warning",terminate:"destructive"};function tc(){const[s,a]=b.useState(!1),[r,t]=b.useState(null),[n,m]=b.useState(!1),[l,i]=b.useState(null),[x,g]=b.useState(null),[p,F]=b.useState(""),{hasPermission:y,requirePermission:D}=je(),c=y("core_hr","probation","create"),w=y("core_hr","probation","update"),_=y("core_hr","probation","delete"),{pagination:o,setPagination:u,sorting:O,setSorting:z,globalFilter:I,setGlobalFilter:j,queryParams:S}=ls(),N={...S,...p&&{status:p}},{data:P,isLoading:L}=Mn(N),ae=(P==null?void 0:P.results)??[],te=On(),ne=Rn(),W=qn(),he=zn(),{data:U}=$a(r??""),[Y,k]=b.useState(""),{data:ee,isLoading:$}=Xe({search:Y||void 0}),Z=(ee==null?void 0:ee.results)??[];function Ce(A){F(A==="__all__"?"":A),u(xe=>({...xe,pageIndex:0}))}const pe=Te({resolver:Ee(Ri)}),V=Te({resolver:Ee(qi),defaultValues:{recommendation:"confirm"}}),q=V.watch("recommendation");function H(){D("core_hr","probation","create")&&(i(null),pe.reset({}),a(!0))}function d(A){D("core_hr","probation","update")&&(i(A),pe.reset({employee:A.employee,start_date:A.start_date,original_end_date:A.original_end_date,current_end_date:A.current_end_date}),a(!0))}function X(A){const xe=A,f={onSuccess:()=>a(!1)};l?ne.mutate({id:l.id,...xe},f):te.mutate(xe,f)}function ge(){D("core_hr","probation","delete")&&x&&W.mutate(x.id,{onSuccess:()=>g(null)})}function He(A){D("core_hr","probation","create")&&(t(A),V.reset({recommendation:"confirm"}),m(!0))}function R(A){if(!r)return;const xe={probationId:r,review_date:A.review_date,assessment:A.assessment,recommendation:A.recommendation,...A.recommendation==="extend"&&{extension_days:A.extension_days??null,extension_reason:A.extension_reason}};he.mutate(xe,{onSuccess:()=>{m(!1)}})}const re=[{key:"employee_name",header:"Employee",render:A=>e.jsx(Ke,{to:`/core-hr/probations/${A.id}`,className:"font-medium text-primary hover:underline",children:A.employee_name??"—"})},{key:"period",header:"Period",render:A=>e.jsxs("span",{className:"text-[12px] text-slate-600",children:[me(ie(A.start_date),"dd MMM yy")," — ",me(ie(A.current_end_date),"dd MMM yy")]})},{key:"days_remaining",header:"Days Left",render:A=>{if(A.status!=="active"&&A.status!=="extended")return"—";const xe=Yn(ie(A.current_end_date),new Date);return e.jsx("span",{className:Pe("text-[12px] tabular-nums font-medium",xe<7?"text-red-600":xe<30?"text-amber-600":"text-slate-600"),children:xe<0?"Overdue":`${xe}d`})}},{key:"extension_count",header:"Extensions",render:A=>A.extension_count>0?e.jsxs(B,{variant:"warning",children:[A.extension_count,"×"]}):"—"},{key:"status",header:"Status",render:A=>e.jsx(B,{variant:zi[A.status],children:A.status})},{key:"actions",header:"",className:"w-10",render:A=>{const xe=A.status==="confirmed"||A.status==="terminated";return e.jsxs(Ie,{open:(x==null?void 0:x.id)===A.id,onOpenChange:f=>!f&&g(null),children:[e.jsxs(ns,{children:[e.jsx(rs,{asChild:!0,children:e.jsx(C,{variant:"ghost",size:"icon-sm",children:e.jsx(vs,{className:"h-4 w-4"})})}),e.jsxs(is,{align:"end",children:[e.jsxs($e,{onClick:()=>t(A.id),children:[e.jsx(Us,{className:"mr-2 h-3.5 w-3.5"})," View Reviews"]}),c&&(A.status==="active"||A.status==="extended")&&e.jsxs($e,{onClick:()=>He(A.id),children:[e.jsx(cr,{className:"mr-2 h-3.5 w-3.5"})," Add Review"]}),w&&!xe&&e.jsxs($e,{onClick:()=>d(A),children:[e.jsx(ke,{className:"mr-2 h-3.5 w-3.5"})," Edit"]}),_&&!xe&&e.jsxs($e,{className:"text-red-600",onClick:()=>g(A),children:[e.jsx(De,{className:"mr-2 h-3.5 w-3.5"})," Delete"]})]})]}),e.jsxs(Le,{children:[e.jsxs(Me,{children:[e.jsx(Oe,{children:"Delete this probation?"}),e.jsxs(Re,{children:["The probation for ",e.jsx("strong",{children:x==null?void 0:x.employee_name})," and all its reviews will be permanently removed. This cannot be undone."]})]}),e.jsxs(qe,{children:[e.jsx(ze,{children:"Cancel"}),e.jsx(Ue,{className:"bg-red-600 hover:bg-red-700",onClick:ge,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(Fa,{className:"h-5 w-5 text-primary"})," Probations"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"Probation tracking and reviews"})]}),c&&e.jsxs(C,{size:"sm",onClick:H,children:[e.jsx(se,{className:"mr-1.5 h-3.5 w-3.5"})," Add Probation"]})]}),e.jsx(es,{actions:e.jsx("div",{className:"flex gap-2",children:e.jsxs(le,{value:p,onValueChange:Ce,children:[e.jsx(ce,{className:"w-[140px] h-9",children:e.jsx(oe,{placeholder:"All statuses"})}),e.jsxs(de,{children:[e.jsx(T,{value:"__all__",children:"All"}),e.jsx(T,{value:"active",children:"Active"}),e.jsx(T,{value:"confirmed",children:"Confirmed"}),e.jsx(T,{value:"extended",children:"Extended"}),e.jsx(T,{value:"terminated",children:"Terminated"})]})]})}),columns:re,data:ae,isLoading:L,searchPlaceholder:"Search probations...",emptyMessage:"No probations tracked",emptyDescription:"Add a probation period to track.",totalCount:(P==null?void 0:P.count)??0,pagination:o,onPaginationChange:u,sorting:O,onSortingChange:z,globalFilter:I,onGlobalFilterChange:j}),e.jsx(fe,{open:s,onOpenChange:a,children:e.jsxs(ve,{children:[e.jsxs(ye,{children:[e.jsx(be,{children:l?"Edit Probation":"Add Probation"}),e.jsx(Ne,{children:l?"Update the probation dates.":"Track a new probation period."})]}),e.jsx("form",{onSubmit:pe.handleSubmit(X),className:"flex-1 overflow-y-auto px-6 py-5 space-y-4",children:e.jsxs(fs,{...pe,children:[e.jsxs("div",{children:[e.jsx(h,{children:"Employee *"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(K,{value:pe.watch("employee")??null,onValueChange:A=>pe.setValue("employee",A,{shouldValidate:!0}),onSearch:k,isLoading:$,options:Z.map(A=>({value:A.id,label:`${A.first_name} ${A.last_name}`,hint:A.employee_id})),placeholder:"Select employee",searchPlaceholder:"Search employees..."})}),pe.formState.errors.employee&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:pe.formState.errors.employee.message})]}),e.jsx(Ze,{name:"start_date",maxField:"original_end_date",label:"Start Date",required:!0}),e.jsx(Ze,{name:"original_end_date",minField:"start_date",label:"End Date",required:!0}),e.jsx(Ze,{name:"current_end_date",minField:"start_date",label:"Current End Date",required:!0})]})}),e.jsxs(Ae,{children:[e.jsx(C,{variant:"outline",onClick:()=>a(!1),children:"Cancel"}),e.jsx(C,{onClick:pe.handleSubmit(X),disabled:te.isPending||ne.isPending,children:l?"Save Changes":"Create Probation"})]})]})}),e.jsx(fe,{open:!!r&&!n,onOpenChange:A=>!A&&t(null),children:e.jsxs(ve,{size:"lg",children:[e.jsxs(ye,{children:[e.jsx(be,{children:"Probation Reviews"}),e.jsx(Ne,{children:U==null?void 0:U.employee_name})]}),e.jsxs("div",{className:"px-6 py-5 space-y-3",children:[(U==null?void 0:U.reviews.length)===0&&e.jsx("p",{className:"text-center text-[13px] text-slate-400 py-8",children:"No reviews yet."}),U==null?void 0:U.reviews.map(A=>e.jsxs("div",{className:"rounded-lg border px-4 py-3",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("span",{className:"text-[12px] text-slate-500",children:[A.reviewer_display??"Unknown"," · ",me(ie(A.review_date),"dd MMM yyyy")]}),e.jsx(B,{variant:Ui[A.recommendation],className:"text-[10px]",children:A.recommendation})]}),e.jsx("p",{className:"text-[13px] text-slate-700",children:A.assessment}),A.extension_days&&e.jsxs("p",{className:"text-[11px] text-amber-600 mt-1",children:["Extended by ",A.extension_days," days",A.extension_reason&&` — ${A.extension_reason}`]})]},A.id))]})]})}),e.jsx(fe,{open:n,onOpenChange:A=>!A&&m(!1),children:e.jsxs(ve,{children:[e.jsxs(ye,{children:[e.jsx(be,{children:"Submit Review"}),e.jsx(Ne,{children:U==null?void 0:U.employee_name})]}),e.jsx("form",{onSubmit:V.handleSubmit(R),className:"flex-1 overflow-y-auto px-6 py-5 space-y-4",children:e.jsxs(fs,{...V,children:[e.jsx(Ze,{name:"review_date",label:"Review Date",required:!0}),e.jsxs("div",{children:[e.jsx(h,{children:"Assessment *"}),e.jsx(M,{...V.register("assessment"),className:"mt-1.5",placeholder:"Overall assessment..."}),V.formState.errors.assessment&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:V.formState.errors.assessment.message})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Recommendation *"}),e.jsxs(le,{value:q,onValueChange:A=>V.setValue("recommendation",A),children:[e.jsx(ce,{className:"mt-1.5",children:e.jsx(oe,{})}),e.jsxs(de,{children:[e.jsx(T,{value:"confirm",children:"Confirm"}),e.jsx(T,{value:"extend",children:"Extend"}),e.jsx(T,{value:"terminate",children:"Terminate"})]})]})]}),q==="extend"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx(h,{children:"Extension Days *"}),e.jsx(M,{type:"number",min:1,...V.register("extension_days"),className:"mt-1.5",placeholder:"e.g. 30"}),V.formState.errors.extension_days&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:V.formState.errors.extension_days.message})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Extension Reason"}),e.jsx(M,{...V.register("extension_reason"),className:"mt-1.5"})]})]})]})}),e.jsxs(Ae,{children:[e.jsx(C,{variant:"outline",onClick:()=>m(!1),children:"Cancel"}),e.jsx(C,{onClick:V.handleSubmit(R),disabled:he.isPending,children:"Submit Review"})]})]})})]})}const Vi={active:"warning",confirmed:"success",extended:"secondary",terminated:"destructive"};function nc(){var n;const{id:s}=Cs(),{data:a,isLoading:r,refetch:t}=$a(s??"");return e.jsx(oa,{recordId:a==null?void 0:a.id,title:a?`Probation — ${a.employee_name??""}`:"Probation",subtitle:a==null?void 0:a.employee_name,backTo:"/core-hr/probations",notFoundText:"Probation record not found.",isLoading:r,found:!!a,onDecided:()=>t(),children:a&&e.jsxs("div",{className:"grid grid-cols-3 gap-6",children:[e.jsx("div",{className:"col-span-2 space-y-4",children:e.jsxs(G,{children:[e.jsx(ms,{className:"pb-3",children:e.jsx(xs,{className:"text-[14px]",children:"Probation Details"})}),e.jsxs(Q,{className:"grid grid-cols-2 gap-4",children:[e.jsx(_e,{label:"Start Date",value:me(ie(a.start_date),"dd MMM yyyy")}),e.jsx(_e,{label:"Original End",value:me(ie(a.original_end_date),"dd MMM yyyy")}),e.jsx(_e,{label:"Current End",value:me(ie(a.current_end_date),"dd MMM yyyy")}),e.jsx(_e,{label:"Extensions",value:a.extension_count}),e.jsx(_e,{label:"Confirmed At",value:a.confirmed_at?me(ie(a.confirmed_at),"dd MMM yyyy"):null})]})]})}),e.jsx("div",{className:"space-y-4",children:e.jsxs(G,{children:[e.jsx(ms,{className:"pb-3",children:e.jsx(xs,{className:"text-[14px]",children:"Summary"})}),e.jsxs(Q,{className:"space-y-3",children:[e.jsx(_e,{label:"Employee",value:a.employee_name}),e.jsx(_e,{label:"Reviews",value:((n=a.reviews)==null?void 0:n.length)??0}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wide text-slate-400",children:"Status"}),e.jsx(B,{variant:Vi[a.status]??"secondary",className:"mt-1",children:a.status.replace(/_/g," ")})]})]})]})})]})})}const $i=Ms(ue({employee:v().min(1,"Employee is required"),separation_type:v().min(1,"Type is required"),reason_code:v().min(1,"Reason code is required"),reason_detail:v().min(1,"Details are required"),resignation_date:Ls().nullable(),last_working_date:ss("Last working date is required"),notice_period_days:_a.number().min(0),notice_served_days:_a.number().min(0).optional(),notice_buyout_amount:v().optional(),clearance_assignments:Zs(ue({department:v().min(1),assigned_to:v().nullable().optional()})).min(1,"Select at least one department to clear")}),"resignation_date","last_working_date"),Bi={pending:"secondary",accepted:"default",clearance:"warning",fnf_pending:"orange",completed:"success",withdrawn:"destructive"},Gi={pending:"Pending",accepted:"Accepted",clearance:"Clearance",fnf_pending:"FnF Pending",completed:"Completed",withdrawn:"Withdrawn"},ka={resignation:"Resignation",termination:"Termination",retirement:"Retirement",absconding:"Absconding"};function rc(){const[s,a]=b.useState(!1),[r,t]=b.useState(null),[n,m]=b.useState(""),[l,i]=b.useState(""),{hasPermission:x,requirePermission:g}=je(),p=x("core_hr","separation","create"),F=x("core_hr","separation","update"),{pagination:y,setPagination:D,sorting:c,setSorting:w,globalFilter:_,setGlobalFilter:o,queryParams:u}=ls(),O={...u,...n&&{status:n},...l&&{separation_type:l}},{data:z,isLoading:I}=Un(O),j=(z==null?void 0:z.results)??[],S=Vn(),N=$n(),{data:P}=Bn(r??""),[L,ae]=b.useState(""),{data:te,isLoading:ne}=Xe({search:L||void 0}),W=(te==null?void 0:te.results)??[],[he,U]=b.useState(""),{data:Y,isLoading:k}=Xe({search:he||void 0}),ee=(Y==null?void 0:Y.results)??[],{data:$}=za({is_active:!0,page_size:200}),Z=($==null?void 0:$.results)??[];function Ce(R){m(R==="__all__"?"":R),D(re=>({...re,pageIndex:0}))}function pe(R){i(R==="__all__"?"":R),D(re=>({...re,pageIndex:0}))}const V=Te({resolver:Ee($i),defaultValues:{separation_type:"resignation",notice_period_days:30,notice_served_days:0,clearance_assignments:[]}});function q(){g("core_hr","separation","create")&&(V.reset({separation_type:"resignation",notice_period_days:30,notice_served_days:0,clearance_assignments:Z.map(R=>({department:R.department,assigned_to:R.default_owner}))}),a(!0))}const H=V.watch("clearance_assignments")??[];function d(R,re){const A=re?[...H,{department:R,assigned_to:null}]:H.filter(xe=>xe.department!==R);V.setValue("clearance_assignments",A,{shouldValidate:!0})}function X(R,re){V.setValue("clearance_assignments",H.map(A=>A.department===R?{...A,assigned_to:re}:A),{shouldValidate:!0})}function ge(R){var E;const re=(E=W.find(J=>J.id===R.employee))==null?void 0:E.date_of_joining;if(re){if(R.resignation_date&&R.resignation_date<re){V.setError("resignation_date",{message:`Cannot be before the joining date (${re}).`});return}if(R.last_working_date&&R.last_working_date<re){V.setError("last_working_date",{message:`Cannot be before the joining date (${re}).`});return}}const{notice_buyout_amount:A,...xe}=R,f={...xe,separation_type:R.separation_type,resignation_date:R.resignation_date||null,...A?{notice_buyout_amount:A}:{}};S.mutate(f,{onSuccess:()=>a(!1)})}const He=[{key:"employee_name",header:"Employee",render:R=>e.jsx("span",{className:"font-medium text-slate-900",children:R.employee_name??"—"})},{key:"separation_type",header:"Type",render:R=>e.jsx(B,{variant:"secondary",children:ka[R.separation_type]})},{key:"last_working_date",header:"LWD",render:R=>me(ie(R.last_working_date),"dd MMM yyyy")},{key:"clearance_progress",header:"Clearance",render:R=>e.jsxs("div",{className:"flex items-center gap-2 min-w-[120px]",children:[e.jsx(Is,{value:R.clearance_progress.percent,className:"flex-1 h-1.5"}),e.jsxs("span",{className:"text-[11px] text-slate-500 tabular-nums w-11 text-right",children:[R.clearance_progress.cleared,"/",R.clearance_progress.total]})]})},{key:"status",header:"Status",render:R=>e.jsx(B,{variant:Bi[R.status],children:Gi[R.status]})},{key:"actions",header:"",className:"w-10",render:R=>e.jsxs(ns,{children:[e.jsx(rs,{asChild:!0,children:e.jsx(C,{variant:"ghost",size:"icon-sm",children:e.jsx(vs,{className:"h-4 w-4"})})}),e.jsx(is,{align:"end",children:e.jsxs($e,{onClick:()=>t(R.id),children:[e.jsx(Us,{className:"mr-2 h-3.5 w-3.5"})," View Clearance"]})})]})}];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(ir,{className:"h-5 w-5 text-primary"})," Separations"]}),e.jsx("p",{className:"mt-0.5 text-[13px] text-slate-400",children:"Exit management and clearance"})]}),p&&e.jsxs(C,{size:"sm",onClick:q,children:[e.jsx(se,{className:"mr-1.5 h-3.5 w-3.5"})," New Separation"]})]}),e.jsx(es,{actions:e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(le,{value:n,onValueChange:Ce,children:[e.jsx(ce,{className:"w-[140px] h-9",children:e.jsx(oe,{placeholder:"All statuses"})}),e.jsxs(de,{children:[e.jsx(T,{value:"__all__",children:"All"}),e.jsx(T,{value:"pending",children:"Pending"}),e.jsx(T,{value:"accepted",children:"Accepted"}),e.jsx(T,{value:"clearance",children:"Clearance"}),e.jsx(T,{value:"fnf_pending",children:"FnF Pending"}),e.jsx(T,{value:"completed",children:"Completed"}),e.jsx(T,{value:"withdrawn",children:"Withdrawn"})]})]}),e.jsxs(le,{value:l,onValueChange:pe,children:[e.jsx(ce,{className:"w-[140px] h-9",children:e.jsx(oe,{placeholder:"All types"})}),e.jsxs(de,{children:[e.jsx(T,{value:"__all__",children:"All"}),e.jsx(T,{value:"resignation",children:"Resignation"}),e.jsx(T,{value:"termination",children:"Termination"}),e.jsx(T,{value:"retirement",children:"Retirement"}),e.jsx(T,{value:"absconding",children:"Absconding"})]})]})]}),columns:He,data:j,isLoading:I,searchPlaceholder:"Search separations...",emptyMessage:"No separations yet",emptyDescription:"Initiate a separation request.",totalCount:(z==null?void 0:z.count)??0,pagination:y,onPaginationChange:D,sorting:c,onSortingChange:w,globalFilter:_,onGlobalFilterChange:o}),e.jsx(fe,{open:s,onOpenChange:a,children:e.jsxs(ve,{size:"lg",children:[e.jsxs(ye,{children:[e.jsx(be,{children:"New Separation"}),e.jsx(Ne,{children:"Initiate employee separation."})]}),e.jsx("form",{onSubmit:V.handleSubmit(ge),className:"flex-1 overflow-y-auto px-6 py-5 space-y-4",children:e.jsxs(fs,{...V,children:[e.jsxs("div",{children:[e.jsx(h,{children:"Employee *"}),e.jsx("div",{className:"mt-1.5",children:e.jsx(K,{value:V.watch("employee")??null,onValueChange:R=>V.setValue("employee",R,{shouldValidate:!0}),onSearch:ae,isLoading:ne,options:W.map(R=>({value:R.id,label:`${R.first_name} ${R.last_name}`,hint:R.employee_id})),placeholder:"Select employee",searchPlaceholder:"Search employees..."})}),V.formState.errors.employee&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:V.formState.errors.employee.message})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(h,{children:"Separation Type *"}),e.jsxs(le,{value:V.watch("separation_type"),onValueChange:R=>V.setValue("separation_type",R),children:[e.jsx(ce,{className:"mt-1.5",children:e.jsx(oe,{})}),e.jsxs(de,{children:[e.jsx(T,{value:"resignation",children:"Resignation"}),e.jsx(T,{value:"termination",children:"Termination"}),e.jsx(T,{value:"retirement",children:"Retirement"}),e.jsx(T,{value:"absconding",children:"Absconding"})]})]})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Reason Code *"}),e.jsx(M,{...V.register("reason_code"),className:"mt-1.5",placeholder:"e.g. PERSONAL"}),V.formState.errors.reason_code&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:V.formState.errors.reason_code.message})]})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Reason Details *"}),e.jsx(ps,{...V.register("reason_detail"),className:"mt-1.5",rows:3}),V.formState.errors.reason_detail&&e.jsx("p",{className:"mt-1 text-[12px] text-red-500",children:V.formState.errors.reason_detail.message})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(Ze,{name:"resignation_date",maxField:"last_working_date",label:"Resignation Date"}),e.jsx(Ze,{name:"last_working_date",minField:"resignation_date",label:"Last Working Date",required:!0})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsxs("div",{children:[e.jsx(h,{children:"Notice Period (days) *"}),e.jsx(M,{type:"number",...V.register("notice_period_days"),className:"mt-1.5"})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Notice Served (days)"}),e.jsx(M,{type:"number",...V.register("notice_served_days"),className:"mt-1.5"})]}),e.jsxs("div",{children:[e.jsx(h,{children:"Buyout Amount"}),e.jsx(M,{type:"number",step:"0.01",...V.register("notice_buyout_amount"),className:"mt-1.5",placeholder:"0.00"})]})]}),e.jsxs("div",{className:"rounded-lg border border-slate-200 p-4",children:[e.jsx(h,{children:"Clearance Departments *"}),e.jsx("p",{className:"mt-0.5 text-[11px] text-slate-400",children:"Departments that must sign this exit off before final settlement."}),e.jsxs("div",{className:"mt-3 space-y-2",children:[Z.map(R=>{const re=H.find(A=>A.department===R.department);return e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("label",{className:"flex flex-1 items-center gap-2 text-[13px] text-slate-700",children:[e.jsx("input",{type:"checkbox",className:"h-3.5 w-3.5 rounded border-slate-300",checked:!!re,onChange:A=>d(R.department,A.target.checked)}),R.department_name]}),e.jsx("div",{className:"w-56",children:e.jsx(K,{value:(re==null?void 0:re.assigned_to)??null,onValueChange:A=>X(R.department,A),onSearch:U,options:ee.map(A=>({value:A.id,label:`${A.first_name} ${A.last_name}`,hint:A.employee_id})),isLoading:k,placeholder:re?"Assign owner…":"—",disabled:!re})})]},R.id)}),Z.length===0&&e.jsx("p",{className:"text-[12px] text-slate-400",children:"No clearance departments configured. Set them up in Settings → Exit Clearance."})]}),V.formState.errors.clearance_assignments&&e.jsx("p",{className:"mt-2 text-[12px] text-red-500",children:V.formState.errors.clearance_assignments.message})]})]})}),e.jsxs(Ae,{children:[e.jsx(C,{variant:"outline",onClick:()=>a(!1),children:"Cancel"}),e.jsx(C,{onClick:V.handleSubmit(ge),disabled:S.isPending,children:"Submit Separation"})]})]})}),e.jsx(fe,{open:!!r,onOpenChange:R=>!R&&t(null),children:e.jsxs(ve,{size:"lg",children:[e.jsxs(ye,{children:[e.jsx(be,{children:"Clearance Status"}),e.jsxs(Ne,{children:[P==null?void 0:P.employee_name," — ",P?ka[P.separation_type]:""]})]}),e.jsxs("div",{className:"px-6 py-5 space-y-3",children:[(P==null?void 0:P.onboarding_summary)&&e.jsxs("div",{className:"flex items-center justify-between rounded-lg border px-4 py-3 bg-slate-50/50 mb-1",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(Pa,{className:"h-3.5 w-3.5 text-slate-400 shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"text-[12px] font-medium text-slate-700",children:["Onboarded via ",P.onboarding_summary.template_name??"no template"]}),e.jsxs("p",{className:"text-[11px] text-slate-400 mt-0.5",children:["Started ",me(ie(P.onboarding_summary.started_at),"dd MMM yyyy"),P.onboarding_summary.completed_at&&` · Completed ${me(ie(P.onboarding_summary.completed_at),"dd MMM yyyy")}`," · ",P.onboarding_summary.items_completed,"/",P.onboarding_summary.items_total," tasks"]})]})]}),e.jsx(B,{variant:P.onboarding_summary.status==="completed"?"success":P.onboarding_summary.status==="overdue"?"destructive":"warning",className:"text-[10px] shrink-0",children:P.onboarding_summary.status.replace("_"," ")})]}),P&&e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx(Is,{value:P.clearance_progress.percent,className:"flex-1 h-2"}),e.jsxs("span",{className:"text-[13px] text-slate-600 tabular-nums",children:[P.clearance_progress.cleared,"/",P.clearance_progress.total]})]}),(()=>{const R=(P==null?void 0:P.clearance_items)??[],re=R.filter(f=>f.department),A=R.filter(f=>!f.department),xe=(f,E)=>e.jsxs("div",{className:Pe("flex items-center justify-between rounded-lg border px-4 py-3 transition-colors",f.status==="cleared"&&"bg-green-50/50 border-green-100"),children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:Pe("text-[13px] font-medium",f.status==="cleared"&&"text-slate-400"),children:f.display_name}),e.jsxs("p",{className:"text-[11px] text-slate-400 mt-0.5",children:[E,f.cleared_at&&` · Cleared ${me(ie(f.cleared_at),"dd MMM")}`]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(B,{variant:f.status==="cleared"?"success":f.status==="not_applicable"?"secondary":"warning",className:"text-[10px]",children:f.status.replace("_"," ")}),F&&f.status==="pending"&&r&&e.jsx(C,{size:"sm",variant:"outline",className:"text-[11px] h-7",onClick:()=>N.mutate({separationId:r,clearanceId:f.id,status:"cleared"}),disabled:N.isPending,children:"Clear"})]})]},f.id);return e.jsxs(e.Fragment,{children:[re.map(f=>xe(f,f.assigned_to_display??"Unassigned")),A.length>0&&e.jsxs("div",{className:"pt-2",children:[e.jsxs("p",{className:"text-[12px] font-medium text-slate-500 mb-2",children:["Items to Return (",A.length,")"]}),e.jsx("div",{className:"space-y-2",children:A.map(f=>xe(f,"Issued at onboarding"))})]}),R.length===0&&e.jsx("p",{className:"text-center text-[13px] text-slate-400 py-8",children:"No clearance items."})]})})(),P&&P.outstanding_assets.length>0&&e.jsxs("div",{className:"pt-4",children:[e.jsxs("p",{className:"flex items-center gap-1.5 text-[12px] font-medium text-slate-500 mb-2",children:[e.jsx(rr,{className:"h-3.5 w-3.5"}),"Assets Still With Employee (",P.outstanding_assets.length,")"]}),e.jsx("div",{className:"space-y-2",children:P.outstanding_assets.map(R=>e.jsxs("div",{className:"flex items-center justify-between rounded-lg border px-4 py-3 bg-amber-50/50 border-amber-100",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-[13px] font-medium",children:R.asset_name}),e.jsxs("p",{className:"text-[11px] text-slate-400 mt-0.5",children:[R.asset_code," · Allocated ",me(ie(R.allocation_date),"dd MMM yyyy"),R.expected_return_date&&` · Due ${me(ie(R.expected_return_date),"dd MMM")}`]})]}),e.jsx(B,{variant:"warning",className:"text-[10px]",children:"not returned"})]},R.id))}),e.jsx("p",{className:"text-[11px] text-slate-400 mt-2",children:"Process returns under Assets → Returns."})]})]})]})})]})}export{Bl as CoreHRIndexRedirect,Gl as CoreHRLayout,Wl as EmployeeCreatePage,Hl as EmployeeDetailPage,Ql as EmployeesPage,Xl as ExitClearanceSettingsPage,Jl as OnboardingChecklistsPage,Yl as OnboardingTemplatesPage,Zl as PositionsPage,nc as ProbationDetailPage,tc as ProbationsPage,ac as PromotionDetailPage,sc as PromotionsPage,rc as SeparationsPage,ec as TransferDetailPage,Kl as TransfersPage};
