1import{r as w,j as e}from"./vendor-react-Dv9R7nxN.js";import{A as q,h as se,I as be,S as z,l as G,m as V,n as W,o as A,B as ne,u as Oe,b as Ee,T as Be,v as Ke,w as H,x as Q,U as qe,r as Ue}from"./index-LKdaOVk8.js";import{u as ze}from"./use-swipeable-tabs-BVOP_Zd9.js";import{u as F,a as Ge}from"./vendor-query-Cs9kLC36.js";import{C as _,a as $,b as Y,c as X}from"./card-BOpl-5Al.js";import{T as xe,a as ue,b as L,c as y,d as he,e as j}from"./table-DJef6aVz.js";import{B as J}from"./badge-DTpno4lY.js";import{a as D}from"./currency-e_P5Or2T.js";import{S as ge}from"./skeleton-DtWMMqY8.js";import{P as je}from"./progress-BV954SuN.js";import{T as Ve,R as We,A as He,d as ye,X as ve,Y as Ne,e as we,B as Qe,a as ke}from"./vendor-charts-BjAw6YHQ.js";import{x as Z,a6 as Ae,bl as Ye,am as Xe,bm as Ce,ak as Ze,b3 as et,P as Te,aw as ae,T as Se,k as tt,e as U,n as st,z as rt,d as re,a0 as ee,aO as Le,ay as pe,bn as te,bo as le,aq as at,j as _e,ao as lt,U as oe,c as nt}from"./vendor-icons-BQiY-VJc.js";import"./vendor-pdf-CBfJt2qT.js";import"./vendor-radix-cpQ7LkmK.js";const ot={light:"",dark:".dark"},Me=w.createContext(null);function Je(){const a=w.useContext(Me);if(!a)throw new Error("useChart must be used within a <ChartContainer />");return a}const ce=w.forwardRef(({id:a,className:t,children:c,config:l,...x},g)=>{const u=w.useId(),m=`chart-${a||u.replace(/:/g,"")}`;return e.jsx(Me.Provider,{value:{config:l},children:e.jsxs("div",{"data-chart":m,ref:g,className:q("flex aspect-video justify-center text-xs [&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-border/50 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-border [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-none [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-border [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke='#ccc']]:stroke-border [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-sector]:outline-none [&_.recharts-surface]:outline-none",t),...x,children:[e.jsx(ct,{id:m,config:l}),e.jsx(We,{children:c})]})})});ce.displayName="Chart";const ct=({id:a,config:t})=>{const c=Object.entries(t).filter(([,l])=>l.theme||l.color);return c.length?e.jsx("style",{dangerouslySetInnerHTML:{__html:Object.entries(ot).map(([l,x])=>` 2${x} [data-chart=${a}] { 3${c.map(([g,u])=>{const m=u.theme?.[l]||u.color;return m?` --color-${g}: ${m};`:null}).join(` 4`)} 5} 6`).join(` 7`)}}):null},$e=Ve,ie=w.forwardRef(({active:a,payload:t,className:c,indicator:l="dot",hideLabel:x=!1,hideIndicator:g=!1,label:u,labelFormatter:m,labelClassName:f,formatter:k,color:v,nameKey:n,labelKey:N},b)=>{const{config:C}=Je(),d=w.useMemo(()=>{if(x||!t?.length)return null;const[i]=t,I=`${N||i?.dataKey||i?.name||"value"}`,R=de(C,i,I),r=!N&&typeof u=="string"?C[u]?.label||u:R?.label;return m?e.jsx("div",{className:q("font-medium",f),children:m(r,t)}):r?e.jsx("div",{className:q("font-medium",f),children:r}):null},[u,m,t,x,f,C,N]);if(!a||!t?.length)return null;const o=t.length===1&&l!=="dot";return e.jsxs("div",{ref:b,className:q("grid min-w-[8rem] items-start gap-1.5 rounded-lg border border-border/50 bg-background px-2.5 py-1.5 text-xs shadow-xl",c),children:[o?null:d,e.jsx("div",{className:"grid gap-1.5",children:t.filter(i=>i.type!=="none").map((i,I)=>{const R=`${n||i.name||i.dataKey||"value"}`,r=de(C,i,R),p=v||i.payload.fill||i.color;return e.jsx("div",{className:q("flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5 [&>svg]:text-muted-foreground",l==="dot"&&"items-center"),children:k&&i?.value!==void 0&&i.name?k(i.value,i.name,i,I,i.payload):e.jsxs(e.Fragment,{children:[r?.icon?e.jsx(r.icon,{}):!g&&e.jsx("div",{className:q("shrink-0 rounded-[2px] border-[--color-border] bg-[--color-bg]",{"h-2.5 w-2.5":l==="dot","w-1":l==="line","w-0 border-[1.5px] border-dashed bg-transparent":l==="dashed","my-0.5":o&&l==="dashed"}),style:{"--color-bg":p,"--color-border":p}}),e.jsxs("div",{className:q("flex flex-1 justify-between leading-none",o?"items-end":"items-center"),children:[e.jsxs("div",{className:"grid gap-1.5",children:[o?d:null,e.jsx("span",{className:"text-muted-foreground",children:r?.label||i.name})]}),i.value&&e.jsx("span",{className:"font-mono font-medium tabular-nums text-foreground",children:i.value.toLocaleStr
7ing()})]})]})},i.dataKey)})})]})});ie.displayName="ChartTooltip";const it=w.forwardRef(({className:a,hideIcon:t=!1,payload:c,verticalAlign:l="bottom",nameKey:x},g)=>{const{config:u}=Je();return c?.length?e.jsx("div",{ref:g,className:q("flex items-center justify-center gap-4",l==="top"?"pb-3":"pt-3",a),children:c.filter(m=>m.type!=="none").map(m=>{const f=`${x||m.dataKey||"value"}`,k=de(u,m,f);return e.jsxs("div",{className:q("flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3 [&>svg]:text-muted-foreground"),children:[k?.icon&&!t?e.jsx(k.icon,{}):e.jsx("div",{className:"h-2 w-2 shrink-0 rounded-[2px]",style:{backgroundColor:m.color}}),k?.label]},m.value)})}):null});it.displayName="ChartLegend";function de(a,t,c){if(typeof t!="object"||t===null)return;const l="payload"in t&&typeof t.payload=="object"&&t.payload!==null?t.payload:void 0;let x=c;return c in t&&typeof t[c]=="string"?x=t[c]:l&&c in l&&typeof l[c]=="string"&&(x=l[c]),x in a?a[x]:a[c]}const dt="";async function mt(a,t){const c=localStorage.getItem("msg_auth_token"),l=t&&Object.keys(t).length>0?`?${new URLSearchParams(t)}`:"",x=await fetch(`${dt}${a}${l}`,{headers:{Authorization:`Bearer ${c}`}});if(!x.ok){const g=await x.json().catch(()=>({}));throw new Error(g.message??"Request failed")}return x.json()}function Pe(){const{t:a}=se(),t=a.productionReport,c=new Date,[l,x]=w.useState(()=>new Date(c.getFullYear(),c.getMonth(),1).toISOString().slice(0,10)),[g,u]=w.useState(()=>c.toISOString().slice(0,10)),[m,f]=w.useState("all"),[k,v]=w.useState("all"),[n,N]=w.useState("all"),[b,C]=w.useState("all"),[d,o]=w.useState(()=>new URLSearchParams(window.location.search).get("metric")),i=s=>a.orders.stageLabels[s]??s.replace(/_/g," "),I=s=>t.statuses[s]??s.replace(/_/g," "),R=s=>t.materialStatuses[s]??s.replace(/_/g," "),{data:r,isLoading:p,error:S}=F({queryKey:["/api/performance/production-report",l,g,m,k,n,b],queryFn:()=>{const s={};return l&&(s.dateFrom=l),g&&(s.dateTo=g),m!=="all"&&(s.branchId=m),k!=="all"&&(s.responsibleId=k),n!=="all"&&(s.stage=n),b!=="all"&&(s.status=b),mt("/api/performance/production-report",s)},refetchInterval:6e4}),T=()=>{x(""),u(""),f("all"),v("all"),N("all"),C("all"),o(null)},P=r?.jobs||[],h=r?.summary||{},O=r?.filterOptions||{},E=w.useMemo(()=>d?P.filter(s=>{switch(d){case"totalJobs":return!0;case"activeJobs":case"avgActiveAgeDays":return s.status==="active"||s.status==="delayed";case"completedJobs":case"completionRate":case"avgCycleTimeDays":return s.status==="completed"||s.stage==="delivered";case"overdueJobs":return s.overdue===!0;case"reworkJobs":return(s.reworkCount||0)>0;case"qualityIssues":return(s.qualityIssues||0)>0;case"materialReadyJobs":return s.materialStatus==="ready";case"materialPendingJobs":return s.materialStatus==="pending";case"materialNotRequestedJobs":return s.materialStatus==="not_requested";case"readyForDispatch":return s.stage==="ready_for_delivery";case"dispatchPending":return s.dispatchStatus==="pending";case"dispatchInTransit":return s.dispatchStatus==="in_transit";case"partialDeliveries":return s.fulfillmentStatus==="partially_delivered";case"fulfilledJobs":return s.fulfillmentStatus==="fully_delivered";case"fulfillmentPercent":return s.deliveredQuantity>0;case"noDueDate":return!s.dueDate&&s.status!=="completed";case"bottleneckStage":return s.stage===h.bottleneckStage;case"dueNext7Days":{if(!s.dueDate)return!1;const M=(new Date(s.dueDate).getTime()-Date.now())/(1e3*3600*24);return M>=0&&M<=7}default:return!0}}):P,[P,d,h.bottleneckStage]);if(S)return e.jsxs("div",{className:"p-6 text-center text-red-400 bg-red-500/10 rounded-xl border border-red-500/20",children:[e.jsx(Z,{className:"w-8 h-8 mx-auto mb-2 opacity-50"}),e.jsx("p",{children:t.error})]});const fe=h?[{id:"totalJobs",label:t.summary.totalJobs,value:h.totalJobs,color:"text-violet-400",bg:"bg-violet-500/10",border:"border-violet-500/20",ring:"ring-violet-500/50",icon:Ae},{id:"activeJobs",label:t.summary.activeJobs,value:h.activeJobs,color:"text-blue-400",bg:"bg-blue-500/10",border:"border-blue-500/20",ring:"ring-blue-500/50",icon:Ye},{id:"overdueJobs",label:t.summary.overdueJobs,value:h.overdueJobs,color:"text-red-400",bg:"bg-red-500/10",border:"border-red-500/20",ring:"ring-red-500/50",icon:Xe},{id:"dueNext7Days",label:t.summary.dueNext7Days,value:h.dueNext7Days,color:"text-amber-400",bg:"bg-amber-500/10",border:"border-amber-500/20",ring:"ring-amber-500/50",icon:Ce},{id:"completedJobs",label:t.summary.completedJobs,value:h.completedJobs,color:"text-emerald-400",bg:"bg-emerald-500/10",border:"border-emerald-500/20",ring:"ring-emerald-500/50",icon:Ze},{id:"qualityIssues",label:t.summary.qualityIssues,value:h.qualityIssues,color:"text-rose-400",bg:"bg-rose-500/10",border:"border-rose-500/20",ring:"ring-rose-500/50",icon:et},{id:"partialDeliveries",label:t.summary.partialDeliveries,value:h.partialDeliveries,color:"text-purple-400",bg:"bg-purple-500/10",border:"border-purple-500/20",ring:"ring-purple-500/50",icon:Te},{id:"reworkJobs",label:t.summary.reworkJobs,value:h.reworkJobs,color:"text-orange-400",bg:"bg-orange-500/10",border:"border-orange-500/20",ring:"ring-orange-500/50",icon:Z},{id:"materialPendingJobs",label:t.summary.materialPending,value:h.materialPendingJobs,color:"text-yellow-400",bg:"bg-yellow-500/10",border:"border-yellow-500/20",ring:"ring-yellow-500/50",icon:ae},{id:"materialReadyJobs",label:t.summary.materialReady,value:h.materialReadyJobs,color:"text-lime-400",bg:"bg-lime-500/10",border:"border-lime-500/20",ring:"ring-lime-500/50",icon:ae},{id:"noDueDate",label:t.summary.noDueDate,value:h.noDueDate,color:"text-slate-400",bg:"bg-slate-500/10",border:"border-slate-500/20",ring:"ring-slate-500/50",icon:Ce},{id:"readyForDispatch",label:t.summary.readyForDispatch,value:h.readyForDispatch,color:"text-cyan-400",bg:"bg-cyan-500/10",border:"border-cyan-500/20",ring:"ring-cyan-500/50",icon:Se},{id:"dispatchInTransit",label:t.summary.dispatchInTransit,value:h.dispatchInTransit,color:"text-sky-400",bg:"bg-sky-500/10",border:"border-sky-500/20",ring:"ring-sky-500/50",icon:Se},{id:"fulfilledJobs",label:t.summary.fulfilledJobs,value:h.fulfilledJobs,color:"text-teal-400",bg:"bg-teal-500/10",border:"border-teal-500/20",ring:"ring-teal-500/50",icon:Te}]:[];return e.jsxs("div",{className:"space-y-6 pb-12",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-display font-bold",children:t.title}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:t.subtitle})]}),e.jsx("div",{className:"flex flex-col xl:flex-row xl:items-end justify-between gap-4 bg-card/40 p-4 rounded-xl border border-white/5",children:e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 xl:grid-cols-7 gap-3 flex-1",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-[10px] uppercase tracking-wider text-muted-foreground font-semibold",children:t.filters.dateFrom}
7),e.jsx(be,{type:"date",value:l,onChange:s=>x(s.target.value),className:"h-9 text-xs bg-black/20"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-[10px] uppercase tracking-wider text-muted-foreground font-semibold",children:t.filters.dateTo}),e.jsx(be,{type:"date",value:g,onChange:s=>u(s.target.value),className:"h-9 text-xs bg-black/20"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-[10px] uppercase tracking-wider text-muted-foreground font-semibold",children:t.filters.branch}),e.jsxs(z,{value:m,onValueChange:f,children:[e.jsx(G,{className:"h-9 text-xs bg-black/20",children:e.jsx(V,{placeholder:t.filters.allBranches})}),e.jsxs(W,{children:[e.jsx(A,{value:"all",children:t.filters.allBranches}),O.branches?.map(s=>e.jsx(A,{value:String(s.id),children:s.name},s.id))]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-[10px] uppercase tracking-wider text-muted-foreground font-semibold",children:t.filters.manager}),e.jsxs(z,{value:k,onValueChange:v,children:[e.jsx(G,{className:"h-9 text-xs bg-black/20",children:e.jsx(V,{placeholder:t.filters.allManagers})}),e.jsxs(W,{children:[e.jsx(A,{value:"all",children:t.filters.allManagers}),O.responsibleMembers?.map(s=>e.jsx(A,{value:String(s.id),children:s.name},s.id))]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-[10px] uppercase tracking-wider text-muted-foreground font-semibold",children:t.filters.stage}),e.jsxs(z,{value:n,onValueChange:N,children:[e.jsx(G,{className:"h-9 text-xs bg-black/20",children:e.jsx(V,{placeholder:t.filters.allStages})}),e.jsxs(W,{children:[e.jsx(A,{value:"all",children:t.filters.allStages}),O.stages?.map(s=>e.jsx(A,{value:s,children:i(s)},s))]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-[10px] uppercase tracking-wider text-muted-foreground font-semibold",children:t.filters.status}),e.jsxs(z,{value:b,onValueChange:C,children:[e.jsx(G,{className:"h-9 text-xs bg-black/20",children:e.jsx(V,{placeholder:t.filters.allStatuses})}),e.jsxs(W,{children:[e.jsx(A,{value:"all",children:t.filters.allStatuses}),["active","delayed","completed","ready_for_delivery"].map(s=>e.jsx(A,{value:s,children:I(s)},s))]})]})]}),e.jsx("div",{className:"space-y-1.5 flex items-end",children:e.jsxs(ne,{variant:"outline",onClick:T,className:"w-full h-9 text-xs border-white/10 hover:bg-white/5",children:[e.jsx(tt,{className:"w-3.5 h-3.5 mr-2"})," ",t.filters.clear]})})]})}),p?e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-3",children:[...Array(6)].map((s,M)=>e.jsx(ge,{className:"h-24 rounded-xl"},M))}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 xl:grid-cols-6 gap-3",children:fe.map(s=>{const M=s.icon,B=d===s.id;return e.jsxs("button",{onClick:()=>o(B?null:s.id),className:`text-left p-4 rounded-xl border transition-all duration-200 relative overflow-hidden group ${B?`${s.bg} ${s.border} ring-1 ring-inset ${s.ring}`:"bg-card/40 border-white/5 hover:bg-white/5 hover:border-white/10"}`,children:[e.jsxs("div",{className:"flex justify-between items-start mb-2",children:[e.jsx("p",{className:`text-[10px] uppercase tracking-wider font-semibold ${B?s.color:"text-muted-foreground group-hover:text-foreground/80 transition-colors"}`,children:s.label}),e.jsx(M,{className:`w-4 h-4 ${B?s.color:"text-muted-foreground/50"}`})]}),e.jsx("p",{className:`text-2xl font-bold font-display ${B?s.color:"text-foreground"}`,children:s.value||0})]},s.id)})}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4",children:[e.jsx("button",{type:"button",onClick:()=>o(d==="fulfillmentPercent"?null:"fulfillmentPercent"),className:`text-left rounded-xl border md:col-span-1 transition-colors ${d==="fulfillmentPercent"?"border-primary/50 bg-primary/10":"border-white/5 bg-card/40 hover:bg-white/5"}`,children:e.jsxs("div",{className:"p-5 flex flex-col justify-center h-full",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1 font-semibold uppercase tracking-wider",children:t.summary.fulfillmentPercent}),e.jsx("div",{className:"flex items-end gap-2 mb-2",children:e.jsxs("p",{className:"text-3xl font-bold font-display text-primary",children:[h.fulfillmentPercent,"%"]})}),e.jsx(je,{value:h.fulfillmentPercent,className:"h-2 bg-white/5"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-3",children:t.unitsDelivered.replace("{del}",String(h.deliveredUnits||0)).replace("{ord}",String(h.orderedUnits||0))})]})}),e.jsx(_,{className:"bg-card/40 border-white/5 md:col-span-3",children:e.jsxs($,{className:"p-5 grid grid-cols-2 md:grid-cols-4 gap-4 h-full items-center",children:[e.jsxs("button",{type:"button",className:"text-left rounded-lg p-2 hover:bg-white/5",onClick:()=>o(d==="avgCycleTimeDays"?null:"avgCycleTimeDays"),children:[e.jsx("p",{className:"text-[10px] uppercase tracking-wider text-muted-foreground font-semibold mb-1",children:t.summary.avgCycleTime}),e.jsxs("p",{className:"text-xl font-bold text-foreground",children:[h.avgCycleTimeDays," ",e.jsx("span",{className:"text-sm font-normal text-muted-foreground",children:t.summary.days})]})]}),e.jsxs("button",{type:"button",className:"text-left rounded-lg p-2 hover:bg-white/5",onClick:()=>o(d==="avgActiveAgeDays"?null:"avgActiveAgeDays"),children:[e.jsx("p",{className:"text-[10px] uppercase tracking-wider text-muted-foreground font-semibold mb-1",children:t.summary.avgActiveAge}),e.jsxs("p",{className:"text-xl font-bold text-foreground",children:[h.avgActiveAgeDays," ",e.jsx("span",{className:"text-sm font-normal text-muted-foreground",children:t.summary.days})]})]}),e.jsxs("button",{type:"button",className:"text-left rounded-lg p-2 hover:bg-white/5",onClick:()=>o(d==="bottleneckStage"?null:"bottleneckStage"),children:[e.jsx("p",{className:"text-[10px] uppercase tracking-wider text-muted-foreground font-semibold mb-1",children:t.summary.bottleneck}),e.jsx("div",{className:"flex items-center gap-1.5",children:h.bottleneckStage?e.jsx(J,{variant:"outline",className:"text-orange-400 border-orange-500/30 bg-
7orange-500/10 capitalize",children:i(h.bottleneckStage)}):e.jsx("span",{className:"text-sm text-muted-foreground",children:t.noBottleneck})}),h.bottleneckCount>0&&e.jsx("p",{className:"text-[10px] text-muted-foreground mt-1",children:t.jobsCount.replace("{count}",String(h.bottleneckCount))})]}),e.jsxs("button",{type:"button",className:"text-left rounded-lg p-2 hover:bg-white/5",onClick:()=>o(d==="completionRate"?null:"completionRate"),children:[e.jsx("p",{className:"text-[10px] uppercase tracking-wider text-muted-foreground font-semibold mb-1",children:t.summary.completionRate}),e.jsxs("p",{className:"text-xl font-bold text-emerald-400",children:[h.completionRate,"%"]})]})]})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[e.jsxs(_,{className:"bg-card/40 border-white/5",children:[e.jsx(Y,{className:"pb-2",children:e.jsxs(X,{className:"text-sm font-display flex items-center gap-2",children:[e.jsx(U,{className:"w-4 h-4 text-primary"})," ",t.trends]})}),e.jsx($,{className:"px-2 pb-4",children:e.jsx(ce,{config:{completed:{label:t.completed,color:"hsl(var(--emerald-500))"},created:{label:t.started,color:"hsl(var(--primary))"}},className:"h-[200px] w-full",children:e.jsxs(He,{data:r?.trend||[],margin:{top:10,right:10,left:-20,bottom:0},children:[e.jsxs("defs",{children:[e.jsxs("linearGradient",{id:"fillStarted",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:"var(--color-created)",stopOpacity:.3}),e.jsx("stop",{offset:"95%",stopColor:"var(--color-created)",stopOpacity:0})]}),e.jsxs("linearGradient",{id:"fillCompleted",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:"var(--color-completed)",stopOpacity:.3}),e.jsx("stop",{offset:"95%",stopColor:"var(--color-completed)",stopOpacity:0})]})]}),e.jsx(ye,{strokeDasharray:"3 3",vertical:!1,stroke:"hsl(var(--border))"}),e.jsx(ve,{dataKey:"date",tickLine:!1,axisLine:!1,tickMargin:8,tickFormatter:s=>new Date(s).toLocaleDateString(void 0,{month:"short",day:"numeric"})}),e.jsx(Ne,{tickLine:!1,axisLine:!1,tickMargin:8}),e.jsx($e,{content:e.jsx(ie,{})}),e.jsx(we,{type:"monotone",dataKey:"created",stroke:"var(--color-created)",fill:"url(#fillStarted)",strokeWidth:2}),e.jsx(we,{type:"monotone",dataKey:"completed",stroke:"var(--color-completed)",fill:"url(#fillCompleted)",strokeWidth:2})]})})})]}),e.jsxs(_,{className:"bg-card/40 border-white/5",children:[e.jsx(Y,{className:"pb-2",children:e.jsxs(X,{className:"text-sm font-display flex items-center gap-2",children:[e.jsx(ae,{className:"w-4 h-4 text-purple-400"})," ",t.stageAnalysis]})}),e.jsx($,{className:"px-2 pb-4",children:e.jsx(ce,{config:{count:{label:t.summary.activeJobs,color:"hsl(var(--purple-500))"},overdue:{label:t.summary.overdueJobs,color:"hsl(var(--red-500))"}},className:"h-[200px] w-full",children:e.jsxs(Qe,{data:r?.byStage||[],margin:{top:10,right:10,left:-20,bottom:0},children:[e.jsx(ye,{strokeDasharray:"3 3",vertical:!1,stroke:"hsl(var(--border))"}),e.jsx(ve,{dataKey:"stage",tickLine:!1,axisLine:!1,tickMargin:8,tickFormatter:s=>i(String(s)).substring(0,12)}),e.jsx(Ne,{tickLine:!1,axisLine:!1,tickMargin:8}),e.jsx($e,{content:e.jsx(ie,{})}),e.jsx(ke,{dataKey:"count",fill:"var(--color-count)",radius:[4,4,0,0],maxBarSize:40}),e.jsx(ke,{dataKey:"overdueCount",fill:"var(--color-overdue)",radius:[4,4,0,0],maxBarSize:40})]})})})]})]}),e.jsxs("div",{className:"space-y-3 pt-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h3",{className:"text-base font-display font-semibold text-foreground flex items-center gap-2",children:[t.jobsList,d&&e.jsx(J,{variant:"outline",className:"ml-2 border-primary/30 text-primary bg-primary/10",children:t.metricSelected.replace("{metric}",fe.find(s=>s.id===d)?.label||d)})]}),d&&e.jsx(ne,{variant:"ghost",size:"sm",onClick:()=>o(null),className:"h-8 text-xs text-muted-foreground hover:text-foreground",children:t.showAllJobs})]}),e.jsx(_,{className:"bg-card/40 border-white/5 overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(xe,{children:[e.jsx(ue,{className:"bg-black/20",children:e.jsxs(L,{className:"border-white/5 hover:bg-transparent",children:[e.jsx(y,{className:"w-[100px]",children:t.jobs.orderId}),e.jsx(y,{children:t.jobs.customer}),e.jsx(y,{children:t.jobs.stage}),e.jsx(y,{children:t.jobs.responsible}),e.jsx(y,{children:t.jobs.dueDate}),e.jsx(y,{className:"text-center",children:t.jobs.fulfillment}),e.jsx(y,{className:"text-center",children:t.jobs.materials}),e.jsx(y,{className:"text-right",children:t.jobs.cycle})]})}),e.jsx(he,{children:E.length===0?e.jsx(L,{className:"hover:bg-transparent border-0",children:e.jsxs(j,{colSpan:8,className:"h-32 text-center text-muted-foreground",children:[e.jsx("p",{children:t.empty.title}),e.jsx("p",{className:"text-xs mt-1",children:t.empty.description})]})}):E.map(s=>e.jsxs(L,{className:"border-white/5 group hover:bg-white/[0.02] cursor-default",children:[e.jsxs(j,{className:"font-mono font-medium",children:[s.orderNumber,s.overdue&&e.jsx(J,{variant:"outline",className:"mt-1 flex w-fit text-[9px] px-1 py-0 border-red-500/30 text-red-400 bg-red-500/10",children:t.jobs.overdue})]}),e.jsxs(j,{children:[e.jsx("p",{className:"font-medium text-sm text-foreground truncate max-w-[200px]",children:s.customerName}),e.jsxs("p",{className:"text-xs text-muted-foreground truncate max-w-[200px]",children:[s.productCategory," · ",t.quantityUnits.replace("{count}",String(s.quantity))]})]}),e.jsx(j,{children:e.jsxs("div",{className:"flex flex-col gap-1.5 items-start",children:[e.jsx(J,{variant:"outline",className:"capitalize text-xs font-normal border-white/10 bg-black/20 text-foreground",children:i(String(s.stage))}),(s.reworkCount>0||s.qualityIssues>0)&&e.jsxs("div",{className:"flex gap-1.5",children:[s.reworkCount>0&&e.jsxs("span",{className:"text-[10px] text-orange-400 font-medium",children:[s.reworkCount," ",t.jobs.rework]}),s.qualityIssues>0&&e.jsxs("span",{className:"text-[10px] text-red-400 font-medium",children:[s.qualityIssues," ",t.jobs.issues]})]})]})}),e.jsxs(j,{children:[e.jsx("p",{className:"text-xs font-medium",children:s.assignedManagerName??t.unassigned}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:s.branchName??t.noBranch})]}),e.jsx(j,{children:e.jsx("p",{className:`text-xs ${s.overdue?"text-red-400 font-medium":"text-muted-foreground"}`,children:s.dueDate?new Date(s.dueDate).toLocaleDateString():t.noDueDate})}),e.jsx(j,{className:"text-center align-top pt-4",children:e.jsxs("div",{className:"flex flex-col items-center gap-1.5",children:[e.jsxs("div",{className:"text-xs font-medium text-foreground",children:[s.fulfillmentPercent,"%"]}),e.jsx(je,{value:s.fulfillmentPercent,className:"h-1.5 w-16 bg-white/10"}),e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[s.deliveredQuantity," / ",s.quantity]})]})}),e.jsx(j,{className:"text-center",children:e.jsx(J,{variant:"outline",className:`text-[10px] font-normal ${s.materialStatus==="ready"?"text-emerald-400 border-emerald-500/30 bg-emerald-500/10":s.materialStatus==="pending"?"text-yellow-400 border-yellow-500/30 bg-yellow-500/10":"text-muted-foreground border-white/10 bg-white/5"}`,children:R(String(s.materialStatus||"not_requested"))})}),e.jsxs(j,{className:"text-right",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:s.cycleDays===null?t.inProgress:`${s.cycleDays} ${t.summary.days}`}),s.taskCount>0&&e.jsx("p",{className:"text-[10px] text-muted-foreground mt-0.5",children:t.tasksOpen.replace("{open}",String(s.openTaskCount)).replace("{total}",String(s.taskCount))})]})]},s.id))})]})})})]})]})]})}function K(a,t){const c=localStorage.getItem("msg_auth_token"),l=t?`${a}?${new URLSearchParams(t)}
7`:a;return fetch(l,{headers:{Authorization:`Bearer ${c}`}}).then(x=>x.json())}const De={daily:"Today",monthly:"Monthly",quarterly:"Quarterly",annual:"Annual"};function xt({icon:a,label:t,value:c,sub:l,color:x="text-primary"}){return e.jsx(_,{className:"bg-card/50 border-white/5",children:e.jsx($,{className:"p-5",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:t}),e.jsx("p",{className:`text-2xl font-bold font-display ${x}`,children:c}),l&&e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:l})]}),e.jsx("div",{className:"w-10 h-10 rounded-xl bg-primary/10 flex items-center justify-center",children:e.jsx(a,{className:"w-5 h-5 text-primary"})})]})})})}const me={excellent:{label:"Excellent",color:"text-emerald-400",bg:"bg-emerald-500/10",border:"border-emerald-500/30",Icon:Ae},on_track:{label:"On Track",color:"text-blue-400",bg:"bg-blue-500/10",border:"border-blue-500/30",Icon:te},warning:{label:"Warning",color:"text-yellow-400",bg:"bg-yellow-500/10",border:"border-yellow-500/30",Icon:Z},lagging:{label:"Lagging",color:"text-red-400",bg:"bg-red-500/10",border:"border-red-500/30",Icon:pe}},Fe={revenue:U,leads:oe,quotations:_e,orders:te,tasks:te,deliveries:lt,totalOpen:_e,pending:at,inProd:ee,delayed:Z},ut={revenue:"Revenue",leads:"Leads",quotations:"Quotations",orders:"Orders",tasks:"Tasks",deliveries:"Deliveries",totalOpen:"Open Tasks",pending:"Pending Deliveries",inProd:"Jobs in Production",delayed:"Delayed Jobs"},Ie={revenue:!0,ar:!0,ap:!0,payroll:!0};function ht({pg:a,isRevenue:t,canShowFinancials:c}){const l=me[a.status]??me.lagging,x=l.Icon,g=Fe[a.targetType]??re,u=Math.min(a.pct,100),m=Math.min(a.expectedPct,100);return e.jsx(_,{className:`border ${l.border} ${l.bg} relative overflow-hidden`,children:e.jsxs($,{className:"p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(g,{className:`w-4 h-4 shrink-0 ${l.color}`}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-xs text-muted-foreground capitalize",children:a.period}),e.jsx("p",{className:"text-sm font-semibold text-foreground truncate",children:ut[a.targetType]??a.targetType})]})]}),e.jsxs("div",{className:`flex items-center gap-1 px-2 py-0.5 rounded-full text-[10px] font-semibold border shrink-0 ${l.color} ${l.bg} ${l.border}`,children:[e.jsx(x,{className:"w-2.5 h-2.5"}),l.label]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex justify-between text-xs",children:[e.jsxs("span",{className:`font-bold text-sm ${l.color}`,children:[a.pct,"%"]}),e.jsxs("span",{className:"text-muted-foreground",children:["Target: ",t&&c?D(a.target):a.target]})]}),e.jsxs("div",{className:"relative h-3 rounded-full bg-white/10 overflow-hidden",children:[e.jsx("div",{className:`h-full rounded-full transition-all ${a.status==="excellent"?"bg-emerald-500":a.status==="on_track"?"bg-blue-500":a.status==="warning"?"bg-yellow-500":"bg-red-500"}`,style:{width:`${u}%`}}),m>0&&e.jsx("div",{className:"absolute top-0 bottom-0 w-0.5 bg-white/50",style:{left:`${m}%`},title:`Expected by now: ${a.expectedPct}%`})]}),e.jsxs("div",{className:"flex justify-between text-[10px] text-muted-foreground",children:[e.jsxs("span",{children:["Actual: ",t&&c?D(Math.round(a.actual)):a.actual]}),e.jsxs("span",{children:["Expected: ",a.expectedPct,"%"]})]})]}),e.jsxs("div",{className:`flex items-center gap-1.5 text-[11px] font-medium ${a.lag>=0?"text-emerald-400":"text-red-400"}`,children:[a.lag>=0?e.jsx(U,{className:"w-3 h-3"}):e.jsx(pe,{className:"w-3 h-3"}),a.lag>=0?`+${a.lag}% ahead of pace`:`${Math.abs(a.lag)}% behind pace`]})]})})}function Re({userId:a,userRole:t}){const[c,l]=w.useState("monthly"),{t:x}=se(),g=x.performance,u=x.leaderboard,m=["sales_executive","marketing_executive","branch_sales_lead","branch_manager"].includes(t),{data:f,isLoading:k}=F({queryKey:["/api/performance/me"],queryFn:()=>K("/api/performance/me"),refetchInterval:3e4,refetchOnWindowFocus:!0,staleTime:0}),{data:v=[]}=F({queryKey:["/api/performance/sales",c],queryFn:()=>K("/api/performance/sales",{period:c}),enabled:m,refetchInterval:3e4,refetchOnWindowFocus:!0,staleTime:0}),n=f?.stats?.[c],N=f?.visibility?.personalFinancialValues===!0||f?.visibility?.financialValues===!0,C=(Array.isArray(f?.kpiMetadata)?f.kpiMetadata:[]).reduce((r,p)=>(p?.key&&(r[p.key]=p),r),{}),d=Object.entries(n??{}).filter(([r])=>{const p=C[r];return p&&(!p.financial||N)}),o=v.find(r=>r.userId===a),i=f?.paceData,I=f?.targetProgress,R=I?Object.values(I).filter(r=>r.period===c&&(!Ie[r.targetType]||N)):[];return k?e.jsx("div",{className:"space-y-4",children:[...Array(4)].map((r,p)=>e.jsx(ge,{className:"h-24 rounded-xl"},p))}):f?e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-3",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-display font-bold text-foreground",children:g.myDashboard}),e.jsx("p",{className:"text-muted-foreground text-sm mt-0.5",children:i?`${i.elapsedWorkDays} of ${i.totalWorkDays} working days elapsed this month (${i.monthPace}% of month)`:g.myMetrics})]}),e.jsx("div",{className:"flex rounded-lg overflow-hidden border border-white/10",children:["daily","monthly","quarterly","annual"].map(r=>e.jsx("button",{onClick:()=>l(r),className:`px-3 py-2 text-xs font-medium transition-colors capitalize ${c===r?"bg-primary text-white":"bg-card/50 text-muted-foreground hover:text-foreground"}`,children:r==="daily"?"Today":r==="monthly"?g.monthly:r==="quarterly"?g.quarterly:g.annual},r))})]}),i&&c==="monthly"&&e.jsx(_,{className:"bg-card/50 border-white/5",children:e.jsxs($,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("p",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wider flex items-center gap-1.5",children:[e.jsx(Le,{className:"w-3.5 h-3.5"})," Monthly Pace"]}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[i.elapsedWorkDays," / ",i.totalWorkDays," work days"]})]}),e.jsx("div",{className:"h-2.5 rounded-full bg-white/10 overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full bg-primary/60",style:{width:`${i.monthPace}%`}})}),e.jsxs("p",{className:"text-[10px] text-muted-foreground mt-1.5",children:[i.monthPace,"% of the working month has elapsed. Your actuals should be at least this % of target to be on pace."]})]})}),R.length>0&&e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-display font-semibold text-muted-foreground uppercase tracking-wider mb-3 flex items-center gap-2",children:[e.jsx(re,{className:"w-4 h-4"})," Performance vs Targets"]}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-3 gap-4",children:R.map(r=>e.jsx(ht,{pg:r,isRevenue:Ie[r.targetType]??!1,canShowFinancials:N},`${r.targetType}::${r.period}`))})]}),R.length>0&&(()=>{const r={excellent:0,on_track:0,warning:0,lagging:0};return R.forEach(p=>{r[p.status]!==void 0&&r[p.status]++}),e.jsx("div",{className:"flex gap-3 flex-wrap",children:Object.entries(r).filter(([,p])=>p>0).map(([p,S])=>{const T=me[p],P=T.Icon;return e.jsxs("div",{className:`flex items-center gap-1.5 px-3 py-1.5 rounded-full text-xs font-semibold border ${T.color} ${T.bg} ${T.border}`,children:[e.jsx(P,{className:"w-3 h-3"}),S," ",T.label]},p)})})})(),n&&e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-display font-semibold text-muted-foreground uppercase tracking-wider mb-3 flex items-center gap-2",children:[e.jsx(le,{className:"w-4 h-4"})," Activity"]}),e.jsx("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4",children:d.map(([r,p]
7)=>{const S=C[r],T=typeof p=="number"?p:Number(p)||0,P=S.format==="percentage"||S.format==="percent"||/(?:conversion|onTime|ledgerHealth)/i.test(r);return e.jsx(xt,{icon:Fe[r]??le,label:S.label??r,value:S.financial?D(T):P?`${T}%`:T,color:S.financial?"text-emerald-400":void 0},r)})})]}),c==="annual"&&d.length===0&&e.jsx(_,{className:"bg-card/50 border-white/5",children:e.jsx($,{className:"p-5 text-sm text-muted-foreground",children:"Annual performance is not available yet for this role. Your annual targets remain visible when they are configured."})}),(()=>{const r=o?.rank??f.teamRank,p=v.length||f.teamSize,S=I?Object.values(I).find(E=>E.period===c&&E.targetType==="revenue"):null,T=S?Math.round(S.pct??0):null,P=c==="monthly"&&i?i.monthPace:null,h=P!==null&&T!==null?T>=P:null,O=r===1?"ð¥":r===2?"ð¥":r===3?"ð¥":null;return e.jsx(_,{className:`border ${r===1?"bg-yellow-500/5 border-yellow-500/20":r<=3?"bg-primary/5 border-primary/20":"bg-card/50 border-white/5"}`,children:e.jsx($,{className:"p-5",children:e.jsxs("div",{className:"flex items-start justify-between gap-4 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:`w-16 h-16 rounded-2xl flex items-center justify-center font-bold text-2xl shrink-0 ${r===1?"bg-yellow-500/20 text-yellow-400":r===2?"bg-slate-400/20 text-slate-300":r===3?"bg-orange-600/20 text-orange-400":"bg-primary/10 text-primary"}`,children:O??`#${r??"?"}`}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-xs text-muted-foreground uppercase tracking-wider font-semibold",children:["My Position â ",c==="daily"?"Today":c==="monthly"?"This Month":c==="quarterly"?"This Quarter":"This Year"]}),e.jsx("p",{className:"text-xl font-display font-bold text-foreground mt-0.5",children:r?`#${r} of ${p}`:"No rank yet"}),S&&N&&e.jsxs("p",{className:"text-sm text-muted-foreground mt-0.5",children:[D(S.actual)," / ",D(S.target)," target"]})]})]}),e.jsxs("div",{className:"flex flex-col items-end gap-2",children:[h!==null&&e.jsxs("div",{className:`flex items-center gap-1.5 px-3 py-1.5 rounded-full text-xs font-semibold ${h?"bg-emerald-500/15 text-emerald-400 border border-emerald-500/30":"bg-red-500/15 text-red-400 border border-red-500/30"}`,children:[h?e.jsx(U,{className:"w-3 h-3"}):e.jsx(pe,{className:"w-3 h-3"}),h?"Ahead of pace":"Behind pace"]}),T!==null&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:[T,"% of target achieved"]}),P!==null&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:[P,"% of month elapsed"]})]})]})})})})(),v.length>0&&e.jsxs("div",{children:[e.jsxs("h3",{className:"text-base font-display font-semibold text-foreground mb-3 flex items-center gap-2",children:[e.jsx(le,{className:"w-4 h-4 text-muted-foreground"}),g.teamLeaderboard]}),e.jsx(_,{className:"bg-card/50 border-white/5",children:e.jsx($,{className:"p-0",children:e.jsxs(xe,{children:[e.jsx(ue,{children:e.jsxs(L,{className:"border-white/5 hover:bg-transparent",children:[e.jsx(y,{className:"w-12",children:u.rank}),e.jsx(y,{children:u.executive}),e.jsx(y,{className:"text-center",children:u.leads}),e.jsx(y,{className:"text-center",children:u.quotes}),e.jsx(y,{className:"text-center",children:u.closed}),e.jsx(y,{className:"text-right",children:u.revenue}),e.jsx(y,{className:"text-right",children:u.winRate})]})}),e.jsx(he,{children:v.map(r=>e.jsxs(L,{className:`border-white/5 ${r.userId===a?"bg-primary/5":""}`,children:[e.jsx(j,{className:"font-mono",children:r.rank===1?"ð¥":r.rank===2?"ð¥":r.rank===3?"ð¥":`#${r.rank}`}),e.jsx(j,{className:"font-medium",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(qe,{userId:r.userId,name:r.userName,avatar:r.avatar,size:"sm"}),e.jsx("span",{children:r.userName}),r.userId===a&&e.jsx(J,{variant:"outline",className:"text-xs border-primary/30 text-primary",children:g.you})]})}),e.jsx(j,{className:"text-center",children:r.leadsCreated}),e.jsx(j,{className:"text-center",children:r.quotationsSent}),e.jsx(j,{className:"text-center text-emerald-400 font-medium",children:r.ordersClosed}),e.jsx(j,{className:"text-right font-semibold text-primary",children:D(r.revenueGenerated)}),e.jsxs(j,{className:"text-right",children:[r.conversionRate.toFixed(1),"%"]})]}
7,r.userId))})]})})})]})]}):e.jsx("div",{className:"text-muted-foreground text-sm p-4",children:"Could not load your data."})}function gt(){const[a,t]=w.useState("monthly"),{t:c}=se(),l=c.performance,x=c.leaderboard,{data:g,isLoading:u}=F({queryKey:["/api/performance/branches",a],queryFn:()=>K("/api/performance/branches",{period:a})}),m=g?.branches??[],f=n=>n===null?"text-muted-foreground":n>=100?"text-emerald-400":n>=70?"text-yellow-400":n>=40?"text-orange-400":"text-red-400",k=n=>n===null?"bg-muted/30":n>=100?"bg-emerald-500":n>=70?"bg-yellow-500":n>=40?"bg-orange-500":"bg-red-500",v=n=>n===0?"ð¥":n===1?"ð¥":n===2?"ð¥":`#${n+1}`;return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-3",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-display font-bold",children:l.branchTitle}),e.jsx("p",{className:"text-muted-foreground text-sm mt-0.5",children:l.branchSubtitle})]}),e.jsx("div",{className:"flex rounded-lg overflow-hidden border border-white/10",children:["daily","monthly","quarterly","annual"].map(n=>e.jsx("button",{onClick:()=>t(n),className:`px-4 py-2 text-sm font-medium transition-colors ${a===n?"bg-primary text-white":"bg-card/50 text-muted-foreground hover:text-foreground"}`,children:n==="daily"?"Today":n==="monthly"?l.monthly:n==="quarterly"?l.quarterly:l.annual},n))})]}),!u&&m.length>0&&(()=>{const n=m.reduce((d,o)=>d+o.revenueActual,0),N=m.reduce((d,o)=>d+o.revenueTarget,0),b=m.reduce((d,o)=>d+o.leadsCreated,0),C=m.reduce((d,o)=>d+o.ordersClosed,0);return e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-4",children:[{icon:U,label:l.totalRevenue,value:D(n),color:"text-primary bg-primary/10"},{icon:re,label:l.revenueTarget,value:D(N),color:"text-blue-400 bg-blue-500/10"},{icon:oe,label:l.totalLeads,value:b,color:"text-purple-400 bg-purple-500/10"},{icon:te,label:l.closedOrders,value:C,color:"text-emerald-400 bg-emerald-500/10"}].map((d,o)=>{const i=d.icon;return e.jsx(_,{className:"bg-card/50 border-white/5",children:e.jsxs($,{className:"p-4 flex items-center gap-3",children:[e.jsx("div",{className:`p-2 rounded-lg ${d.color}`,children:e.jsx(i,{className:"w-4 h-4"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:d.label}),e.jsx("p",{className:"text-lg font-bold",children:d.value})]})]})},o)})})})(),u?e.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[...Array(4)].map((n,N)=>e.jsx(ge,{className:"h-64 rounded-xl"},N))}):m.length===0?e.jsx(_,{className:"bg-card/50 border-white/5",children:e.jsxs($,{className:"p-12 text-center",children:[e.jsx(ee,{className:"w-12 h-12 text-muted-foreground mx-auto mb-3 opacity-40"}),e.jsx("p",{className:"text-muted-foreground",children:l.noBranches})]})}):e.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:m.map((n,N)=>e.jsxs(_,{className:"bg-card/50 border-white/5 overflow-hidden",children:[e.jsx(Y,{className:"pb-3 border-b border-white/5",children:e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-lg font-bold",children:v(N)}),e.jsxs("div",{children:[e.jsxs(X,{className:"text-base font-display flex items-center gap-1.5",children:[e.jsx(ee,{className:"w-4 h-4 text-primary"}),n.branchName,n.isHeadquarters&&e.jsx("span",{className:"text-xs bg-primary/20 text-primary px-1.5 py-0.5 rounded-md",children:"HQ"})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[n.branchCity&&e.jsxs("span",{className:"text-xs text-muted-foreground flex items-center gap-1",children:[e.jsx(nt,{className:"w-3 h-3"}),n.branchCity]}),n.managerName&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["· ",n.managerName]})]})]})]}),e.jsxs("div",{className:"text-right shrink-0",children:[e.jsx("p",{className:`text-xl font-bold font-display ${f(n.revenuePct)}`,children:n.revenuePct!==null?`${n.revenuePct}%`:"â"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l.ofTarget})]})]})}),e.jsxs($,{className:"pt-4 space-y-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between text-xs mb-1.5",children:[e.jsx("span",{className:"text-muted-foreground",children:x.revenue}),e.jsxs("span",{className:"font-medium",children:[D(n.revenueActual)," / ",n.revenueTarget>0?D(n.revenueTarget):l.noTarget]})]}),e.jsx("div",{className:"h-2 rounded-full bg-white/5 overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full transition-all duration-700 ${k(n.revenuePct)}`,style:{width:`${Math.min(n.revenuePct??0,100)}%`}})})]}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-2",children:[{label:l.leadsLabel,value:n.leadsCreated,target:n.leadsTarget,color:"text-purple-400"},{label:l.quotesLabel,value:n.quotationsSent,target:n.quotationsTarget,color:"text-blue-400"},{label:l.ordersLabel,value:n.ordersClosed,target:n.ordersTarget,color:"text-emerald-400"}].map(b=>e.jsxs("div",{className:"bg-white/3 rounded-lg p-2.5 text-center",children:[e.jsx("p",{className:`text-lg font-bold ${b.color}`,children:b.value}),b.target>0&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["/",b.target]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:b.label})]},b.label))}),e.jsxs("div",{className:"flex items-center justify-between text-xs text-muted-foreground pt-1 border-t border-white/5",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(oe,{className:"w-3 h-3"})," ",n.memberCount," ",l.membersUnit]}),e.jsxs("span",{children:[n.salesCount," ",l.salesUnit]})]}),n.members.length>0&&e.jsxs("div",{className:"space-y-1.5 pt-1",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wider",children:l.topPerformers}),n.members.slice(0,3).map((b,C)=>e.jsxs("div",{className:"flex items-center justify-between bg-white/3 rounded-lg px-3 py-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-xs text-muted-foreground w-4",children:[C+1,"."]}),e.jsx("span",{className:"text-sm font-medium",children:b.name}),e.jsx("span",{className:"text-xs text-muted-foreground hidden sm:inline",children:Ue(b.role)})]}),e.jsx("span",{className:"text-xs font-semibold text-primary",children:D(b.revenue??0)})]}
7,b.userId))]})]})]},n.branchId))})]})}const pt=["sales_executive","marketing_executive","branch_sales_lead","tailor","cutting_operator","cutter","embroidery_operator","screen_printing_operator","branding_operator","cnc_operator","large_format_operator","qc_inspector","quality_control","driver","production_manager","inventory_manager","stores_keeper","accountant","senior_accountant","junior_accountant","customer_support","hr_officer","hr_manager","procurement_officer","legal_officer","security_officer","office_attendant","branch_manager"],ft=["admin","managing_director","general_manager","branch_manager"],bt=["admin","managing_director","general_manager"];function Rt(){const{user:a}=Oe(),t=a?.role==="production_manager",c=a?.role&&pt.includes(a.role),l=a?.role&&ft.includes(a.role),x=a?.role&&bt.includes(a.role),{data:g=[]}=F({queryKey:["/api/performance/production"],queryFn:()=>K("/api/performance/production"),enabled:!!l}),[u,m]=w.useState("monthly"),{data:f=[]}=F({queryKey:["/api/performance/sales",u],queryFn:()=>K("/api/performance/sales",{period:u}),enabled:!!l}),{t:k}=se(),v=k.performance,{toast:n}=Ee(),{tab:N,setTab:b,...C}=ze(["mine","branches","production","sales"],"production"),d=Ge({mutationFn:()=>{const o=localStorage.getItem("msg_auth_token");return fetch("/api/targets/recompute-rollups",{method:"POST",headers:{Authorization:`Bearer ${o}`,"Content-Type":"application/json"}}).then(i=>i.json())},onSuccess:o=>{n({title:"MD Rollup Targets Recomputed",description:`Types updated: ${o.recomputedTypes?.join(", ")||"none"}`,variant:"default"})},onError:()=>{n({title:"Recompute Failed",description:"Please try again.",variant:"destructive"})}});return t?e.jsx(Pe,{}):c&&!l&&a?e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-display font-bold text-foreground",children:v.title}),e.jsx("p",{className:"text-muted-foreground mt-1",children:v.subtitle})]}),e.jsx(Re,{userId:a.id,userRole:a.role})]}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-display font-bold text-foreground",children:v.title}),e.jsx("p",{className:"text-muted-foreground mt-1",children:v.subtitle})]}),x&&e.jsxs(ne,{variant:"outline",size:"sm",className:"shrink-0 border-white/10 text-muted-foreground hover:text-foreground",onClick:()=>d.mutate(),disabled:d.isPending,title:"Recompute MD/GM auto-rollup targets from individual staff targets",children:[d.isPending?e.jsx(st,{className:"w-3.5 h-3.5 animate-spin mr-1.5"}):e.jsx(rt,{className:"w-3.5 h-3.5 mr-1.5"}),"Recompute Rollups"]})]}),e.jsxs(Be,{value:N,onValueChange:b,...C,children:[e.jsxs(Ke,{className:"bg-card/50 border border-white/5",children:[a&&e.jsxs(H,{value:"mine",className:"flex items-center gap-1.5",children:[e.jsx(re,{className:"w-3.5 h-3.5"}),"My Performance"]}),e.jsxs(H,{value:"branches",className:"flex items-center gap-1.5",children:[e.jsx(ee,{className:"w-3.5 h-3.5"}),v.branchesTab]}),e.jsx(H,{value:"production",children:v.productionTab}),e.jsx(H,{value:"sales",children:v.salesTab})]}),a&&e.jsx(Q,{value:"mine",className:"mt-4",children:e.jsx(Re,{userId:a.id,userRole:a.role})}),e.jsx(Q,{value:"branches",className:"mt-4",children:e.jsx(gt,{})}),e.jsx(Q,{value:"production",className:"mt-4",children:e.jsx(Pe,{})}),e.jsxs(Q,{value:"sales",className:"mt-4 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-2",children:[e.jsxs("p",{className:"text-muted-foreground text-sm",children:["Sales team performance â ",De[u]]}),e.jsx("div",{className:"flex rounded-lg overflow-hidden border border-white/10",children:["daily","monthly","quarterly","annual"].map(o=>e.jsx("button",{onClick:()=>m(o),className:`px-4 py-2 text-sm font-medium transition-colors ${u===o?"bg-primary text-white":"bg-card/50 text-muted-foreground hover:text-foreground"}`,children:o==="daily"?"Today":o==="monthly"?"Monthly":o==="quarterly"?"Quarterly":"Annual"},o))})]}),e.jsxs(_,{className:"bg-card/50 border-white/5",children:[e.jsx(Y,{children:e.jsxs(X,{className:"text-base font-display flex items-center gap-2",children:[e.jsx(Le,{className:"w-4 h-4 text-muted-foreground"}),"Sales Team KPIs â ",De[u]]})}),e.jsx($,{children:e.jsxs(xe,{children:[e.jsx(ue,{children:e.jsxs(L,{className:"border-white/5 hover:bg-transparent",children:[e.jsx(y,{children:"Rank"}),e.jsx(y,{children:"Executive"}),e.jsx(y,{className:"text-center",children:"Leads"}),e.jsx(y,{className:"text-center",children:"Quotes"}),e.jsx(y,{className:"text-center",children:"Closed"}),e.jsx(y,{className:"text-right",children:"Revenue"}),e.jsx(y,{className:"text-right",children:"Win Rate"})]})}),e.jsx(he,{children:f.map(o=>e.jsxs(L,{className:"border-white/5",children:[e.jsx(j,{className:"font-mono",children:o.rank===1?"ð¥":o.rank===2?"ð¥":o.rank===3?"ð¥"
7:`#${o.rank}`}),e.jsx(j,{className:"font-medium",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(qe,{userId:o.userId,name:o.userName,avatar:o.avatar,size:"sm"}),e.jsx("span",{children:o.userName})]})}),e.jsx(j,{className:"text-center",children:o.leadsCreated}),e.jsx(j,{className:"text-center",children:o.quotationsSent}),e.jsx(j,{className:"text-center text-emerald-400 font-medium",children:o.ordersClosed}),e.jsx(j,{className:"text-right font-semibold text-primary",children:D(o.revenueGenerated)}),e.jsxs(j,{className:"text-right",children:[o.conversionRate.toFixed(1),"%"]})]},o.userId))})]})})]})]})]})]})}export{Rt 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.