PageSourceSearch

https://app.deepwind.ai/assets/js/team-CgDAdSHy-1791218975594.js

js deepwind.ai collected 2026-10-09 04:47:36 UTC 220,416 bytes, 2 lines download raw bytes

1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/js/features/settings/ResourceCapacityTab-D-O1xtNY-1791218976559.js","assets/js/vendors/vendor-YUfIzhZH-1791218974056.js","assets/css/vendor-z_gCOZND-1791218977403.css","assets/js/sprint-planning/sprint-planning-core-D8DFNeL2-1791218975454.js","assets/js/table-Cs2PlXlt-1791218975720.js","assets/js/separator-CyKDL0sU-1791218975709.js","assets/js/useWorkspaceCapacity-CJZJY21f-1791218976581.js"])))=>i.map(i=>d[i]);
2import{bk as de,r as m,bl as le,aP as e,aV as vs,b3 as Y,ds as Fs,cQ as ze,fH as fs,eg as Dt,di as Pt,bn as oe,be as Na,bd as ue,dq as _e,bu as Ss,cs as Ps,ct as We,f5 as Be,da as is,dw as ba,cI as Fe,cL as bs,j8 as ya,cj as ys,bq as Rt,a_ as js,bz as Lt,cp as ts,ei as Us,bh as Zs,R as Ue,ci as Ke,gx as Mt,eT as wa,ce as It,bA as tt,c7 as Ca,dj as Sa,cu as ws,cJ as pe,e_ as ht,h3 as as,i9 as Ft,d5 as $t,jP as Ot,bf as $s,ju as Qe,gU as ka,bm as Ie,cx as Aa,eW as qt,dN as Ea,f9 as Ta,cz as pt,bv as Rs,h0 as Da,eM as Pa,eO as et,fa as Vt,jQ as Ra,dM as Ut,cG as at,fb as La,jz as Ma,j5 as Ia,jR as ns,eY as Fa,bi as $a,cn as _t,ja as Oa,bj as qa,aG as Va}from"./vendors/vendor-YUfIzhZH-1791218974056.js";import{A as Ua}from"./AdminLayout-77MLlZuN-1791218976523.js";import{u as ge,n as Ns,k as Q,t as $,B as C,L as J,E as ls,F as _a,a5 as za,D as Ce,a as Se,b as Ee,c as Te,d as Ge,I as ee,m as rs,e as Je,av as Ba,a4 as me,l as F,f as _,p as Le,q as He,r as st,s as z,aK as De,aL as Pe,aM as $e,aN as Re,aO as te,Q as X,au as ye,ai as nt,b6 as ss,aY as Ka,aZ as Qa,a_ as Ha,o as zt,br as Wa,bs as Ga,w as Ls,x as Ms,aU as Ja,ak as rt,a6 as Ya,aV as gt,aF as Ye}from"./sprint-planning/sprint-planning-core-D8DFNeL2-1791218975454.js";import{T as ks,a as As,b as be,c as ae,d as Es,e as G}from"./table-Cs2PlXlt-1791218975720.js";import{P as Xa,l as Os,m as qs,n as je,o as ve}from"./index-BqcUo8yk-1791218901832.js";import{A as Za,a as en,b as sn,c as tn}from"./accordion-Bb9BO6T4-1791218976408.js";import{A as cs,a as os,b as ds,c as ms,d as us,e as xs,f as hs,g as ps}from"./stripe-DXSJviaI-1791218975691.js";import{g as an}from"./errorUtils-DCvhEWMx-1791218976293.js";import{A as nn}from"./AddSeatsDialog-4QccvLqC-1791218975696.js";import{u as rn}from"./useAccessControl-60tcUcKu-1791218976226.js";import{f as ln}from"./date-utils-tWfG1o1J-1791218975878.js";import{a as cn,b as on}from"./useSeatManagement-Dd9oTjy5-1791218975696.js";import{Q as it,R as lt,T as ct,U as Cs,d as Bt,f as Kt,h as Qt,i as Ht,Z as dn,X as mn,j as un,b5 as xn}from"./PostAuthShell-CGTWuJSs-1791218975571.js";import{u as Wt,a as hn,b as pn,c as Gt,d as gn,e as fn,f as ot,g as Jt,h as jn,i as vn,j as Nn}from"./useEmployees-sT6TXFLR-1791218976581.js";import{b as bn}from"./synthesizeVelocityProvenance-BwKT3ctu-1791218976428.js";import{S as yn}from"./sp-tooltip-JjKz-3He-1791218976428.js";import{u as wn}from"./useWorkspaceLanes-B11BFiJc-1791218976293.js";import{u as Cn}from"./useSkillTaxonomy-BgUz5zG8-1791218976428.js";import{A as Sn,a as kn}from"./avatar-Dk4UfzmK-1791218975878.js";import{S as Yt}from"./separator-CyKDL0sU-1791218975709.js";import{u as An}from"./useWorkspaceCapacity-CJZJY21f-1791218976581.js";import"./breadcrumb-CVm6OMTC-1791218976141.js";import"./usageCredit-qfbiNRjQ-1791218975691.js";import"./pushServiceWorkerRegistration-DqD1wY4R-1791218975571.js";import"./useOnboardingV2-BaJC-1WO-1791218975691.js";import"./onboardingFlowConfig-Bvk52W2j-1791218975692.js";import"./runHandoff-ylshTy2o-1791218975692.js";import"./founder-run-entry-CnqzgYiQ-1791218975692.js";import"./vendors/charts-DyYnQkLd-1791218975263.js";import"./vendors/export-tools-B8MmWLNG-1791218975334.js";import"./useWorkspaceScopedQueries-B2v4MycN-1791218976188.js";function En({selectedUserIds:s,selectedUsers:t,onClearSelection:a}){const{toast:r}=ge(),d=de(),[i,l]=m.useState({open:!1,action:null,reason:""}),o=t.filter(n=>n.invitationStatus==="pending").length,x=le({mutationFn:async({action:n,reason:c})=>Ns("/api/admin/users/bulk-action",{method:"POST",body:{userIds:s,action:n,reason:c}}),onSuccess:n=>{const{successCount:c,failedCount:k}=n.data;r(k===0?{title:"Success",description:`${c} user${c!==1?"s":""} updated successfully`}:c===0?{title:"Error",description:`All ${k} operations failed`,variant:"destructive"}:{title:"Partial Success",description:`${c} succeeded, ${k} failed`}),d.invalidateQueries({queryKey:["admin","users"]}),a(),l({open:!1,action:null,reason:""})},onError:n=>{r({title:"Error",description:n.message,variant:"destructive"})}}),u=le({mutationFn:async()=>{const n=t.filter(T=>T.invitationStatus==="pending").map(T=>T.email),c=await Promise.all(n.map(async T=>{try{return await Q("/api/invitations/resend-by-email",{method:"POST",body:{email:T}}),{email:T,success:!0}}catch(w){return{email:T,success:!1,error:w}}})),k=c.filter(T=>T.success).length,E=c.filter(T=>!T.success).length;return{successCount:k,failedCount:E,total:n.length}},onSuccess:n=>{const{successCount:c,failedCount:k}=n;r(k===0?{title:"Invitations Resent",description:`${c} invitation${c!==1?"s":""} resent successfully`}:c===0?{title:"Error",description:`Failed to resend all ${k} invitations`,variant:"destructive"}:{title:"Partial Success",description:`${c} resent, ${k} failed`}),d.invalidateQueries({queryKey:["admin","users"]}),a(),l({open:!1,action:null,reason:""})},onError:n=>{r({title:"Error",description:n.message||"Failed to resend invitations",variant:"destructive"})}}),v=n=>{l({open:!0,action:n,reason:""})},j=()=>{i.action&&(i.action==="resend_invites"?u.mutate():x.mutate({action:i.action,reason:i.reason||void 0}))},f=(()=>{switch(i.action){case"suspend":return{title:`Suspend ${s.length} User${s.length!==1?"s":""}?`,description:`This will suspend ${s.length} user account${s.length!==1?"s":""}. They will not be able to log in.`,requireReason:!0};case"activate":return{title:`Activate ${s.length} User${s.length!==1?"s":""}?`,description:`This will activate ${s.length} user account${s.length!==1?"s":""} and restore access.`,requireReason:!1};case"verify":return{title:`Verify ${s.length} User${s.length!==1?"s":""}?`,description:`This will mark ${s.length} user email${s.length!==1?"s":""} as verified.`,requireReason:!1};case"delete":return{title:`Delete ${s.length} User${s.length!==1?"s":""}?`,description:`This will permanently delete ${s.length} user account${s.length!==1?"s":""}. This action cannot be undone.`,requireReason:!0};case"resend_invites":return{title:`Resend Invitations to ${o} User${o!==1?"s":""}?`,description:`This will resend invitation emails to ${o} user${o!==1?"s":""} with pending invitations.`,requireReason:!1};default:return{title:"Confirm Action",description:"Are you sure?",requireReason:!1}}})(),N=x.isPending||u.isPending;return s.length===0?null:e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between p-4 bg-primary/10 border rounded-lg mb-4 flex-wrap gap-2",children:[e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsxs($,{variant:"default",className:"text-sm",children:[s.length," selected"]}),e.jsxs(C,{variant:"ghost",size:"sm",onClick:a,children:[e.jsx(vs,{className:"w-4 h-4 mr-2"}),"Clear Selection"]})]}),e.jsxs("div",{className:"flex items-center space-x-2 flex-wrap gap-2",children:[o>0&&e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>v("resend_invites"),disabled:N,children:[u.isPending?e.jsx(Y,{className:"w-4 h-4 mr-2 animate-spin"}):e.jsx(Fs,{className:"w-4 h-4 mr-2"}),"Resend Invites (",o,")"]}),e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>v("verify"),disabled:N,children:[e.jsx(ze,{className:"w-4 h-4 mr-2"}),"Verify"]}),e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>v("activate"),disabled:N,children:[e.jsx(ze,{className:"w-4 h-4 mr-2"}),"Activate"]}),e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>v("suspend"),disabled:N,children:[e.jsx(fs,{className:"w-4 h-4 mr-2"}),"Suspend"]}),e.jsxs(C,{variant:"destructive",size:"sm",onClick:()=>v("delete"),disabled:N,children:[e.jsx(Dt,{className:"w-4 h-4 mr-2"}),"Delete"]})]})]}),e.jsx(cs,{open:i.open,onOpenChange:n=>l({...i,open:n}),children:e.jsxs(os,{className:"max-w-2xl",children:[e.jsxs(ds,{children:[e.jsx(ms,{children:f.title}),e.jsx(us,{children:f.description})]}),e.jsxs("div",{className:"max-h-60 overflow-y-auto border rounded-md p-4 space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-muted-foreground mb-2",children:"Affected Users:"}),t.slice(0,10).map(n=>e.jsxs("div",{className:"text-sm flex items-center space-x-2",children:[e.jsx(Pt,{className:"w-3 h-3 text-muted-foreground"}),e.jsx("span",{children:n.username||n.email}),n.invitationStatus==="pending"&&e.jsx($,{variant:"outline",className:"text-xs bg-deepwind-warning-soft text-deepwind-warning-fg border-[var(--deepwind-warning)]",children:"Pending"})]},n.id)),t.length>10&&e.jsxs("p",{className:"text-xs text-muted-foreground italic",children:["... and ",t.length-10," more"]})]}),f.requireReason&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(J,{htmlFor:"reason",children:"Reason (required)"}),e.jsx(ls,{id:"reason",placeholder:"Enter the reason for this bulk action...",value:i.reason,onChange:n=>l({...i,reason:n.target.value}),rows:3})]}),e.jsxs(xs,{children:[e.jsx(hs,{children:"Cancel"}),e.jsx(ps,{onClick:j,disabled:N||f.requireReason&&!i.reason.trim(),children:N?"Processing...":"Confirm"})]})]})})]})}function Tn({open:s,onOpenChange:t}){const a=de(),{toast:r}=ge(),{showWidget:d}=_a(),[i,l]=m.useState({email:"",firstName:"",lastName:"",sendInvitation:!0}),[o,x]=m.useState(null),u=le({mutationFn:async b=>{try{return await Ns("/api/admin/users/create",{method:"POST",body:b})}catch(f){const N=new Error(f.message||"Failed to create user");throw N.status=f.status,N.details=f.response?.error||f.message,N}},onSuccess:async b=>{r({title:"User Created Successfully",description:`${i.firstName} ${i.lastName} has been invited to the organization.`}),await a.invalidateQueries({queryKey:["admin","users"],refetchType:"none"}),l({email:"",firstName:"",lastName:"",sendInvitation:!0}),x(null),t(!1)},onError:(b,f)=>{x(b.message),za.error("user-invite-failed",{component:"InviteUserModal",operation:"inviteUser",errorMessage:"Failed to invite user",error:b?.message,status:b?.status,details:b?.details,timestamp:new Date().toISOString()}),r({title:"Failed to Create User",description:an(b),variant:"destructive"}),b?.status>=500&&d({featureId:"user-management",context:"invite_user_error",triggerType:"error",errorDetails:{title:"Failed to Invite User",description:b?.details||b?.message||"Unknown server error",errorCode:b?.status||500,endpoint:"/api/admin/users/create",method:"POST",requestData:f,timestamp:new Date().toISOString(),stackTrace:b?.stack,troubleshooting:{possibleCauses:["Permission/role issue","Domain validation failure","Database connection error","Invalid email format"],nextSteps:["Verify you have admin permissions","Check email is valid and domain is authorized","Check server logs for detailed error","Contact support if issue persists"]}}})}}),v=b=>
2{if(b.preventDefault(),x(null),!i.email||!i.firstName||!i.lastName){x("All fields are required");return}if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(i.email)){x("Please enter a valid email address");return}u.mutate(i)},j=()=>{l({email:"",firstName:"",lastName:"",sendInvitation:!0}),x(null),t(!1)};return e.jsx(Ce,{open:s,onOpenChange:t,children:e.jsxs(Se,{className:"sm:max-w-[500px]",children:[e.jsxs(Ee,{children:[e.jsx(Te,{children:"Invite New User"}),e.jsx(Ge,{children:"Create a new user account in your organization and optionally send them an invitation email."})]}),e.jsxs("form",{onSubmit:v,children:[e.jsxs("div",{className:"space-y-4 py-4",children:[o&&e.jsxs("div",{className:"flex items-center gap-2 p-3 text-sm text-destructive bg-destructive/10 rounded-md",children:[e.jsx(oe,{className:"w-4 h-4"}),e.jsx("span",{children:o})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(J,{htmlFor:"email",children:"Email Address *"}),e.jsx(ee,{id:"email",type:"email",placeholder:"[email protected]",value:i.email,onChange:b=>l({...i,email:b.target.value}),disabled:u.isPending,required:!0})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(J,{htmlFor:"firstName",children:"First Name *"}),e.jsx(ee,{id:"firstName",type:"text",placeholder:"John",value:i.firstName,onChange:b=>l({...i,firstName:b.target.value}),disabled:u.isPending,required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(J,{htmlFor:"lastName",children:"Last Name *"}),e.jsx(ee,{id:"lastName",type:"text",placeholder:"Doe",value:i.lastName,onChange:b=>l({...i,lastName:b.target.value}),disabled:u.isPending,required:!0})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(rs,{id:"sendInvitation",checked:i.sendInvitation,onCheckedChange:b=>l({...i,sendInvitation:b===!0}),disabled:u.isPending}),e.jsx(J,{htmlFor:"sendInvitation",className:"text-sm font-normal cursor-pointer",children:"Send invitation email to user"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:'A temporary password will be generated for the user. If "Send invitation email" is checked, they will receive their credentials via email.'})]}),e.jsxs(Je,{children:[e.jsx(C,{type:"button",variant:"outline",onClick:j,disabled:u.isPending,children:"Cancel"}),e.jsxs(C,{type:"submit",disabled:u.isPending,children:[u.isPending&&e.jsx(Y,{className:"mr-2 h-4 w-4 animate-spin"}),u.isPending?"Creating...":"Create User"]})]})]})]})})}function Dn(s){switch(s){case"allocated":return"default";case"deallocated":return"destructive";case"upgraded":return"default";case"downgraded":return"secondary";default:return"outline"}}function Pn({users:s}){const{data:t,isLoading:a}=ue({queryKey:me.admin.seatHistory(),queryFn:async()=>Q("/api/seats/history?page=1&limit=10"),staleTime:3e5}),r=i=>{if(!i)return"System";const l=s.find(o=>o.id===i);return l?l.firstName&&l.lastName?`${l.firstName} ${l.lastName}`:l.email:i.substring(0,8)+"..."},d=t?.history||[];return e.jsx(Za,{type:"single",collapsible:!0,className:"w-full",children:e.jsxs(en,{value:"seat-history",className:"border rounded-lg",children:[e.jsx(sn,{className:"px-4 py-3 hover:no-underline",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ts,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm font-medium",children:"Seat Activity"}),t?.pagination?.total?e.jsx($,{variant:"secondary",className:"text-xs",children:t.pagination.total}):null]})}),e.jsx(tn,{className:"px-4 pb-4",children:a?e.jsx("div",{className:"space-y-2",children:[...Array(3)].map((i,l)=>e.jsx(X,{className:"h-10 w-full"},l))}):d.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-4",children:"No seat allocation history"}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(ks,{children:[e.jsx(As,{children:e.jsxs(be,{children:[e.jsx(ae,{className:"text-xs",children:"Time"}),e.jsx(ae,{className:"text-xs",children:"Action"}),e.jsx(ae,{className:"text-xs",children:"User"}),e.jsx(ae,{className:"text-xs",children:"By"}),e.jsx(ae,{className:"text-xs",children:"Reason"})]})}),e.jsx(Es,{children:d.map(i=>e.jsxs(be,{children:[e.jsx(G,{className:"text-xs text-muted-foreground",children:ln(i.createdAt)}),e.jsx(G,{children:e.jsx($,{variant:Dn(i.action),className:"text-xs",children:i.action})}),e.jsx(G,{className:"text-xs",children:r(i.userId)}),e.jsx(G,{className:"text-xs",children:r(i.performedByUserId)}),e.jsx(G,{className:"text-xs text-muted-foreground",children:i.reason||"-"})]},i.id))})]})})})]})})}function Rn(s,t,a){const r=t==="enterprise",d=s==="canceled",i=s==="past_due",l=s==="trialing",o=a&&a.remaining===0;return r?{label:"",visible:!1,navigateToBilling:!1}:d||i?{label:"Reactivate",visible:!0,navigateToBilling:!0}:l?{label:"Upgrade Plan",visible:!0,navigateToBilling:!1}:o?{label:"Upgrade Plan",visible:!0,navigateToBilling:!1}:{label:"Change Plan",visible:!0,navigateToBilling:!1}}function Ln({seatData:s,pendingCount:t,activeCount:a,isLoading:r,subscriptionStatus:d,planId:i,onNavigateToBilling:l,onOpenUpgradeModal:o,onAddSeats:x,isAdmin:u}){const v=d==="trialing",j=Rn(d,i,s);return e.jsxs("div",{className:"space-y-3",children:[v&&e.jsx(_,{className:"bg-gradient-to-r from-deepwind-warning-soft to-deepwind-warning-soft border-[var(--deepwind-warning)]",children:e.jsxs(z,{className:"p-3 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ba,{className:"h-4 w-4 text-deepwind-warning-fg"}),e.jsx("span",{className:"text-sm font-medium text-deepwind-warning-fg",children:"You are on a trial plan"}),e.jsx("span",{className:"text-xs text-deepwind-warning-fg",children:"-- Upgrade to unlock more seats and features"})]}),e.jsx(C,{variant:"outline",size:"sm",onClick:o,className:"border-[var(--deepwind-warning)] text-deepwind-warning-fg hover:bg-deepwind-warning-soft",children:"Upgrade Plan"})]})}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[e.jsx(_,{className:"bg-gradient-to-br from-[var(--info-soft)] to-[var(--deepwind-accent-soft)] border-[var(--info)]",children:e.jsx(z,{className:"p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 bg-[var(--info-soft)] rounded-lg",children:e.jsx(Fe,{className:"h-5 w-5 text-[var(--info-fg)]"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Seats Used"}),r?e.jsx(X,{className:"h-7 w-20 mt-1"}):e.jsxs("p",{className:"text-2xl font-bold",children:[s?.used||0,e.jsxs("span",{className:"text-sm font-normal text-muted-foreground",children:["/",s?.total||0]})]})]})]}),e.jsxs("div",{className:"text-right space-y-1",children:[r?e.jsx(X,{className:"h-2 w-16"}):e.jsx(Xa,{value:s?.percentage||0,className:"w-20 h-2"}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsxs("p",{className:"text-xs text-muted-foreground",children:[s?.remaining||0," remaining"]}),!r&&(s?.percentage||0)>=80&&e.jsx("span",{className:"text-xs font-medium text-deepwind-warning-fg",children:"Low"})]}),u&&x&&e.jsxs(C,{variant:"outline",size:"sm",onClick:x,className:"h-7 text-xs gap-1",children:[e.jsx(bs,{className:"h-3 w-3"}),"Add Seats"]}),j.visible&&e.jsxs(C,{variant:"link",size:"sm",onClick:j.navigateToBilling?l:o,className:"h-auto p-0 text-xs text-[var(--info-fg)]",children:[e.jsx(ya,{className:"h-3 w-3 mr-1"}),j.label]})]})]})})}),e.jsx(_,{className:F("bg-gradient-to-br border",t>0?"from-deepwind-warning-soft to-deepwind-warning-soft border-[var(--deepwind-warning)]":"from-deepwind-surface to-deepwind-surface border-deepwind-border"),children:e.jsx(z,{className:"p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:F("p-2 rounded-lg",t>0?"bg-deepwind-warning-soft":"bg-deepwind-bg"),children:e.jsx(is,{className:F("h-5 w-5",t>0?"text-deepwind-warning-fg":"text-muted-foreground")})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Pending Invites"}),r?e.jsx(X,{className:"h-7 w-16 mt-1"}):e.jsx("p",{className:F("text-2xl font-bold",t>0?"text-deepwind-warning-fg":""),children:t})]})]}),t>0&&e.jsxs("div",{className:"text-right",children:[e.jsx(ys,{className:"h-4 w-4 text-deepwind-warning-fg ml-auto"}),e.jsx("p",{className:"text-xs text-deepwind-warning-fg mt-1",children:"Awaiting response"})]})]})})}),e.jsx(_,{className:"bg-gradient-to-br from-[var(--success-soft)] to-[var(--success-soft)] border-[var(--success)]",children:e.jsx(z,{className:"p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 bg-[var(--success-soft)] rounded-lg",children:e.jsx(ze,{className:"h-5 w-5 text-[var(--success-fg)]"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Active Members"}),r?e.jsx(X,{className:"h-7 w-16 mt-1"}):e.jsx("p",{className:"text-2xl font-bold",children:a})]})]}),e.jsxs("div",{className:"text-right",children:[e.jsx(Rt,{className:"h-4 w-4 text-[var(--success-fg)] ml-auto"}),e.jsx("p",{className:"text-xs text-[var(--success-fg)] mt-1",children:"On the team"})]})]})})})]})]})}function Mn(){const s=de(),{toast:t}=ge(),[a,r]=m.useState({search:"",status:"all",invitationStatus:"all",limit:20,offset:0}),[d,i]=m.useState(""),[,l]=Na(),[o,x]=m.useState([]),[u,v]=m.useState(!1),[j,b]=m.useState(null),[f,N]=m.useState(!1),[n,c]=m.useState(null),[k,E]=m.useState(!1),{data:T}=Ba(),{hasMinimumRole:w}=rn(),V=w("admin"),g=cn(),A=on(),{data:R}=ue({queryKey:me.billing.subscription(),queryFn:async()=>{try{return await Ns("/api/billing/subscription")}catch{return null}},staleTime:5*60*1e3}),ne=le({mutationFn:async({userId:h,role:O})=>Q(`/api/admin/users/${h}/membership-role`,{method:"PATCH",body:{role:O}}),onSuccess:(h,O)=>{t({title:"Role Updated",description:`User role changed to ${O.role}`}),s.invalidateQueries({queryKey:me.admin.users()})},onError:h=>{t({title:"Failed to Update Role",description:h?.message||"Please try again.",variant:"destructive"})}}),{data:se,isLoading:Ne}=ue({queryKey:me.admin.seatUsage(),queryFn:async()=>{try{const h=await Q("/api/seats/current"),O=h.seatStatus||h,Z=O.summary||O;return{total:Z.totalSeats||O.seats||0,used:Z.allocatedSeats||O.seatsUsed||
20,remaining:Z.availableSeats||O.seatsAvailable||0,percentage:(Z.totalSeats||O.seats)>0?(Z.allocatedSeats||O.seatsUsed)/(Z.totalSeats||O.seats)*100:0,perSeatMonthlyCents:h.perSeatMonthlyCents||O.perSeatMonthlyCents||0,isTrialing:h.isTrialing||O.isTrialing||!1}}catch{return{total:0,used:0,remaining:0,percentage:0,perSeatMonthlyCents:0,isTrialing:!1}}},staleTime:5*60*1e3}),{data:re,isLoading:q,error:ce,refetch:ke,isFetching:Xe}=ue({queryKey:me.admin.users(a),queryFn:async()=>{const h=new URLSearchParams({search:a.search,status:a.status,invitation_status:a.invitationStatus,limit:a.limit.toString(),page:(Math.floor(a.offset/a.limit)+1).toString()});return Ns(`/api/admin/users?${h}`)}}),Ze=le({mutationFn:async h=>Q("/api/invitations/resend-by-email",{method:"POST",body:{email:h}}),onSuccess:()=>{t({title:"Invitation Resent",description:"The invitation has been resent successfully."}),s.invalidateQueries({queryKey:me.admin.users()}),b(null)},onError:h=>{t({title:"Failed to Resend Invitation",description:h?.message||"Please try again later.",variant:"destructive"}),b(null)}}),Oe=le({mutationFn:async h=>{const Z=(await Ns(`/api/invitations?status=pending&search=${encodeURIComponent(h)}`)).data?.invitations?.[0];if(!Z)throw new Error("No pending invitation found for this email");return Q(`/api/invitations/${Z.id}`,{method:"DELETE"})},onSuccess:()=>{t({title:"Invitation Revoked",description:"The invitation has been revoked."}),s.invalidateQueries({queryKey:me.admin.users()}),N(!1),c(null)},onError:h=>{t({title:"Failed to Revoke",description:h?.message||"Please try again.",variant:"destructive"})}}),ie=re?.data?.users||[],Ae=re?.data?.pagination?.total||0,qe=a.offset+a.limit<Ae,es=m.useMemo(()=>ie.filter(h=>h.invitationStatus==="pending").length,[ie]),gs=m.useMemo(()=>ie.filter(h=>h.invitationStatus==="accepted"||h.invitationStatus===null).length,[ie]),S=()=>{r(h=>({...h,search:d,offset:0}))},H=h=>{r(O=>({...O,status:h,offset:0}))},p=h=>{r(O=>({...O,invitationStatus:h,offset:0}))},y=Math.floor(a.offset/a.limit)+1,P=Math.ceil(Ae/a.limit),I=()=>{r(h=>({...h,offset:Math.max(0,h.offset-h.limit)}))},U=()=>{r(h=>({...h,offset:h.offset+h.limit}))},D=R?.subscription?.status,L=R?.subscription?.trialEndsAt,W=L?new Date(L):null,B=W?Math.max(0,Math.ceil((W.getTime()-Date.now())/(1e3*60*60*24))):null,M=R?.subscription?.tier,K=R?.subscription?.currentPeriodEnd?new Date(R.subscription.currentPeriodEnd):null,fe=h=>h?{free:"Free",starter:"Starter",prd:"PRD",professional:"Professional",enterprise:"Enterprise"}[h]||h.charAt(0).toUpperCase()+h.slice(1):null,Ve=h=>{const O=h.subscriptionStatus,Z=fe(M),he=D==="active"&&O==="trialing"?"no_seat":O;switch(he){case"no_seat":return e.jsxs("div",{className:"space-y-0.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(oe,{className:"w-3.5 h-3.5 text-muted-foreground"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"No Seat"})]}),Z&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:[Z," plan"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Seat not allocated"}),V&&se&&se.remaining>0?e.jsx(C,{variant:"link",size:"sm",className:"h-auto p-0 text-xs text-[var(--info-fg)]",disabled:g.isPending,onClick:Me=>{Me.stopPropagation(),g.mutate({userId:h.id,reason:"Admin assignment"})},children:g.isPending?"Allocating...":"Allocate seat"}):e.jsx(C,{variant:"link",size:"sm",className:"h-auto p-0 text-xs text-[var(--info-fg)]",onClick:Me=>{Me.stopPropagation(),E(!0)},children:"Add seats to allocate"})]});case"active":return e.jsxs("div",{className:"space-y-0.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(js,{className:"w-3.5 h-3.5 text-[var(--success)]"}),e.jsx("span",{className:"text-sm text-[var(--success-fg)]",children:"Active"})]}),Z&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:[Z," plan"]}),K&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Renews ",K.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})]})]});case"trialing":{const Me=W&&(B===null||B<=0);return e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("div",{className:"flex items-center gap-1.5",children:Me?e.jsxs(e.Fragment,{children:[e.jsx(oe,{className:"w-3.5 h-3.5 text-[var(--danger)]"}),e.jsx("span",{className:"text-sm text-[var(--danger-fg)]",children:"Expired"})]}):e.jsxs(e.Fragment,{children:[e.jsx(ys,{className:"w-3.5 h-3.5 text-deepwind-warning"}),e.jsx("span",{className:"text-sm text-deepwind-warning-fg",children:"Trial"})]})}),Z&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:[Z," plan"]}),W?e.jsx("p",{className:F("text-xs",Me?"text-[var(--danger-fg)]":"text-muted-foreground"),children:Me?`Expired on ${W.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}`:`Expires ${W.toLocaleDateString("en-US",{month:"short",day:"numeric"})} (${B}d)`}):e.jsx("p",{className:"text-xs text-[var(--danger-fg)]",children:"Trial expired"}),e.jsx(C,{variant:"link",size:"sm",className:"h-auto p-0 text-xs text-[var(--info-fg)]",onClick:va=>{va.stopPropagation(),l("/pricing")},children:"Subscribe now"})]})}case"past_due":return e.jsxs("div",{className:"space-y-0.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(oe,{className:"w-3.5 h-3.5 text-[var(--danger)]"}),e.jsx("span",{className:"text-sm text-[var(--danger-fg)]",children:"Past Due"})]}),Z&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:[Z," plan"]}),K&&e.jsxs("p",{className:"text-xs text-[var(--danger-fg)]",children:["Due since ",K.toLocaleDateString("en-US",{month:"short",day:"numeric"})]})]});case"canceled":return e.jsxs("div",{className:"space-y-0.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(vs,{className:"w-3.5 h-3.5 text-[var(--danger)]"}),e.jsx("span",{className:"text-sm text-[var(--danger-fg)]",children:"Expired"})]}),Z&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:[Z," plan"]}),K?e.jsxs("p",{className:"text-xs text-[var(--danger-fg)]",children:["Expired on ",
2K.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})]}):W?e.jsxs("p",{className:"text-xs text-[var(--danger-fg)]",children:["Expired on ",W.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})]}):null,e.jsx(C,{variant:"link",size:"sm",className:"h-auto p-0 text-xs text-[var(--info-fg)]",onClick:Me=>{Me.stopPropagation(),l("/pricing")},children:"Subscribe now"})]});default:return e.jsx("span",{className:"text-sm text-muted-foreground",children:he||"Unknown"})}},ut=h=>{switch(h){case"super_admin":return"Super Admin";case"admin":return"Admin";case"manager":return"Manager";default:return"Member"}},ca=h=>{const O=h.membershipRole||h.invitedRole||"member",Z=ut(O);return V?e.jsxs(it,{children:[e.jsx(lt,{asChild:!0,onClick:he=>he.stopPropagation(),children:e.jsxs(C,{variant:"ghost",size:"sm",className:"h-7 px-2 text-xs gap-1",children:[O==="admin"||O==="super_admin"?e.jsx(Rt,{className:"w-3 h-3 text-deepwind-accent"}):null,Z,e.jsx(Lt,{className:"w-3 h-3 opacity-50"})]})}),e.jsx(ct,{align:"start",onClick:he=>he.stopPropagation(),children:["admin","manager","member"].map(he=>e.jsxs(Cs,{onClick:()=>ne.mutate({userId:h.id,role:he}),disabled:he===O||ne.isPending,className:F(he===O&&"font-medium bg-muted"),children:[he===O&&e.jsx(js,{className:"w-3 h-3 mr-2"}),ut(he)]},he))})]}):e.jsx("span",{className:"text-sm",children:Z})},oa=h=>h.invitationStatus==="pending"?e.jsxs($,{variant:"outline",className:"bg-deepwind-warning-soft text-deepwind-warning-fg border-[var(--deepwind-warning)]",children:[e.jsx(ys,{className:"w-3 h-3 mr-1"}),"Pending Invite"]}):h.invitationStatus==="expired"?e.jsxs($,{variant:"destructive",children:[e.jsx(oe,{className:"w-3 h-3 mr-1"}),"Expired"]}):h.invitationStatus==="revoked"?e.jsxs($,{variant:"secondary",children:[e.jsx(fs,{className:"w-3 h-3 mr-1"}),"Revoked"]}):h.lastLoginAt?e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(js,{className:"w-3.5 h-3.5 text-[var(--success)]"}),e.jsx("span",{className:"text-sm text-[var(--success-fg)]",children:"Active"})]}):h.emailVerified?e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(js,{className:"w-3.5 h-3.5 text-[var(--info)]"}),e.jsx("span",{className:"text-sm text-[var(--info-fg)]",children:"Verified"})]}):e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(vs,{className:"w-3.5 h-3.5 text-muted-foreground"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Unverified"})]}),Vs=h=>{if(!h)return"N/A";const O=new Date(h);return isNaN(O.getTime())?"Invalid Date":O.toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"})},da=h=>(h.firstName&&h.lastName?`${h.firstName} ${h.lastName}`:h.username||h.email.split("@")[0]).split(" ").map(Z=>Z[0]).join("").slice(0,2).toUpperCase(),ma=h=>{b(h),Ze.mutate(h)},xt=h=>{c(h),N(!0)},ua=()=>{n&&Oe.mutate(n.email)},xa=(h,O)=>{x(O?Z=>[...Z,h]:Z=>Z.filter(he=>he!==h))},ha=h=>{x(h?ie.map(O=>O.id):[])},pa=h=>o.includes(h),ga=ie.length>0&&o.length===ie.length,fa=ie.filter(h=>o.includes(h.id)),ja=a.search||a.status!=="all"||a.invitationStatus!=="all";return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold tracking-tight",children:"Team Management"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Manage team members, invitations, and roles"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(C,{onClick:()=>v(!0),variant:"default",size:"sm",children:[e.jsx(_e,{className:"w-4 h-4 mr-2"}),"Invite User"]}),e.jsxs(C,{onClick:()=>ke(),disabled:Xe,variant:"outline",size:"sm",children:[e.jsx(Ss,{className:F("w-4 h-4 mr-2",Xe&&"animate-spin")}),"Refresh"]})]})]}),e.jsx(Ln,{seatData:se,pendingCount:es,activeCount:gs,isLoading:Ne||q,subscriptionStatus:D||T?.subscriptionStatus,planId:M||T?.planId,onNavigateToBilling:()=>l("/pricing"),onOpenUpgradeModal:()=>l("/pricing"),onAddSeats:()=>E(!0),isAdmin:V}),e.jsxs(_,{children:[e.jsxs(Le,{className:"pb-3",children:[e.jsxs(He,{className:"flex items-center text-base",children:[e.jsx(Ps,{className:"w-4 h-4 mr-2"}),"Search & Filters"]}),e.jsx(st,{className:"text-xs",children:"Search by username or email, and filter by provider, status, or invitation state"})]}),e.jsxs(z,{children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4",children:[e.jsx("div",{className:"md:col-span-2",children:e.jsxs("div",{className:"flex space-x-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(We,{className:"absolute left-2 top-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(ee,{placeholder:"Search by username or email...",value:d,onChange:h=>i(h.target.value),onKeyDown:h=>h.key==="Enter"&&S(),className:"pl-8"})]}),e.jsx(C,{onClick:S,children:"Search"})]})}),e.jsxs(De,{value:a.status,onValueChange:H,children:[e.jsx(Pe,{children:e.jsx($e,{placeholder:"All Statuses"})}),e.jsxs(Re,{children:[e.jsx(te,{value:"all",children:"All Statuses"}),e.jsx(te,{value:"active",children:"Active"}),e.jsx(te,{value:"suspended",children:"Suspended"}),e.jsx(te,{value:"verified",children:"Verified"}),e.jsx(te,{value:"unverified",children:"Unverified"})]})]}),e.jsxs(De,{value:a.invitationStatus,onValueChange:p,children:[e.jsx(Pe,{children:e.jsx($e,{placeholder:"All Invitations"})}),e.jsxs(Re,{children:[e.jsx(te,{value:"all",children:"All Invitations"}),e.jsx(te,{value:"pending",children:"Pending Invite"}),e.jsx(te,{value:"accepted",children:"Accepted"}),e.jsx(te,{value:"expired",children:"Expired"}),e.jsx(te,{value:"revoked",children:"Revoked"}),e.jsx(te,{value:"none",children:"No Invitation"})]})]})]}),ja&&e.jsxs("div",{className:"mt-4 flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Active filters:"}),a.search&&e.jsxs($,{variant:"secondary",children:["Search: ",a.search]}),a.status!=="all"&&e.jsxs($,{variant:"secondary",children:["Status: ",a.status]}),a.invitationStatus!=="all"&&e.jsxs($,{variant:"secondary",children:["Invitation: ",a.inv
2itationStatus]}),e.jsx(C,{variant:"ghost",size:"sm",onClick:()=>{r({search:"",status:"all",invitationStatus:"all",limit:20,offset:0}),i("")},children:"Clear all"})]})]})]}),e.jsxs(_,{children:[e.jsx(Le,{className:"pb-3",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs(He,{className:"flex items-center text-base",children:[e.jsx(Be,{className:"w-4 h-4 mr-2"}),"Users (",Ae,")"]}),e.jsxs(st,{className:"text-xs",children:["Showing ",ie.length," of ",Ae," users"]})]}),e.jsxs("div",{className:"text-sm text-muted-foreground",children:["Page ",y," of ",P]})]})}),e.jsxs(z,{children:[e.jsx(En,{selectedUserIds:o,selectedUsers:fa,onClearSelection:()=>x([])}),q&&e.jsx("div",{className:"space-y-3",children:[...Array(5)].map((h,O)=>e.jsx(X,{className:"h-16 w-full"},O))}),ce&&e.jsxs("div",{className:"flex items-center justify-center p-8 text-destructive",children:[e.jsx(oe,{className:"w-5 h-5 mr-2"}),e.jsx("span",{children:"Failed to load users. Please try again."})]}),!q&&!ce&&ie.length===0&&e.jsxs("div",{className:"flex flex-col items-center justify-center p-12 text-muted-foreground",children:[e.jsx(Be,{className:"w-12 h-12 mb-4 opacity-50"}),e.jsx("p",{className:"text-lg font-medium",children:"No users found"}),e.jsx("p",{className:"text-sm mb-4",children:"Try adjusting your search filters"}),e.jsxs(C,{onClick:()=>v(!0),children:[e.jsx(_e,{className:"w-4 h-4 mr-2"}),"Invite User"]})]}),!q&&!ce&&ie.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"border rounded-lg overflow-hidden",children:e.jsxs(ks,{children:[e.jsx(As,{children:e.jsxs(be,{children:[e.jsx(ae,{className:"w-12",children:e.jsx(rs,{checked:ga,onCheckedChange:ha,"aria-label":"Select all users"})}),e.jsx(ae,{children:"User"}),e.jsx(ae,{children:"Email"}),e.jsx(ae,{children:"Subscription"}),e.jsx(ae,{children:"Role"}),e.jsx(ae,{children:"Account State"}),e.jsx(ae,{children:"Joined/Invited"}),e.jsx(ae,{className:"text-right",children:"Actions"})]})}),e.jsx(Es,{children:ie.map(h=>e.jsxs(be,{className:F("cursor-pointer",h.invitationStatus==="pending"&&"bg-deepwind-warning-soft",h.invitationStatus==="expired"&&"bg-[var(--danger-soft)]"),onClick:()=>l(`/admin/users/${h.id}`),children:[e.jsx(G,{onClick:O=>O.stopPropagation(),children:e.jsx(rs,{checked:pa(h.id),onCheckedChange:O=>xa(h.id,O),"aria-label":`Select ${h.firstName&&h.lastName?`${h.firstName} ${h.lastName}`:h.username||h.email}`})}),e.jsx(G,{children:e.jsxs("div",{className:"flex items-center space-x-2",children:[h.avatarUrl?e.jsx("img",{src:h.avatarUrl,alt:"",className:"w-8 h-8 rounded-full object-cover"}):e.jsx("div",{className:"w-8 h-8 rounded-full bg-gradient-to-br from-[var(--info-soft)] to-[var(--deepwind-accent-soft)] flex items-center justify-center text-xs font-medium text-[var(--info-fg)]",children:da(h)}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:h.firstName&&h.lastName?`${h.firstName} ${h.lastName}`:h.username||"N/A"}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["ID: ",h.id.substring(0,8),"..."]})]})]})}),e.jsx(G,{children:e.jsxs("div",{className:"flex items-center space-x-1",children:[e.jsx(is,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm",children:h.email})]})}),e.jsx(G,{children:Ve(h)}),e.jsx(G,{children:ca(h)}),e.jsx(G,{children:oa(h)}),e.jsx(G,{children:e.jsx("div",{className:"flex flex-col text-sm",children:h.invitationStatus==="pending"&&h.invitedAt?e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"text-deepwind-warning-fg",children:["Invited ",Vs(h.invitedAt)]}),h.invitedBy&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["by ",h.invitedBy.firstName," ",h.invitedBy.lastName]})]}):h.acceptedAt?e.jsxs("span",{className:"text-[var(--success-fg)]",children:["Joined ",Vs(h.acceptedAt)]}):e.jsx("span",{className:"text-muted-foreground",children:Vs(h.createdAt)})})}),e.jsx(G,{className:"text-right",onClick:O=>O.stopPropagation(),children:e.jsxs("div",{className:"flex items-center justify-end gap-1",children:[h.invitationStatus==="pending"&&e.jsxs(e.Fragment,{children:[e.jsxs(C,{variant:"ghost",size:"sm",onClick:()=>ma(h.email),disabled:j===h.email,children:[j===h.email?e.jsx(Y,{className:"w-4 h-4 mr-1 animate-spin"}):e.jsx(Fs,{className:"w-4 h-4 mr-1"}),"Resend"]}),e.jsxs(C,{variant:"ghost",size:"sm",onClick:()=>xt(h),className:"text-[var(--danger)] hover:text-[var(--danger-fg)] hover:bg-[var(--danger-soft)]",children:[e.jsx(fs,{className:"w-4 h-4 mr-1"}),"Revoke"]})]}),h.invitationStatus==="expired"&&e.jsxs(C,{variant:"ghost",size:"sm",onClick:()=>xt(h),className:"text-[var(--danger)] hover:text-[var(--danger-fg)] hover:bg-[var(--danger-soft)]",children:[e.jsx(fs,{className:"w-4 h-4 mr-1"}),"Revoke"]}),V&&h.invitationStatus!=="pending"&&h.subscriptionStatus!=="active"&&se&&se.remaining>0&&e.jsxs(C,{variant:"ghost",size:"sm",onClick:()=>g.mutate({userId:h.id,reason:"Admin assignment"}),disabled:g.isPending,className:"text-[var(--success-fg)] hover:text-[var(--success-fg)] hover:bg-[var(--success-soft)]",children:[g.isPending?e.jsx(Y,{className:"w-4 h-4 mr-1 animate-spin"}):e.jsx(_e,{className:"w-4 h-4 mr-1"}),"Assign Seat"]}),V&&h.invitationStatus!=="pending"&&h.subscriptionStatus==="active"&&e.jsxs(C,{variant:"ghost",size:"sm",onClick:()=>A.mutate({userId:h.id}),disabled:A.isPending,className:"text-[var(--danger)] hover:text-[var(--danger-fg)] hover:bg-[var(--danger-soft)]",children:[A.isPending?e.jsx(Y,{className:"w-4 h-4 mr-1 animate-spin"}):e.jsx(vs,{className:"w-4 h-4 mr-1"}),"Remove Seat"]}),e.jsx(C,{variant:"ghost",size:"sm",onClick:()=>l(`/admin/users/${h.id}`),children:"View"})]})})]}
2,h.id))})]})}),e.jsxs("div",{className:"flex items-center justify-between mt-4",children:[e.jsxs("div",{className:"text-sm text-muted-foreground",children:["Showing ",a.offset+1," to ",Math.min(a.offset+a.limit,Ae)," of ",Ae," users"]}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(C,{variant:"outline",size:"sm",onClick:I,disabled:a.offset===0,children:"Previous"}),e.jsx(C,{variant:"outline",size:"sm",onClick:U,disabled:!qe,children:"Next"})]})]})]})]})]}),V&&e.jsx(Pn,{users:ie}),e.jsx(cs,{open:f,onOpenChange:N,children:e.jsxs(os,{children:[e.jsxs(ds,{children:[e.jsx(ms,{children:"Revoke Invitation?"}),e.jsxs(us,{children:["Are you sure you want to revoke the invitation for"," ",e.jsx("span",{className:"font-medium text-foreground",children:n?.email}),"? They will no longer be able to accept this invitation."]})]}),e.jsxs(xs,{children:[e.jsx(hs,{children:"Cancel"}),e.jsx(ps,{onClick:ua,disabled:Oe.isPending,className:"bg-[var(--danger)] hover:bg-[var(--danger)] text-deepwind-text-on-accent",children:Oe.isPending?e.jsxs(e.Fragment,{children:[e.jsx(Y,{className:"w-4 h-4 mr-2 animate-spin"}),"Revoking..."]}):e.jsxs(e.Fragment,{children:[e.jsx(fs,{className:"w-4 h-4 mr-2"}),"Revoke"]})})]})]})}),e.jsx(Tn,{open:u,onOpenChange:v}),e.jsx(nn,{open:k,onOpenChange:E,currentSeats:se?.total||0,allocatedSeats:se?.used||0,perSeatMonthlyCents:se?.perSeatMonthlyCents||0,isTrialing:se?.isTrialing||!1})]})}const xe={all:()=>ye(["absences"]),lists:()=>[...xe.all(),"list"],list:s=>[...xe.lists(),s],employee:s=>[...xe.lists(),{employeeId:s}],pending:()=>[...xe.all(),"pending"],approvals:()=>[...xe.all(),"approvals"],availability:(s,t,a)=>[...xe.all(),"availability",s,t,a],teamAvailability:s=>[...xe.all(),"team-availability",s||"current"]};async function In(s={}){const t=new URLSearchParams;s.employeeId&&t.set("employeeId",s.employeeId),s.startDate&&t.set("startDate",s.startDate),s.endDate&&t.set("endDate",s.endDate),s.status&&t.set("status",s.status),s.type&&t.set("type",s.type);const a=`/api/absences?${t.toString()}`,r=await Q(a);return r.data??r.absences??[]}async function Fn(){return(await Q("/api/absences/pending-approvals")).approvals}async function $n({id:s,data:t}){return await Q(`/api/absences/${s}/approve`,{method:"POST",body:t||{}})}async function On({id:s,data:t}){return await Q(`/api/absences/${s}/reject`,{method:"POST",body:t})}function qn(s,t={}){return ue({queryKey:xe.employee(s),queryFn:()=>In({employeeId:s,...t}),enabled:!!s,staleTime:6e4,refetchInterval:6e4})}function Vn(){return ue({queryKey:xe.pending(),queryFn:Fn,staleTime:5e3,refetchInterval:1e4})}function Un(){const s=de();return le({mutationFn:$n,onSuccess:t=>{s.invalidateQueries({queryKey:xe.pending()}),s.invalidateQueries({queryKey:xe.employee(t.employeeId)}),s.invalidateQueries({queryKey:xe.all()}),s.invalidateQueries({queryKey:xe.teamAvailability()}),s.invalidateQueries({queryKey:xe.lists()})}})}function _n(){const s=de();return le({mutationFn:On,onSuccess:t=>{s.invalidateQueries({queryKey:xe.pending()}),s.invalidateQueries({queryKey:xe.employee(t.employeeId)}),s.invalidateQueries({queryKey:xe.lists()})}})}const we={all:()=>ye(["deduplication"]),conflicts:()=>[...we.all(),"conflicts"],conflict:s=>[...we.all(),"conflict",s]};function Xt(s){return{id:s.id,tenantId:"",primaryEmployeeId:s.employeeAId,primaryEmployee:s.employeeA,secondaryEmployeeId:s.employeeBId,secondaryEmployee:s.employeeB,confidenceScore:Math.round(s.similarityScore*100),matchingFields:s.matchingFields,status:s.status,resolution:s.status==="MERGED"?"MERGE":s.status==="FALSE_POSITIVE"?"KEEP_BOTH":null,resolvedAt:s.reviewedAt,resolvedBy:s.reviewedBy,createdAt:s.createdAt}}async function zn(){return(await Q("/api/admin/employees/duplicates/candidates?status=pending")).candidates.map(Xt)}async function Zt({matchId:s,action:t,primaryId:a,secondaryId:r}){const i={action:t==="MERGE"?"merge":"false_positive",sourceEmployeeId:r,targetEmployeeId:a},l=await Q(`/api/admin/employees/duplicates/${s}/review`,{method:"POST",body:i});return Xt(l)}async function Bn(s){let t=0,a=0;for(const r of s)try{await Zt(r),t++}catch{a++}return{resolved:t,failed:a}}async function Kn(s){return Q("/api/admin/employees/merge/preview",{method:"POST",body:s})}async function Qn(s){return Q("/api/admin/employees/merge",{method:"POST",body:s})}async function Hn(s){return Q(`/api/admin/employees/${s}/merge-history`)}async function Wn(){return Q("/api/admin/employees/merges/history")}async function Gn(){return Q("/api/admin/employees/duplicates/stats")}async function Jn(){return Q("/api/admin/employees/duplicates/run-detection?dryRun=false",{method:"POST"})}async function Yn(s,t){return Q(`/api/admin/employees/merges/${s}/revert`,{method:"POST",body:{reason:t}})}function Xn(){return ue({queryKey:we.conflicts(),queryFn:zn,staleTime:3e4,refetchInterval:3e4})}function Zn(){return le({mutationFn:Kn})}function er(){const s=de();return le({mutationFn:Zt,onSuccess:()=>{s.invalidateQueries({queryKey:we.conflicts()}),s.invalidateQueries({queryKey:ye(["employees"])})}})}function sr(){const s=de();return le({mutationFn:Bn,onSuccess:()=>{s.invalidateQueries({queryKey:we.conflicts()}),s.invalidateQueries({queryKey:ye(["employees"])})}})}function tr(){const s=de();return le({mutationFn:Qn,onSuccess:()=>{s.invalidateQueries({queryKey:we.conflicts()}),s.invalidateQueries({queryKey:ye(["employees"])})}})}
2function ar(s){return ue({queryKey:[...we.all(),"history",s],queryFn:()=>Hn(s),enabled:!!s})}function nr(){return ue({queryKey:[...we.all(),"history","all"],queryFn:Wn,staleTime:3e4})}function rr(){return ue({queryKey:[...we.all(),"stats"],queryFn:Gn,staleTime:6e4})}function ir(){const s=de();return le({mutationFn:Jn,onSuccess:()=>{s.invalidateQueries({queryKey:we.conflicts()}),s.invalidateQueries({queryKey:[...we.all(),"stats"]})}})}function lr(){const s=de();return le({mutationFn:({mergeId:t,reason:a})=>Yn(t,a),onSuccess:()=>{s.invalidateQueries({queryKey:we.conflicts()}),s.invalidateQueries({queryKey:ye(["employees"])}),s.invalidateQueries({queryKey:[...we.all(),"stats"]})}})}function cr(s,t){if(!s||!t)return 0;const a=s.toLowerCase().trim(),r=t.toLowerCase().trim();if(a===r)return 100;const d=a.length,i=r.length,l=[];for(let u=0;u<=d;u++)l[u]=[u];for(let u=0;u<=i;u++)l[0][u]=u;for(let u=1;u<=d;u++)for(let v=1;v<=i;v++){const j=a[u-1]===r[v-1]?0:1;l[u][v]=Math.min(l[u-1][v]+1,l[u][v-1]+1,l[u-1][v-1]+j)}const o=l[d][i],x=Math.max(d,i);return Math.round((x-o)/x*100)}function or(s){const t=[];return s.matchingFields.includes("email")&&t.push("email matches"),s.matchingFields.includes("name")&&t.push("name is similar"),s.matchingFields.includes("phone")&&t.push("phone matches"),s.matchingFields.includes("department")&&t.push("same department"),t.length===0?"Multiple fields match":t.join(", ")}function dr(s){return s>=90?{label:"Very High",color:"text-green-600"}:s>
2=75?{label:"High",color:"text-green-500"}:s>=60?{label:"Medium",color:"text-yellow-500"}:{label:"Low",color:"text-orange-500"}}function mr(s){return{pending:s.filter(t=>t.status==="PENDING"||t.status==="REVIEWED"),resolved:s.filter(t=>t.status==="MERGED"||t.status==="FALSE_POSITIVE")}}const ft={all:()=>ye(["employee-skill-overrides"]),byEmail:s=>[...ye(["employee-skill-overrides"]),s]};function jt(s){const t=de(),{toast:a}=ge(),{reportError:r}=nt("employee-skill-overrides"),d=ue({queryKey:ft.byEmail(s),queryFn:()=>Q(`/api/employees/skills?email=${encodeURIComponent(s)}`),enabled:!!s,staleTime:6e4}),i=le({mutationFn:l=>Q("/api/employees/skill-overrides",{method:"PUT",body:{email:s,overrides:l}}),onSuccess:()=>{t.invalidateQueries({queryKey:ft.byEmail(s)}),t.invalidateQueries({queryKey:ye(["skill-coverage"])}),t.invalidateQueries({queryKey:ye(["capacity-baseline"])}),t.invalidateQueries({queryKey:ye(["employees"])}),a({title:"Skill overrides saved"})},onError:l=>{l.status&&l.status>=500&&r(l,{endpoint:"/api/unknown"}),a({title:"Failed to save skill overrides",description:l.message||"An unexpected error occurred.",variant:"destructive"})}});return{...d,saveOverrides:i}}const dt={all:()=>ye(["unmapped-assignees"]),list:()=>[...dt.all(),"list"]};async function ur(){return Q("/api/admin/unmapped-assignees")}async function xr(s){return Q("/api/admin/unmapped-assignees/map",{method:"POST",body:s})}function hr(){return ue({queryKey:dt.list(),queryFn:ur,staleTime:6e4,select:s=>s.data})}function ea(){const s=de(),{reportError:t}=nt("identity-mapping");return le({mutationFn:xr,onSuccess:()=>{s.invalidateQueries({queryKey:dt.list()})},onError:a=>{a.message&&parseInt(a.message)>=500&&t(a)}})}function sa({velocityDataSource:s="none",estimatedVelocityPerSprint:t,hasExtractedSkills:a=!1,compact:r=!1}){const d=bn(s,t);if(r){if(s==="none")return e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsxs($,{variant:"outline",className:F("text-muted-foreground border-dashed cursor-pointer","hover:bg-accent hover:text-foreground transition-colors gap-1"),children:[e.jsx(Us,{className:"h-3 w-3"}),"Set Skills"]}),a&&e.jsxs($,{variant:"outline",className:"bg-deepwind-accent-soft text-deepwind-accent border-deepwind-accent-border gap-0.5 px-1.5",children:[e.jsx(Zs,{className:"h-3 w-3"}),"Extracted"]})]});if(s==="extracted")return t?e.jsx(ss,{value:t,provenance:d,density:"inline-badge",unit:"SP"}):e.jsxs($,{className:F("bg-[var(--info-soft)] text-[var(--info-fg)] border-[var(--info)] cursor-pointer","bg-[var(--info)] text-[var(--info-fg)] border-[var(--info)]","hover:bg-[var(--info-soft)] transition-colors gap-1"),children:[e.jsx(Us,{className:"h-3 w-3"}),"Auto"]});if(s==="admin_verified")return e.jsxs("span",{className:"inline-flex items-center gap-1",children:[t?e.jsx(ss,{value:t,provenance:d,density:"inline-badge",unit:"SP"}):e.jsxs($,{className:F("bg-[var(--success-soft)] text-[var(--success-fg)] border-[var(--success)] cursor-pointer","bg-[var(--success)] text-[var(--success-fg)] border-[var(--success)]","hover:bg-[var(--success-soft)] transition-colors gap-1"),children:[e.jsx(Us,{className:"h-3 w-3"}),"Verified"]}),a&&e.jsxs($,{variant:"outline",className:"bg-deepwind-accent-soft text-deepwind-accent border-deepwind-accent-border gap-0.5 px-1.5",children:[e.jsx(Zs,{className:"h-3 w-3"}),"Extracted"]})]})}return s==="none"?e.jsx($,{variant:"outline",className:"text-muted-foreground dark:text-muted-foreground",children:"No velocity data"}):s==="extracted"?e.jsx($,{className:F("bg-[var(--info-soft)] text-[var(--info-fg)] border-[var(--info)]","bg-[var(--info)] text-[var(--info-fg)] border-[var(--info)]"),children:"Auto-classified"}):s==="admin_verified"?e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx($,{className:F("bg-[var(--success-soft)] text-[var(--success-fg)] border-[var(--success)]","bg-[var(--success)] text-[var(--success-fg)] border-[var(--success)]"),children:"Admin verified"}),t?e.jsx(ss,{value:t,provenance:d,density:"inline-badge",unit:"SP/sprint"}):null]}):null}function Is(s){return s.replace(/&amp;/g,"&").replace(/&#x2F;/g,"/").replace(/&#47;/g,"/").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').replace(/&#39;/g,"'")}const vt={backend:[{label:"Languages",skills:["Python","Node.js","Java","Go","TypeScript","Ruby","C#","PHP","Rust","Kotlin"]},{label:"Data",skills:["Postgresql","MongoDB","Redis","MySQL","Elasticsearch","DynamoDB","Sql"]},{label:"Frameworks",skills:["Express","FastAPI","Django","Spring Boot","Rails","Laravel","Flask"]},{label:"APIs & Integration",skills:["Api Design","GraphQL","Mulesoft","Stripe","Oauth2","Jwt"]}],frontend:[{label:"Frameworks",skills:["React","Angular","Vue","Next.js","Svelte"]},{label:"Core",skills:["TypeScript","Javascript","Html","Css","Tailwind","SASS"]}
2,{label:"UI/UX",skills:["Ui Design","Ui Components","Responsive Design","User Experience (ux) Design","Data Visualization"]},{label:"Testing",skills:["Ui Testing","E2E Testing","Testing Frameworks"]}],devops:[{label:"Cloud",skills:["Aws","Azure","GCP","Serverless","CloudFormation","Terraform"]},{label:"Containers",skills:["Docker","Kubernetes","Helm"]},{label:"CI/CD",skills:["CI/CD","GitHub Actions","GitLab CI","Jenkins"]},{label:"Data Ops",skills:["Airflow","Etl","S3","Snowflake","Monitoring","Logging"]}],qa:[{label:"Testing",skills:["Unit Testing","Integration Testing","E2E Testing","Performance Testing","Security Testing","QA Testing"]}]},Nt={FRONTEND:["frontend"],BACKEND:["backend"],FULLSTACK:["frontend","backend"],DEVOPS:["devops"],QA:["qa"],AI_ML:["data"],DATA:["data"],PRODUCT:["general"],DESIGN:["frontend"],OTHER:["general"]};function pr({row:s,overrideValue:t,laneTotal:a,onChange:r,onRemove:d}){const i=`${s.schedulerCategory}::${s.skillName}`,l=t!==""&&parseFloat(t)||0,o=a>0&&l>a;return e.jsxs("div",{className:"flex items-center gap-2 py-1.5 group",children:[e.jsxs("span",{className:"flex-1 text-sm text-foreground truncate",title:Is(s.skillName),children:[Is(s.skillName),!s.isAdminAdded&&e.jsx("span",{className:"ml-1.5 text-[10px] text-[var(--info)] font-medium",title:"Discovered via extraction",children:"extracted"})]}),e.jsx(ee,{type:"number",min:0,max:999,step:1,value:t,onChange:x=>r(i,x.target.value),placeholder:s.systemVelocity!==null?String(s.systemVelocity):"0",autoComplete:"off","data-1p-ignore":!0,"data-lpignore":"true",className:F("w-20 h-7 text-sm text-right",o&&"border-[var(--deepwind-warning)]"),"aria-label":`SP capacity for ${s.skillName}`}),e.jsx("button",{type:"button",onClick:()=>d(i),className:"text-xs text-muted-foreground/50 hover:text-destructive opacity-0 group-hover:opacity-100 transition-opacity shrink-0","aria-label":`Remove ${s.skillName}`,children:"x"})]})}const gr=new Set;function fr({category:s,existingSkillNames:t,allAssignedSkills:a=gr,taxonomySkillsByCategory:r,onAdd:d}){const[i,l]=m.useState(""),[o,x]=m.useState(!1),u=new Set(t.map(n=>n.toLowerCase())),v=(r.get(s)??[]).filter(n=>!u.has(n.toLowerCase())),j=Ue.useMemo(()=>{const n=i.trim().toLowerCase();if(n.length<2)return[];const c=[];for(const[E,T]of r)for(const w of T)w.toLowerCase().includes(n)&&c.push({name:w,category:E,isInTaxonomy:!0,isAssigned:a.has(w.toLowerCase()),isThisLane:E===s&&u.has(w.toLowerCase())});return!c.some(E=>E.isInTaxonomy&&E.name.toLowerCase()===n)&&n.length>=2&&c.push({name:i.trim(),category:null,isInTaxonomy:!1,isAssigned:a.has(n),isThisLane:u.has(n)}),c.slice(0,12)},[i,r,a,u,s]),b=n=>{a.has(n.toLowerCase())||(d(s,n),l(""))},f=o&&i.trim().length>=2&&j.length>0,N=Ue.useMemo(()=>{const n=i.trim().toLowerCase();return n.length<1?v:v.filter(c=>c.toLowerCase().includes(n))},[v,i]);return e.jsxs("div",{className:"pt-2 space-y-2",children:[e.jsxs("div",{className:"relative",children:[e.jsx(ee,{type:"text",value:i,onChange:n=>l(n.target.value),onFocus:()=>x(!0),onBlur:()=>setTimeout(()=>x(!1),200),onKeyDown:n=>{if(n.key==="Enter"){n.preventDefault();const c=i.trim();if(!c)return;const k=j.filter(T=>!T.isAssigned&&!T.isThisLane),E=k.find(T=>T.isInTaxonomy&&T.name.toLowerCase()===c.toLowerCase());E?b(E.name):k.length===1?b(k[0].name):a.has(c.toLowerCase())||b(c)}n.key==="Escape"&&(l(""),n.target.blur())},placeholder:"Search skills or type custom...",className:"h-7 text-sm","aria-label":`Search skills for ${s} lane`}),f&&e.jsx("ul",{className:"absolute top-full left-0 right-0 mt-1 z-20 bg-popover border border-border rounded-md shadow-lg py-1 max-h-48 overflow-y-auto",children:j.map(n=>e.jsx("li",{children:e.jsxs("button",{type:"button",disabled:n.isAssigned,onMouseDown:c=>c.preventDefault(),onClick:()=>b(n.name),className:F("w-full text-left px-3 py-1.5 text-sm flex items-center justify-between gap-2",n.isAssigned?"opacity-40 cursor-not-allowed":"hover:bg-accent cursor-pointer"),children:[e.jsxs("span",{className:"truncate",children:[n.name,n.isInTaxonomy&&n.category!==s&&e.jsxs("span",{className:"ml-1.5 text-[10px] text-muted-foreground",children:["(",n.category,")"]})]}),e.jsxs("span",{className:"shrink-0 flex items-center gap-1",children:[n.isAssigned&&e.jsx("span",{className:"text-[10px] text-deepwind-warning",children:"assigned"}),n.isInTaxonomy?e.jsx("span",{className:"text-[10px] text-[var(--success)]",children:"taxonomy"}):e.jsx("span",{className:"text-[10px] text-muted-foreground",children:"custom"})]})]})},`${n.name}-${n.category}`))})]}),N.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5",children:N.map(n=>{const c=a.has(n.toLowerCase())&&!u.has(n.toLowerCase());return e.jsxs("button",{type:"button",onClick:()=>
2!c&&d(s,n),disabled:c,className:F("text-xs px-2 py-1 rounded-md border border-dashed border-border transition-colors",c?"opacity-40 cursor-not-allowed line-through":"text-muted-foreground hover:text-foreground hover:bg-accent hover:border-foreground/20"),"aria-label":c?`${n} already assigned in another lane`:`Add ${n} to ${s}`,title:c?"Already assigned in another lane":void 0,children:["+ ",n]},n)})})]})}function jr({existingCategories:s,allLanes:t,onAdd:a}){const r=t.filter(l=>!s.includes(l.id)),[d,i]=m.useState(!1);return r.length===0?null:e.jsxs("div",{className:"relative mt-2",children:[e.jsx("button",{type:"button",onClick:()=>i(l=>!l),className:F("text-sm px-3 py-1.5 rounded border border-dashed border-border","text-muted-foreground hover:text-foreground hover:border-border/80 hover:bg-accent","transition-colors w-full text-left"),"aria-expanded":d,"aria-haspopup":"listbox",children:"+ Add Lane"}),d&&e.jsx("ul",{role:"listbox",className:F("absolute top-full left-0 mt-1 z-10 min-w-[160px]","bg-popover border border-border rounded shadow-md py-1"),children:r.map(l=>e.jsx("li",{children:e.jsx("button",{type:"button",role:"option","aria-selected":!1,onClick:()=>{a(l.id),i(!1)},className:"w-full text-left px-3 py-1.5 text-sm hover:bg-accent",children:l.label})},l.id))})]})}function ta({open:s,onOpenChange:t,employee:a,onUpdateEmployee:r}){const{data:d,isLoading:i,isError:l}=jt(s?a.email:""),{saveOverrides:o}=jt(a.email),{lanes:x,laneLabelMap:u}=wn(),v=Ue.useMemo(()=>x.map(p=>({id:p.id,label:p.label})),[x]),j=Ue.useMemo(()=>x.map(p=>p.id),[x]),{data:b}=Cn(),f=Ue.useMemo(()=>{const p=new Map;if(!b?.skills)return p;for(const y of b.skills){const P=y.schedulerCategory;P&&(p.has(P)||p.set(P,[]),p.get(P).push(y.canonicalSkillName))}for(const[,y]of p)y.sort((P,I)=>P.localeCompare(I));return p},[b]),[N,n]=m.useState(new Map),[c,k]=m.useState({}),[E,T]=m.useState([]),[w,V]=m.useState([]),[g,A]=m.useState(new Map),[R,ne]=m.useState(null),[se,Ne]=m.useState(new Set);m.useEffect(()=>{if(!d?.data)return;const p=d.data.categories,y={};for(const M of j)y[M]=[];const P=new Map,I=[];for(const M of Object.keys(p))if(p[M]){I.push(M),y[M]||(y[M]=[]);for(const K of p[M].skills){const fe={skillName:K.skillName,schedulerCategory:M,systemVelocity:K.systemVelocity,systemProficiency:K.systemProficiency,isAdminAdded:K.isAdminAdded};y[M].push(fe);const Ve=`${M}::${K.skillName}`;K.overrideVelocity!==null&&P.set(Ve,String(K.overrideVelocity))}}const U=new Map;for(const M of Object.keys(p))if(p[M]){for(const K of p[M].skills)(K.skillName==="__lane_total__"||K.skillName===`__lane_total__::${M}`)&&K.overrideVelocity!==null&&U.set(M,String(K.overrideVelocity));y[M]&&(y[M]=y[M].filter(K=>!K.skillName.startsWith("__lane_total__")))}k(y),n(P),A(U);const D=a.primarySpecialization||"",L=(Nt[D]??[]).filter(M=>j.includes(M)),W=new Set([...I,...L]),B=Array.from(W);T(B),V(B)},[d,j]);const re=m.useCallback((p,y)=>{n(P=>{const I=new Map(P);return y===""?I.delete(p):I.set(p,y),I})},[]),q=Ue.useMemo(()=>{const p=new Set;for(const y of Object.values(c))for(const P of y)p.add(P.skillName.toLowerCase());return p},[c]),ce=m.useCallback((p,y)=>{k(P=>{const I=P[p]??[];if(I.some(B=>B.skillName.toLowerCase()===y.toLowerCase()))return P;for(const[B,M]of Object.entries(P))if(B!==p&&M.some(K=>K.skillName.toLowerCase()===y.toLowerCase()))return P;const U={skillName:y,schedulerCategory:p,systemVelocity:null,systemProficiency:null,isAdminAdded:!0},D=[...I,U],L=D.every(B=>B.isAdminAdded),W=parseFloat(g.get(p)??"")||0;if(W>0&&L){const B=Math.round(W/D.length*100)/100;setTimeout(()=>{n(M=>{const K=new Map(M);return D.forEach(fe=>{K.set(`${p}::${fe.skillName}`,String(B))}),K})},0)}return{...P,[p]:D}})},[g]),ke=m.useCallback(p=>{const[y,P]=p.split("::");k(I=>({...I,[y]:(I[y]??[]).filter(U=>U.skillName!==P)})),n(I=>{const U=new Map(I);return U.delete(p),U})},[]);m.useCallback(p=>{k(y=>{const P=new Set;for(const[,M]of Object.entries(y))for(const K of M)P.add(K.skillName.toLowerCase());const I=(f.get(p)??[]).filter(M=>!P.has(M.toLowerCase()));if(I.length===0)return y;const U=y[p]??[],D=I.map(M=>({skillName:M,schedulerCategory:p,systemVelocity:null,systemProficiency:null,isAdminAdded:!0})),L=[...U,...D],W=L.every(M=>
2M.isAdminAdded),B=parseFloat(g.get(p)??"")||0;if(B>0&&L.length>0&&W){const M=Math.round(B/L.length*100)/100;setTimeout(()=>{n(K=>{const fe=new Map(K);return L.forEach(Ve=>{fe.set(`${p}::${Ve.skillName}`,String(M))}),fe})},0)}return{...y,[p]:L}})},[f,g]);const Xe=m.useCallback(p=>{k(y=>({...y,[p]:[]})),n(y=>{const P=new Map(y);for(const I of Array.from(P.keys()))I.startsWith(`${p}::`)&&P.delete(I);return P})},[]),Ze=m.useCallback(p=>{T(y=>{const P=y.includes(p)?y:[...y,p];if(!y.includes(p)&&a.estimatedVelocityPerSprint){const I=Array.from(g.values()).reduce((D,L)=>D+(parseFloat(L)||0),0),U=Math.max(0,a.estimatedVelocityPerSprint-I);U>0&&A(D=>{const L=new Map(D);return L.has(p)||L.set(p,String(Math.round(U*10)/10)),L})}return P}),k(y=>y[p]?y:{...y,[p]:[]}),V(y=>y.includes(p)?y:[...y,p])},[a.estimatedVelocityPerSprint,g]),Oe=m.useCallback(p=>{R===p?(k(y=>({...y,[p]:[]})),n(y=>{const P=new Map(y);for(const I of Array.from(P.keys()))I.startsWith(`${p}::`)&&P.delete(I);return P}),A(y=>{const P=new Map(y);return P.delete(p),P}),T(y=>y.filter(P=>P!==p)),ne(null)):ne(p)},[R]),ie=m.useCallback(()=>ne(null),[]),Ae=Ue.useMemo(()=>{let p=0;for(const y of E){const P=g.get(y);p+=P!==void 0&&P!==""&&parseFloat(P)||0}return Math.round(p*10)/10},[E,g]),qe=m.useCallback(async()=>{const p=[];for(const y of E){const P=parseFloat(g.get(y)??"")||0;p.push({skillName:`__lane_total__::${y}`,schedulerCategory:y,velocityPerSprint:P});const I=c[y]??[];for(const U of I){const D=`${y}::${U.skillName}`,L=N.get(D),W=L!==void 0&&L!==""?parseFloat(L)||0:null;p.push({skillName:U.skillName,schedulerCategory:y,velocityPerSprint:W})}}await o.mutateAsync(p),t(!1)},[E,c,N,g,o,t]),es=m.useCallback(()=>{ne(null),t(!1)},[t]),{data:gs}=Wt(),S=a.skillsJson?.specialization??null,H=a.skillsJson?.confidence??null;return e.jsx(Bt,{open:s,onOpenChange:t,children:e.jsxs(Kt,{side:"right",className:"sm:max-w-lg flex flex-col gap-0 p-0 overflow-hidden",children:[e.jsx(Qt,{className:"px-6 py-4 border-b border-border shrink-0",children:e.jsxs(Ht,{className:"text-base font-semibold",children:["Skill Configuration — ",a.fullName]})}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-6 py-4 space-y-5",children:[e.jsxs("section",{className:"rounded-lg border border-border bg-muted/30 p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-foreground",children:a.fullName}),S&&e.jsxs("div",{className:"text-xs text-muted-foreground capitalize",children:[S,H!==null&&` (${Math.round(H*100)}% confidence)`]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ee,{type:"number",min:0,max:999,step:.1,value:a.estimatedVelocityPerSprint??"",onChange:p=>{r?.("estimatedVelocityPerSprint",p.target.value)},placeholder:"0",autoComplete:"off","data-1p-ignore":!0,"data-lpignore":"true",className:"w-20 h-9 text-right text-base font-semibold","aria-label":"Overall velocity SP/sprint"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"SP/sprint"})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Total capacity this person can deliver per sprint. The scheduler uses lane totals below (which should sum to this) and auto-normalizes to prevent double-counting."})]}),r&&e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:"Department"}),e.jsxs("select",{defaultValue:a.department||"",onChange:p=>r("department",p.target.value),className:"w-full h-8 rounded-md border border-input bg-background px-2 text-sm","aria-label":"Department",children:[e.jsx("option",{value:"",children:"Select..."}),(gs||[]).map(p=>e.jsx("option",{value:p,children:p},p))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:"Specialization"}),e.jsxs("select",{defaultValue:a.primarySpecialization||"",onChange:p=>{const y=p.target.value;r("primarySpecialization",y);const I=(Nt[y]??[]).filter(U=>j.includes(U));I.length>0&&(T(U=>{const D=new Set(U);for(const L of I)D.add(L);return Array.from(D)}),V(U=>{const D=new Set(U);for(const L of I)D.add(L);return Array.from(D)}),k(U=>{const D={...U};for(const L of I)D[L]||(D[L]=[]);return D}))},className:"w-full h-8 rounded-md border border-input bg-background px-2 text-sm","aria-label":"Specialization",children:[e.jsx("option",{value:"",children:"Select..."}),e.jsx("option",{value:"FRONTEND",children:"Frontend"}),e.jsx("option",{value:"BACKEND",children:"Backend"}),e.jsx("option",{value:"FULLSTACK",children:"Full Stack"}),e.jsx("option",{value:"PRODUCT",children:"Product"}),e.jsx("option",{value:"DESIGN",children:"Design"}),e.jsx("option",{value:"QA",children:"QA"}),e.jsx("option",{value:"DEVOPS",children:"DevOps"}),e.jsx("option",{value:"AI_ML",children:"AI/ML"}),e.jsx("option",{value:"DATA",children:"Data"}),e.jsx("option",{value:"OTHER",children:"Other"})]})]})]}),i&&e.jsx("div",{className:"space-y-2",children:[1,2].map(p=>e.jsx(X,{className:"h-16 w-full rounded"},p))}),l&&e.jsx("p",{className:"text-sm text-destructive",children:"Failed to load skill data. Please close and try again."}),!i&&!l&&e.jsxs("div",{className:"space-y-3",children:[E.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground py-2",children:"Select a specialization above to add skill lanes."}),E.map(p=>{const y=c[p]??[],P=R===p,I=u[p]??p,U=se.has(p);return e.jsxs("div",{className:"rounded-lg border border-border",children:[e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2.5",children:[e.jsx("span",{className:"text-sm font-medium text-foreground flex-1",children:I}),e.jsx(ee,{type:"number",min:0,max:999,step:1,value:g.get(p)??"",onChange:D=>{const L=D.target.value;if(A(B=>{const M=new Map(B);return L===""?M.delete(p):M.set(p,L),M}),!y.some(B=>!B.isAdminAdded)&&y.length>0){const B=parseFloat(L)||0;if(B>0){const M=Math.round(B/y.length*100)/100;n(K=>{const fe=new Map(K);
2return y.forEach(Ve=>{fe.set(`${p}::${Ve.skillName}`,String(M))}),fe})}else n(M=>{const K=new Map(M);return y.forEach(fe=>K.delete(`${p}::${fe.skillName}`)),K})}},placeholder:"0",autoComplete:"off","data-1p-ignore":!0,"data-lpignore":"true",className:"w-20 h-7 text-sm text-right","aria-label":`${I} velocity`}),e.jsx("span",{className:"text-xs text-muted-foreground shrink-0",children:"SP/sprint"}),P?e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>Oe(p),className:"text-xs text-destructive hover:underline",children:"Yes"}),e.jsx("button",{type:"button",onClick:ie,className:"text-xs text-muted-foreground hover:underline",children:"No"})]}):e.jsx("button",{type:"button",onClick:()=>Oe(p),className:"text-xs text-muted-foreground hover:text-destructive shrink-0","aria-label":`Remove ${I}`,children:"x"})]}),y.length>0&&e.jsx("div",{className:"px-3 pb-2",children:e.jsx("div",{className:"flex flex-wrap gap-1.5",children:y.map(D=>{const L=`${p}::${D.skillName}`,W=N.get(L),B=W!==void 0&&W!=="";return e.jsxs("span",{className:F("text-[11px] px-1.5 py-0.5 rounded inline-flex items-center gap-1",D.isAdminAdded?"bg-muted text-muted-foreground":"bg-[var(--info-soft)] text-[var(--info-fg)]"),children:[Is(D.skillName),!D.isAdminAdded&&D.systemVelocity!=null&&D.systemVelocity>0&&e.jsx("span",{className:"text-[10px] opacity-70",children:e.jsx(ss,{value:B?parseFloat(String(W)):D.systemVelocity,provenance:null,density:"inline-badge",unit:"SP"})})]},D.skillName)})})}),e.jsxs("div",{className:"px-3 pb-2 flex items-center gap-3",children:[e.jsx("button",{type:"button",onClick:()=>Ne(D=>{const L=new Set(D);return L.has(p)?L.delete(p):L.add(p),L}),className:"text-[11px] text-muted-foreground hover:text-foreground transition-colors",children:U?"Hide skill details":`Fine-tune ${y.length} skills`}),(()=>
2{const D=y.filter(B=>!B.isAdminAdded&&B.systemVelocity!=null&&B.systemVelocity>0),L=y.some(B=>N.has(`${p}::${B.skillName}`));if(D.length===0||!L)return null;const W=Math.round(D.reduce((B,M)=>B+(M.systemVelocity??0),0)*10)/10;return e.jsxs("button",{type:"button",onClick:()=>{n(B=>{const M=new Map(B);return y.forEach(K=>M.delete(`${p}::${K.skillName}`)),M}),A(B=>{const M=new Map(B);return M.set(p,String(W)),M})},className:"text-[11px] text-[var(--info-fg)] hover:text-[var(--info-fg)] hover:underline transition-colors",children:["Reset to extracted (",W," SP)"]})})()]}),U&&e.jsxs("div",{className:"border-t border-border/50 px-3 py-2 space-y-1 bg-muted/20",children:[y.some(D=>!D.isAdminAdded)&&e.jsx("div",{className:"pb-0.5",children:e.jsx("span",{className:"text-[11px] text-muted-foreground font-medium",children:"From history (fine-tune SP)"})}),y.filter(D=>!D.isAdminAdded).map(D=>{const L=`${p}::${D.skillName}`,W=parseFloat(g.get(p)??"")||0;return e.jsx(pr,{row:D,overrideValue:N.get(L)??"",laneTotal:W,onChange:re,onRemove:ke},L)}),y.some(D=>D.isAdminAdded)&&e.jsx("div",{className:"pt-1.5 pb-0.5",children:e.jsx("span",{className:"text-[11px] text-muted-foreground font-medium",children:"Added manually (capacity managed by lane total)"})}),y.some(D=>D.isAdminAdded)&&e.jsx("div",{className:"flex flex-wrap gap-1 pb-1",children:y.filter(D=>D.isAdminAdded).map(D=>e.jsxs("span",{className:"text-[11px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground inline-flex items-center gap-1 group",children:[Is(D.skillName),e.jsx("button",{type:"button",onClick:()=>ke(`${p}::${D.skillName}`),className:"text-muted-foreground/50 hover:text-destructive opacity-0 group-hover:opacity-100 transition-opacity text-[10px]","aria-label":`Remove ${D.skillName}`,children:"x"})]},D.skillName))}),(vt[p]??[]).length>0&&e.jsxs("div",{className:"pt-2 space-y-2",children:[e.jsx("span",{className:"text-[11px] text-muted-foreground font-medium",children:"Quick add"}),(vt[p]??[]).map(D=>{const L=D.skills.filter(W=>!q.has(W.toLowerCase()));return L.length===0?null:e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[11px] text-muted-foreground",children:D.label}),e.jsxs("button",{type:"button",onClick:()=>L.forEach(W=>ce(p,W)),className:"text-[10px] text-[var(--info-fg)] hover:underline",children:["add all ",L.length]})]}),e.jsx("div",{className:"flex flex-wrap gap-1",children:L.map(W=>e.jsxs("button",{type:"button",onClick:()=>ce(p,W),className:"text-[11px] px-1.5 py-0.5 rounded border border-dashed border-border text-muted-foreground hover:text-foreground hover:bg-accent hover:border-foreground
2/20 transition-colors",children:["+ ",W]},W))})]},D.label)})]}),e.jsx("div",{className:"flex items-center gap-2 pt-2",children:y.length>0&&e.jsxs("button",{type:"button",onClick:()=>Xe(p),className:"text-xs px-2 py-1 rounded border border-border text-muted-foreground hover:text-destructive hover:bg-destructive/10 transition-colors",children:["Remove All (",y.length,")"]})}),e.jsx(fr,{category:p,existingSkillNames:y.map(D=>D.skillName),allAssignedSkills:q,taxonomySkillsByCategory:f,onAdd:ce})]})]},p)}),e.jsx(jr,{existingCategories:E,allLanes:v,onAdd:Ze})]})]}),e.jsx(dn,{className:"px-6 py-4 border-t border-border shrink-0",children:e.jsxs("div",{className:"flex items-center justify-between w-full",children:[e.jsxs("span",{className:"text-sm text-muted-foreground",children:["Total:"," ",e.jsx("span",{className:"font-medium text-foreground",children:e.jsx(yn,{children:e.jsx(ss,{value:Ae,provenance:null,density:"inline-badge",unit:"SP/sprint"})})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(C,{type:"button",variant:"outline",size:"sm",onClick:es,disabled:o.isPending,children:"Cancel"}),e.jsx(C,{type:"button",size:"sm",onClick:qe,disabled:i||l||o.isPending,children:o.isPending?"Saving...":"Apply"})]})]})})]})})}const aa={first:{label:"first",example:"john",generate:s=>s.split(/\s+/)[0].toLowerCase()},"first.last":{label:"first.last",example:"john.doe",generate:s=>{const t=s.split(/\s+/);return`${t[0]}.${t[t.length-1]}`.toLowerCase()}},first_last:{label:"first_last",example:"john_doe",generate:s=>{const t=s.split(/\s+/);return`${t[0]}_${t[t.length-1]}`.toLowerCase()}},firstlastinitial:{label:"first(lastinitial)",example:"johnd",generate:s=>{const t=s.split(/\s+/);return`${t[0]}${(t[t.length-1]||"")[0]||""}`.toLowerCase()}}},vr=[20,50,100];function Nr({onCreateEmployee:s,onEditEmployee:t,onArchiveEmployee:a}){const[r,d]=m.useState(""),[i,l]=m.useState(""),[o,x]=m.useState(""),[u,v]=m.useState(0),[j,b]=m.useState(50),[f,N]=m.useState(new Set),[n,c]=m.useState(null),{data:k}=Wt(),E=hn(),T=pn(),w=Gt(),V=gn(),g=fn(),{toast:A}=ge(),R=m.useCallback(S=>{N(H=>{const p=new Set(H);return p.has(S)?p.delete(S):p.add(S),p})},[]),ne=m.useCallback(S=>{N(H=>{const p=S.map(P=>P.id);return p.every(P=>H.has(P))?new Set:new Set(p)})},[]),se=m.useCallback((S,H)=>{f.size!==0&&V.mutate({ids:Array.from(f),updates:{[S]:H}},{onSuccess:p=>{A({title:"Bulk Updated",description:`${p.updatedCount} employees updated.`}),N(new Set)},onError:p=>{A({title:"Bulk Update Failed",description:p.message,variant:"destructive"})}})},[f,V,A]),Ne=m.useCallback((S,H,p)=>{if(f.size===0||!H)return;const y=aa[S]?.generate;if(!y)return;const P=p.filter(U=>f.has(U.id)),I={};for(const U of P){const D=y(U.fullName);if(!D)continue;const L=`${D}@${H}`;L!==U.email&&(I[U.id]=L)}Object.keys(I).length!==0&&V.mutate({ids:Array.from(f),emailAssignments:I},{onSuccess:U=>{A({title:"Emails Assigned",description:`${U.updatedCount} emails updated.`}),N(new Set)},onError:U=>{A({title:"Email Assignment Failed",description:U.message,variant:"destructive"})}})},[f,V,A]),re=m.useCallback((S,H)=>{if(f.size===0)return;const p=H.filter(I=>f.has(I.id)),y=p.filter(I=>I.email),P=p.length-y.length;if(y.length===0){A({title:"No Eligible Employees",description:"Selected employees need an email address before they can be invited.",variant:"destructive"});return}g.mutate({invitations:y.map(I=>({email:I.email,role:S}))},{onSuccess:()=>{P>0&&A({title:"Note",description:`${P} employee(s) skipped — no email address.`}),N(new Set)}})},[f,g,A]),q=m.useCallback((S,H,p)=>{const y={department:"department",primarySpecialization:"specialization",email:"email",availabilityStatus:"status",estimatedVelocityPerSprint:"velocity"},P={department:S.department,primarySpecialization:S.primarySpecialization,email:S.email,availabilityStatus:S.availabilityStatus,estimatedVelocityPerSprint:S.estimatedVelocityPerSprint!=null?String(S.estimatedVelocityPerSprint):void 0};if(p===(P[H]||""))return;const I=H==="estimatedVelocityPerSprint"?p?parseFloat(p):void 0:p||void 0;w.mutate({id:S.id,data:{[H]:I}},{onSuccess:()=>{A({title:"Updated",description:`${S.fullName}
2's ${y[H]} updated.`})},onError:U=>{A({title:"Update Failed",description:U.message,variant:"destructive"})}})},[w,A]),ce=m.useMemo(()=>({search:r||void 0,status:i||void 0,department:o||void 0,skip:u,limit:j}),[r,i,o,u,j]),{data:ke,isLoading:Xe,error:Ze,refetch:Oe}=ot(ce),ie=ke?.data||[],Ae=ke?.pagination?.total||0,qe=ke?.pagination?.hasMore||!1,es=m.useCallback(S=>{S==="next"&&qe?v(H=>H+j):S==="prev"&&u>0&&v(H=>Math.max(0,H-j))},[qe,u,j]),gs=m.useCallback(S=>{b(S),v(0)},[]);return Xe?e.jsxs("div",{className:"flex items-center justify-center py-12",role:"status",children:[e.jsx(Y,{className:"h-8 w-8 animate-spin text-muted-foreground"}),e.jsx("span",{className:"ml-3 text-muted-foreground dark:text-muted-foreground",children:"Loading employees..."})]}):Ze?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",role:"alert",children:[e.jsx(oe,{className:"h-12 w-12 text-[var(--danger)] mb-4"}),e.jsx("p",{className:"text-lg font-medium text-foreground",children:"Failed to fetch employees"}),e.jsx("p",{className:"text-sm text-muted-foreground dark:text-muted-foreground mt-1",children:Ze.message||"An unexpected error occurred"}),e.jsx(C,{variant:"outline",onClick:()=>Oe(),className:"mt-4",children:"Retry"})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:[e.jsxs("div",{className:"relative flex-1 max-w-md",children:[e.jsx(We,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(ee,{type:"text",placeholder:"Search by name or email...",value:r,onChange:S=>{d(S.target.value),v(0)},className:"pl-10","aria-label":"Search employees"})]}),s&&e.jsxs(C,{onClick:s,children:[e.jsx(bs,{className:"h-4 w-4 mr-2"}),"Add Employee"]})]}),e.jsxs("div",{className:"flex flex-wrap gap-3",children:[e.jsxs("select",{className:"h-9 rounded-md border border-input bg-background px-3 text-sm",value:i,onChange:S=>{l(S.target.value),v(0)},"aria-label":"Filter by status",children:[e.jsx("option",{value:"",children:"All Statuses"}),e.jsx("option",{value:"AVAILABLE",children:"Available"}),e.jsx("option",{value:"ON_LEAVE",children:"On Leave"}),e.jsx("option",{value:"INACTIVE",children:"Inactive"}),e.jsx("option",{value:"TERMINATED",children:"Terminated"})]}),e.jsxs("select",{className:"h-9 rounded-md border border-input bg-background px-3 text-sm",value:o,onChange:S=>{x(S.target.value),v(0)},"aria-label":"Filter by department",children:[e.jsx("option",{value:"",children:"All Departments"}),(k||[]).map(S=>e.jsx("option",{value:S,children:S},S))]})]}),f.size>0&&e.jsx(yr,{selectedCount:f.size,departments:k||[],employees:ie,onBulkUpdate:se,onBulkEmailAssign:Ne,onBulkInvite:re,onClearSelection:()=>N(new Set),isPending:V.isPending,isInviting:g.isPending}),ie.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[e.jsx(Fe,{className:"h-12 w-12 text-muted-foreground mb-4"}),e.jsx("p",{className:"text-lg font-medium text-foreground",children:"No employees found"}),e.jsx("p",{className:"text-sm text-muted-foreground dark:text-muted-foreground mt-1",children:r||i||o?"Try adjusting your filters.":"Add your first employee to get started"})]}):e.jsxs(e.Fragment,{children:[ie&&ie.length>0&&e.jsxs("div",{className:"text-sm text-muted-foreground px-1 pb-2",children:[ie.filter(S=>S.velocityDataSource&&S.velocityDataSource!=="none").length," of ",ie.length," team members with velocity data"]}),e.jsx("div",{className:"overflow-x-auto rounded-lg border border-deepwind-border dark:border-deepwind-border",children:e.jsxs("table",{className:"min-w-full divide-y divide-deepwind-border",role:"table","aria-label":"Employee list",children:[e.jsx("thead",{className:"bg-deepwind-surface",children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",className:"w-10 px-3 py-3",children:e.jsx("input",{type:"checkbox",checked:ie.length>0&&ie.every(S=>f.has(S.id)),onChange:()=>ne(ie),className:"h-4 w-4 rounded border-deepwind-border-strong text-primary focus:ring-primary/30","aria-label":"Select all employees"})}),e.jsx("th",{scope:"col",className:"px-4 py-3 text-left text-xs font-medium text-muted-foreground dark:text-muted-foreground uppercase tracking-wider",children:"Full Name"}),e.jsx("th",{scope:"col",className:"px-4 py-3 text-left text-xs font-medium text-muted-foreground dark:text-muted-foreground uppercase tracking-wider",children:"Email"}),e.jsx("th",{scope:"col",className:"px-4 py-3 text-left text-xs font-medium text-muted-foreground dark:text-muted-foreground uppercase tracking-wider hidden md:table-cell",children:"Department"}),e.jsx("th",{scope:"col",className:"hidden lg:table-cell px-3 py-2 text-left text-xs font-medium text-muted-foreground",children:"Velocity"}),e.jsx("th",{scope:"col",className:"px-4 py-3 text-left text-xs font-medium text-muted-foreground dark:text-muted-foreground uppercase tracking-wider",children:"Status"}),e.jsx("th",{scope:"col",className:"px-4 py-3 text-right text-xs font-medium text-muted-foreground dark:text-muted-foreground uppercase tracking-wider",children:"Actions"})]})}),e.jsx("tbody",{className:"bg-deepwind-surface-raised divide-y divide-deepwind-border",children:ie.map(S=>e.jsxs("tr",{className:"hover:bg-deepwind-surface transition-colors",children:[e.jsx("td",{className:"w-10 px-3 py-3",children:e.jsx("input",{type:"checkbox",checked:f.has(S.id),onChange:()=>
2R(S.id),className:"h-4 w-4 rounded border-deepwind-border-strong text-primary focus:ring-primary/30","aria-label":`Select ${S.fullName}`})}),e.jsx("td",{className:"px-4 py-3 text-sm font-medium text-foreground whitespace-nowrap",children:S.fullName}),e.jsx("td",{className:"px-4 py-3 text-sm text-deepwind-text-body dark:text-foreground whitespace-nowrap",children:e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx("input",{type:"email",defaultValue:S.email,onBlur:H=>q(S,"email",H.target.value.trim()),onKeyDown:H=>{H.key==="Enter"&&H.target.blur()},className:"bg-transparent border-0 border-b border-transparent hover:border-muted-foreground/30 focus:border-primary focus:ring-0 px-0 py-0.5 text-sm text-deepwind-text-body dark:text-foreground outline-none transition-colors w-48","aria-label":`Email for ${S.fullName}`}),S.emailVerified?e.jsx(ze,{className:"h-3.5 w-3.5 text-[var(--success)] shrink-0","aria-label":"Email verified"}):e.jsx(Ke,{className:"h-3.5 w-3.5 text-deepwind-warning shrink-0","aria-label":"Email unverified"})]})}),e.jsx("td",{className:"px-4 py-3 text-sm hidden md:table-cell",children:e.jsx(br,{value:S.department||"",departments:k||[],onChange:H=>q(S,"department",H),ariaLabel:`Department for ${S.fullName}`})}),e.jsx("td",{className:"hidden lg:table-cell px-3 py-2",children:e.jsx("button",{type:"button",onClick:()=>c(S),className:"hover:opacity-80 transition-opacity","aria-label":`Configure skills for ${S.fullName||S.email}`,children:e.jsx(sa,{velocityDataSource:S.velocityDataSource,estimatedVelocityPerSprint:S.estimatedVelocityPerSprint,hasExtractedSkills:S.hasExtractedSkills,compact:!0})})}),e.jsx("td",{className:"px-4 py-3 whitespace-nowrap",children:e.jsxs("select",{defaultValue:S.availabilityStatus,onChange:H=>q(S,"availabilityStatus",H.target.value),className:"h-7 rounded-md border-0 bg-transparent px-1 py-0 text-xs text-muted-foreground cursor-pointer outline-none hover:text-foreground focus:ring-1 focus:ring-primary/30 transition-colors","aria-label":`Status for ${S.fullName}`,children:[e.jsx("option",{value:"AVAILABLE",children:"Available"}),e.jsx("option",{value:"ON_LEAVE",children:"On Leave"}),e.jsx("option",{value:"UNAVAILABLE",children:"Unavailable"}),e.jsx("option",{value:"INACTIVE",children:"Inactive"}),e.jsx("option",{value:"TERMINATED",children:"Terminated"})]})}),e.jsx("td",{className:"px-4 py-3 text-right whitespace-nowrap",children:e.jsxs("div",{className:"flex justify-end gap-1",children:[!S.emailVerified&&e.jsx(C,{variant:"ghost",size:"sm",onClick:()=>E.mutate(S.id),disabled:E.isPending,"aria-label":`Validate email for ${S.fullName}`,className:"text-[var(--success-fg)] hover:text-[var(--success-fg)] hover:bg-[var(--success-soft)]",children:e.jsx(ze,{className:"h-4 w-4"})}),S.emailVerified&&e.jsx(C,{variant:"ghost",size:"sm",onClick:()=>T.mutate({email:S.email}),disabled:T.isPending,"aria-label":`Invite ${S.fullName}`,className:"text-[var(--info-fg)] hover:text-[var(--info-fg)] hover:bg-[var(--info-soft)]",children:e.jsx(Fs,{className:"h-4 w-4"})}),t&&e.jsx(C,{variant:"ghost",size:"sm",onClick:()=>t(S),"aria-label":`Edit ${S.fullName}`,children:e.jsx(Mt,{className:"h-4 w-4"})}),a&&e.jsx(C,{variant:"ghost",size:"sm",onClick:()=>a(S),"aria-label":`Archive ${S.fullName}`,children:e.jsx(wa,{className:"h-4 w-4"})})]})})]},S.id))})]})}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-center justify-between gap-4",children:[e.jsxs("div",{className:"text-sm text-muted-foreground dark:text-muted-foreground",children:["Showing ",u+1," to ",Math.min(u+j,Ae)," of"," ",Ae," employees"]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("select",{className:"h-9 rounded-md border border-input bg-background px-3 text-sm",value:j,onChange:S=>gs(Number(S.target.value)),"aria-label":"Rows per page",children:vr.map(S=>e.jsxs("option",{value:S,children:[S," per page"]},S))}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx(C,{variant:"outline",size:"sm",onClick:()=>es("prev"),disabled:u===0,"aria-label":"Previous page",children:e.jsx(It,{className:"h-4 w-4"})}),e.jsx(C,{variant:"outline",size:"sm",onClick:()=>es("next"),disabled:!qe,"aria-label":"Next page",children:e.jsx(tt,{className:"h-4 w-4"})})]})]})]})]}),n&&e.jsx(ta,{open:!!n,onOpenChange:S=>{S||c(null)},employee:{id:n.id,email:n.email,fullName:n.fullName||n.email,department:n.department,primarySpecialization:n.primarySpecialization,estimatedVelocityPerSprint:n.estimatedVelocityPerSprint,skillsJson:n.skillsJson},onUpdateEmployee:(S,H)=>q(n,S,H)})]})}function br({value:s,departments:t,onChange:a,ariaLabel:r}){const[d,i]=m.useState(!1),[l,o]=m.useState("");
2return d?e.jsx("input",{autoFocus:!0,type:"text",value:l,onChange:x=>o(x.target.value),onBlur:()=>{const x=l.trim();x&&a(x),i(!1),o("")},onKeyDown:x=>{x.key==="Enter"&&x.target.blur(),x.key==="Escape"&&(i(!1),o(""))},placeholder:"New department...",className:"w-full bg-transparent border-0 border-b border-primary px-0 py-0.5 text-sm text-deepwind-text-body dark:text-foreground outline-none","aria-label":"Enter new department name"}):e.jsxs("select",{value:s,onChange:x=>{x.target.value==="__add_new__"?i(!0):a(x.target.value)},className:"w-full bg-transparent border-0 border-b border-transparent hover:border-muted-foreground/30 focus:border-primary focus:ring-0 px-0 py-0.5 text-sm text-deepwind-text-body dark:text-foreground outline-none transition-colors cursor-pointer","aria-label":r,children:[e.jsx("option",{value:"",children:"—"}),t.map(x=>e.jsx("option",{value:x,children:x},x)),e.jsx("option",{value:"__add_new__",children:"+ Add new..."})]})}function yr({selectedCount:s,departments:t,employees:a,onBulkUpdate:r,onBulkEmailAssign:d,onBulkInvite:i,onClearSelection:l,isPending:o,isInviting:x}){const[u,v]=m.useState("first.last"),[j,b]=m.useState(""),[f,N]=m.useState("member"),n=m.useMemo(()=>{const c=a.map(E=>E.email?.split("@")[1]).filter(Boolean);if(c.length===0)return"";const k={};for(const E of c)k[E]=(k[E]||0)+1;return Object.entries(k).sort((E,T)=>T[1]-E[1])[0]?.[0]||""},[a]);return e.jsxs("div",{className:"rounded-lg border border-[var(--info)] bg-[var(--info-soft)] px-4 py-3 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-sm font-medium text-[var(--info-fg)]",children:[s," selected"]}),e.jsx(C,{variant:"ghost",size:"sm",onClick:l,className:"h-7 text-xs",children:"Clear"})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground mr-1",children:"Assign:"}),e.jsxs("select",{defaultValue:"",onChange:c=>{c.target.value&&(r("department",c.target.value),c.target.value="")},disabled:o,className:"h-8 rounded-md border border-input bg-background px-2 text-xs","aria-label":"Bulk assign department",children:[e.jsx("option",{value:"",children:"Department..."}),t.map(c=>e.jsx("option",{value:c,children:c},c))]}),e.jsxs("select",{defaultValue:"",onChange:c=>{c.target.value&&(r("availabilityStatus",c.target.value),c.target.value="")},disabled:o,className:"h-8 rounded-md border border-input bg-background px-2 text-xs","aria-label":"Bulk assign status",children:[e.jsx("option",{value:"",children:"Status..."}),e.jsx("option",{value:"AVAILABLE",children:"Available"}),e.jsx("option",{value:"ON_LEAVE",children:"On Leave"}),e.jsx("option",{value:"UNAVAILABLE",children:"Unavailable"}),e.jsx("option",{value:"INACTIVE",children:"Inactive"}),e.jsx("option",{value:"TERMINATED",children:"Terminated"})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground mr-1",children:"Email:"}),e.jsx("select",{value:u,onChange:c=>v(c.target.value),className:"h-8 rounded-md border border-input bg-background px-2 text-xs","aria-label":"Email pattern",children:Object.entries(aa).map(([c,{label:k,example:E}])=>e.jsxs("option",{value:c,children:[k," (",E,")"]},c))}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"@"}),e.jsx("input",{type:"text",value:j,onChange:c=>b(c.target.value),placeholder:n||"company.com",className:"h-8 w-36 rounded-md border border-input bg-background px-2 text-xs","aria-label":"Email domain"}),e.jsx(C,{variant:"outline",size:"sm",className:"h-8 text-xs",disabled:o||!j.includes("."),onClick:()=>d(u,j||n,a),children:"Assign Emails"}),o&&e.jsx(Y,{className:"h-4 w-4 animate-spin text-muted-foreground"})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-t border-[var(--info)] pt-3",children:[e.jsx("span",{className:"text-xs text-muted-foreground mr-1",children:"Invite:"}),e.jsxs("select",{value:f,onChange:c=>N(c.target.value),className:"h-8 rounded-md border border-input bg-background px-2 text-xs","aria-label":"Invitation role",children:[e.jsx("option",{value:"member",children:"Member"}),e.jsx("option",{value:"admin",children:"Admin"}),e.jsx("option",{value:"viewer",children:"Viewer"})]}),e.jsxs(C,{variant:"default",size:"sm",className:"h-8 text-xs gap-1.5",disabled:x,onClick:()=>i(f,a),children:[x?e.jsx(Y,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Fs,{className:"h-3.5 w-3.5"}),"Invite ",s," to Platform"]}
2),e.jsx("span",{className:"text-[10px] text-muted-foreground/70",children:"Requires email address"})]})]})}const wr=[{value:"FRONTEND",label:"Frontend"},{value:"BACKEND",label:"Backend"},{value:"FULLSTACK",label:"Full Stack"},{value:"PRODUCT",label:"Product"},{value:"DESIGN",label:"Design"},{value:"QA",label:"QA"},{value:"DEVOPS",label:"DevOps"},{value:"AI_ML",label:"AI/ML"},{value:"DATA",label:"Data"},{value:"OTHER",label:"Other"}],Cr=[{value:"AVAILABLE",label:"Available"},{value:"ON_LEAVE",label:"On Leave"},{value:"INACTIVE",label:"Inactive"},{value:"TERMINATED",label:"Terminated"}],Sr=[{value:"FULL_TIME",label:"Full Time"},{value:"PART_TIME",label:"Part Time"},{value:"CONTRACT",label:"Contract"},{value:"INTERN",label:"Intern"},{value:"CONSULTANT",label:"Consultant"}],kr=/^[^\s@]+@[^\s@]+\.[^\s@]+$/;function Ar(s){const t={};return s.fullName?.trim()||(t.fullName="Full name is required"),s.email?.trim()?kr.test(s.email)||(t.email="Please enter a valid email address"):t.email="Email is required",s.hourlyRate!==void 0&&s.hourlyRate!==null&&s.hourlyRate<0&&(t.hourlyRate="Hourly rate must be 0 or greater"),t}function bt({employee:s,onSubmit:t,onCancel:a,isPending:r=!1}){const d=!!s,[i,l]=m.useState({fullName:s?.fullName||"",email:s?.email||"",department:s?.department||"",jobTitle:s?.jobTitle||"",primarySpecialization:s?.primarySpecialization||void 0,hourlyRate:s?.hourlyRate??void 0,currency:s?.currency||"USD",employmentType:s?.employmentType||void 0,hoursPerWeek:s?.hoursPerWeek??40,availabilityStatus:s?.availabilityStatus||"AVAILABLE"}),[o,x]=m.useState({}),[u,v]=m.useState(!1),[j,b]=m.useState(!1),f=m.useCallback((n,c)=>{l(k=>({...k,[n]:c})),o[n]&&x(k=>{const E={...k};return delete E[n],E})},[o]),N=m.useCallback(n=>{n.preventDefault();const c=Ar(i);if(Object.keys(c).length>0){x(c);return}t(i)},[i,t]);return e.jsxs("form",{onSubmit:N,className:"space-y-4","aria-label":d?"Edit employee form":"Create employee form",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(J,{htmlFor:"fullName",children:"Full Name"}),e.jsx(ee,{id:"fullName",type:"text",value:i.fullName||"",onChange:n=>f("fullName",n.target.value),placeholder:"Enter full name","aria-invalid":!!o.fullName,"aria-describedby":o.fullName?"fullName-error":void 0}),o.fullName&&e.jsx("p",{id:"fullName-error",className:"text-sm text-[var(--danger-fg)]",role:"alert",children:o.fullName})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(J,{htmlFor:"email",children:"Email"}),e.jsx(ee,{id:"email",type:"email",value:i.email||"",onChange:n=>f("email",n.target.value),placeholder:"Enter email address","aria-invalid":!!o.email,"aria-describedby":o.email?"email-error":void 0}),o.email&&e.jsx("p",{id:"email-error",className:"text-sm text-[var(--danger-fg)]",role:"alert",children:o.email})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(J,{htmlFor:"department",children:"Department"}),e.jsx(ee,{id:"department",type:"text",value:i.department||"",onChange:n=>f("department",n.target.value),placeholder:"Enter department"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(J,{htmlFor:"jobTitle",children:"Job Title"}),e.jsx(ee,{id:"jobTitle",type:"text",value:i.jobTitle||"",onChange:n=>f("jobTitle",n.target.value),placeholder:"Enter job title"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(J,{htmlFor:"primarySpecialization",children:"Specialization"}),e.jsxs("select",{id:"primarySpecialization",className:"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm r
2ing-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",value:i.primarySpecialization||"",onChange:n=>f("primarySpecialization",n.target.value||void 0),children:[e.jsx("option",{value:"",children:"Select specialization"}),wr.map(n=>e.jsx("option",{value:n.value,children:n.label},n.value))]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(J,{htmlFor:"employmentType",children:"Employment Type"}),e.jsxs("select",{id:"employmentType",className:"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",value:i.employmentType||"",onChange:n=>f("employmentType",n.target.value||void 0),children:[e.jsx("option",{value:"",children:"Select employment type"}),Sr.map(n=>e.jsx("option",{value:n.value,children:n.label},n.value))]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(J,{htmlFor:"hourlyRate",children:"Hourly Rate"}),e.jsx(ee,{id:"hourlyRate",type:"number",min:"0",step:"0.01",value:i.hourlyRate??"",onChange:n=>f("hourlyRate",n.target.value?parseFloat(n.target.value):void 0),placeholder:"0.00","aria-invalid":!!o.hourlyRate,"aria-describedby":o.hourlyRate?"hourlyRate-error":void 0}),o.hourlyRate&&e.jsx("p",{id:"hourlyRate-error",className:"text-sm text-[var(--danger-fg)]",role:"alert",children:o.hourlyRate})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(J,{htmlFor:"currency",children:"Currency"}),e.jsx(ee,{id:"currency",type:"text",maxLength:3,value:i.currency||"USD",onChange:n=>f("currency",n.target.value.toUpperCase()),placeholder:"USD"})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(J,{htmlFor:"hoursPerWeek",children:"Hours Per Week"}),e.jsx(ee,{id:"hoursPerWeek",type:"number",min:"0",max:"168",value:i.hoursPerWeek??40,onChange:n=>f("hoursPerWeek",n.target.value?parseInt(n.target.value,10):void 0)})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(J,{htmlFor:"availabilityStatus",children:"Status"}),e.jsx("select",{id:"availabilityStatus",className:"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm r
2ing-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",value:i.availabilityStatus||"AVAILABLE",onChange:n=>f("availabilityStatus",n.target.value),children:Cr.map(n=>e.jsx("option",{value:n.value,children:n.label},n.value))})]}),s&&s.id&&e.jsxs(Ka,{open:j,onOpenChange:b,children:[e.jsx(Qa,{asChild:!0,children:e.jsxs("button",{type:"button",className:"flex items-center justify-between w-full py-2 text-sm font-medium text-muted-foreground hover:text-foreground transition-colors",children:[e.jsxs("span",{className:"flex items-center gap-2",children:["Velocity & Skills",e.jsx(sa,{velocityDataSource:s.velocityDataSource,estimatedVelocityPerSprint:s.estimatedVelocityPerSprint,compact:!0})]}),j?e.jsx(Ca,{className:"h-4 w-4"}):e.jsx(Lt,{className:"h-4 w-4"})]})}),e.jsxs(Ha,{className:"space-y-3 pt-2",children:[s.skillsJson?.specialization&&e.jsxs("div",{className:"text-sm text-muted-foreground",children:["AI detected: ",s.skillsJson.specialization,s.skillsJson.confidence&&` (${Math.round(s.skillsJson.confidence*100)}% confidence)`]}),e.jsx(C,{type:"button",variant:"outline",size:"sm",onClick:()=>v(!0),className:"w-full",children:"Configure Skills & Velocity"})]})]}),s&&s.id&&e.jsx(ta,{open:u,onOpenChange:v,employee:{id:s.id,email:s.email,fullName:s.fullName||s.email,skillsJson:s.skillsJson}}),e.jsxs("div",{className:"flex justify-end gap-3 pt-4 border-t border-deepwind-border dark:border-deepwind-border",children:[e.jsx(C,{type:"button",variant:"outline",onClick:a,disabled:r,children:"Cancel"}),e.jsxs(C,{type:"submit",disabled:r,children:[r&&e.jsx(Y,{className:"mr-2 h-4 w-4 animate-spin"}),d?"Update Employee":"Create Employee"]})]})]})}const Er=[{value:"VACATION",label:"Vacation"},{value:"SICK",label:"Sick Leave"},{value:"PERSONAL",label:"Personal"},{value:"TRAINING",label:"Training"},{value:"CONFERENCE",label:"Conference"},{value:"BEREAVEMENT",label:"Bereavement"},{value:"JURY_DUTY",label:"Jury Duty"},{value:"OTHER",label:"Other"}];function Tr(s){const t={};return s.employeeId||(t.employeeId="Employee is required"),s.startDate||(t.startDate="Start date is required"),s.endDate||(t.endDate="End date is required"),s.startDate&&s.endDate&&new Date(s.endDate)<new Date(s.startDate)&&(t.endDate="End date must be after start date"),s.absenceType||(t.absenceType="Absence type is required"),t}function Dr({employees:s,onSubmit:t,onCancel:a,isPending:r=!1,preselectedEmployeeId:d}){const[i,l]=m.useState({employeeId:d||"",startDate:"",endDate:"",absenceType:void 0}),[o,x]=m.useState({}),u=m.useCallback((j,b)=>{l(f=>({...f,[j]:b})),o[j]&&x(f=>{const N={...f};return delete N[j],N})},[o]),v=m.useCallback(j=>{j.preventDefault();const b=Tr(i);if(Object.keys(b).length>0){x(b);return}const f={employeeId:i.employeeId,startDate:new Date(i.startDate).toISOString(),endDate:new Date(i.endDate).toISOString(),absenceType:i.absenceType};t(f)},[i,t]);return e.jsxs("form",{onSubmit:v,className:"space-y-4","aria-label":"Request absence form",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(J,{htmlFor:"employee",children:"Employee"}),e.jsxs("select",{id:"employee",className:"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm r
2ing-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",value:i.employeeId||"",onChange:j=>u("employeeId",j.target.value),"aria-invalid":!!o.employeeId,"aria-describedby":o.employeeId?"employee-error":void 0,disabled:!!d,children:[e.jsx("option",{value:"",children:"Select employee"}),s.map(j=>e.jsxs("option",{value:j.id,children:[j.fullName," (",j.email,")"]},j.id))]}),o.employeeId&&e.jsx("p",{id:"employee-error",className:"text-sm text-[var(--danger-fg)]",role:"alert",children:o.employeeId})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(J,{htmlFor:"startDate",children:"Start Date"}),e.jsx(ee,{id:"startDate",type:"date",value:i.startDate||"",onChange:j=>u("startDate",j.target.value),"aria-invalid":!!o.startDate,"aria-describedby":o.startDate?"startDate-error":void 0}),o.startDate&&e.jsx("p",{id:"startDate-error",className:"text-sm text-[var(--danger-fg)]",role:"alert",children:o.startDate})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(J,{htmlFor:"endDate",children:"End Date"}),e.jsx(ee,{id:"endDate",type:"date",value:i.endDate||"",onChange:j=>u("endDate",j.target.value),"aria-invalid":!!o.endDate,"aria-describedby":o.endDate?"endDate-error":void 0}),o.endDate&&e.jsx("p",{id:"endDate-error",className:"text-sm text-[var(--danger-fg)]",role:"alert",children:o.endDate})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(J,{htmlFor:"absenceType",children:"Absence Type"}),e.jsxs("select",{id:"absenceType",className:"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm r
2ing-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",value:i.absenceType||"",onChange:j=>u("absenceType",j.target.value),"aria-invalid":!!o.absenceType,"aria-describedby":o.absenceType?"absenceType-error":void 0,children:[e.jsx("option",{value:"",children:"Select absence type"}),Er.map(j=>e.jsx("option",{value:j.value,children:j.label},j.value))]}),o.absenceType&&e.jsx("p",{id:"absenceType-error",className:"text-sm text-[var(--danger-fg)]",role:"alert",children:o.absenceType})]}),e.jsxs("div",{className:"flex justify-end gap-3 pt-4 border-t border-deepwind-border dark:border-deepwind-border",children:[e.jsx(C,{type:"button",variant:"outline",onClick:a,disabled:r,children:"Cancel"}),e.jsxs(C,{type:"submit",disabled:r,children:[r&&e.jsx(Y,{className:"mr-2 h-4 w-4 animate-spin"}),"Request Absence"]})]})]})}function _s(s){return{VACATION:"Vacation",SICK:"Sick Leave",PERSONAL:"Personal",TRAINING:"Training",CONFERENCE:"Conference",BEREAVEMENT:"Bereavement",JURY_DUTY:"Jury Duty",OTHER:"Other"}[s]||s}function zs(s){return{PENDING:"Pending",APPROVED:"Approved",REJECTED:"Rejected",CANCELLED:"Cancelled"}[s]||s}function Bs(s){return{PENDING:"bg-deepwind-warning-soft text-deepwind-warning-fg",APPROVED:"bg-[var(--success-soft)] text-[var(--success-fg)]",REJECTED:"bg-[var(--danger-soft)] text-[var(--danger-fg)]",CANCELLED:"bg-deepwind-bg text-foreground"}[s]||"bg-deepwind-bg text-foreground"}function Ks(s,t){const a=new Date(s).toLocaleDateString("en-US",{month:"short",day:"numeric"}),r=new Date(t).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"});return`${a} - ${r}`}function Pr(){const{toast:s}=ge(),{user:t}=zt(),a=mn(["manager","admin"]),{data:r,isLoading:d,error:i,refetch:l}=Vn(),{data:o,isLoading:x}=qn(t?.id||"",{startDate:new Date(Date.now()-30*24*60*60*1e3).toISOString(),endDate:new Date(Date.now()+365*24*60*60*1e3).toISOString()}),u=Un(),v=_n(),[j,b]=m.useState(null),[f,N]=m.useState(""),n=o?.filter(w=>w.status==="PENDING")||[],c=m.useCallback(w=>{u.mutate({id:w},{onSuccess:()=>{s({title:"Absence Approved",description:"The absence request has been approved."})},onError:V=>
2{s({title:"Approval Failed",description:V.message||"Could not approve the absence request.",variant:"destructive"})}})},[u,s]),k=m.useCallback(w=>{if(!f.trim()){s({title:"Reason Required",description:"Please provide a reason for rejection.",variant:"destructive"});return}v.mutate({id:w,data:{rejectedReason:f}},{onSuccess:()=>{b(null),N(""),s({title:"Absence Rejected",description:"The absence request has been rejected."})},onError:V=>{s({title:"Rejection Failed",description:V.message||"Could not reject the absence request.",variant:"destructive"})}})},[v,f,s]);if(!a)return e.jsxs("div",{className:"space-y-6",children:[e.jsx(_,{className:"border-[var(--deepwind-warning)] bg-deepwind-warning-soft",children:e.jsx(z,{className:"pt-6",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"p-2 bg-deepwind-warning-soft rounded-full",children:e.jsx(Sa,{className:"h-5 w-5 text-deepwind-warning-fg"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h3",{className:"font-medium text-deepwind-warning-fg",children:"Manager Access Required"}),e.jsx("p",{className:"text-sm text-deepwind-warning-fg mt-1",children:"You need manager permissions to approve or reject absence requests. Contact your administrator if you need access."})]})]})})}),e.jsxs(_,{children:[e.jsx(Le,{className:"pb-3",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Be,{className:"h-5 w-5 text-primary"}),e.jsx(He,{className:"text-base",children:"My Pending Requests"})]}),n.length>0&&e.jsxs($,{variant:"secondary",children:[n.length," pending"]})]})}),e.jsx(z,{children:x?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(Y,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):n.length===0?e.jsxs("div",{className:"text-center py-8",children:[e.jsx(ws,{className:"h-10 w-10 text-muted-foreground mx-auto mb-3"}),e.jsx("p",{className:"text-sm text-deepwind-text-body dark:text-muted-foreground",children:"No pending requests"}),e.jsx("p",{className:"text-xs text-muted-foreground dark:text-muted-foreground mt-1",children:"Your submitted requests will appear here"})]}):e.jsx("div",{className:"space-y-3",children:n.map(w=>e.jsxs("div",{className:"flex items-center justify-between p-3 bg-deepwind-surface rounded-lg",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm text-foreground",children:_s(w.absenceType)}),e.jsx("p",{className:"text-xs text-muted-foreground dark:text-muted-foreground",children:Ks(w.startDate,w.endDate)})]}),e.jsx($,{className:Bs(w.status),children:zs(w.status)})]},w.id))})})]})]});if(d)return e.jsxs("div",{className:"flex items-center justify-center py-12",role:"status",children:[e.jsx(Y,{className:"h-8 w-8 animate-spin text-muted-foreground"}),e.jsx("span",{className:"ml-3 text-muted-foreground dark:text-muted-foreground",children:"Loading pending approvals..."})]});if(i)return e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",role:"alert",children:[e.jsx(oe,{className:"h-12 w-12 text-[var(--danger)] mb-4"}),e.jsx("p",{className:"text-lg font-medium text-foreground",children:"Failed to load approvals"}),e.jsx("p",{className:"text-sm text-muted-foreground dark:text-muted-foreground mt-1",children:i.message||"An unexpected error occurred"}),e.jsx(C,{variant:"outline",onClick:()=>l(),className:"mt-4",children:"Retry"})]});const E=r&&r.length>0,T=n.length>0;return!E&&!T?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[e.jsx(ws,{className:"h-12 w-12 text-muted-foreground mb-4"}),e.jsx("p",{className:"text-lg font-medium text-foreground",children:"No pending approvals"}),e.jsx("p",{className:"text-sm text-muted-foreground dark:text-muted-foreground mt-1",children:"All absence requests have been processed."})]}):e.jsxs("div",{className:"space-y-6",children:[T&&e.jsxs(_,{className:"border-[var(--info)] bg-[var(--info-soft)]",children:[e.jsx(Le,{className:"pb-3",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Be,{className:"h-5 w-5 text-[var(--info-fg)]"}),e.jsx(He,{className:"text-base",children:"My Pending Requests"})]}),e.jsxs($,{variant:"secondary",children:[n.length," pending"]})]})}),e.jsxs(z,{children:[e.jsx("div",{className:"space-y-3",children:n.map(w=>e.jsxs("div",{className:"flex items-center justify-between p-3 bg-deepwind-surface-raised rounded-lg border border-[var(--info-soft)]",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm text-foreground",children:_s(w.absenceType)}),e.jsx("p",{className:"text-xs text-muted-foreground dark:text-muted-foreground",children:Ks(w.startDate,w.endDate)}),w.reason&&e.jsxs("p",{className:"text-xs text-muted-foreground dark:text-muted-foreground mt-1 italic",children:['"',w.reason,'"']}
2)]}),e.jsx($,{className:Bs(w.status),children:zs(w.status)})]},w.id))}),e.jsx("p",{className:"text-xs text-muted-foreground dark:text-muted-foreground mt-3 text-center",children:"Another admin or manager must approve your requests"})]})]}),E&&e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("h3",{className:"text-sm font-medium text-deepwind-text-body dark:text-foreground",children:["Pending Approvals (",r.length,")"]})}),e.jsx("div",{className:"overflow-x-auto rounded-lg border border-deepwind-border dark:border-deepwind-border",children:e.jsxs("table",{className:"min-w-full divide-y divide-deepwind-border",role:"table","aria-label":"Pending absence approvals",children:[e.jsx("thead",{className:"bg-deepwind-surface",children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",className:"px-4 py-3 text-left text-xs font-medium text-muted-foreground dark:text-muted-foreground uppercase tracking-wider",children:"Employee"}),e.jsx("th",{scope:"col",className:"px-4 py-3 text-left text-xs font-medium text-muted-foreground dark:text-muted-foreground uppercase tracking-wider",children:"Date Range"}),e.jsx("th",{scope:"col",className:"px-4 py-3 text-left text-xs font-medium text-muted-foreground dark:text-muted-foreground uppercase tracking-wider hidden sm:table-cell",children:"Type"}),e.jsx("th",{scope:"col",className:"px-4 py-3 text-left text-xs font-medium text-muted-foreground dark:text-muted-foreground uppercase tracking-wider",children:"Status"}),e.jsx("th",{scope:"col",className:"px-4 py-3 text-right text-xs font-medium text-muted-foreground dark:text-muted-foreground uppercase tracking-wider",children:"Actions"})]})}),e.jsx("tbody",{className:"bg-deepwind-surface-raised divide-y divide-deepwind-border",children:r.map(w=>e.jsxs("tr",{className:"hover:bg-deepwind-surface transition-colors",children:[e.jsx("td",{className:"px-4 py-3 text-sm",children:e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-foreground",children:w.employeeName||"Unknown"}),w.employeeDepartment&&e.jsx("p",{className:"text-xs text-muted-foreground dark:text-muted-foreground",children:w.employeeDepartment})]})}),e.jsx("td",{className:"px-4 py-3 text-sm text-deepwind-text-body dark:text-foreground",children:Ks(w.startDate,w.endDate)}),e.jsx("td",{className:"px-4 py-3 text-sm text-deepwind-text-body dark:text-foreground hidden sm:table-cell",children:_s(w.absenceType)}),e.jsx("td",{className:"px-4 py-3",children:e.jsx($,{className:Bs(w.status),children:zs(w.status)})}),e.jsx("td",{className:"px-4 py-3 text-right",children:j===w.id?e.jsxs("div",{className:"flex items-center gap-2 justify-end",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(J,{htmlFor:`reject-reason-${w.id}`,className:"sr-only",children:"Rejection reason"}),e.jsx(ee,{id:`reject-reason-${w.id}`,type:"text",placeholder:"Reason for rejection",value:f,onChange:V=>N(V.target.value),"aria-label":"Rejection reason",className:"w-40 h-8 text-sm"})]}),e.jsx(C,{size:"sm",variant:"destructive",onClick:()=>k(w.id),disabled:v.isPending,children:v.isPending?e.jsx(Y,{className:"h-3 w-3 animate-spin"}):"Confirm"}),e.jsx(C,{size:"sm",variant:"ghost",onClick:()=>{b(null),N("")},children:"Cancel"})]}):e.jsxs("div",{className:"flex justify-end gap-1",children:[e.jsxs(C,{size:"sm",variant:"ghost",className:"text-[var(--success-fg)] hover:text-[var(--success-fg)] hover:bg-[var(--success-soft)]",onClick:()=>c(w.id),disabled:u.isPending,"aria-label":`Approve absence for ${w.employeeName||"employee"}`,children:[u.isPending?e.jsx(Y,{className:"h-4 w-4 animate-spin"}):e.jsx(ze,{className:"h-4 w-4 mr-1"}),"Approve"]}),e.jsxs(C,{size:"sm",variant:"ghost",className:"text-[var(--danger-fg)] hover:text-[var(--danger-fg)] hover:bg-[var(--danger-soft)]",onClick:()=>b(w.id),"aria-label":`Reject absence for ${w.employeeName||"employee"}`,children:[e.jsx(Pt,{className:"h-4 w-4 mr-1"}),"Reject"]})]})})]},w.id))})]})})]})]})}const Rr={fullName:{label:"Full Name",icon:Be},email:{label:"Email",icon:is},phone:{label:"Phone",icon:Ot,format:s=>s?String(s):"Not set"},department:{label:"Department",icon:$t,format:s=>s?String(s):"Not set"},jobTitle:{label:"Job Title",icon:as,format:s=>s?String(s):"Not set"},specialization:{label:"Specialization",icon:Ft},employmentType:{label:"Employment Type",icon:as},hoursPerWeek:{label:"Hours/Week",icon:ys,format:s=>s?`${s} hrs`:"Not set"},blendedHourlyRate:{label:"Blended Rate",icon:ht,format:s=>s?`$${s}/hr`:"Not set"},actualHourlyRate:{label:"Actual Rate",icon:ht,format:s=>s?`$${s}/hr`:"Not set"},status:{label:"Status",icon:pe},managerId:{label:"Manager",icon:Be,format:s=>s?"Assigned":"Not set"}};function Lr({fields:s,fieldResolutions:t,onFieldResolutionChange:a,sourceEmployee:r,targetEmployee:d}){const i=s.filter(l=>t[l.field]||na(l));return i.length===0?e.jsxs("div",{className:"text-center py-8",children:[e.jsx(pe,{className:"w-12 h-12 text-green-500 mx-auto mb-3"}),e.jsx("h4",{className:"font-medium",children:"No Field Conflicts"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"All field values are identical or have been automatically resolved."})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-[1fr,auto,1fr] gap-4 px-4",children:[e.jsxs("div",{className:"text-sm font-medium text-muted-foreground text-center",children:[r.fullName," 
2(Source)"]}),e.jsx("div",{className:"w-16"})," ",e.jsxs("div",{className:"text-sm font-medium text-muted-foreground text-center",children:[d.fullName," (Target)"]})]}),e.jsx("div",{className:"space-y-3",children:i.map(l=>e.jsx(Mr,{field:l,selectedSource:t[l.field]||l.selectedSource,onSelect:o=>a(l.field,o)},l.field))}),e.jsx("div",{className:"bg-muted/50 rounded-lg p-4 text-sm",children:e.jsxs("p",{className:"text-muted-foreground",children:[e.jsx("strong",{children:Object.keys(t).length})," of ",i.length," fields manually selected. Unselected fields will use the proposed resolution."]})})]})}function Mr({field:s,selectedSource:t,onSelect:a}){const r=Rr[s.field]||{label:s.field,icon:Ft,format:o=>o!=null?String(o):"Not set"},d=r.format?r.format(s.sourceValue):yt(s.sourceValue),i=r.format?r.format(s.targetValue):yt(s.targetValue),l=na(s);return e.jsx(_,{className:F("overflow-hidden transition-colors",l&&"border-yellow-200 dark:border-yellow-900"),children:e.jsxs(z,{className:"p-0",children:[e.jsxs("div",{className:"grid grid-cols-[1fr,auto,1fr] gap-0",children:[e.jsxs("button",{onClick:()=>a("source"),className:F("p-4 text-left transition-colors hover:bg-muted/50 flex items-center gap-3",t==="source"&&"bg-primary/5 hover:bg-primary/10"),children:[e.jsx("div",{className:F("w-5 h-5 rounded-full border-2 flex items-center justify-center flex-shrink-0",t==="source"?"border-primary bg-primary text-primary-foreground":"border-muted-foreground/30"),children:t==="source"&&e.jsx(pe,{className:"w-3.5 h-3.5"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-xs text-muted-foreground uppercase tracking-wide mb-1",children:r.label}),e.jsx("p",{className:F("text-sm font-medium truncate",!s.sourceValue&&"text-muted-foreground italic"),children:d})]})]}),e.jsx("div",{className:"flex items-center justify-center bg-muted/30 px-2",children:e.jsx($s,{className:F("w-4 h-4 transition-colors",t==="source"&&"text-orange-500 rotate-180",t==="target"&&"text-primary")})}),e.jsxs("button",{onClick:()=>a("target"),className:F("p-4 text-left transition-colors hover:bg-muted/50 flex items-center gap-3",t==="target"&&"bg-primary/5 hover:bg-primary/10"),children:[e.jsx("div",{className:F("w-5 h-5 rounded-full border-2 flex items-center justify-center flex-shrink-0",t==="target"?"border-primary bg-primary text-primary-foreground":"border-muted-foreground/30"),children:t==="target"&&e.jsx(pe,{className:"w-3.5 h-3.5"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-xs text-muted-foreground uppercase tracking-wide mb-1",children:r.label}),e.jsx("p",{className:F("text-sm font-medium truncate",!s.targetValue&&"text-muted-foreground italic"),children:i})]})]})]}),l&&e.jsxs("div",{className:"px-4 py-2 bg-yellow-50 dark:bg-yellow-950/30 border-t border-yellow-100 dark:border-yellow-900 flex items-center gap-2",children:[e.jsx($,{variant:"outline",className:"text-yellow-700 dark:text-yellow-300 border-yellow-300 dark:border-yellow-700",children:"Conflict"}),e.jsx("span",{className:"text-xs text-yellow-700 dark:text-yellow-300",children:"Values differ - select which to keep"})]})]})})}function na(s){return s.sourceValue===s.targetValue||s.sourceValue==null&&s.targetValue==null?!1:s.sourceValue==null||s.targetValue==null?!0:String(s.sourceValue)!==String(s.targetValue)}function yt(s){return s==null?"Not set":typeof s=="boolean"?s?"Yes":"No":typeof s=="number"?s.toString():String(s)}function Ir({isOpen:s,onClose:t,conflict:a,selectedPrimary:r,onConfirmMerge:d}){const[i,l]=m.useState("fields"),[o,x]=m.useState({}),[u,v]=m.useState(""),j=r==="primary"?a.secondaryEmployee:a.primaryEmployee,b=r==="primary"?a.primaryEmployee:a.secondaryEmployee,f=r==="primary"?a.secondaryEmployeeId:a.primaryEmployeeId,N=r==="primary"?a.primaryEmployeeId:a.secondaryEmployeeId,n=Zn(),c=tr();m.useEffect(()=>{s&&f&&N&&n.mutate({sourceEmployeeId:f,targetEmployeeId:N})},[s,f,N]),m.useEffect(()=>{s||(x({}),v(""),l("fields"))},[s]);const k=(A,R)=>{x(ne=>({...ne,[A]:R}))},E=async()=>{if(!(!f||!N))try{await c.mutateAsync({sourceEmployeeId:f,targetEmployeeId:N,fieldResolution:o,mergeReason:u||void 0}),Ie.success("Employees merged successfully"),d?.(),t()}catch{Ie.error("Failed to merge employees")}};if(n.isPending)return e.jsx(Ce,{open:s,onOpenChange:t,children:e.jsx(Se,{className:"max-w-3xl",children:e.jsxs("div",{className:"flex flex-col items-center justify-center py-12",children:[e.jsx(Y,{className:"w-8 h-8 animate-spin text-primary mb-4"}),e.jsx("p",{className:"text-muted-foreground",children:"Generating merge preview..."})]})})});if(n.isError)return e.jsx(Ce,{open:s,onOpenChange:t,children:e.jsx(Se,{className:"max-w-3xl",children:e.jsxs("div",{className:"flex flex-col items-center justify-center py-8",children:[e.jsx(oe,{className:"w-12 h-12 text-destructive mb-4"}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"Preview Failed"}),e.jsx("p",{className:"text-muted-foreground text-center mb-4",children:"Unable to generate merge preview. Please try again."}),e.jsx(C,{onClick:t,children:"Close"})]})})});const T=n.data;if(!T||!j||!b)return null;const w=T.workItemsImpact?.totalAffected||0,V=T.workItemsImpact?.assignments?.filter(A=>A.type==="source")||[],g=T.workItemsImpact?.assignments?.filter(A=>A.type==="target")||[];return e.jsx(Ce,{open:s,onOpenChange:t,children:e.jsxs(Se,{className:"max-w-4xl max-h-[90vh] overflow-y-auto",children:[e.jsxs(Ee,{children:[e.jsxs(Te,{className:"flex items-center gap-2",children:[e.jsx(Qe,{className:"w-5 h-5"}),"Merge Preview"]}),e.jsx(Ge,{children:"Review the impact of merging these employee records before confirming."})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-4 py-4",children:[e.jsx(wt,{employee:j,label:"Source (Will be Archived)",variant:"source"}),e.jsx("div",{className:"flex items-center justify-center",children:e.jsxs("div",{className:"flex flex-col items-center gap-2",children:[e.jsx(Qe,{className:"w-8 h-8 text-primary"}),e.jsx($,{variant:"outline",children:"Merge Into"})]})}),e.jsx(wt,{employee:b,label:"Target (Will be Kept)",variant:"target"})]}),e.jsxs(Os,{value:i,onValueChange:l,children:[e.jsxs(qs,{className:"grid w-full grid-cols-2",children:[e.jsxs(je,{value:"fields",className:"gap-2",children:[e.jsx(ka,{className:"w-4 h-4"}),"Field Resolution",T.proposedResolution?.fields?.length>0&&e.jsx($,{variant:"secondary",className:"ml-1",children:T.proposedResolution.fields.length})]}),e.jsxs(je,{value:"workitems",className:"gap-2",children:[e.jsx(as,{className:"w-4 h-4"}),"Work Items",w>0&&e.jsx($,{variant:"secondary",className:"ml-1",children:w})]})]}),e.jsx(ve,{value:"fields",className:"mt-4",children:e.jsx(Lr,{fields:T.proposedResolution?.fields||[],fieldResolutions:o,onFieldResolutionChange:k,sourceEmployee:j,targetEmployee:b})}),e.jsx(ve,{value:"workitems",className:"mt-4",children:e.jsx(Fr,{totalAffected:w,sourceWorkItems:V,targetWorkItems:g,sourceName:j.fullName,targetName:b.fullName})})]}),w>10&&e.jsxs("div",{className:"bg-yellow-50 dark:bg-yellow-950/30 border border-yellow-200 dark:border-yellow-900 rounded-lg p-4 flex items-start gap-3",children:[e.jsx(Ke,{className:"w-5 h-5 text-yellow-600 dark:text-yellow-400 flex-shrink-0 mt-0.5"}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium text-yellow-800 dark:text-yellow-200",children:"High Impact Merge"}),e.jsxs("p",{className:"text-sm text-yellow-700 dark:text-yellow-300 mt-1",children:["This merge will affect ",w," work items. Please review carefully before proceeding."]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("label",{className:"text-sm font-medium",children:["Merge Reason ",e.jsx("span",{className:"text-red-500",children:"*"})," (required)"]}),e.jsx("textarea",{value:u,onChange:A=>v(A.target.value),placeholder:"Why are these records being merged?",className:"w-full min-h-[80px] px-3 py-2 rounded-md border bg-background text-sm resize-y focus:outline-none focus:ring-2 focus:ring-ring",maxLength:500}),e.jsxs("p",{className:"text-xs text-muted-foreground text-right",children:[u.length,"/500"]})]}),e.jsxs(Je,{className:"gap-2",children:[e.jsx(C,{variant:"outline",onClick:t,children:"Cancel"}),e.jsx(C,{onClick:E,disabled:c.isPending,className:"gap-2",children:c.isPending?e.jsxs(e.Fragment,{children:[e.jsx(Y,{className:"w-4 h-4 animate-spin"}),"Merging..."]}):e.jsxs(e.Fragment,{children:[e.jsx(pe,{className:"w-4 h-4"}),"Confirm Merge"]})})]})]})})}function wt({employee:s,label:t,variant:a}){const r=s.fullName.split(" ").map(d=>d[0]).join("").toUpperCase().slice(0,2);return e.jsxs(_,{className:F(a==="source"&&"border-orange-200 dark:border-orange-900"),children:[e.jsx(Le,{className:"pb-3",children:e.jsx($,{variant:a==="source"?"secondary":"default",className:"w-fit",children:t})}),e.jsxs(z,{children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:F("w-12 h-12 rounded-full flex items-center justify-center text-lg font-semibold",a==="source"?"bg-orange-100 text-orange-700 dark:bg-orange-900/30 dark:text-orange-300":"bg-primary/10 text-primary"),children:r}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h4",{className:"font-semibold truncate",children:s.fullName}),e.jsx("p",{className:"text-sm text-muted-foreground truncate",children:s.email})]})]}),e.jsxs("div",{className:"mt-4 space-y-1 text-sm",children:[s.department&&e.jsx("p",{className:"text-muted-foreground",children:s.department}),s.jobTitle&&e.jsx("p",{className:"text-muted-foreground",children:s.jobTitle}),s.phone&&e.jsx("p",{className:"text-muted-foreground",children:s.phone})]})]})]})}function Fr({totalAffected:s,sourceWorkItems:t,targetWorkItems:a,sourceName:r,targetName:d}){return s===0?e.jsxs("div",{className:"text-center py-8",children:[e.jsx(pe,{className:"w-12 h-12 text-green-500 mx-auto mb-3"}),e.jsx("h4",{className:"font-medium",children:"No Work Items Affected"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"This merge will not affect any work item assignments."})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"bg-muted/50 rounded-lg p-4",children:[e.jsxs("p",{className:"text-sm",children:[e.jsx("strong",{children:s})," work items will be reassigned:"]}),e.jsxs("ul",{className:"text-sm text-muted-foreground mt-2 space-y-1",children:[e.jsxs("li",{children:["• ",t.length," from ",r]}),e.jsxs("li",{children:["• ",a.length," already assigned to ",d]})]})]}),t.length>0&&e.jsxs("div",{children:[e.jsxs("h4",{className:"text-sm font-medium mb-2 flex items-center gap-2",children:[e.jsx($,{variant:"secondary",children:"To be reassigned"}),e.jsxs("span",{className:"text-muted-foreground",children:["from ",r]})]}),e.jsx("div",{className:"border rounded-lg divide-y max-h-48 overflow-y-auto",children:t.map(i=>e.jsxs("div",{className:"p-3 text-sm",children:[e.jsx("p",{className:"font-medium truncate",children:i.workItemTitle}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["ID: ",i.workItemId.slice(0,8)]})]},i.workItemId))})]})]})}function $r({conflict:s,onResolve:t,isResolving:a=!1}){const[r,d]=m.useState(!1),[i,l]=m.useState("primary"),o=s.primaryEmployee,x=s.secondaryEmployee;if(!o||!x)return e.jsx(_,{className:"border-destructive",children:e.jsx(z,{className:"p-4",children:e.jsxs("p",{className:"text-sm text-destructive",children:["Error: Missing employee data for conflict ",s.id]})})});const u=dr(s.confidenceScore),v=or(s),j=cr(o.fullName??"",x.fullName??""),b=(o.email??"").toLowerCase()===(x.email??"").toLowerCase(),f=!!(o.phoneNumber&&x.phoneNumber&&o.phoneNumber.replace(/\D/g,"")===x.phoneNumber.replace(/\D/g,"")),N=!!(o.department&&x.department&&o.department.toLowerCase()===x.department.toLowerCase()),n=()=>{const k=i==="primary"?s.primaryEmployeeId:s.secondaryEmployeeId;t(s.id,"MERGE",k)},c=()=>{t(s.id,"KEEP_BOTH")};return e.jsxs(e.Fragment,{children:[e.jsx(_,{className:F("overflow-hidden transition-all duration-200",a&&"opacity-50 pointer-events-none"),children:e.jsxs(z,{className:"p-0",children:[e.jsxs("div",{className:"px-4 py-3 border-b bg-muted/30 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs($,{variant:s.confidenceScore>=75?"destructive":"default",className:"gap-1",children:[e.jsx(Ke,{className:"w-3 h-3"}),u.label," Confidence (",s.confidenceScore,"%)"]}),e.jsx("span",{className:"text-sm text-muted-foreground",children:v})]}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["ID: ",s.id.slice(0,8)]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 divide-y md:divide-y-0 md:divide-x",children:[e.jsx(Ct,{employee:{...o,phone:o.phoneNumber},isSelected:i==="primary",onSelect:()=>l("primary"),label:"Record A",similarity:{name:j,email:b,phone:f,dept:N},isPrimary:!0}),e.jsx(Ct,{employee:{...x,phone:x.phoneNumber},isSelected:i==="secondary",onSelect:()=>l("secondary"),label:"Record B",similarity:{name:j,email:b,phone:f,dept:N},isPrimary:!1})]}),e.jsxs("div",{className:"px-4 py-3 border-t bg-muted/30 flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(pe,{className:"w-4 h-4"}),e.jsxs("span",{children:["Primary: ",e.jsx("strong",{children:i==="primary"?o.fullName:x.fullName})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>d(!0),className:"gap-2",children:[e.jsx(Aa,{className:"w-4 h-4"}),"Preview"]}),e.jsxs(C,{variant:"secondary",size:"sm",onClick:c,disabled:a,className:"gap-2",children:[e.jsx(qt,{className:"w-4 h-4"}),"Different People"]}),e.jsxs(C,{size:"sm",onClick:n,disabled:a,className:"gap-2",children:[e.jsx(Qe,{className:"w-4 h-4"}),"Merge"]})]})]})]})}),e.jsx(Ir,{isOpen:r,onClose:()=>d(!1),conflict:s,selectedPrimary:i,onConfirmMerge:()=>{n(),d(!1)}})]})}function Ct({employee:s,isSelected:t,onSelect:a,label:r,similarity:d,isPrimary:i}){const l=(s.fullName||s.email||"?").split(" ").map(o=>o[0]).join("").toUpperCase().slice(0,2);return e.jsxs("div",{className:F("p-4 cursor-pointer transition-colors relative",t&&"bg-primary/5"),onClick:a,children:[e.jsx("div",{className:F("absolute top-4 right-4 w-5 h-5 rounded-full border-2 flex items-center justify-center",t?"border-primary bg-primary text-primary-foreground":"border-muted-foreground
2/30"),children:t&&e.jsx(pe,{className:"w-3.5 h-3.5"})}),e.jsx($,{variant:"outline",className:"mb-3",children:r}),e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Sn,{className:"w-12 h-12",children:e.jsx(kn,{className:"text-lg bg-primary/10",children:l})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h4",{className:"font-semibold truncate",children:s.fullName}),e.jsxs("div",{className:"space-y-1 mt-2",children:[e.jsx(Qs,{icon:is,value:s.email,matches:d.email}),s.phone&&e.jsx(Qs,{icon:Ot,value:s.phone,matches:d.phone}),s.department&&e.jsx(Qs,{icon:$t,value:s.department,matches:d.dept}),s.jobTitle&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(as,{className:"w-3.5 h-3.5"}),e.jsx("span",{className:"truncate",children:s.jobTitle})]})]})]})]}),e.jsxs("div",{className:"mt-3 pt-3 border-t",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"text-muted-foreground",children:"Name Similarity"}),e.jsxs("span",{className:F(d.name>=90?"text-green-600":d.name>=70?"text-yellow-600":"text-muted-foreground"),children:[d.name,"%"]})]}),e.jsx("div",{className:"mt-1 h-1.5 bg-muted rounded-full overflow-hidden",children:e.jsx("div",{className:F("h-full rounded-full transition-all",d.name>=90?"bg-green-500":d.name>=70?"bg-yellow-500":"bg-muted-foreground"),style:{width:`${d.name}%`}})})]})]})}function Qs({icon:s,value:t,matches:a}){return e.jsxs("div",{className:F("flex items-center gap-2 text-sm",a?"text-green-600 dark:text-green-400":"text-muted-foreground"),children:[e.jsx(s,{className:"w-3.5 h-3.5"}),e.jsx("span",{className:"truncate",children:t}),a&&e.jsx(pe,{className:"w-3 h-3 ml-auto"})]})}function Or({conflicts:s,isLoading:t=!1}){const[a,r]=m.useState(""),[d,i]=m.useState("confidence-high"),[l,o]=m.useState("all"),[x,u]=m.useState(new Set),[v,j]=m.useState(null),b=de(),f=er(),N=sr(),n=m.useMemo(()=>{let g=[...s];if(a){const A=a.toLowerCase();g=g.filter(R=>{const ne=R.primaryEmployee,se=R.secondaryEmployee;return ne?.fullName.toLowerCase().includes(A)||ne?.email.toLowerCase().includes(A)||se?.fullName.toLowerCase().includes(A)||se?.email.toLowerCase().includes(A)})}return l!=="all"&&(g=g.filter(A=>{const R=A.confidenceScore;switch(l){case"high-confidence":return R>=75;case"medium-confidence":return R>=50&&R<75;case"low-confidence":return R<50;default:return!0}})),g.sort((A,R)=>{switch(d){case"confidence-high":return R.confidenceScore-A.confidenceScore;case"confidence-low":return A.confidenceScore-R.confidenceScore;case"newest":return new Date(R.createdAt).getTime()-new Date(A.createdAt).getTime();case"oldest":return new Date(A.createdAt).getTime()-new Date(R.createdAt).getTime();default:return 0}}),g},[s,a,d,l]),{pending:c,resolved:k}=m.useMemo(()=>mr(n),[n]),E=g=>{const A=new Set(x);A.has(g)?A.delete(g):A.add(g),u(A)},T=()=>{x.size===c.length?u(new Set):u(new Set(c.map(g=>g.id)))},w=async(g,A,R)=>{j(g);const ne=s.find(se=>se.id===g);if(!ne){j(null);return}try{await f.mutateAsync({matchId:g,action:A,primaryId:R,secondaryId:R===ne.primaryEmployeeId?ne.secondaryEmployeeId:ne.primaryEmployeeId}),Ie.success(A==="MERGE"?"Records merged successfully":"Marked as different people"),u(se=>{const Ne=new Set(se);return Ne.delete(g),Ne})}catch(se){se.status===409?(Ie.info("Conflict already resolved — refreshing list"),b.invalidateQueries({queryKey:ye(["deduplication"])}),u(re=>{const q=new Set(re);return q.delete(g),q})):Ie.error("Failed to resolve conflict")}finally{j(null)}},V=async g=>{if(x.size===0)return;const A=Array.from(x).map(R=>{const ne=s.find(se=>se.id===R);return{matchId:R,action:g,primaryId:ne?.primaryEmployeeId,secondaryId:ne?.secondaryEmployeeId}});try{const R=await N.mutateAsync(A);Ie.success(`Processed ${R.resolved} conflicts${R.failed>0?`, ${R.failed} failed`:""}`),u(new Set)}catch{Ie.error("Batch operation failed")}};return t?e.jsx(_,{children:e.jsx(z,{className:"p-8",children:e.jsx("div",{className:"space-y-4",children:Array.from({length:3}).map((g,A)=>e.jsx("div",{className:"h-32 bg-muted animate-pulse rounded-lg"},A))})})}):s.length===0?e.jsx(_,{className:"border-dashed",children:e.jsxs(z,{className:"p-12 text-center",children:[e.jsx(Ea,{className:"w-12 h-12 text-muted-foreground mx-auto mb-4"}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"No Conflicts Found"}),e.jsx("p",{className:"text-muted-foreground max-w-md mx-auto",children:"Great news! There are no duplicate employee records detected at this time. Run detection again after adding new employees."})]})}):n.length===0?e.jsx(_,{className:"border-dashed",children:e.jsxs(z,{className:"p-8 text-center",children:[e.jsx(Ps,{className:"w-10 h-10 text-muted-foreground mx-auto mb-3"}),e.jsx("h3",{className:"font-semibold mb-1",children:"No Matches"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Try adjusting your search or filters"}),e.jsx(C,{variant:"outline",size:"sm",className:"mt-4",onClick:()=>{r(""),o("all")},children:"Clear Filters"})]})}):e.jsxs("div",{className:"space-y-4",children:[e.jsx(_,{children:e.jsxs(z,{className:"p-4",children:[e.jsxs("div",{className:"flex flex-col lg:flex-row lg:items-center gap-4",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(We,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(ee,{placeholder:"Search by name or email...",value:a,onChange:g=>r(g.target.value),className:"pl-9"})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(De,{value:l,onValueChange:g=>o(g),children:[e.jsxs(Pe,{className:"w-[140px]",children:[e.jsx(Ps,{className:"w-4 h-4 mr-2"}),e.jsx($e,{placeholder:"Filter"})]}),e.jsxs(Re,{children:[e.jsx(te,{value:"all",children:"All"}),e.jsx(te,{value:"high-confidence",children:"High (≥75%)"}),e.jsx(te,{value:"medium-confidence",children:"Medium (50-74%)"}),e.jsx(te,{value:"low-confidence",children:"Low (<50%)"})]})]}),e.jsxs(De,{value:d,onValueChange:g=>i(g),children:[e.jsxs(Pe,{className:"w-[160px]",children:[e.jsx(Ta,{className:"w-4 h-4 mr-2"}),e.jsx($e,{placeholder:"Sort"})]}),e.jsxs(Re,{children:[e.jsx(te,{value:"confidence-high",children:"Confidence: High → Low"}),e.jsx(te,{value:"confidence-low",children:"Confidence: Low → High"}),e.jsx(te,{value:"newest",children:"Newest First"}),e.jsx(te,{value:"oldest",children:"Oldest First"})]})]}),x.size>0&&e.jsxs(it,{children:[e.jsx(lt,{asChild:!0,children:e.jsxs(C,{variant:"secondary",className:"gap-2",children:[e.jsx(pt,{className:"w-4 h-4"}),x.size," selected"]})}),e.jsxs(ct,{align:"end",children:[e.jsxs(Cs,{onClick:()=>V("MERGE"),children:[e.jsx(Qe,{className:"w-4 h-4 mr-2"}),"Merge Selected"]}),e.jsxs(Cs,{onClick:()=>V("KEEP_BOTH"),children:[e.jsx(qt,{className:"w-4 h-4 mr-2"}),"Mark as Different"]})]})]})]})]}),c.length>0&&e.jsxs("div",{className:"flex items-center gap-2 mt-4 pt-4 border-t",children:[e.jsx(rs,{checked:x.size===c.length&&c.length>0,onCheckedChange:T}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["Select all ",c.length," pending"]})]})]})}),c.length>0&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("h3",{className:"text-sm font-medium text-muted-foreground flex items-center gap-2",children:[e.jsx(oe,{className:"w-4 h-4"}),"Pending Review (",c.length,")"]}),c.map(g=>e.jsxs("div",{className:"flex gap-3",children:[e.jsx("div",{className:"pt-4",children:e.jsx(rs,{checked:x.has(g.id),onCheckedChange:()=>E(g.id)})}),e.jsx("div",{className:"flex-1",children:e.jsx($r,{conflict:g,onResolve:w,isResolving:v===g.
2id})})]},g.id))]}),k.length>0&&e.jsxs("div",{className:"space-y-3 mt-6",children:[e.jsxs("h3",{className:"text-sm font-medium text-muted-foreground flex items-center gap-2",children:[e.jsx(pt,{className:"w-4 h-4"}),"Recently Resolved (",k.length,")"]}),k.slice(0,5).map(g=>e.jsx(_,{className:"opacity-60",children:e.jsx(z,{className:"p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx($,{variant:g.resolution==="MERGE"?"default":"secondary",children:g.resolution==="MERGE"?"Merged":"Kept Separate"}),e.jsxs("span",{className:"text-sm",children:[g.primaryEmployee?.fullName," / ",g.secondaryEmployee?.fullName]})]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:g.resolvedAt&&new Date(g.resolvedAt).toLocaleDateString()})]})})},g.id)),k.length>5&&e.jsxs("p",{className:"text-center text-sm text-muted-foreground py-2",children:["+",k.length-5," more resolved"]})]})]})}function qr({isOpen:s,onClose:t,mergeRecord:a}){const[r,d]=m.useState(!1),[i,l]=m.useState(""),o=lr(),x=v=>{v||(d(!1),l(""),t())},u=async()=>{if(a)try{await o.mutateAsync({mergeId:a.id,reason:i||void 0}),Ie.success("Merge reverted successfully"),x(!1)}catch{Ie.error("Failed to revert merge")}};return a?e.jsx(Ce,{open:s,onOpenChange:x,children:e.jsxs(Se,{className:"max-w-lg",children:[e.jsxs(Ee,{children:[e.jsxs(Te,{className:"flex items-center gap-2 text-destructive",children:[e.jsx(Ke,{className:"w-5 h-5"}),"Revert Merge"]}),e.jsx(Ge,{children:"This action will undo the merge and restore the original employee record."})]}),e.jsx(_,{className:"bg-muted/50",children:e.jsxs(z,{className:"p-4",children:[e.jsxs("h4",{className:"text-sm font-medium mb-3 flex items-center gap-2",children:[e.jsx(ts,{className:"w-4 h-4"}),"Merge Details"]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Source (to restore)"}),e.jsx("span",{className:"font-medium",children:a.sourceEmployeeName})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Target (kept)"}),e.jsx("span",{className:"font-medium",children:a.targetEmployeeName})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Merged on"}),e.jsx("span",{className:"text-sm",children:new Date(a.mergedAt).toLocaleDateString()})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Work items affected"}),e.jsx($,{variant:"secondary",children:a.workItemsAffected})]})]})]})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("h4",{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(oe,{className:"w-4 h-4 text-yellow-500"}),"What will happen:"]}),e.jsxs("ul",{className:"space-y-2",children:[e.jsx(Hs,{icon:_e,text:`${a.sourceEmployeeName} will be restored as an active employee`}),e.jsx(Hs,{icon:as,text:`Work items will be reassigned back to ${a.sourceEmployeeName}`}),e.jsx(Hs,{icon:ts,text:"This revert will be recorded in the audit log",isWarning:!0})]})]}),Vr(a.mergedAt)&&e.jsxs("div",{className:"bg-yellow-50 dark:bg-yellow-950/30 border border-yellow-200 dark:border-yellow-900 rounded-lg p-4 flex items-start gap-3",children:[e.jsx(Ke,{className:"w-5 h-5 text-yellow-600 dark:text-yellow-400 flex-shrink-0 mt-0.5"}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium text-yellow-800 dark:text-yellow-200 text-sm",children:"Old Merge Warning"}),e.jsx("p",{className:"text-xs text-yellow-700 dark:text-yellow-300 mt-1",children:"This merge is over 30 days old. Some work items may have been modified since the merge. Please review carefully."})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Reason for Revert (Optional)"}),e.jsx(ls,{value:i,onChange:v=>l(v.target.value),placeholder:"Why are you reverting this merge?",className:"min-h-[80px]",maxLength:500}),e.jsxs("p",{className:"text-xs text-muted-foreground text-right",children:[i.length,"/500"]})]}),e.jsxs("div",{className:"flex items-start gap-3 p-4 border rounded-lg bg-destructive/5",children:[e.jsx(rs,{id:"confirm-revert",checked:r,onCheckedChange:v=>d(v===!0),className:"mt-0.5"}),e.jsxs("label",{htmlFor:"confirm-revert",className:"text-sm leading-relaxed cursor-pointer",children:["I understand that reverting this merge will restore",e.jsxs("strong",{children:[" ",a.sourceEmployeeName]})," and reassign work items. This action cannot be undone."]})]}),e.jsxs(Je,{className:"gap-2",children:[e.jsx(C,{variant:"outline",onClick:()=>x(!1),disabled:o.isPending,children:"Cancel"}),e.jsx(C,{variant:"destructive",onClick:u,disabled:!r||o.isPending,className:"gap-2",children:o.isPending?e.jsxs(e.Fragment,{children:[e.jsx(Y,{className:"w-4 h-4 animate-spin"}),"Reverting..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Rs,{className:"w-4 h-4"}),"Revert Merge"]})})]})]})}):null}function Hs({icon:s,text:t,isWarning:a}){return e.jsxs("li",{className:F("flex items-start gap-2 text-sm",a&&"text-yellow-700 dark:text-yellow-300"),children:[e.jsx(s,{className:F("w-4 h-4 mt-0.5 flex-shrink-0",a?"text-yellow-500":"text-muted-foreground")}),e.jsx("span",{children:t})]})}function Vr(s){const t=new Date(s),a=new Date;return a.setDate(a.getDate()-30),t<a}function Ur({employeeId:s}={}){const[t,a]=m.useState(""),[r,d]=m.useState("all"),[i,l]=m.useState(null),[o,x]=m.useState(!1),u=nr(),v=ar(s||""),{data:j=[],isLoading:b}=s?v:u,f=j.filter(n=>{if(t){const c=t.toLowerCase();if(!(n.sourceEmployeeName.toLowerCase().includes(c)||n.targetEmployeeName.toLowerCase().includes(c)||n.mergedBy.toLowerCase().includes(c)))return!1}return!(r==="active"&&n.revertedAt||r==="reverted"&&!n.revertedAt)}),N=n=>{l(n),x(!0)};return b?e.jsx(_,{children:e.jsx(z,{className:"p-8",children:e.jsx("div",{className:"space-y-4",children:Array.from({length:5}).map((n,c)=>e.jsx("div",{className:"h-12 bg-muted animate-pulse rounded"},c))})})}):j.length===0?e.jsx(_,{className:"border-dashed",children:e.jsxs(z,{className:"p-12 text-center",children:[e.jsx(ts,{className:"w-12 h-12 text-muted-foreground mx-auto mb-4"}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"No Merge History"}),e.jsx("p",{className:"text-muted-foreground max-w-md mx-auto",children:"No employee merges have been performed yet. Merge history will appear here after you merge duplicate employee records."})]})}):e.jsxs("div",{className:"space-y-4",children:[e.jsx(_,{children:e.jsx(z,{className:"p-4",children:e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center gap-4",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(We,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(ee,{placeholder:"Search by employee name or user...",value:t,onChange:n=>a(n.target.value),className:"pl-9"})]}),e.jsxs(De,{value:r,onValueChange:n=>d(n),children:[e.jsx(Pe,{className:"w-[140px]",children:e.jsx($e,{placeholder:"Filter"})}),e.jsxs(Re,{children:[e.jsx(te,{value:"all",children:"All Merges"}),e.jsx(te,{value:"active",children:"Active"}),e.jsx(te,{value:"reverted",children:"Reverted"})]})]})]})})}),e.jsx(_,{children:e.jsx(z,{className:"p-0",children:e.jsxs(ks,{children:[e.jsx(As,{children:e.jsxs(be,{children:[e.jsx(ae,{children:"Source → Target"}),e.jsx(ae,{children:"Date"}),e.jsx(ae,{children:"Work Items"}),e.jsx(ae,{children:"Status"}),e.jsx(ae,{className:"w-[100px]",children:"Actions"})]})}),e.jsx(Es,{children:f.length===0?e.jsx(be,{children:e.jsx(G,{colSpan:5,className:"text-center py-8 text-muted-foreground",children:"No merges match your filters"})}):f.map(n=>e.jsx(_r,{record:n,onRevert:()=>N(n)},n.id))})]})})}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsx(Ws,{label:"Total Merges",value:j.length,icon:Qe}),e.jsx(Ws,{label:"Active",value:j.filter(n=>!n.revertedAt).length,icon:pe,variant:"success"}),e.jsx(Ws,{label:"Reverted",value:j.filter(n=>n.revertedAt).length,icon:Rs,variant:"warning"})]}),e.jsx(qr,{isOpen:o,onClose:()=>{x(!1),l(null)},mergeRecord:i})]})}function _r({record:s,onRevert:t}){const a=!!s.revertedAt;return e.jsxs(be,{className:F(a&&"opacity-60"),children:[e.jsx(G,{children:e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium",children:s.sourceEmployeeName}),e.jsx(Da,{className:"w-3 h-3 text-muted-foreground"}),e.jsx("span",{className:"font-medium",children:s.targetEmployeeName})]}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx(Be,{className:"w-3 h-3"}),"by ",s.mergedBy]})]})}),e.jsx(G,{children:e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(ws,{className:"w-3.5 h-3.5 text-muted-foreground"}),new Date(s.mergedAt).toLocaleDateString()]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:new Date(s.mergedAt).toLocaleTimeString()})]})}),e.jsx(G,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(as,{className:"w-4 h-4 text-muted-foreground"}),e.jsxs("span",{className:"text-sm",children:[s.workItemsAffected," affected"]})]})}),e.jsxs(G,{children:[a?e.jsxs($,{variant:"secondary",className:"gap-1",children:[e.jsx(Rs,{className:"w-3 h-3"}),"Reverted"]}):e.jsxs($,{variant:"default",className:"gap-1",children:[e.jsx(pe,{className:"w-3 h-3"}),"Active"]}),a&&s.revertedBy&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["by ",s.revertedBy]})]}),e.jsx(G,{children:e.jsxs(it,{children:[e.jsx(lt,{asChild:!0,children:e.jsx(C,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",children:e.jsx(Pa,{className:"h-4 w-4"})})}),e.jsxs(ct,{align:"end",children:[e.jsxs(Cs,{onClick:()=>{},disabled:a,children:[e.jsx(ts,{className:"w-4 h-4 mr-2"}),"View Details"]}
2),!a&&e.jsxs(Cs,{onClick:t,className:"text-destructive focus:text-destructive",children:[e.jsx(Rs,{className:"w-4 h-4 mr-2"}),"Revert Merge"]})]})]})})]})}function Ws({label:s,value:t,icon:a,variant:r="default"}){const d={default:"bg-card",success:"bg-green-50/50 dark:bg-green-950/20",warning:"bg-yellow-50/50 dark:bg-yellow-950/20"};return e.jsx(_,{className:d[r],children:e.jsxs(z,{className:"p-4 flex items-center gap-3",children:[e.jsx(a,{className:"w-5 h-5 text-muted-foreground"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:t}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s})]})]})})}function zr(){const[s,t]=m.useState("conflicts"),{data:a=[],isLoading:r,error:d}=Xn(),{data:i,isLoading:l}=rr(),o=ir();m.useEffect(()=>{if(new URLSearchParams(window.location.search).get("triggerDedup")==="true"&&!o.isPending){o.mutate();const b=new URL(window.location.href);b.searchParams.delete("triggerDedup"),window.history.replaceState({},"",b.toString())}},[]);const x=()=>{o.mutate()},u=a.filter(v=>v.status?.toLowerCase()==="pending").length;return r||l?e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4",children:Array.from({length:4}).map((v,j)=>e.jsx(_,{className:"animate-pulse",children:e.jsxs(z,{className:"p-6",children:[e.jsx("div",{className:"h-8 bg-muted rounded w-16 mb-2"}),e.jsx("div",{className:"h-4 bg-muted rounded w-24"})]})},j))}),e.jsx(_,{className:"animate-pulse",children:e.jsx(z,{className:"p-12",children:e.jsx("div",{className:"h-32 bg-muted rounded"})})})]}):d?e.jsx(_,{className:"border-destructive",children:e.jsxs(z,{className:"p-8 text-center",children:[e.jsx(oe,{className:"w-12 h-12 text-destructive mx-auto mb-4"}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"Failed to Load Conflicts"}),e.jsx("p",{className:"text-muted-foreground mb-4",children:"There was an error loading the deduplication data."}),e.jsx(C,{variant:"outline",onClick:()=>window.location.reload(),children:"Retry"})]})}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4",children:[e.jsx(Ts,{title:"Pending Conflicts",value:u,icon:et,variant:u>0?"warning":"success",description:u>0?"Requires attention":"All caught up"}),e.jsx(Ts,{title:"Total Candidates",value:i?.totalCandidates??0,icon:Fe,variant:"default",description:"Detected duplicates"}),e.jsx(Ts,{title:"Merged Records",value:i?.merged??0,icon:Qe,variant:"success",description:"Successfully merged"}),e.jsx(Ts,{title:"False Positives",value:i?.falsePositives??0,icon:pe,variant:"default",description:"Marked as different"})]}),e.jsxs(Os,{value:s,onValueChange:t,children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 mb-4",children:[e.jsxs(qs,{children:[e.jsxs(je,{value:"conflicts",className:"gap-2",children:[e.jsx(et,{className:"w-4 h-4"}),"Conflicts",u>0&&e.jsx($,{variant:"destructive",className:"ml-1",children:u})]}),e.jsxs(je,{value:"history",className:"gap-2",children:[e.jsx(ts,{className:"w-4 h-4"}),"Merge History"]})]}),e.jsxs(C,{variant:"outline",size:"sm",onClick:x,disabled:o.isPending,className:"gap-2",children:[e.jsx(Ss,{className:F("w-4 h-4",o.isPending&&"animate-spin")}),o.isPending?"Running...":"Run Detection"]})]}),e.jsx(ve,{value:"conflicts",className:"mt-0",children:e.jsx(Or,{conflicts:a,isLoading:r})}),e.jsx(ve,{value:"history",className:"mt-0",children:e.jsx(Ur,{})})]})]})}function Ts({title:s,value:t,icon:a,variant:r,description:d}){const i={default:"bg-card border-border",warning:"bg-yellow-50/50 border-yellow-200 dark:bg-yellow-950/20 dark:border-yellow-900",success:"bg-green-50/50 border-green-200 dark:bg-green-950/20 dark:border-green-900",destructive:"bg-red-50/50 border-red-200 dark:bg-red-950/20 dark:border-red-900"},l={default:"text-muted-foreground",warning:"text-yellow-600 dark:text-yellow-400",success:"text-green-600 dark:text-green-400",destructive:"text-red-600 dark:text-red-400"};return e.jsx(_,{className:F("border",i[r]),children:e.jsx(z,{className:"p-4",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:s}),e.jsx("p",{className:"text-2xl font-bold mt-1",children:t}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:d})]}),e.jsx(a,{className:F("w-5 h-5 mt-1",l[r])})]})})})}function ra(s){const t=["jira","linear","asana","github"];return s.find(r=>t.includes(r))??"manual"}function Br(s){if(!s)return"Unknown";const t=Date.now()-new Date(s).getTime(),a=Math.floor(t/864e5);return a===0?"Today":a===1?"Yesterday":a<30?`${a}d ago`:a<365?`${Math.floor(a/30)}mo ago`:`${Math.floor(a/365)}y ago`}function Gs({title:s,value:t,description:a,icon:r,variant:d}){const i={default:"bg-card border-border",warning:"bg-yellow-50/50 border-yellow-200 dark:bg-yellow-950/20 dark:border-yellow-900",success:"bg-green-50/50 border-green-200 dark:bg-green-950/20 dark:border-green-900"}[d],l={default:"text-muted-foreground",warning:"text-yellow-600 dark:text-yellow-400",success:"text-green-600 dark:text-green-400"}[d];return e.jsx(_,{className:F("border",i),children:e.jsx(z,{className:"p-4",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:s}),e.jsx("p",{className:"text-2xl font-bold mt-1",children:t}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:a})]}),e.jsx(r,{className:F("w-5 h-5 mt-1",l)})]})})})}function Kr({assignee:s,onMapExisting:t,onCreateNew:a}){return e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center gap-3 py-3 border-b border-border last:border-0",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"font-medium text-sm truncate max-w-[240px]",title:s.name,children:s.name}),e.jsxs($,{variant:"secondary",className:"text-xs shrink-0",children:[s.itemCount," ",s.itemCount===1?"item":"items"]}),s.sources.map(r=>e.jsx($,{variant:"outline",className:"text-xs shrink-0 capitalize",children:r},r))]}),s.sampleTitles.length>0&&e.jsx("p",{className:"text-xs text-muted-foreground mt-1 truncate max-w-sm",children:s.sampleTitles.slice(0,3).join(" · ")}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:["Last seen: ",Br(s.lastSeenAt)]})]}),e.jsxs("div",{className:"flex gap-2 shrink-0",children:[e.jsxs(C,{size:"sm",variant:"outline",onClick:()=>t(s),className:"gap-1.5 text-xs",children:[e.jsx(Vt,{className:"h-3.5 w-3.5"}),"Map to existing"]}),e.jsxs(C,{size:"sm",variant:"ghost",onClick:()=>a(s),className:"gap-1.5 text-xs",children:[e.jsx(_e,{className:"h-3.5 w-3.5"}),"Create new"]})]})]})}function Qr({assignee:s,isOpen:t,onClose:a}){const{toast:r}=ge(),[d,i]=m.useState(""),[l,o]=m.useState(null),[x,u]=m.useState(!1),{data:v}=ot({search:d||void 0,limit:50}),j=v?.data??[],b=ea(),f=m.useMemo(()=>j.find(c=>c.id===l),[j,l]),N=()=>{i(""),o(null),u(!1),a()},n=()=>{!s||!l||b.mutate({name:s.name,employeeId:l,source:ra(s.sources)},{onSuccess:c=>
2{r({title:"Assignee mapped",description:c.message}),N()},onError:c=>{r({title:"Mapping failed",description:c.message||"Could not map assignee.",variant:"destructive"})}})};return s?e.jsx(Ce,{open:t,onOpenChange:c=>{c||N()},children:e.jsxs(Se,{className:"sm:max-w-lg",children:[e.jsxs(Ee,{children:[e.jsx(Te,{children:"Map to existing employee"}),e.jsxs(Ge,{children:["Select the employee who corresponds to"," ",e.jsxs("span",{className:"font-medium text-foreground",children:["“",s.name,"”"]}),". All ",s.itemCount," work ",s.itemCount===1?"item":"items"," will be re-attributed to the selected employee."]})]}),x?e.jsxs("div",{className:"py-4 text-sm text-muted-foreground",children:["Confirming mapping — this will update ",s.itemCount," work"," ",s.itemCount===1?"item":"items"," and create an identity link."]}):e.jsxs("div",{className:"space-y-4 py-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(J,{htmlFor:"emp-search",children:"Search employees"}),e.jsxs("div",{className:"relative",children:[e.jsx(We,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground pointer-events-none"}),e.jsx(ee,{id:"emp-search",placeholder:"Name or email...",value:d,onChange:c=>{i(c.target.value),o(null)},className:"pl-9"})]})]}),e.jsx("div",{className:"border rounded-md max-h-60 overflow-y-auto divide-y divide-border",children:j.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-6",children:"No employees found"}):j.map(c=>e.jsxs("button",{type:"button",onClick:()=>o(c.id),className:F("w-full text-left px-4 py-2.5 text-sm hover:bg-muted/50 transition-colors flex items-center gap-3",l===c.id&&"bg-primary/10 ring-1 ring-inset ring-primary/30"),children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium truncate",children:c.fullName}),e.jsx("p",{className:"text-xs text-muted-foreground truncate",children:c.email})]}),l===c.id&&e.jsx(pe,{className:"h-4 w-4 text-primary shrink-0"})]},c.id))}),f&&e.jsxs("div",{className:"rounded-md border border-primary/30 bg-primary/5 px-4 py-3 text-sm",children:[e.jsxs("strong",{children:[s.itemCount," ",s.itemCount===1?"item":"items"]})," will be re-attributed to"," ",e.jsx("strong",{children:f.fullName})," (",f.email,")."]})]}),e.jsxs(Je,{children:[e.jsx(C,{variant:"outline",onClick:N,disabled:b.isPending,children:"Cancel"}),e.jsxs(C,{onClick:n,disabled:!l||b.isPending,className:"gap-2",children:[b.isPending&&e.jsx(Ss,{className:"h-4 w-4 animate-spin"}),b.isPending?"Mapping...":"Confirm mapping"]})]})]})}):null}const Hr=[{value:"FRONTEND",label:"Frontend"},{value:"BACKEND",label:"Backend"},{value:"FULLSTACK",label:"Full-stack"},{value:"PRODUCT",label:"Product"},{value:"DESIGN",label:"Design"},{value:"QA",label:"QA"},{value:"DEVOPS",label:"DevOps"},{value:"AI_ML",label:"AI / ML"},{value:"DATA",label:"Data"},{value:"OTHER",label:"Other"}];function Wr({assignee:s,isOpen:t,onClose:a}){const{toast:r}=ge(),[d,i]=m.useState(s?.name??""),[l,o]=m.useState(""),[x,u]=m.useState("OTHER"),v=Jt(),j=ea(),[b,f]=m.useState(null);s&&s.name!==b&&(f(s.name),i(s.name),o(""),u("OTHER"));const N=()=>{a()},n=d.trim().length>0&&l.trim().length>0&&l.includes("@"),c=v.isPending||j.isPending,k=()=>{if(!s||!n)return;const E={fullName:d.trim(),email:l.trim().toLowerCase(),primarySpecialization:x,availabilityStatus:"AVAILABLE",hoursPerWeek:40,currency:"USD"};v.mutate(E,{onSuccess:T=>{j.mutate({name:s.name,employeeId:T.id,source:ra(s.sources)},{onSuccess:w=>{r({title:"Employee created and mapped",description:`${T.fullName} created. ${w.message}`}),N()},onError:w=>{r({title:"Employee created, mapping failed",description:`${T.fullName} was created but the identity mapping failed: ${w.message}`,variant:"destructive"}),N()}})},onError:T=>{r({title:"Employee creation failed",description:T.message||"Could not create employee.",variant:"destructive"})}})};return s?e.jsx(Ce,{open:t,onOpenChange:E=>{E||N()},children:e.jsxs(Se,{className:"sm:max-w-md",children:[e.jsxs(Ee,{children:[e.jsx(Te,{children:"Create new employee"}),e.jsxs(Ge,{children:["Create a new employee record for"," ",e.jsxs("span",{className:"font-medium text-foreground",children:["“",s.name,"”"]})," and map all ",s.itemCount," ",s.itemCount===1?"item":"items"," to them."]})]}),e.jsxs("div",{className:"space-y-4 py-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(J,{htmlFor:"new-full-name",children:"Full name"}),e.jsx(ee,{id:"new-full-name",value:d,onChange:E=>i(E.target.value),placeholder:"Full name"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(J,{htmlFor:"new-email",children:["Email ",e.jsx("span",{className:"text-destructive",children:"*"})]}
2),e.jsx(ee,{id:"new-email",type:"email",value:l,onChange:E=>o(E.target.value),placeholder:"[email protected]"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(J,{htmlFor:"new-spec",children:"Primary specialization"}),e.jsxs(De,{value:x,onValueChange:u,children:[e.jsx(Pe,{id:"new-spec",children:e.jsx($e,{})}),e.jsx(Re,{children:Hr.map(E=>e.jsx(te,{value:E.value,children:E.label},E.value))})]})]}),e.jsxs("div",{className:"rounded-md border border-primary/30 bg-primary/5 px-4 py-3 text-sm",children:["After creation, ",e.jsx("strong",{children:s.itemCount})," ",s.itemCount===1?"item":"items"," will be re-attributed to"," ",e.jsx("strong",{children:d||s.name}),"."]})]}),e.jsxs(Je,{children:[e.jsx(C,{variant:"outline",onClick:N,disabled:c,children:"Cancel"}),e.jsxs(C,{onClick:k,disabled:!n||c,className:"gap-2",children:[c&&e.jsx(Ss,{className:"h-4 w-4 animate-spin"}),c?"Creating...":"Create and map"]})]})]})}):null}function Gr(){const{data:s=[],isLoading:t,error:a,refetch:r,isFetching:d}=hr(),[i,l]=m.useState(""),[o,x]=m.useState(null),u=m.useMemo(()=>{if(!i)return s;const N=i.toLowerCase();return s.filter(n=>n.name.toLowerCase().includes(N))},[s,i]),v=s.reduce((N,n)=>N+n.itemCount,0),j=N=>x({assignee:N,mode:"map-existing"}),b=N=>x({assignee:N,mode:"create-new"}),f=()=>x(null);return t?e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:Array.from({length:3}).map((N,n)=>e.jsx(_,{className:"animate-pulse",children:e.jsxs(z,{className:"p-6",children:[e.jsx("div",{className:"h-8 bg-muted rounded w-16 mb-2"}),e.jsx("div",{className:"h-4 bg-muted rounded w-24"})]})},n))}),e.jsx(_,{className:"animate-pulse",children:e.jsx(z,{className:"p-12",children:e.jsx("div",{className:"h-32 bg-muted rounded"})})})]}):a?e.jsx(_,{className:"border-destructive",children:e.jsxs(z,{className:"p-8 text-center",children:[e.jsx(oe,{className:"w-12 h-12 text-destructive mx-auto mb-4"}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"Failed to load unmapped assignees"}),e.jsx("p",{className:"text-muted-foreground mb-4",children:"There was an error retrieving the data."}),e.jsx(C,{variant:"outline",onClick:()=>r(),children:"Retry"})]})}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[e.jsx(Gs,{title:"Unmapped names",value:s.length,description:s.length>0?"Need resolution":"All resolved",icon:Fe,variant:s.length>0?"warning":"success"}),e.jsx(Gs,{title:"Affected work items",value:v,description:"Missing velocity attribution",icon:oe,variant:v>0?"warning":"success"}),e.jsx(Gs,{title:"Showing",value:u.length,description:i?"Matching filter":"Total distinct names",icon:pe,variant:"default"})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center gap-3",children:[e.jsxs("div",{className:"relative flex-1 max-w-xs",children:[e.jsx(We,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground pointer-events-none"}),e.jsx(ee,{placeholder:"Filter by name...",value:i,onChange:N=>l(N.target.value),className:"pl-9"})]}),e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>r(),disabled:d,className:"gap-2 shrink-0",children:[e.jsx(Ss,{className:F("h-4 w-4",d&&"animate-spin")}),d?"Refreshing...":"Refresh"]})]}),s.length===0?e.jsx(_,{children:e.jsxs(z,{className:"p-12 text-center",children:[e.jsx(pe,{className:"w-12 h-12 text-green-500 dark:text-green-400 mx-auto mb-4"}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"All assignees are mapped"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:"Every work item assignee in this workspace resolves to a known employee. Velocity attribution is complete."})]})}):u.length===0?e.jsx(_,{children:e.jsx(z,{className:"p-8 text-center",children:e.jsxs("p",{className:"text-muted-foreground text-sm",children:["No unmapped names match “",i,"”."]})})}):e.jsx(_,{children:e.jsxs(z,{className:"p-0",children:[e.jsx("div",{className:"px-4 pt-4 pb-1 flex items-center justify-between border-b border-border",children:e.jsxs("p",{className:"text-sm font-medium text-muted-foreground",children:[u.length," ",u.length===1?"name":"names"," — select a resolution for each"]})}),e.jsx("div",{className:"px-4 divide-y divide-border",children:u.map(N=>e.jsx(Kr,{assignee:N,onMapExisting:j,onCreateNew:b},N.name))})]})}),e.jsx(Qr,{assignee:o?.mode==="map-existing"?o.assignee:null,isOpen:o?.mode==="map-existing",onClose:f}),e.jsx(Wr,{assignee:o?.mode==="create-new"?o.assignee:null,isOpen:o?.mode==="create-new",onClose:f})]})}function Jr(){zt();const{toast:s}=ge(),t=Jt(),a=Gt(),r=jn(),d=vn(),i=Nn(),[l,o]=m.useState("idle"),[x,u]=m.useState(!1),v=m.useCallback(async()=>{try{o("syncing"),await d.mutateAsync({source:"WORK_ITEMS",deduplicateMatches:!0,overwriteExisting:!1}),o("classifying"),await i.mutateAsync()}finally{o("idle")}},[d,i]),j=m.useCallback(async()=>{u(!0);try{(await d.mutateAsync({source:"PLATFORM_USERS",deduplicateMatches:!0,overwriteExisting:!1})).importedCount>0&&await i.mutateAsync()}finally{u(!1)}},[d,i]),[b,f]=m.useState(!1),[N,n]=m.useState(!1),[c,k]=m.useState(!1),[E,T]=m.useState(null),w=m.useRef(!1),{data:V}=ot({limit:1e3}),g=V?.data||[];m.useEffect(()=>{V&&g.length===0&&!w.current&&!d.isPending&&(w.current=!0,d.mutate({source:"WORK_ITEMS",deduplicateMatches:!0,overwriteExisting:!1}))},[V,g.length,d]);const A=m.useCallback(re=>{t.mutate(re,{onSuccess:()=>{f(!1),s({title:"Employee Created",description:`${re.fullName} has been added successfully.`})},onError:q=>{s({title:"Creation Failed",description:q.message||"Could not create employee.",variant:"destructive"})}})},[t,s]),R=m.useCallback(re=>{E&&a.mutate({id:E.id,data:re},{onSuccess:()=>{n(!1),T(null),s({title:"Employee Updated",description:`${re.fullName} has been updated successfully.`})},onError:q=>{s({title:"Update Failed",description:q.message||"Could not update employee.",variant:"destructive"})}})},[E,a,s]),ne=m.useCallback(re=>{T(re),n(!0)},[]),se=m.useCallback(re=>{window.confirm(`Are you sure you want to archive ${re.fullName}?`)&&r.mutate(re.id,{onSuccess:()=>{s({title:"Employee Archived",description:`${re.fullName} has been archived.`})},onError:q=>{s({title:"Archive Failed",description:q.message||"Could not archive employee.",variant:"destructive"})}})},[r,s]),Ne=m.useCallback(re=>{k(!1),s({title:"Absence Requested",description:"The absence request has been submitted for approval."})},[s]);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold text-foreground",children:"Employee Management"}),e.jsx("p",{className:"text-sm text-muted-foreground dark:text-muted-foreground mt-1",children:"Manage employees, absences, and deduplication"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(C,{variant:"outline",onClick:()=>k(!0),children:[e.jsx(ws,{className:"h-4 w-4 mr-2"}),"Request Absence"]}),e.jsxs(C,{variant:"outline",onClick:j,disabled:x||d.isPending,children:[e.jsx(Ra,{className:"h-4 w-4 mr-2"}),x?"Importing seats...":"Import from Workspace Members"]}),e.jsxs(C,{variant:"outline",onClick:v,disabled:l!=="idle",children:[e.jsx(Zs,{className:"h-4 w-4 mr-2"}),l==="syncing"?"Syncing employees...":l==="classifying"?"Classifying skills...":"Enrich Employee Skills from Backlog"]}),e.jsxs(C,{onClick:()=>f(!0),children:[e.jsx(bs,{className:"h-4 w-4 mr-2"}),"Add Employee"]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-border bg-muted/30 px-4 py-2.5 text-xs text-muted-foreground",children:[e.jsx(Ut,{className:"h-3.5 w-3.5 shrink-0","aria-hidden":"true"}),e.jsxs("span",{children:["Configure quarterly capacity for scheduling in the"," ",e.jsxs(at,{href:"/admin/team?tab=capacity",className:"font-medium text-primary underline-offset-2 hover:underline inline-flex items-center gap-0.5",children:["Capacity Planning tab",e.jsx($s,{className:"h-3 w-3","aria-hidden":"true"})]})]})]}),e.jsxs(Os,{defaultValue:"employees",className:"w-full",children:[e.jsxs(qs,{className:"grid w-full grid-cols-4 max-w-2xl",children:[e.jsxs(je,{value:"employees",className:"flex items-center gap-2",children:[e.jsx(Fe,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Employees"}),e.jsx("span",{className:"sm:hidden",children:"Staff"})]}),e.jsxs(je,{value:"absences",className:"flex items-center gap-2",children:[e.jsx(ws,{className:"h-4 w-4"}
2),e.jsx("span",{className:"hidden sm:inline",children:"Absences"}),e.jsx("span",{className:"sm:hidden",children:"Out"})]}),e.jsxs(je,{value:"deduplication",className:"flex items-center gap-2",children:[e.jsx(Qe,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Deduplication"}),e.jsx("span",{className:"sm:hidden",children:"Merge"})]}),e.jsxs(je,{value:"identity-mapping",className:"flex items-center gap-2",children:[e.jsx(Vt,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Identity Mapping"}),e.jsx("span",{className:"sm:hidden",children:"Map"})]})]}),e.jsx(ve,{value:"employees",className:"mt-6",children:e.jsx(Nr,{onEditEmployee:ne,onArchiveEmployee:se})}),e.jsx(ve,{value:"absences",className:"mt-6",children:e.jsx(Pr,{})}),e.jsx(ve,{value:"deduplication",className:"mt-6",children:e.jsx(zr,{})}),e.jsxs(ve,{value:"identity-mapping",className:"mt-6",children:[e.jsx("div",{className:"text-sm text-muted-foreground mb-4",children:"Resolve assignee names that appear in work items but cannot be matched to any employee. Mapping these names enables accurate velocity attribution on the Team tab."}),e.jsx(Gr,{})]})]}),e.jsx(Ce,{open:b,onOpenChange:f,children:e.jsxs(Se,{className:"sm:max-w-lg max-h-[90vh] overflow-y-auto",children:[e.jsx(Ee,{children:e.jsx(Te,{children:"Create Employee"})}),e.jsx(bt,{onSubmit:A,onCancel:()=>f(!1),isPending:t.isPending})]})}),e.jsx(Ce,{open:N,onOpenChange:n,children:e.jsxs(Se,{className:"sm:max-w-lg max-h-[90vh] overflow-y-auto",children:[e.jsx(Ee,{children:e.jsx(Te,{children:"Edit Employee"})}),E&&e.jsx(bt,{employee:E,onSubmit:R,onCancel:()=>{n(!1),T(null)},isPending:a.isPending})]})}),e.jsx(Ce,{open:c,onOpenChange:k,children:e.jsxs(Se,{className:"sm:max-w-lg max-h-[90vh] overflow-y-auto",children:[e.jsx(Ee,{children:e.jsx(Te,{children:"Request Absence"})}),e.jsx(Dr,{employees:g,onSubmit:Ne,onCancel:()=>k(!1)})]})})]})}function Yr(s,t=1,a=50){const r=me.admin.accessMatrix(s??"none",t,a),{data:d,isLoading:i,error:l,refetch:o}=ue({queryKey:r,enabled:!!s,queryFn:async()=>{const x=new URLSearchParams({page:String(t),limit:String(a)});return s&&x.set("workspaceId",s),await Q(`/api/admin/users?${x}`)},staleTime:3e4});return{users:d?.data?.users??[],pagination:d?.data?.pagination??{page:1,limit:a,total:0},isLoading:i,error:l,refetch:o,queryKey:r}}function Xr(){const s=de(),{toast:t}=ge(),{reportError:a}=nt("user-access-matrix"),r=le({mutationFn:async({userId:i,dataAccessLevel:l,workspaceId:o})=>Q(`/api/admin/users/${i}/access-level`,{method:"PATCH",body:{dataAccessLevel:l,workspaceId:o}}),onSuccess:(i,l)=>{s.invalidateQueries({queryKey:me.admin.accessMatrix()}),t({title:"Access level updated",description:`Data access level set to ${l.dataAccessLevel}`})},onError:i=>{const l=i?.response?.error||i?.message||"Failed to update access level",o=typeof l=="string"?l.replace(/^\d{3}:\s*/,""):"Failed to update access level";t({title:"Update failed",description:o,variant:"destructive"}),i?.status>=500&&a(i,{endpoint:"/api/admin/users/:userId/access-level"})}});return{updateAccessLevel:async i=>{try{return await r.mutateAsync(i),{ok:!0}}catch(l){return{ok:!1,error:l}}}
2,isPending:r.isPending,pendingUserId:r.variables?.userId??null}}const St={public:"bg-deepwind-bg text-deepwind-text-body",internal:"bg-[var(--info-soft)] text-[var(--info-fg)]",confidential:"bg-deepwind-warning-soft text-deepwind-warning-fg",restricted:"bg-[var(--danger-soft)] text-[var(--danger-fg)]"};function Zr({workspaceId:s}){const{requests:t,pendingCount:a,isLoading:r,error:d}=Wa(s),{resolveRequest:i,isPending:l,pendingRequestId:o}=Ga(),[x,u]=m.useState(null),[v,j]=m.useState(""),b=async c=>{await i({requestId:c.id,action:"approve"})},f=c=>{u(c),j("")},N=async()=>{x&&(await i({requestId:x.id,action:"deny",resolverNote:v.trim()}),u(null),j(""))},n=v.trim().length>=10;return r?e.jsxs(_,{children:[e.jsx(Le,{className:"pb-3",children:e.jsx(X,{className:"h-5 w-48"})}),e.jsxs(z,{className:"space-y-2",children:[e.jsx(X,{className:"h-16 w-full"}),e.jsx(X,{className:"h-16 w-full"})]})]}):d?e.jsxs(Ls,{variant:"destructive",children:[e.jsx(oe,{className:"h-4 w-4"}),e.jsx(Ms,{children:"Failed to load pending access requests."})]}):t.length===0?null:e.jsxs(e.Fragment,{children:[e.jsxs(_,{className:"border-[var(--deepwind-warning)]",children:[e.jsx(Le,{className:"pb-3",children:e.jsxs(He,{className:"text-base flex items-center gap-2",children:[e.jsx(et,{className:"h-4 w-4 text-deepwind-warning-fg"}),"Pending Access Requests",e.jsx($,{className:"bg-deepwind-warning-soft text-deepwind-warning-fg ml-1",children:a})]})}),e.jsx(z,{className:"space-y-3",children:t.map(c=>{const k=l&&o===c.id;return e.jsx("div",{className:"border rounded-md p-3 bg-muted/20 space-y-2",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"font-medium text-sm",children:c.userName||c.userEmail||"Unknown user"}),c.userEmail&&c.userName&&e.jsx("span",{className:"text-xs text-muted-foreground",children:c.userEmail})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-1 text-xs",children:[e.jsx($,{className:`${St[c.currentLevel]} text-[10px] px-1.5 py-0`,children:c.currentLevel}),e.jsx("span",{className:"text-muted-foreground",children:"→"}),e.jsx($,{className:`${St[c.requestedLevel]} text-[10px] px-1.5 py-0`,children:c.requestedLevel}),e.jsxs("span",{className:"text-muted-foreground",children:["· ",new Date(c.createdAt).toLocaleDateString()]})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2 whitespace-pre-wrap",children:c.justification})]}),e.jsxs("div",{className:"flex gap-2 shrink-0",children:[e.jsxs(C,{size:"sm",variant:"outline",onClick:()=>f(c),disabled:k,children:[e.jsx(vs,{className:"h-3 w-3 mr-1"}),"Deny"]}),e.jsxs(C,{size:"sm",onClick:()=>b(c),disabled:k,children:[k?e.jsx(Y,{className:"h-3 w-3 animate-spin mr-1"}):e.jsx(js,{className:"h-3 w-3 mr-1"}),"Approve"]})]})]})},c.id)})})]}),e.jsx(cs,{open:!!x,onOpenChange:c=>{c||(u(null),j(""))},children:e.jsxs(os,{children:[e.jsxs(ds,{children:[e.jsx(ms,{children:"Deny Access Request"}),e.jsx(us,{children:"Explain why this request is being denied. The requester will see this note. Minimum 10 characters."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(ls,{value:v,onChange:c=>j(c.target.value),placeholder:"e.g., Access to confidential data requires manager approval first. Please discuss with your manager and resubmit.",rows:4,maxLength:500}),e.jsxs("div",{className:"flex justify-between text-xs text-muted-foreground",children:[e.jsxs("span",{className:n?"text-[var(--success-fg)]":"",children:[v.trim().length," / 10 minimum"]}),e.jsxs("span",{children:[v.length," / 500"]})]})]}),e.jsxs(xs,{children:[e.jsx(hs,{children:"Cancel"}),e.jsx(ps,{onClick:N,disabled:!n||l,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:l?e.jsxs(e.Fragment,{children:[e.jsx(Y,{className:"h-4 w-4 animate-spin mr-2"}),"Denying..."]}):"Deny Request"})]})]})})]})}const kt=[{value:"public",label:"Public",description:"All users, including guests"},{value:"internal",label:"Internal",description:"All authenticated workspace members"},{value:"confidential",label:"Confidential",description:"Managers and above only"},{value:"restricted",label:"Restricted",description:"Admins only"}],At={public:"bg-deepwind-bg text-deepwind-text-body",internal:"bg-[var(--info-soft)] text-[var(--info-fg)]",confidential:"bg-deepwind-warning-soft text-deepwind-warning-fg",restricted:"bg-[var(--danger-soft)] text-[var(--danger-fg)]"},ia=[{value:"member",label:"User"},{value:"portfolio_admin",label:"Portfolio Admin"},{value:"admin",label:"Admin"}],Et=Object.fromEntries(ia.map(s=>[s.value,s.label]));function Js(s){return s==="active"}function ei(s){return s.firstName&&s.lastName?`${s.firstName[0]}${s.lastName[0]}`.toUpperCase():s.email[0]?.toUpperCase()??"?"}function Tt(s){return s.firstName&&s.lastName?`${s.firstName} ${s.lastName}`:s.username||s.email}function si(){const s=Ja(),t=de(),{toast:a}=ge(),[r,d]=m.useState(1),[i,l]=m.useState("all"),[o,x]=m.useState(null),{users:u,pagination:v,isLoading:j,error:b}=Yr(s,r),{updateAccessLevel:f,isPending:N,pendingUserId:n}=Xr();ue({queryKey:me.billing.subscription(),queryFn:async()=>await Q("/api/billing/subscription"),staleTime:6e4});const c=le({mutationFn:async({userId:g,action:A})=>Q(`/api/admin/users/${g}/seat`,{method:"POST",body:{action:A}}),onSuccess:(g,A)=>{a({title:"Seat updated",description:`Seat ${A.action}d successfully`}),t.invalidateQueries({queryKey:me.admin.accessMatrix()}),t.invalidateQueries({queryKey:me.admin.users()}),t.invalidateQueries({queryKey:me.billing.subscription()})},onError:g=>{const A=g?.message?.replace(/^\d{3}:\s*/,"")||"Failed to update seat";a({title:"Seat update failed",description:A,variant:"destructive"})}}),k=le({mutationFn:async({userId:g,role:A})=>Q(`/api/admin/users/${g}/membership-role`,{method:"PATCH",body:{role:A}}),onSuccess:(g,A)=>{a({title:"Role updated",description:`Role changed to ${Et[A.role]||A.role}`}),t.invalidateQueries({queryKey:me.admin.accessMatrix()}),t.invalidateQueries({queryKey:me.admin.users()})},onError:g=>{a({title:"Failed to update role",description:g?.message||"Please try again.",variant:"destructive"})}}),E=m.useMemo(()=>i==="all"?u:u.filter(g=>g.dataAccessLevel===i),[u,i]),T=async(g,A)=>{if(A!==g.dataAccessLevel){if(A==="confidential"||A==="restricted"){x({user:g,newLevel:A});return}s&&await f({userId:g.id,dataAccessLevel:A,workspaceId:s})}},w=async()=>
2{if(!o||!s)return;(await f({userId:o.user.id,dataAccessLevel:o.newLevel,workspaceId:s})).ok&&x(null)};if(!s)return e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground p-8 justify-center",children:[e.jsx(oe,{className:"h-4 w-4"}),e.jsx("span",{children:"No workspace selected. Select a workspace to view access levels."})]});if(b)return e.jsxs("div",{className:"flex items-center gap-2 text-destructive p-8 justify-center",children:[e.jsx(oe,{className:"h-4 w-4"}),e.jsx("span",{children:"Failed to load users. Please try again."})]});const V=Math.ceil(v.total/v.limit);return e.jsxs("div",{className:"space-y-4",children:[e.jsx(Zr,{workspaceId:s}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ps,{className:"h-4 w-4 text-muted-foreground"}),e.jsxs(De,{value:i,onValueChange:g=>{l(g),d(1)},children:[e.jsx(Pe,{className:"w-[180px] h-8 text-sm",children:e.jsx($e,{placeholder:"Filter by level"})}),e.jsxs(Re,{children:[e.jsx(te,{value:"all",children:"All Levels"}),kt.map(g=>e.jsx(te,{value:g.value,children:g.label},g.value))]})]})]}),e.jsxs("span",{className:"text-xs text-muted-foreground ml-auto",children:[E.length," of ",v.total," users"]})]}),e.jsx("div",{className:"border rounded-lg overflow-hidden",children:e.jsxs(ks,{children:[e.jsx(As,{children:e.jsxs(be,{children:[e.jsx(ae,{className:"w-[25%]",children:"User"}),e.jsx(ae,{className:"w-[18%]",children:"Role"}),e.jsx(ae,{className:"w-[22%]",children:"License"}),e.jsx(ae,{className:"w-[25%]",children:"Data Access"})]})}),e.jsx(Es,{children:j?[...Array(3)].map((g,A)=>e.jsxs(be,{children:[e.jsx(G,{children:e.jsx(X,{className:"h-10 w-full"})}),e.jsx(G,{children:e.jsx(X,{className:"h-6 w-20"})}),e.jsx(G,{children:e.jsx(X,{className:"h-6 w-12"})}),e.jsx(G,{children:e.jsx(X,{className:"h-8 w-40"})})]},A)):E.length===0?e.jsx(be,{children:e.jsx(G,{colSpan:4,className:"text-center text-muted-foreground py-8",children:i!=="all"?`No users with ${i} access level`:"No users found"})}):E.map(g=>{const A=N&&n===g.id;return e.jsxs(be,{children:[e.jsx(G,{children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"h-8 w-8 rounded-full bg-muted flex items-center justify-center text-xs font-medium shrink-0",children:ei(g)}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-medium text-sm truncate",children:Tt(g)}),e.jsx("div",{className:"text-xs text-muted-foreground truncate",children:g.email})]})]})}),e.jsx(G,{children:e.jsxs(De,{value:g.membershipRole||"member",onValueChange:R=>k.mutate({userId:g.id,role:R}),disabled:k.isPending&&k.variables?.userId===g.id,children:[e.jsx(Pe,{className:"w-[150px] h-8 text-sm",children:k.isPending&&k.variables?.userId===g.id?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Y,{className:"h-3 w-3 animate-spin"}),"Updating..."]}):e.jsx($e,{children:Et[g.membershipRole]||"User"})}),e.jsx(Re,{children:ia.map(R=>e.jsx(te,{value:R.value,children:R.label},R.value))})]})}),e.jsx(G,{children:e.jsx(C,{variant:Js(g.subscriptionStatus)?"ghost":"outline",size:"sm",className:"h-7 text-xs",disabled:c.isPending&&c.variables?.userId===g.id,onClick:()=>{const R=Js(g.subscriptionStatus)?"deallocate":"allocate";c.mutate({userId:g.id,action:R})},children:c.isPending&&c.variables?.userId===g.id?e.jsx(Y,{className:"h-3 w-3 animate-spin"}):Js(g.subscriptionStatus)?e.jsx($,{className:"bg-[var(--success-soft)] text-[var(--success-fg)] cursor-pointer",children:"Active"}):e.jsx($,{variant:"secondary",className:"text-muted-foreground cursor-pointer",children:"No Seat"})})}),e.jsx(G,{children:e.jsxs(De,{value:g.dataAccessLevel,onValueChange:R=>T(g,R),disabled:A,children:[e.jsx(Pe,{className:"w-[200px] h-8 text-sm",children:A?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Y,{className:"h-3 w-3 animate-spin"}),"Updating..."]}):e.jsx("div",{className:"flex items-center gap-2",children:e.jsx($,{className:`${At[g.dataAccessLevel]} text-[10px] px-1.5 py-0`,children:g.dataAccessLevel})})}),e.jsx(Re,{children:kt.map(R=>e.jsx(te,{value:R.value,children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"font-medium",children:R.label}),e.jsx("span",{className:"text-xs text-muted-foreground",children:R.description})]})},R.value))})]})})]},g.id)})})]})}),V>1&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-sm text-muted-foreground",children:["Page ",r," of ",V]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>d(g=>Math.max(1,g-1)),disabled:r<=1,children:[e.jsx(It,{className:"h-4 w-4"}),"Previous"]}),e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>d(g=>Math.min(V,g+1)),disabled:r>=V,children:["Next",e.jsx(tt,{className:"h-4 w-4"})]})]})]}),e.jsx(cs,{open:!!o,onOpenChange:g=>!g&&x(null),children:e.jsxs(os,{children:[e.jsxs(ds,{children:[e.jsx(ms,{children:"Elevate Data Access Level"}),e.jsxs(us,{className:"space-y-2",children:[e.jsxs("span",{className:"block",children:["You are about to grant ",e.jsx("strong",{children:o?.user?Tt(o.user):""})," "," ",e.jsx($,{className:o?.newLevel?At[o.newLevel]:"",children:o?.newLevel})," ","data access."]}),e.jsx("span",{className:"block text-deepwind-warning-fg",children:"This grants access to sensitive data. Ensure this user requires this level of access per your organization's data classification policy."})]})]}),e.jsxs(xs,{children:[e.jsx(hs,{children:"Cancel"}),e.jsx(ps,{onClick:w,disabled:N,children:N?e.jsxs(e.Fragment,{children:[e.jsx(Y,{className:"h-4 w-4 animate-spin mr-2"}
2),"Updating..."]}):"Confirm Elevation"})]})]})})]})}function ti({points:s}){if(!s||s.length===0)return e.jsx("span",{className:"text-muted-foreground text-xs",children:"—"});const t=Math.max(...s,1),a=80,r=24,d=s.map((i,l)=>{const o=l/Math.max(s.length-1,1)*a,x=r-i/t*r;return`${o},${x}`}).join(" ");return e.jsx("svg",{width:a,height:r,className:"inline-block ml-2",children:e.jsx("polyline",{points:d,fill:"none",stroke:"#3B82F6",strokeWidth:"1.5"})})}function ai({specialization:s}){if(!s)return e.jsx($,{variant:"outline",className:"bg-muted text-muted-foreground",children:"Unassigned"});const t={FRONTEND:"bg-blue-500/15 text-blue-700 border-blue-200",BACKEND:"bg-purple-500/15 text-purple-700 border-purple-200",FULLSTACK:"bg-indigo-500/15 text-indigo-700 border-indigo-200",PRODUCT:"bg-pink-500/15 text-pink-700 border-pink-200",DESIGN:"bg-amber-500/15 text-amber-700 border-amber-200",QA:"bg-orange-500/15 text-orange-700 border-orange-200",DEVOPS:"bg-green-500/15 text-green-700 border-green-200",AI_ML:"bg-cyan-500/15 text-cyan-700 border-cyan-200",DATA:"bg-violet-500/15 text-violet-700 border-violet-200",OTHER:"bg-gray-500/15 text-gray-700 border-gray-200"};return e.jsx($,{variant:"outline",className:t[s]||t.OTHER,children:s.replace(/_/g," ")})}function ni({pressure:s}){const t=Math.round(s*100),a=Math.min(100,Math.max(0,t));let r="bg-emerald-500";return t>100?r="bg-red-500":t>85&&(r="bg-amber-500"),e.jsxs("div",{className:"flex items-center gap-2 min-w-[120px]",children:[e.jsx("div",{className:"flex-1 h-1.5 bg-muted rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full ${r}`,style:{width:`${a}%`}})}),e.jsxs("span",{className:"text-xs tabular-nums font-medium whitespace-nowrap",children:[t,"%"]})]})}function ri(){const{currentWorkspace:s}=rt(),[t,a]=m.useState("name"),[r,d]=m.useState("asc"),i=Ya(["/api/velocity/contributors",`workspaceId=${s?.id??""}`,"sprintCount=12"]),{data:l,isLoading:o,error:x}=ue({queryKey:i,enabled:!!s?.id,staleTime:3e4}),u=f=>{t===f?d(r==="asc"?"desc":"asc"):(a(f),d("asc"))},v=f=>t===f?r==="asc"?"↑":"↓":"";if(x)return e.jsxs(Ls,{variant:"destructive",children:[e.jsx(Ke,{className:"h-4 w-4"}),e.jsx(Ms,{children:"Failed to load employee performance data. Please try refreshing the page."})]});if(o)return e.jsx("div",{className:"space-y-4",children:e.jsxs(_,{children:[e.jsxs(Le,{children:[e.jsx(X,{className:"h-6 w-48"}),e.jsx(X,{className:"h-4 w-72 mt-2"})]}),e.jsx(z,{children:e.jsx("div",{className:"space-y-3",children:[1,2,3,4,5].map(f=>e.jsx(X,{className:"h-12 w-full"},f))})})]})});const j=l?.data?.contributors||[],b=[...j].sort((f,N)=>{const n=f[t],c=N[t];if(n==null&&c==null)return 0;if(n==null)return r==="asc"?1:-1;if(c==null)return r==="asc"?-1:1;if(typeof n=="number"&&typeof c=="number")return r==="asc"?n-c:c-n;const k=String(n).localeCompare(String(c));return r==="asc"?k:-k});return e.jsx("div",{className:"space-y-6",children:e.jsxs(_,{children:[e.jsxs(Le,{children:[e.jsxs(He,{className:"flex items-center gap-2",children:[e.jsx(Fe,{className:"h-5 w-5"}),"Employee Performance"]}),e.jsx(st,{children:"Detailed velocity metrics and allocation data for all team members"})]}),e.jsx(z,{children:j.length===0?e.jsxs("div",{className:"text-center py-12",children:[e.jsx(Fe,{className:"h-12 w-12 text-gray-400 mx-auto mb-4"}),e.jsx("h3",{className:"text-lg font-semibold text-gray-600",children:"No performance data available"}),e.jsx("p",{className:"text-muted-foreground mt-2",children:"Ensure employees are assigned to work items in sprints to see performance metrics."})]}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(ks,{children:[e.jsx(As,{children:e.jsxs(be,{children:[e.jsxs(ae,{className:"cursor-pointer hover:bg-muted/50",onClick:()=>u("name"),children:["Name ",v("name")]}),e.jsxs(ae,{className:"cursor-pointer hover:bg-muted/50",onClick:()=>u("specialization"),children:["Specialization ",v("specialization")]}),e.jsx(ae,{className:"text-right",children:e.jsxs("div",{className:"cursor-pointer hover:bg-muted/50 inline-block px-2 py-1 rounded",onClick:()=>u("avgVelocity"),children:["Avg Velocity ",v("avgVelocity")]})}),e.jsx(ae,{className:"text-right",children:e.jsxs("div",{className:"cursor-pointer hover:bg-muted/50 inline-block px-2 py-1 rounded",onClick:()=>u("allocationPressure"),children:["Allocation ",v("allocationPressure")]})}),e.jsx(ae,{children:"Trend"}),e.jsx(ae,{className:"text-right",children:"Actions"})]})}),e.jsx(Es,{children:b.map((f,N)=>e.jsxs(be,{children:[e.jsx(G,{className:"font-medium",children:e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold",children:f.name}),e.jsx("div",{className:"text-xs text-muted-foreground",children:f.email})]})}),e.jsx(G,{children:e.jsx(ai,{specialization:f.specialization})}),e.jsxs(G,{className:"text-right",children:[e.jsx("div",{className:"font-medium",children:f.avgVelocity>
20?e.jsx(ss,{value:f.avgVelocity,provenance:null,density:"inline-badge",unit:""}):"—"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:e.jsx(ti,{points:f.sprintVelocities.map(n=>n.velocity)})})]}),e.jsx(G,{className:"text-right",children:e.jsx(ni,{pressure:f.allocationPressure})}),e.jsx(G,{children:e.jsxs("span",{className:"text-xs text-muted-foreground",children:[f.currentAllocation,"/",f.capacity," SP"]})}),e.jsx(G,{className:"text-right",children:e.jsxs(at,{href:"/velocity?tab=team",className:"inline-flex items-center gap-1 text-xs text-blue-600 hover:text-blue-700 font-medium",children:["View",e.jsx($s,{className:"h-3 w-3"})]})})]},f.email||f.name||`emp-${N}`))})]})})})]})})}const ii=13,li=.6;function ci({data:s,isLoading:t}){if(t)return e.jsxs("div",{className:"rounded-lg border border-border bg-muted/30 p-4 space-y-2",children:[e.jsx(X,{className:"h-4 w-48"}),e.jsx(X,{className:"h-4 w-64"})]});if(!s||s.declarations.length===0)return e.jsxs(Ls,{className:"border-[var(--info)] bg-[var(--info-soft)]",children:[e.jsx(La,{className:"h-4 w-4 text-[var(--info-fg)]","aria-hidden":"true"}),e.jsx(gt,{className:"text-sm font-medium text-[var(--info-fg)]",children:"No capacity declared yet"}),e.jsx(Ms,{className:"text-xs text-[var(--info-fg)] mt-1",children:"Declare available hours per role to improve portfolio scheduling accuracy. The scheduler uses these declarations to size sprint lanes and detect over-commitment across your team."})]});const{declarations:a,totalAvailableHoursPerWeek:r,totalHeadcount:d,byRole:i}=s,l=r*ii,o=i??{},x=Object.keys(o).length,u=[];if(r>0)for(const[j,b]of Object.entries(o))b.availableHoursPw/r>li&&x>1&&u.push(j);const v=u.length>0;return e.jsxs(Ls,{className:v?"border-deepwind-warning bg-deepwind-warning-soft":"border-[var(--success)] bg-[var(--success-soft)]",children:[v?e.jsx(Ke,{className:"h-4 w-4 text-deepwind-warning-fg","aria-hidden":"true"}):e.jsx(ze,{className:"h-4 w-4 text-[var(--success-fg)]","aria-hidden":"true"}),e.jsx(gt,{className:"text-sm font-medium",children:v?"Capacity concentration detected":"Capacity feeds portfolio scheduling"}),e.jsxs(Ms,{className:"mt-1 space-y-2",children:[e.jsxs("p",{className:"text-xs text-muted-foreground",children:[e.jsx("span",{className:"font-semibold text-foreground",children:a.length})," ","declaration",a.length!==1?"s":""," across"," ",e.jsx("span",{className:"font-semibold text-foreground",children:x})," ","role",x!==1?"s":""," · ",e.jsx("span",{className:"font-semibold text-foreground",children:d})," headcount"," · ",e.jsx("span",{className:"font-semibold text-foreground",children:l.toLocaleString()})," ","hours this quarter"]}),v&&e.jsxs("p",{className:"text-xs text-deepwind-warning-fg",children:[e.jsx("span",{className:"font-medium",children:u.join(", ")})," ","account",u.length===1?"s":""," for >60% of total hours. Consider diversifying capacity or verifying this matches your actual team composition."]}),e.jsx("p",{className:"text-xs",children:e.jsxs(at,{href:"/backlog?view=backlog",className:"inline-flex items-center gap-1 font-medium text-primary underline-offset-2 hover:underline",children:["View workload by assignee in Backlog",e.jsx($s,{className:"h-3 w-3","aria-hidden":"true"})]})})]})]})}function oi({teamId:s,teamName:t,memberCount:a,className:r}){const{currentWorkspace:d}=rt(),i=d?.id,{data:l,isLoading:o}=ue({queryKey:["team-cadence",i,s],enabled:!!(i&&s),queryFn:async()=>{try{return await Q(`/api/workspaces/${i}/teams/${s}/cadence`,{method:"GET",suppressLogout:!0})}catch{return null}}}),x=l?Math.round(l.sprintLengthDays/7):null;return e.jsxs(_,{"data-testid":`team-cadence-card-${s}`,className:F("",r),children:[e.jsx(Le,{className:"pb-2",children:e.jsxs(He,{className:"text-sm font-medium flex items-center justify-between",children:[e.jsx("span",{className:"truncate",children:t}),e.jsxs("span",{className:"flex items-center gap-1 text-xs text-[color:var(--muted-foreground)] font-normal shrink-0 ml-2",children:[e.jsx(Fe,{className:"h-3 w-3"}),a]})]})}),e.jsx(z,{className:"pt-0 space-y-2",children:o?e.jsx("div",{className:"h-8 rounded bg-[color:var(--muted)] animate-pulse"}):l?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-[color:var(--muted-foreground)]",children:[e.jsx(ys,{className:"h-3 w-3 shrink-0"}),e.jsxs("span",{children:[x===1?"1 week":`${x??l.sprintLengthDays} ${x?"weeks":"days"}`," sprint"]})]}),l.anchorDate&&e.jsxs("div",{className:"flex items-center gap-2 text-xs text-[color:var(--muted-foreground)]",children:[e.jsx(Ma,{className:"h-3 w-3 shrink-0"}),e.jsxs("span",{children:["Anchor: ",new Date(l.anchorDate).toLocaleDateString()]})]}),l.source&&l.source!=="native"&&e.jsx($,{variant:"outline",className:"text-[10px] h-4 px-1.5",children:l.source})]}):e.jsx("p",{className:"text-xs text-[color:var(--muted-foreground)]",children:"No cadence configured"})})]})}function di({className:s}){const{currentWorkspace:t}=rt(),a=t?.id,{data:r,isLoading:d,isError:i}=ue({queryKey:me.workspaces.teams(a),enabled:!!a,queryFn:async()=>
2{try{return(await Q(`/api/workspaces/${a}/teams`,{method:"GET",suppressLogout:!0}))?.teams??[]}catch(l){if(l?.status===404)return[];throw l}}});return e.jsxs("section",{"data-testid":"team-cadence-section",className:F("space-y-4",s),"aria-labelledby":"team-cadence-heading",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ia,{className:"h-4 w-4 text-[color:var(--muted-foreground)]"}),e.jsx("h3",{id:"team-cadence-heading",className:"text-base font-semibold text-[color:var(--foreground)]",children:"Sprint cadences"})]}),e.jsx("p",{className:"text-sm text-[color:var(--muted-foreground)]",children:"Configure the sprint anchor date, length, and source for each team. Future sprint windows derive from these settings."}),d&&e.jsx("div",{"data-testid":"team-cadence-section-loading",className:"h-24 rounded bg-[color:var(--muted)] animate-pulse"}),i&&e.jsx("div",{"data-testid":"team-cadence-section-error",className:F("rounded-md border border-[color:var(--destructive)]/40","bg-[color:var(--destructive)]/5 px-3 py-2","text-sm text-[color:var(--destructive)]"),children:"Could not load teams. Refresh the page to try again."}),!d&&!i&&r&&r.length===0&&e.jsx("div",{"data-testid":"team-cadence-section-empty",className:F("rounded-lg border border-dashed border-[color:var(--border)]","px-4 py-6 text-sm text-[color:var(--muted-foreground)]"),children:"No teams in this workspace yet. Add a team to configure its sprint cadence."}),!d&&!i&&r&&r.length>0&&e.jsx("div",{className:F("grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4"),children:r.map(l=>e.jsx(oi,{teamId:l.id,teamName:l.name,memberCount:l.memberCount??0},l.id))})]})}const la=(s,t)=>["team",t,s],mt=(s,t)=>["team",t,s,"members"];function mi(s){const t=Ye();return ue({queryKey:la(s??"",t??void 0),queryFn:async()=>await Q(`/api/settings/team/${s}`),enabled:!!t&&!!s,staleTime:3e4})}function ui(s){const t=Ye();return ue({queryKey:mt(s??"",t??void 0),queryFn:async()=>await Q(`/api/settings/team/${s}/members`),enabled:!!t&&!!s,staleTime:3e4})}function xi(){const s=de(),t=Ye();return le({mutationFn:async a=>await Q("/api/settings/team",{method:"POST",body:a}),onSuccess:()=>{s.invalidateQueries({queryKey:me.workspaces.teams(t??void 0)}),s.invalidateQueries({queryKey:["workspace",t,"teams"]})}})}function hi(s){const t=de(),a=Ye();return le({mutationFn:async r=>await Q(`/api/settings/team/${s}`,{method:"PUT",body:r}),onSuccess:()=>{t.invalidateQueries({queryKey:la(s??"",a??void 0)}),t.invalidateQueries({queryKey:me.workspaces.teams(a??void 0)}),t.invalidateQueries({queryKey:["workspace",a,"teams"]})}})}function pi(){const s=de(),t=Ye();return le({mutationFn:async a=>{await Q(`/api/settings/team/${a}`,{method:"DELETE"})},onSuccess:()=>{s.invalidateQueries({queryKey:me.workspaces.teams(t??void 0)}),s.invalidateQueries({queryKey:["workspace",t,"teams"]})}})}function gi(s){const t=de(),a=Ye();return le({mutationFn:async r=>await Q(`/api/settings/team/${s}/members/invite`,{method:"POST",body:r}),onSuccess:()=>{t.invalidateQueries({queryKey:mt(s??"",a??void 0)})}})}function fi(s){const t=de(),a=Ye();return le({mutationFn:async r=>{await Q(`/api/settings/team/${s}/members/${r}`,{method:"DELETE"})},onSuccess:()=>{t.invalidateQueries({queryKey:mt(s??"",a??void 0)})}})}const Ys=100,Ds=500;function ji({open:s,onOpenChange:t,onCreated:a}){const{toast:r}=ge(),d=xi(),[i,l]=m.useState(""),[o,x]=m.useState(""),[u,v]=m.useState(null),j=i.trim(),b=j.length>=1&&j.length<=Ys,f=o.length<=Ds,N=b&&f&&!d.isPending,n=()=>{l(""),x(""),v(null)},c=E=>{E||n(),t(E)},k=async E=>{if(E.preventDefault(),!!N){v(null);try{const T=await d.mutateAsync({name:j,description:o.trim()||void 0});r({title:"Team created",description:`${j} is ready for members.`});const w=typeof T=="object"&&T!==null&&"id"in T?T.id:void 0;a?.(w),c(!1)}catch(T){const w=T instanceof Error?T.message:"Failed to create team";v(w),r({title:"Could not create team",description:w,variant:"destructive"})}}};return e.jsx(Ce,{open:s,onOpenChange:c,children:e.jsxs(Se,{className:"sm:max-w-lg","aria-describedby":"create-team-description",children:[e.jsx(Ee,{children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-full bg-gradient-to-br from-[var(--deepwind-accent-soft)] via-[var(--deepwind-accent-soft)] to-[var(--info-soft)] ring-1 ring-deepwind-accent","aria-hidden":!0,
2children:e.jsx(ns,{className:"h-5 w-5 text-deepwind-accent"})}),e.jsxs("div",{children:[e.jsx(Te,{children:"New team"}),e.jsx(Ge,{id:"create-team-description",children:"Group employees for planning, capacity, and access. You can invite members after the team is created."})]})]})}),e.jsxs("form",{onSubmit:k,className:"space-y-4 pt-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(J,{htmlFor:"team-name",children:["Name ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(ee,{id:"team-name",autoFocus:!0,maxLength:Ys,value:i,onChange:E=>l(E.target.value),placeholder:"e.g. Platform Foundations","aria-invalid":!b&&i.length>0,"aria-describedby":"team-name-counter"}),e.jsxs("div",{id:"team-name-counter",className:"flex justify-between text-xs text-muted-foreground",children:[e.jsx("span",{children:b||i.length===0?" ":"Required, 1–100 characters"}),e.jsxs("span",{children:[j.length,"/",Ys]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(J,{htmlFor:"team-description",children:"Description"}),e.jsx(ls,{id:"team-description",rows:4,maxLength:Ds+50,value:o,onChange:E=>x(E.target.value),placeholder:"What does this team own? (optional)","aria-invalid":!f,"aria-describedby":"team-desc-counter"}),e.jsxs("div",{id:"team-desc-counter",className:"flex justify-between text-xs text-muted-foreground",children:[e.jsx("span",{children:f?" ":`Description must be ≤ ${Ds} characters`}),e.jsxs("span",{children:[o.length,"/",Ds]})]})]}),u&&e.jsx("div",{role:"alert",className:"rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-sm text-destructive",children:u}),e.jsxs(Je,{className:"pt-2",children:[e.jsx(C,{type:"button",variant:"ghost",onClick:()=>c(!1),disabled:d.isPending,children:"Cancel"}),e.jsx(C,{type:"submit",disabled:!N,children:d.isPending?e.jsxs(e.Fragment,{children:[e.jsx(Y,{className:"mr-2 h-4 w-4 animate-spin"}),"Creating"]}):"Create team"})]})]})]})})}const vi=[{value:"owner",label:"Owner",hint:"Full control of team settings."},{value:"admin",label:"Admin",hint:"Manage members and configuration."},{value:"member",label:"Member",hint:"Standard contributor access."},{value:"viewer",label:"Viewer",hint:"Read-only access."},{value:"guest",label:"Guest",hint:"Limited, time-boxed access."}],Ni=/^[^\s@]+@[^\s@]+\.[^\s@]+$/;function bi({open:s,onOpenChange:t,teamId:a,teamName:r}){const{toast:d}=ge(),i=gi(a),[l,o]=m.useState(""),[x,u]=m.useState("member"),[v,j]=m.useState(""),[b,f]=m.useState(null),N=l.trim(),n=Ni.test(N),c=n&&!i.isPending,k=()=>{o(""),u("member"),j(""),f(null)},E=w=>{w||k(),t(w)},T=async w=>{if(w.preventDefault(),!!c){f(null);try{await i.mutateAsync({email:N,role:x,message:v.trim()||void 0}),d({title:"Invitation sent",description:`${N} has been invited to ${r}.`}),E(!1)}catch(V){const g=V instanceof Error?V.message:"Failed to invite member",A=/409|already/i.test(g)?"That email is already a member or has a pending invitation.":g;f(A),d({title:"Could not send invitation",description:A,variant:"destructive"})}}};return e.jsx(Ce,{open:s,onOpenChange:E,children:e.jsxs(Se,{className:"sm:max-w-lg","aria-describedby":"invite-desc",children:[e.jsx(Ee,{children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-full bg-gradient-to-br from-[var(--success-soft)] via-[var(--deepwind-accent-soft)] to-[var(--info-soft)] ring-1 ring-[var(--success)]","aria-hidden":!0,children:e.jsx(is,{className:"h-5 w-5 text-[var(--success-fg)]"})}),e.jsxs("div",{children:[e.jsx(Te,{children:"Invite member"}),e.jsxs(Ge,{id:"invite-desc",children:["Send an invitation to ",e.jsx("span",{className:"font-medium",children:r}),"."]})]})]})}),e.jsxs("form",{onSubmit:T,className:"space-y-4 pt-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(J,{htmlFor:"invite-email",children:["Email ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(ee,{id:"invite-email",type:"email",autoFocus:!0,value:l,onChange:w=>o(w.target.value),placeholder:"[email protected]","aria-invalid":!n&&l.length>0}),l.length>0&&!n&&e.jsx("p",{className:"text-xs text-destructive",children:"Enter a valid email address."})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(J,{htmlFor:"invite-role",children:"Role"}),e.jsxs(De,{value:x,onValueChange:w=>u(w),children:[e.jsx(Pe,{id:"invite-role",children:e.jsx($e,{})}),e.jsx(Re,{children:vi.map(w=>e.jsx(te,{value:w.value,children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"font-medium",children:w.label}),e.jsx("span",{className:"text-xs text-muted-foreground",children:w.hint})]})},w.value))})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(J,{htmlFor:"invite-message",children:"Message (optional)"}
2),e.jsx(ls,{id:"invite-message",rows:3,value:v,onChange:w=>j(w.target.value),placeholder:"Add a short note for the invitee."})]}),b&&e.jsx("div",{role:"alert",className:"rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-sm text-destructive",children:b}),e.jsxs(Je,{className:"pt-2",children:[e.jsx(C,{type:"button",variant:"ghost",onClick:()=>E(!1),disabled:i.isPending,children:"Cancel"}),e.jsx(C,{type:"submit",disabled:!c,children:i.isPending?e.jsxs(e.Fragment,{children:[e.jsx(Y,{className:"mr-2 h-4 w-4 animate-spin"}),"Sending"]}):"Send invitation"})]})]})]})})}function yi({role:s}){const t={owner:"border-deepwind-warning bg-deepwind-warning-soft text-deepwind-warning-fg",admin:"border-deepwind-accent-border bg-deepwind-accent-soft text-deepwind-accent",member:"border-deepwind-border bg-deepwind-surface-sunken text-deepwind-text-body",viewer:"border-[var(--info)] bg-[var(--info-soft)] text-[var(--info-fg)]",guest:"border-deepwind-border-strong bg-deepwind-surface-sunken text-deepwind-text-body"},a=s==="owner"?$a:s==="admin"?_t:ns;return e.jsxs($,{variant:"outline",className:F("gap-1 px-1.5 py-0 text-[10px] font-medium uppercase tracking-wide",t[s]),children:[e.jsx(a,{className:"h-3 w-3","aria-hidden":!0}),s]})}function Xs(s){return s.name||s.user?.name||s.email||s.user?.email||s.userId||"Unknown member"}function wi(s){return s.email||s.user?.email||null}function Ci({name:s}){const t=m.useMemo(()=>{const a=s.trim().split(/[\s.@]+/).filter(Boolean);return a.length===0?"?":a.length===1?a[0].slice(0,2).toUpperCase():(a[0][0]+a[a.length-1][0]).toUpperCase()},[s]);return e.jsx("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-gradient-to-br from-[var(--deepwind-accent-soft)] via-[var(--deepwind-accent-soft)] to-[var(--info-soft)] text-[11px] font-semibold text-deepwind-accent ring-1 ring-deepwind-accent","aria-hidden":!0,children:t})}function Si({open:s,onOpenChange:t,teamId:a,teamName:r,onRequestDelete:d}){const{toast:i}=ge(),l=mi(a??void 0),o=ui(a??void 0),x=hi(a??void 0),u=fi(a??void 0),[v,j]=m.useState(!1),[b,f]=m.useState(""),[N,n]=m.useState(""),[c,k]=m.useState(null),[E,T]=m.useState(!1),[w,V]=m.useState(null);m.useEffect(()=>{if(!s){j(!1),k(null);return}const q=l.data?.name??r??"",ce=l.data?.description??"";f(q),n(ce)},[s,l.data?.name,l.data?.description,r]);const g=b.trim(),A=g.length>=1&&g.length<=100,R=N.length<=500,ne=A&&R&&!x.isPending,se=async()=>{if(!(!ne||!a)){k(null);try{await x.mutateAsync({name:g,description:N.trim()||void 0}),i({title:"Team updated"}),j(!1)}catch(q){const ce=q instanceof Error?q.message:"Failed to update team";k(ce),i({title:"Could not update team",description:ce,variant:"destructive"})}}},Ne=async()=>{if(!(!w||!a))try{await u.mutateAsync(w.id),i({title:"Member removed",description:`${Xs(w)} no longer belongs to this team.`})}catch(q){const ce=q instanceof Error?q.message:"Failed to remove member";i({title:"Could not remove member",description:ce,variant:"destructive"})}finally{V(null)}},re=o.data?.members??[];return e.jsxs(e.Fragment,{children:[e.jsx(Bt,{open:s,onOpenChange:t,children:e.jsxs(Kt,{side:"right",className:"flex w-full flex-col gap-0 p-0 sm:max-w-xl",role:"dialog","aria-label":r?`${r} details`:"Team details",children:[e.jsx(Qt,{className:"border-b border-border/60 px-6 pt-6 pb-4",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"flex h-12 w-12 shrink-0 items-center justify-center rounded-2xl bg-gradient-to-br from-[var(--deepwind-accent-soft)] via-[var(--deepwind-accent-soft)] to-[var(--info-soft)] ring-1 ring-deepwind-accent","aria-hidden":!0,children:e.jsx(ns,{className:"h-6 w-6 text-deepwind-accent"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx(Ht,{className:"truncate text-left text-xl",children:l.data?.name||r||"Team"}),e.jsx(un,{className:"text-left",children:l.isLoading?"Loading team details…":`${re.length} ${re.length===1?"member":"members"}`})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[!v&&e.jsxs(C,{variant:"ghost",size:"sm",onClick:()=>j(!0),disabled:l.isLoading,"aria-label":"Edit team",children:[e.jsx(Mt,{className:"mr-1.5 h-3.5 w-3.5"}),"Edit"]}),a&&d&&!v&&e.jsxs(C,{variant:"ghost",size:"sm",className:"text-destructive hover:bg-destructive/10 hover:text-destructive",onClick:()=>d(a,l.data?.name||r||"this team"),"aria-label":"Delete team",children:[e.jsx(Dt,{className:"mr-1.5 h-3.5 w-3.5"}),"Delete"]})]})]})}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-6 pb-8 pt-5",children:[e.jsxs("section",{"aria-labelledby":"team-meta-heading",className:"space-y-4",children:[e.jsx("h3",{id:"team-meta-heading",className:"text-[11px] font-semibold uppercase tracking-[0.12em] text-muted-foreground",children:"Details"}),l.isLoading?e.jsxs("div",{className:"space-y-3",children:[e.jsx(X,{className:"h-9 w-full"}),e.jsx(X,{className:"h-20 w-full"})]}):l.isError?e.jsxs("div",{role:"alert",className:"flex items-start gap-3 rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2.5 text-sm text-destructive",children:[e.jsx(oe,{className:"h-4 w-4 shrink-0","aria-hidden":!0}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"font-medium",children:"Could not load team details."}),e.jsx("button",{type:"button",onClick:()=>l.refetch(),className:"mt-1 text-xs underline hover:no-underline",children:"Retry"})]})]}):v?e.jsxs("div",{className:"space-y-4 rounded-lg border border-border/60 bg-muted/30 p-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(J,{htmlFor:"edit-team-name",children:"Name"}),e.jsx(ee,{id:"edit-team-name",value:b,maxLength:100,onChange:q=>f(q.target.value),"aria-invalid":!A})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(J,{htmlFor:"edit-team-desc",children:"Description"}),e.jsx(ls,{id:"edit-team-desc",value:N,maxLength:550,rows:4,onChange:q=>n(q.target.value),"aria-invalid":!R}),e.jsxs("div",{className:"flex justify-end text-xs text-muted-foreground",children:[N.length,"/500"]})]}),c&&e.jsx("div",{role:"alert",className:"rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-sm text-destructive",children:c}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(C,{variant:"ghost",size:"sm",onClick:()=>j(!1),disabled:x.isPending,children:"Cancel"}),e.jsx(C,{size:"sm",onClick:se,disabled:!ne,children:x.isPending?e.jsxs(e.Fragment,{children:[e.jsx(Y,{className:"mr-2 h-3.5 w-3.5 animate-spin"}),"Saving"]}):"Save changes"})]})]}):e.jsxs("dl",{className:"grid gap-3 text-sm",children:[e.jsxs("div",{className:"grid grid-cols-[7rem_1fr] gap-3",children:[e.jsx("dt",{className:"text-muted-foreground",children:"Name"}),e.jsx("dd",{className:"font-medium",children:l.data?.name||r||"—"})]}),e.jsxs("div",{className:"grid grid-cols-[7rem_1fr] gap-3",children:[e.jsx("dt",{className:"text-muted-foreground",children:"Description"}
2),e.jsx("dd",{className:"whitespace-pre-wrap text-foreground/90",children:l.data?.description||e.jsx("span",{className:"italic text-muted-foreground",children:"No description"})})]}),l.data?.createdAt&&e.jsxs("div",{className:"grid grid-cols-[7rem_1fr] gap-3",children:[e.jsx("dt",{className:"text-muted-foreground",children:"Created"}),e.jsx("dd",{className:"text-foreground/80",children:new Date(l.data.createdAt).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})})]})]})]}),e.jsx(Yt,{className:"my-6"}),e.jsxs("section",{"aria-labelledby":"team-members-heading",className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("h3",{id:"team-members-heading",className:"text-[11px] font-semibold uppercase tracking-[0.12em] text-muted-foreground",children:"Members"}),e.jsxs(C,{size:"sm",onClick:()=>T(!0),disabled:!a,children:[e.jsx(_e,{className:"mr-1.5 h-3.5 w-3.5"}),"Add member"]})]}),o.isLoading?e.jsx("div",{className:"space-y-2",children:[0,1,2].map(q=>e.jsx(X,{className:"h-14 w-full"},q))}):o.isError?e.jsxs("div",{role:"alert",className:"flex items-start gap-3 rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2.5 text-sm text-destructive",children:[e.jsx(oe,{className:"h-4 w-4 shrink-0","aria-hidden":!0}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"font-medium",children:"Could not load members."}),e.jsx("button",{type:"button",onClick:()=>o.refetch(),className:"mt-1 text-xs underline hover:no-underline",children:"Retry"})]})]}):re.length===0?e.jsxs("div",{className:"rounded-lg border border-dashed border-border/60 bg-muted/20 px-4 py-8 text-center",children:[e.jsx(ns,{className:"mx-auto h-8 w-8 text-muted-foreground/60","aria-hidden":!0}),e.jsx("p",{className:"mt-3 text-sm font-medium",children:"No members yet"}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Invite teammates by email to start collaborating."}),e.jsxs(C,{size:"sm",className:"mt-4",onClick:()=>T(!0),children:[e.jsx(_e,{className:"mr-1.5 h-3.5 w-3.5"}),"Invite first member"]})]}):e.jsx("ul",{className:"divide-y divide-border/60 rounded-lg border border-border/60 bg-card/40",children:re.map(q=>{const ce=Xs(q),ke=wi(q);return e.jsxs("li",{className:"flex items-center gap-3 px-3 py-2.5",children:[e.jsx(Ci,{name:ce}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"truncate text-sm font-medium",children:ce}),e.jsx(yi,{role:q.role})]}),ke&&e.jsxs("p",{className:"flex items-center gap-1 truncate text-xs text-muted-foreground",children:[e.jsx(is,{className:"h-3 w-3","aria-hidden":!0}),ke]})]}),e.jsx(C,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:bg-destructive/10 hover:text-destructive",onClick:()=>V(q),"aria-label":`Remove ${ce}`,disabled:u.isPending,children:u.isPending&&w?.id===q.id?e.jsx(Y,{className:"h-4 w-4 animate-spin"}):e.jsx(Fa,{className:"h-4 w-4"})})]},q.id)})})]})]})]})}),a&&e.jsx(bi,{open:E,onOpenChange:T,teamId:a,teamName:l.data?.name||r||"this team"}),e.jsx(cs,{open:!!w,onOpenChange:q=>!q&&V(null),children:e.jsxs(os,{children:[e.jsxs(ds,{children:[e.jsx(ms,{children:"Remove member?"}),e.jsx(us,{children:w?`${Xs(w)} will lose access to this team. You can re-invite them later.`:""})]}),e.jsxs(xs,{children:[e.jsx(hs,{disabled:u.isPending,children:"Cancel"}),e.jsx(ps,{onClick:Ne,disabled:u.isPending,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:u.isPending?e.jsxs(e.Fragment,{children:[e.jsx(Y,{className:"mr-2 h-4 w-4 animate-spin"}),"Removing"]}):"Remove"})]})]})})]})}function ki(){return e.jsx("div",{className:"rounded-xl border border-border/60 bg-card/40 p-5",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(X,{className:"h-11 w-11 rounded-2xl"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx(X,{className:"h-4 w-3/4"}),e.jsx(X,{className:"h-3 w-full"}),e.jsx(X,{className:"h-3 w-2/3"})]})]})})}function Ai({team:s,onOpen:t}){const a=m.useMemo(()=>{const r=s.name.trim().split(/\s+/);return r.length===1?r[0].slice(0,2).toUpperCase():(r[0][0]+r[1][0]).toUpperCase()},[s.name]);return e.jsxs("button",{type:"button",onClick:()=>t(s),className:F("group relative flex w-full items-start gap-4 overflow-hidden rounded-xl border border-border/60 bg-card/60 p-5 text-left","transition-all duration-200 hover:border-deepwind-accent-border hover:bg-card hover:shadow-md hover:shadow-[var(--deepwind-accent)]","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-deepwind-accent focus-visible:ring-offset-2"),"aria-label":`Open ${s.name}
2`,children:[e.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute -right-6 -top-6 h-24 w-24 rounded-full bg-gradient-to-br from-[var(--deepwind-accent-soft)] via-[var(--deepwind-accent-soft)] to-transparent opacity-60 blur-xl transition-opacity group-hover:opacity-100"}),e.jsx("div",{className:"relative flex h-11 w-11 shrink-0 items-center justify-center rounded-2xl bg-gradient-to-br from-[var(--deepwind-accent-soft)] via-[var(--deepwind-accent-soft)] to-[var(--info-soft)] text-sm font-semibold text-deepwind-accent ring-1 ring-deepwind-accent","aria-hidden":!0,children:a}),e.jsxs("div",{className:"relative min-w-0 flex-1",children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("h4",{className:"truncate text-sm font-semibold text-foreground",children:s.name})}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Open to view members and details"})]}),e.jsx(tt,{"aria-hidden":!0,className:"relative mt-1.5 h-4 w-4 shrink-0 text-muted-foreground transition-transform group-hover:translate-x-0.5 group-hover:text-foreground"})]})}function Ei(){const{toast:s}=ge(),t=xn(),a=pi(),[r,d]=m.useState(""),[i,l]=m.useState(!1),[o,x]=m.useState(null),[u,v]=m.useState(null),j=t.data?.teams??[],b=m.useMemo(()=>{const c=r.trim().toLowerCase();return c?j.filter(k=>k.name.toLowerCase().includes(c)):j},[j,r]),f=async()=>{if(u)try{await a.mutateAsync(u.id),s({title:"Team deleted",description:`${u.name} has been removed. Members have been unassigned.`}),o?.id===u.id&&x(null)}catch(c){const k=c instanceof Error?c.message:"Failed to delete team";s({title:"Could not delete team",description:k,variant:"destructive"})}finally{v(null)}},N=t.isLoading,n=t.isError;return e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-semibold leading-tight",children:"Teams"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Group employees for planning, capacity, and access. Teams can hold members across departments."})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"relative",children:[e.jsx(We,{"aria-hidden":!0,className:"pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),e.jsx(ee,{value:r,onChange:c=>d(c.target.value),placeholder:"Search teams",className:"h-9 w-full pl-8 sm:w-56","aria-label":"Search teams"})]}),e.jsxs(C,{onClick:()=>l(!0),className:"shrink-0",children:[e.jsx(bs,{className:"mr-1.5 h-4 w-4"}),"New team"]})]})]}),N?e.jsx("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3",children:[0,1,2,3,4,5].map(c=>e.jsx(ki,{},c))}):n?e.jsxs("div",{role:"alert",className:"flex items-start gap-3 rounded-lg border border-destructive/30 bg-destructive/5 p-4 text-sm text-destructive",children:[e.jsx(oe,{className:"mt-0.5 h-5 w-5 shrink-0","aria-hidden":!0}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"font-medium",children:"Could not load teams."}),e.jsx("p",{className:"text-xs text-destructive/80",children:t.error instanceof Error?t.error.message:"Unknown error."}),e.jsx(C,{variant:"outline",size:"sm",className:"mt-3 border-destructive/40 text-destructive hover:bg-destructive/10",onClick:()=>t.refetch(),children:"Try again"})]})]}):j.length===0?e.jsxs("div",{className:"overflow-hidden rounded-xl border border-dashed border-border/60 bg-gradient-to-br from-[var(--deepwind-accent-soft)] via-transparent to-[var(--deepwind-accent-soft)] px-6 py-12 text-center",children:[e.jsx("div",{className:"mx-auto flex h-14 w-14 items-center justify-center rounded-2xl bg-gradient-to-br from-[var(--deepwind-accent-soft)] via-[var(--deepwind-accent-soft)] to-[var(--info-soft)] ring-1 ring-deepwind-accent","aria-hidden":!0,children:e.jsx(ns,{className:"h-7 w-7 text-deepwind-accent"})}),e.jsx("h3",{className:"mt-4 text-base font-semibold",children:"No teams configured"}),e.jsx("p",{className:"mx-auto mt-1.5 max-w-sm text-sm text-muted-foreground",children:"Create your first team to start grouping employees for planning, capacity, and access."}),e.jsxs(C,{className:"mt-5",onClick:()=>l(!0),children:[e.jsx(bs,{className:"mr-1.5 h-4 w-4"}),"Create team"]})]}):b.length===0?e.jsxs("div",{className:"rounded-lg border border-border/60 bg-muted/20 px-6 py-10 text-center text-sm text-muted-foreground",children:["No teams match",e.jsxs("span",{className:"mx-1 font-medium text-foreground",children:["“",r,"”"]}),".",e.jsx(C,{variant:"link",size:"sm",onClick:()=>d(""),className:"ml-1 h-auto p-0",children:"Clear search"})]}):e.jsx("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3",children:b.map(c=>e.jsx(Ai,{team:c,onOpen:x},c.id))}),!N&&!n&&j.length>0&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Member counts and creation dates load when you open a team."}),e.jsx(ji,{open:i,onOpenChange:l,onCreated:()=>{}}),e.jsx(Si,{open:!!o,onOpenChange:c=>!c&&x(null),teamId:o?.id??null,teamName:o?.name??null,onRequestDelete:(c,k)=>v({id:c,name:k})}),e.jsx(cs,{open:!!u,onOpenChange:c=>!c&&v(null),children:e.jsxs(os,{children:[e.jsxs(ds,{children:[e.jsx(ms,{children:"Delete team?"}),e.jsx(us,{children:u?e.jsxs(e.Fragment,{children:["This will remove",e.jsx("span",{className:"mx-1 font-medium text-foreground",children:u.name}),"and unassign all members. Continue?"]}):""})]}),e.jsxs(xs,{children:[e.jsx(hs,{disabled:a.isPending,children:"Cancel"}),e.jsx(ps,{onClick:f,disabled:a.isPending,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:a.isPending?e.jsxs(e.Fragment,{children:[e.jsx(Y,{className:"mr-2 h-4 w-4 animate-spin"}),"Deleting"]}):"Delete team"})]})]})})]})}const Ti=m.lazy(()=>Va(()=>import("./features/settings/ResourceCapacityTab-D-O1xtNY-1791218976559.js"),__vite__mapDeps([0,1,2,3,4,5,6])));function Di(){return e.jsxs("div",{className:"space-y-4",children:[e.jsx(X,{className:"h-16 w-full"}),e.jsx(X,{className:"h-10 w-full"}),e.jsx(X,{className:"h-10 w-full"}),e.jsx(X,{className:"h-10 w-full"})]})}function Pi(){const{data:s,isLoading:t}=An();return e.jsxs("div",{className:"space-y-6",children:[e.jsx(ci,{data:s,isLoading:t}),e.jsx(Ti,{})]})}function ol(){const[s,t]=m.useState(()=>{const d=new URLSearchParams(window.location.search).get("tab");return d==="team"?"team":d==="teams"?"teams":d==="capacity"?"capacity":d==="matrix"?"matrix":d==="performance"?"performance":"users"}),a=r=>{t(r);const d=new URL(window.location.href);d.searchParams.set("tab",r),window.history.replaceState({},"",d.toString())};return e.jsx(Ua,{title:"Team",breadcrumbs:[{label:"Team"}],children:e.jsxs(Os,{value:s,onValueChange:a,className:"space-y-6",children:[e.jsxs(qs,{className:"flex gap-1 w-full sm:w-auto justify-start rounded-none h-auto p-0 bg-transparent border-b border-border overflow-x-auto scrollbar-hide",children:[e.jsxs(je,{value:"users",className:"flex items-center gap-1.5 px-3 sm:px-4 py-2 text-sm font-medium",children:[e.jsx(Fe,{className:"h-4 w-4"}),"Users"]}),e.jsxs(je,{value:"team",className:"flex items-center gap-1.5 px-3 sm:px-4 py-2 text-sm font-medium",children:[e.jsx(ns,{className:"h-4 w-4"}),"Team"]}),e.jsxs(je,{value:"teams",className:"flex items-center gap-1.5 px-3 sm:px-4 py-2 text-sm font-medium",children:[e.jsx(Oa,{className:"h-4 w-4"}),"Teams"]}),e.jsxs(je,{value:"performance",className:"flex items-center gap-1.5 px-3 sm:px-4 py-2 text-sm font-medium",children:[e.jsx(qa,{className:"h-4 w-4"}),"Performance"]}),e.jsxs(je,{value:"capacity",className:"flex items-center gap-1.5 px-3 sm:px-4 py-2 text-sm font-medium",children:[e.jsx(Ut,{className:"h-4 w-4"}),"Capacity Planning"]}),e.jsxs(je,{value:"matrix",className:"flex items-center gap-1.5 px-3 sm:px-4 py-2 text-sm font-medium",children:[e.jsx(_t,{className:"h-4 w-4"}),"Access Matrix"]})]}),e.jsx(ve,{value:"users",className:"space-y-4",children:e.jsx(Mn,{})}),e.jsxs(ve,{value:"team",className:"space-y-6",children:[e.jsx("div",{className:"text-sm text-muted-foreground mb-4",children:"Manage team members for resource planning, track absences, and configure cost modeling."}),e.jsx(Jr,{}),e.jsx(Yt,{className:"my-2"}),e.jsx(di,{})]}),e.jsx(ve,{value:"teams",className:"space-y-4",children:e.jsx(Ei,{})}),e.jsxs(ve,{value:"performance",className:"space-y-4",children:[e.jsx("div",{className:"text-sm text-muted-foreground mb-4",children:"View detailed performance metrics and velocity trends across all team members."}),e.jsx(ri,{})]}),e.jsxs(ve,{value:"capacity",className:"space-y-4",children:[e.jsx("div",{className:"text-sm text-muted-foreground mb-4",children:"Declare available hours per role or skill so the portfolio scheduler can size sprint lanes accurately and detect over-commitment."}),e.jsx(m.Suspense,{fallback:e.jsx(Di,{}),children:e.jsx(Pi,{})})]}),e.jsxs(ve,{value:"matrix",className:"space-y-4",children:[e.jsx("div",{className:"text-sm text-muted-foreground mb-4",children:"View and manage data access levels for users in the current workspace."}),e.jsx(si,{})]})]})})}export{ol as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.