1import{d6 as be,d5 as ge,di as ye,c_ as we,dr as Ce,d7 as Ne,r as o,j as a,as as ve,eb as je,b4 as Ie,bT as ke,aI as Le,b9 as Me,ad as Se,bS as Te}from"./index-CpeGhXo5.js";import{c as Fe,m as Ae}from"./financeMappers-CUv1G2pV.js";import{u as Ee}from"./companySettingsMockApi-D8Uh5efq.js";import{u as De}from"./useCurrencyHelpers-D5hUvgaW.js";import{F as Re}from"./FilterBar-B_jdgGzl.js";import{u as z}from"./useGlobalFilter-BkOUrZeG.js";import{u as Pe}from"./filters-DQMtevU2.js";import{a as Ge,T as Qe}from"./EntityPill-btGCy98_.js";import"./currency-CACMzR5Q.js";import"./mock-Ci00pIzy.js";function b(r){return r?r.replace(/pv[t\.]*\s*ltd[\.]*/gi,"").replace(/tws/gi,"tekkiwebsolutions").replace(/[^a-z0-9]/gi,"").toLowerCase():""}function g(r){return r?r.replace(/\bteam\b/gi,"").replace(/[^a-z0-9]/gi,"").toLowerCase():""}function $e(r){return Number(r.annualCtc)>0?Number(r.annualCtc):0}function Je(){const r=Pe(),{fmtConvCompact:y,fmtConv:v}=De(),{data:j=[],isLoading:H,isFetching:O,refetch:K}=be(),{data:I=[],isLoading:q,isFetching:V,refetch:W}=ge(),{data:Y,isLoading:_,isFetching:J,refetch:U}=ye({limit:500}),{data:k=[]}=we(),{data:L=[]}=Ee(),{data:M,isLoading:X,isFetching:Z,refetch:ee}=Ce({limit:2e3}),{data:S,isLoading:te,isFetching:ae,refetch:se}=Ne({limit:2e3}
1),[ne,T]=o.useState([]),[re,F]=o.useState(!1),[h,A]=o.useState(""),[w,oe]=o.useState("All"),ie=O||V||J||Z||ae||re,le=H||q||_||X||te,p=Y?.items??[],me=o.useMemo(()=>(M?.items??[]).map(Fe),[M]),de=o.useMemo(()=>(S?.items??[]).map(Ae),[S]),E=z(me,"date"),D=z(de,"date"),R=o.useMemo(()=>{const e=new Map;return(k||[]).forEach(s=>e.set(s.id,s.name)),(L||[]).forEach(s=>e.set(s.id,s.name)),e},[k,L]),f=o.useMemo(()=>j.map(e=>{const s=I.find(t=>t.id===e.departmentId),u=s?.name??"â",d=e.companyId||s?.companyId;let i=d&&R.get(d)||"â";i==="â"&&(i="Tekki Web Solutions Pvt. Ltd.");let c=p.find(t=>t.id===e.leadEmployeeId);c||(c=p.find(t=>t.teams?.some(n=>n.teamId===e.id&&n.role==="Lead"))),c||(c=p.find(t=>t.teams?.some(n=>n.teamId===e.id)&&(t.designation?.toLowerCase().includes("lead")||t.designation?.toLowerCase().includes("manager"))));const ue=c?`${c.firstName||""} ${c.lastName||""}`.trim():"â",C=p.filter(t=>t.teams?.some(n=>n.teamId===e.id)),pe=C.length,fe=C.reduce((t,n)=>t+$e(n),0),Q=new Set(C.map(t=>`${t.firstName||""} ${t.lastName||""}`.trim().toLowerCase())),x=E.filter(t=>{if(t.companyId&&d&&t.companyId!==d)return!1;if(t.company&&i&&i!=="â"){const l=b(t.company),m=b(i);if(l&&m&&l!==m&&!l.includes(m)&&!m.includes(l))return!1}const n=!!(t.teamId&&e.id&&t.teamId===e.id),N=!!(t.team&&e.name&&g(t.team)===g(e.name));return n||N?!0:!t.team&&!t.teamId&&t.employee?Q.has(t.employee.trim().toLowerCase()):!1}).reduce((t,n)=>t+(n.gross||n.net||0),0),he=D.filter(t=>{if(t.companyId&&d&&t.companyId!==d)return!1;if(t.company&&i&&i!=="â"){const l=b(t.company),m=b(i);if(l&&m&&l!==m&&!l.includes(m)&&!m.includes(l))return!1}const n=!!(t.teamId&&e.id&&t.teamId===e.id),N=!!(t.team&&e.name&&g(t.team)===g(e.name));return n||N?!0:!t.team&&!t.teamId&&t.employee?Q.has(t.employee.trim().toLowerCase()):!1}).reduce((t,n)=>t+(n.net||0),0),$=fe+he,B=x-$,xe=x>0?B/x*100:0;return{id:e.id,team:e.name,teamId:e.id,company:i,department:u,members:pe,lead:ue,revenue:x,cost:$,profit:B,margin:xe}}).filter(e=>{const s=e.department.toLowerCase();return s.includes("it & production")||s.includes("it and production")}),[j,I,R,E,D,p]),P=o.useMemo(()=>[...f].sort((e,s)=>s.profit-e.profit)[0],[f]),G=o.useMemo(()=>f.filter(e=>{if(r.company!=="All Companies"&&e.company&&e.company!==r.company)return!1;const s=w!=="All"?w:r.department;if(s&&s!=="All"&&s!=="All Departments"&&e.department!==s)return!1;if(h.trim()){const u=h.toLowerCase();if(!(e.team.toLowerCase().includes(u)||e.department.toLowerCase().includes(u)||e.company.toLowerCase().includes(u)||e.lead.toLowerCase().includes(u)))return!1}return!0}),[f,r.company,r.department,w,h]);Array.from(new Set(f.map(e=>e.department).filter(e=>e!=="â"))).sort();const ce=o.useMemo(()=>[{key:"team",label:"Team Name",sortable:!0,render:e=>a.jsxs("span",{className:"font-medium flex items-center gap-1.5",children:[e.team,e.teamId===P?.teamId&&a.jsx("span",{className:"text-[9px] px-1 rounded bg-emerald-500/15 text-emerald-600 dark:text-emerald-400 font-semibold",children:"TOP"})]})},{key:"company",label:"Company",sortable:!0,width:"190px",render:e=>a.jsx(Ge,{name:e.company})},{key:"department",label:"Department",sortable:!0,width:"140px",render:e=>a.jsx(Qe,{name:e.department})},{key:"members",label:"Members",align:"right",width:"80px",sortable:!0,render:e=>e.members},{key:"revenue",label:"Revenue",align:"right",width:"120px",sortable:!0,defaultSortDir:"desc",render:e=>a.jsx("span",{className:"font-data font-semibold",children:y(e.revenue)})},{key:"cost",label:"Cost",align:"right",width:"130px",sortable:!0,defaultSortDir:"desc",render:e=>a.jsx("span",{className:"font-data font-semibold text-slate-700 dark:text-slate-300",children:e.cost>0?y(e.cost):a.jsx("span",{className:"text-slate-400 font-normal",children:"â"})})},{key:"profit",label:"Profit",align:"right",width:"130px",sortable:!0,defaultSortDir:"desc",render:e=>a.jsx("span",{className:ve("font-data font-semibold",e.profit>
1=0?"text-emerald-600 dark:text-emerald-400":"text-rose-600 dark:text-rose-400"),children:e.revenue>0||e.cost>0?v(e.profit):a.jsx("span",{className:"text-slate-400 font-normal",children:"â"})})},{key:"margin",label:"Margin %",align:"right",width:"90px",sortable:!0,defaultSortDir:"desc",render:e=>a.jsx("span",{className:"font-data font-semibold",children:e.revenue>0?je(e.margin):a.jsx("span",{className:"text-slate-400 font-normal",children:"â"})})},{key:"lead",label:"Team Lead",width:"160px",render:e=>a.jsx("span",{className:"text-muted-foreground font-medium",children:e.lead})}],[y,v,P]);return a.jsxs("div",{className:"flex flex-col flex-1 h-full min-h-0 overflow-hidden bg-slate-50/50",children:[a.jsx(Ie,{title:"Team Performance",subtitle:`${G.length} teams · IT & Production · live revenue & expense data`,accentVar:"--mod-team",showMonthYearFilter:!1}),a.jsx("div",{className:"shrink-0 bg-surface/50 border-b border-border px-4 py-2 flex items-center justify-between flex-wrap gap-2",children:a.jsx(Re,{showMonths:!0})}),a.jsx("div",{className:"p-3 pb-3 flex-1 min-h-0 flex flex-col overflow-hidden",children:a.jsx(ke,{searchSlot:a.jsx(Te,{value:h,onChange:A,placeholder:"Search teamsâ¦",className:"w-[280px] shrink-0"}),toolbar:a.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[a.jsx("span",{className:"inline-flex items-center gap-1.5 px-2.5 py-1 rounded-[5px] bg-blue-50 dark:bg-blue-950/60 border border-blue-200 dark:border-blue-800 text-blue-700 dark:text-blue-300 text-xs font-semibold shadow-2xs",children:"Department: IT & Production"}),a.jsxs("button",{type:"button",onClick:()=>{oe("All"),A(""),r.reset()},className:"h-8 px-3 rounded-[5px] border border-border bg-background hover:bg-accent text-xs font-medium inline-flex items-center gap-1.5 shadow-sm shrink-0",children:[a.jsx(Se,{className:"w-3.5 h-3.5 text-muted-foreground"})," Clear Filters"]})]}),selectable:!0,selectedIds:ne,onSelectionChange:T,bulkActions:[{id:"delete",label:"Delete",icon:a.jsx(Me,{className:"w-3.5 h-3.5"}),variant:"destructive",onAction:e=>{confirm(`Delete ${e.length} selected team(s)?`)&&(Le.success(`Deleted ${e.length} team(s)`),T([]))}}],rows:G,columns:ce,rowKey:e=>e.id,storageKey:"team-performance",initialPageSize:10,fetching:ie||le,empty:"No teams found",fillHeight:!0,onRefresh:async()=>{F(!0),await Promise.all([K(),W(),U(),ee(),se()]),setTimeout(()=>F(!1),500)}})})]})}export{Je as TeamPerformancePage,Je 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.