PageSourceSearch

https://rolesynx.com/assets/LiveScoreCardPublic-zR-cH4I-.js

js rolesynx.com collected 2026-10-06 12:37:57 UTC 46,392 bytes, 1 lines download raw bytes

1import{a as as,j as e}from"./vendor-query-Bxlh8gey.js";import{f as os,a as c}from"./vendor-router-IDK_JTI1.js";import{q as rs,R as re}from"./index-Do82Yw9z.js";import{a as ye,D as ls,n as Ee,S as ns,c as is,d as cs,s as I,e as Se}from"./marketingSource-BIxPovlf.js";import{S as t,s as Ie,a as ds,b as Me,m as us,u as He,k as Fe,l as ze,c as ms,d as ps,e as xs,f as Ke,g as gs,L as me,h as je,P as qe,i as We,M as ke,C as Ne,j as Ye,E as Qe,A as Je,T as Xe,n as oe,o as Ge,p as hs,q as fs}from"./scorecardLeaderboardAggregators-B9fETv-N.js";import{u as bs}from"./use-tekmetric-metric-display-Bkexpdbm.js";import{A as te}from"./activity-CJVpPDGh.js";import{C as ys}from"./circle-alert-DTMGbmF2.js";import{P as vs}from"./play-BD-k7WBD.js";import{P as ws}from"./pause-CtZa1jQe.js";import{C as Ze}from"./chevron-down-PtIFI9Xo.js";import"./vendor-react-PQjUvtv3.js";import"./trophy-QkYlX_A5.js";import"./flame-LIqYbvs0.js";import"./arrow-up-down-BRpQSSY9.js";import"./arrow-up-BuCEK_lz.js";import"./avatar-Cspk9CC5.js";import"./smile-plus-BOK1XYi_.js";import"./send-DDlq7bhP.js";import"./tekmetricMetricDisplay-JmwkTPyw.js";class ee extends Error{constructor(r,p){super(r),this.status=p,this.name="ScorecardRequestError"}}function se({companyLogoUrl:s,companyName:r}){return e.jsxs("div",{className:"w-full px-4 py-2 flex items-center justify-between gap-3",style:{background:`linear-gradient(to right, ${t.pageBg}, ${t.rsx})`,borderBottom:`1px solid ${t.rsxBorder}`},children:[e.jsx("div",{className:"shrink-0 flex items-center min-w-0",children:s?e.jsx("img",{src:s,alt:r??"Company logo",className:"h-10 max-h-10 max-w-[180px] object-contain"}):e.jsx("span",{className:"font-semibold text-sm truncate max-w-[200px]",style:{color:t.heading},children:r??""})}),e.jsx("span",{className:"text-xs font-bold text-white whitespace-nowrap shrink-0",style:{opacity:.85},children:"Powered by RoleSynx"})]})}const pe=160;function Te({goal:s,trackingSales:r,trackingUnavailableLabel:p,height:y}){const f=typeof r=="number"&&Number.isFinite(r);return e.jsx("div",{className:"min-w-0 border-l",style:{borderColor:t.divider},children:e.jsx(me,{current:f?r:0,goal:s,height:y,width:pe,columnLabel:"Tracking Sales",variant:"tracking",unavailableLabel:f?void 0:p})})}function Cs({shops:s,expanded:r,onToggle:p,combinedGoal:y,metricGoals:f,sectionVisibility:v,display:b,activeView:l,goalPeriodLabel:R,headerTabs:j,openDows:x,holidayDates:g,combinedGamification:S,combinedMedianRo:h,ownerDefaultRingCount:i,marketingSourceSettings:w}){const O=s.every(n=>n.kpis==null),U=s.filter(n=>n.kpis==null),K=!O&&U.length>0,q=s.length-U.length,F=U.map(n=>n.shopName),m=ms(s,h),le=s.filter(n=>n.kpis!=null).map(n=>({shopId:n.shopId,kpis:n.kpis})),_=(()=>{const n=cs(f,le),P=f.combined??{};for(const[H,D]of Object.entries(P))typeof D=="number"&&D>0&&(n[H]=D);return n})(),X=(()=>{if(y<=0)return null;const n=s.filter(k=>k.kpis!=null);if(!n.length||n.length!==s.length)return null;if(l==="today"){if(!n.every(N=>N.todayOpenTime===n[0].todayOpenTime&&N.todayCloseTime===n[0].todayCloseTime&&(N.todayShopTimezone??"UTC")===(n[0].todayShopTimezone??"UTC"))||!n.every(N=>N.hourlySales))return null;const T={};for(const N of n)for(const[M,Z]of Object.entries(N.hourlySales))T[M]=(T[M]??0)+Z;let B=null;if(n.every(N=>N.approvedHourlySales)){B={};for(const N of n)for(const[M,Z]of Object.entries(N.approvedHourlySales))B[M]=(B[M]??0)+Z}return ps(T,n[0].todayOpenTime,n[0].todayCloseTime,n[0].todayShopNowMinutes,B)}if(!n.every(k=>k.dailySales))return null;const P={};for(const k of n)for(const[T,B]of Object.entries(k.dailySales))P[T]=(P[T]??0)+B;let H=null;if(n.every(k=>k.approvedDailySales)){H={};for(const k of n)for(const[T,B]of Object.entries(k.approvedDailySales))H[T]=(H[T]??0)+B}const D=l==="this_year"?xs(s):null,A=new Set;for(const k of n)for(const T of k.openDows??[])A.add(T);return Ke(l,{dailySales:P,hourlySales:null,approvedDailySales:H,approvedHourlySales:null,priorYearMonthlySales:D,shopTimezone:n[0].shopTimezone},A.size?Array.from(A).sort((k,T)=>k-T):x,g)})(),L=!I(l),W=gs(s),ne=!L&&W!=null,ae={approvedSales:m.approvedSales??void 0,trackingSales:L?null:W??void 0,postedSales:m.postedSales,gpDollars:m.grossProfit??0,carCount:m.carCount,aro:m.aro,medianRo:m.medianRo??void 0,awro:m.awro,closeRatio:m.closeRatio,gpPerHour:m.grossProfitPerHour,gpPercent:m.gpPercent,partsGpPercent:m.partsGrossProfitPercent,hoursPerCar:m.hoursPerCar,newCustomers:m.newCustomerCount,repeatCustomers:m.returnCustomerCount},$=(()=>
1{if(l!=="today"||O||y<=0)return null;const n=Math.min(100,m.postedSales/y*100);let P=null;if(s.length>0&&s.every(N=>N.todayOpenTime===s[0].todayOpenTime&&N.todayCloseTime===s[0].todayCloseTime&&(N.todayShopTimezone??"UTC")===(s[0].todayShopTimezone??"UTC"))&&s[0].todayOpenTime&&s[0].todayCloseTime&&s[0].todayShopNowMinutes!=null){const N=xe=>{const[z,ge]=xe.split(":").map(Number);return z*60+(ge??0)},M=N(s[0].todayOpenTime),V=N(s[0].todayCloseTime)-M;V>0&&(P=Math.min(100,Math.max(0,(s[0].todayShopNowMinutes-M)/V*100)))}else(s[0]?.businessDaysTotal??0)>0&&(P=Math.min(100,(s[0].businessDaysElapsed??0)/s[0].businessDaysTotal*100));if(P===null)return null;const D=n-P,A=D>=0?"#22c55e":D>=-10?"#f59e0b":"#ef4444",k=D>=0?"rgba(34,197,94,0.12)":D>=-10?"rgba(245,158,11,0.12)":"rgba(239,68,68,0.12)",T=D>=0?"rgba(34,197,94,0.35)":D>=-10?"rgba(245,158,11,0.35)":"rgba(239,68,68,0.35)",B=D>=0?"On track":D>=-10?"Slightly behind":"Behind";return{salesPct:n,elapsedPct:P,color:A,bg:k,border:T,label:B}})();return e.jsxs("div",{className:"w-full rounded-xl overflow-hidden",style:{background:t.cardBg,border:`2px solid ${t.rsxBorderHi}`,boxShadow:"0 4px 24px rgba(59,130,246,0.18), 0 2px 8px rgba(0,0,0,0.4)"},"data-testid":"shop-pillar-combined",children:[e.jsxs("div",{className:"w-full px-4 py-3 flex items-center justify-between gap-2",style:{borderBottom:`1px solid ${t.rsxBorder}`,background:"linear-gradient(90deg, rgba(59,130,246,0.22) 0%, rgba(37,99,235,0.14) 60%, rgba(30,64,175,0.10) 100%)"},children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1 flex-wrap",children:[j??e.jsxs("button",{onClick:p,className:"flex items-center gap-2 min-w-0 flex-1 text-left transition-colors","aria-expanded":r,"data-testid":"btn-expand-shop-combined",children:[e.jsx("span",{className:"font-semibold text-sm truncate",style:{color:t.heading},children:"Combined"}),e.jsxs("span",{className:"shrink-0 rounded-full text-[10px] font-semibold px-1.5 py-0.5 leading-none",style:{background:t.rsxDim,border:`1px solid ${t.rsxBorder}`,color:t.heading},children:[s.length," shops"]})]}),K&&e.jsxs("span",{className:"shrink-0 rounded-full text-[10px] font-semibold px-1.5 py-0.5 leading-none cursor-default",style:{background:"rgba(245,158,11,0.15)",color:t.gold,border:"1px solid rgba(245,158,11,0.3)"},"data-testid":"combined-partial-sync-badge",title:`${q}/${s.length} synced — pending: ${F.join(", ")}`,children:["⚠ ",q,"/",s.length," synced — ",F.join(", ")," pending"]})]}),$&&e.jsxs("span",{className:"shrink-0 hidden sm:inline-flex items-center rounded-full text-[10px] font-semibold px-2 py-0.5 leading-none whitespace-nowrap",style:{background:$.bg,color:$.color,border:`1px solid ${$.border}`},"data-testid":"combined-pace-chip",title:`${$.label}: ${Math.round($.salesPct)}% of goal with ${Math.round($.elapsedPct)}
1% of day elapsed`,children:[$.label," · ",Math.round($.salesPct),"% of goal with ",Math.round($.elapsedPct),"% of day elapsed"]}),e.jsx("button",{onClick:p,className:"transition-colors","aria-label":"Expand/collapse Combined pillar","aria-expanded":r,children:e.jsx(Ze,{className:`h-4 w-4 shrink-0 transition-transform duration-200 ${r?"rotate-180":""}`,style:{color:t.labelColor}})})]}),O?e.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 px-4 py-10",style:{color:t.labelColor},"data-testid":"shop-kpis-syncing-combined",children:[e.jsx(re,{className:"h-5 w-5 animate-spin"}),e.jsx("p",{className:"text-xs font-medium",children:"Syncing data…"}),e.jsx("p",{className:"text-[11px] text-center leading-snug",children:"All Locations KPIs will appear once the first sync completes."})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"px-4 py-4 w-full flex flex-col gap-1",style:{borderBottom:`1px solid ${t.divider}`},children:[e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-wide",style:{color:t.labelColor},children:"All Locations Revenue vs Goal"}),e.jsxs("div",{className:`flex items-center gap-3 w-full ${X?"flex-col md:flex-row":"justify-center"}`,children:[e.jsxs("div",{className:"flex w-full max-w-full min-w-0 flex-col items-center justify-center gap-3 sm:w-auto sm:shrink-0 sm:flex-row sm:gap-1",children:[e.jsxs("div",{className:"grid w-[320px] max-w-full grid-cols-2 items-stretch overflow-hidden rounded-lg border",style:{background:t.cardBgDeep,borderColor:t.divider},"data-testid":"scorecard-connected-thermometers",children:[e.jsx(me,{current:m.postedSales,goal:y,columnLabel:"Posted Sales",width:pe,daysTotal:s[0]?.businessDaysTotal,daysCurrent:s[0]?.businessDaysElapsed,openTime:l==="today"&&s.length>0&&s.every(n=>n.todayOpenTime===s[0].todayOpenTime&&n.todayCloseTime===s[0].todayCloseTime)?s[0].todayOpenTime:void 0,closeTime:l==="today"&&s.length>0&&s.every(n=>n.todayOpenTime===s[0].todayOpenTime&&n.todayCloseTime===s[0].todayCloseTime)?s[0].todayCloseTime:void 0,shopNowMinutes:l==="today"&&s.length>0&&s.every(n=>(n.todayShopTimezone??"UTC")===(s[0].todayShopTimezone??"UTC"))?s[0]?.todayShopNowMinutes:void 0}),e.jsx(Te,{goal:y,trackingSales:ne?W:null,height:330,trackingUnavailableLabel:L?"Not projected for this range":"Awaiting complete sync"})]}),e.jsx(je,{postedSales:m.postedSales,approvedSales:m.approvedSales,rolloverAmount:m.rolloverAmount,goal:y,layout:"column",trackingSales:ne?W:null,metricActuals:{...ae,gpDollars:m.grossProfit},metricGoals:_,customerMixVisible:v.customerMix??!0,gamification:S,ownerDefaultRingCount:i})]}),X&&e.jsx(qe,{buckets:X,goalTotal:y,currentLabel:We[l]??"Goal",testIdSuffix:"combined",showDayDeltas:!0,gamification:S,businessDaysTotal:L?void 0:s[0]?.businessDaysTotal,businessDaysElapsed:L?void 0:s[0]?.businessDaysElapsed})]})]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-5 gap-2 px-3 py-3",style:{borderTop:`1px solid ${t.divider}`},"data-testid":"combined-metric-goal-cards",children:[Se.filter(n=>n!=="trackingSales"||!L).map(n=>e.jsx(ke,{metricKey:n,actual:ae[n],goal:_[n],periodLabel:R},n)),(v.customerMix??!0)&&e.jsx(Ne,{newCount:m.newCustomerCount,repeatCount:m.returnCustomerCount,newGoal:_.newCustomers,repeatGoal:_.repeatCustomers})]}),e.jsx(Ye,{settings:w,sourceLists:s.map(n=>n.kpis?.marketingSources),testIdSuffix:"combined",activeView:l}),r&&(()=>{const n=Fe(s),P=ze(s);return e.jsxs(e.Fragment,{children:[e.jsx(Qe,{kpis:m,display:b,sectionVisibility:v}),(v.advisorLeaderboard??!0)&&n.length>0&&e.jsx(Je,{rows:n,shopId:"combined"}),(v.techLeaderboard??!0)&&P.length>0&&e.jsx(Xe,{rows:P,shopId:"combined",sectionVisibility:v})]})})()]})]})}function Oe({shop:s,expanded:r,onToggle:p,revenueGoal:y,sectionVisibility:f,display:v,activeView:b,goalPeriodLabel:l,headerTabs:R,openDows:j,holidayDates:x,metricGoals:g,ownerDefaultRingCount:S,marketingSourceSettings:h}){const i=s.kpis,w=s.shopName??`Shop ${s.shopId}`,O=s.periodGoal??y,U=O>0?Ke(b,s,s.openDows??j,x):null,K=!!U;return e.jsxs("div",{className:"w-full rounded-xl overflow-hidden",style:{background:t.cardBg,border:`1px solid ${t.rsxBorder}`,boxShadow:"0 4px 16px rgba(0,0,0,0.35), 0 1px 4px rgba(59,130,246,0.1)"},"data-testid":`shop-pillar-${s.shopId}`,children:[e.jsxs("div",{className:"w-full px-4 py-3 flex items-center justify-between gap-2",style:{borderBottom:`1px solid ${t.divider}`,background:t.cardBgDeep},children:[e.jsx("div",{className:"flex items-center gap-2 min-w-0 flex-1 flex-wrap",children:R??e.jsx("button",{onClick:p,className:"font-semibold text-sm truncate text-left flex-1 transition-colors",style:{color:t.heading},"aria-expanded":r,"data-testid":`btn-expand-shop-${s.shopId}`,children:w})}),e.jsx("button",{onClick:p,className:"transition-colors","aria-label":`Expand/collapse ${w} pillar`,"aria-expanded":r,children:e.jsx(Ze,{className:`h-4 w-4 shrink-0 transition-transform duration-200 ${r?"rotate-180":""}`,style:{color:t.labelColor}})})]}),i==null?e.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 px-4 py-10",style:{color:t.labelColor},"data-testid":`shop-kpis-syncing-${s.shopId}`,children:[e.jsx(re,{className:"h-5 w-5 animate-spin"}),e.jsx("p",{className:"text-xs font-medium",children:"Syncing data…"}),e.jsx("p",{className:"text-[11px] text-center leading-snug",children:"KPIs will appear once the first sync completes."})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"px-4 py-4 flex flex-col items-center gap-1",style:{borderBottom:`1px solid ${t.divider}`},children:[e.jsxs("p",{className:"text-[10px] font-medium uppercase tracking-wide",style:{color:t.labelColor},children:["Score Card - ",w]}),e.jsxs("div",{className:`flex items-center gap-2 w-full min-w-0 ${K?"flex-col md:flex-row":"justify-center"}`,children:[e.jsxs("div",{className:"flex w-full max-w-full min-w-0 flex-col items-center justify-center gap-3 sm:w-auto 
1sm:shrink-0 sm:flex-row sm:gap-1",children:[e.jsxs("div",{className:"grid w-[320px] max-w-full grid-cols-2 items-stretch overflow-hidden rounded-lg border",style:{background:t.cardBgDeep,borderColor:t.divider},"data-testid":`scorecard-connected-thermometers-${s.shopId}`,children:[e.jsx("div",{className:"flex flex-col items-center gap-1 min-w-0",children:e.jsx(me,{height:390,current:i.postedSales,goal:s.periodGoal??y,columnLabel:"Posted Sales",width:pe,daysTotal:s.businessDaysTotal,daysCurrent:s.businessDaysElapsed,openTime:b==="today"?s.todayOpenTime:void 0,closeTime:b==="today"?s.todayCloseTime:void 0,shopNowMinutes:b==="today"?s.todayShopNowMinutes:void 0})}),e.jsx(Te,{goal:s.periodGoal??y,height:390,trackingSales:I(b)?s.trackingSales??null:null,trackingUnavailableLabel:I(b)?"Awaiting complete sync":"Not projected for this range"})]}),e.jsx(je,{postedSales:i.postedSales,approvedSales:i.approvedSales,rolloverAmount:i.rolloverAmount,goal:s.periodGoal??y,layout:"column",gamification:s.gamification,teamBonus:s.teamBonus,ownerDefaultRingCount:S,trackingSales:I(b)?s.trackingSales??null:null,metricActuals:{approvedSales:i.approvedSales??void 0,trackingSales:I(b)?s.trackingSales??void 0:null,postedSales:i.postedSales,gpDollars:i.grossProfit,carCount:i.carCount,aro:i.aro,medianRo:i.medianRo??void 0,awro:i.awro,closeRatio:i.closeRatio,gpPerHour:i.grossProfitPerHour,gpPercent:i.gpPercent,partsGpPercent:i.partsGrossProfitPercent,hoursPerCar:i.hoursPerCar,newCustomers:i.newCustomerCount,repeatCustomers:i.returnCustomerCount},metricGoals:g,customerMixVisible:f.customerMix??!0})]}),K&&e.jsx(qe,{buckets:U,goalTotal:O,currentLabel:We[b]??"Goal",testIdSuffix:`shop-${s.shopId}`,gamification:s.gamification,businessDaysTotal:I(b)?s.businessDaysTotal:void 0,businessDaysElapsed:I(b)?s.businessDaysElapsed:void 0})]})]}),(()=>{const q=!I(b),F={approvedSales:i.approvedSales,trackingSales:q?null:s.trackingSales??void 0,postedSales:i.postedSales,gpDollars:i.grossProfit??0,carCount:i.carCount,aro:i.aro,medianRo:i.medianRo??void 0,awro:i.awro,closeRatio:i.closeRatio,gpPerHour:i.grossProfitPerHour,gpPercent:i.gpPercent,partsGpPercent:i.partsGrossProfitPercent,hoursPerCar:i.hoursPerCar,newCustomers:i.newCustomerCount,repeatCustomers:i.returnCustomerCount};return e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-5 gap-2 px-3 py-3",style:{borderTop:`1px solid ${t.divider}`},"data-testid":`shop-metric-goal-cards-${s.shopId}`,children:[Se.filter(m=>m!=="trackingSales"||!q).map(m=>e.jsx(ke,{metricKey:m,actual:F[m],goal:g[m],periodLabel:l},m)),(f.customerMix??!0)&&e.jsx(Ne,{newCount:i.newCustomerCount,repeatCount:i.returnCustomerCount,newGoal:g.newCustomers,repeatGoal:g.repeatCustomers})]})})(),e.jsx(Ye,{settings:h,sourceLists:[s.kpis?.marketingSources],testIdSuffix:`shop-${s.shopId}`,activeView:b}),r&&e.jsxs(e.Fragment,{children:[e.jsx(Qe,{kpis:i,display:v,sectionVisibility:f}),(f.advisorLeaderboard??!0)&&s.advisorRows.length>0&&e.jsx(Je,{rows:s.advisorRows,shopId:s.shopId}),(f.techLeaderboard??!0)&&(s.technicianRows?.length??0)>0&&e.jsx(Xe,{rows:s.technicianRows,shopId:s.shopId,sectionVisibility:f})]})]})]})}function Ss({shop:s,revenueGoal:r,activeView:p,goalPeriodLabel:y,metricGoals:f,sectionVisibility:v,ownerDefaultRingCount:b}){const l=s.kpis,R=s.shopName??`Shop ${s.shopId}`,j=s.periodGoal??r,x=s.lastSyncedAt?new Date(s.lastSyncedAt).toLocaleTimeString():null;return e.jsxs("div",{className:"w-full rounded-xl overflow-hidden flex flex-col",style:{background:t.cardBg,border:`1px solid ${t.rsxBorder}`,boxShadow:"0 4px 16px rgba(0,0,0,0.35), 0 1px 4px rgba(59,130,246,0.1)"},"data-testid":`comparison-column-${s.shopId}`,children:[e.jsxs("div",{className:"w-full px-4 py-3 flex flex-col gap-0.5",style:{borderBottom:`1px solid ${t.divider}`,background:t.cardBgDeep},children:[e.jsx("span",{className:"font-semibold text-sm truncate",style:{color:t.heading},children:R}),x&&e.jsxs("span",{className:"text-[10px] tabular-nums",style:{color:t.labelColor},children:["Synced ",x]})]}),l==null?e.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 px-4 py-10",style:{color:t.labelColor},"data-testid":`comparison-syncing-${s.shopId}`,children:[e.jsx(re,{className:"h-5 w-5 animate-spin"}),e.jsx("p",{className:"text-xs font-medium",children:"Syncing data…"}),e.jsx("p",{className:"text-[11px] text-center leading-snug",children:"KPIs will appear once the first sync completes."})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"px-3 py-4",style:{borderBottom:`1px solid ${t.divider}`},children:e.jsxs("div",{className:"grid w-[320px] max-w-full grid-cols-2 items-stretch overflow-hidden rounded-lg border",style:{background:t.cardBgDeep,borderColor:t.divider},"data-testid":`scorecard-connected-thermometers-comparison-${s.shopId}`,children:[e.jsx(me,{current:l.postedSales,goal:j,columnLabel:"Posted Sales",width:pe,daysTotal:s.businessDaysTotal,daysCurrent:s.businessDaysElapsed,openTime:p==="today"?s.todayOpenTime:void 0,closeTime:p==="today"?s.todayCloseTime:void 0,shopNowMinutes:p==="today"?s.todayShopNowMinutes:void 0}),e.jsx(Te,{goal:j,height:330,trackingSales:I(p)?s.trackingSales??null:null,trackingUnavailableLabel:I(p)?"Awaiting complete sync":"Not projected for this range"})]})}),e.jsx("div",{className:"px-3 py-3",style:{borderBottom:`1px solid ${t.divider}`},children:e.jsx(je,{postedSales:l.postedSales,approvedSales:l.approvedSales,rolloverAmount:l.rolloverAmount,goal:j,layout:"row",gamification:s.gamification,teamBonus:s.teamBonus,ownerDefaultRingCount:b,trackingSales:I(p)?s.trackingSales??null:null,metricActuals:{approvedSales:l.approvedSales??void 0,trackingSales:I(p)?s.trackingSales??void 0:null,postedSales:l.postedSales,gpDollars:l.grossProfit,carCount:l.carCount,aro:l.aro,medianRo:l.medianRo??void 0,awro:l.awro,closeRatio:l.closeRatio,gpPerHour:l.grossProfitPerHour,gpPercent:l.gpPercent,partsGpPercent:l.partsGrossProfitPercent,hoursPerCar:l.hoursPerCar,newCustomers:l.newCustomerCount,repeatCustomers:l.returnCustomerCount},metricGoals:f,customerMixVisible:v.customerMix??!0})}),(()=>{const g=!I(p),S={approvedSales:l.approvedSales??void 0,trackingSales:g?null:s.trackingSales??void 0,postedSales:l.postedSales,gpDollars:l.grossProfit??0,carCount:l.carCount,aro:l.aro,medianRo:l.medianRo??void 0,awro:l.awro,closeRatio:l.closeRatio,gpPerHour:l.grossProfitPerHour,gpPercent:l.gpPercent,partsGpPercent:l.partsGrossProfitPercent,hoursPerCar:l.hoursPerCar,newCustomers:l.newCustomerCount,repeatCustomers:l.returnCustomerCount};return e.jsxs("div",{className:"grid grid-cols-2 gap-2 px-3 py-3","data-testid":`comparison-metric-goal-cards-${s.shopId}`,children:[Se.filter(h=>h!=="trackingSales"||!g).map(h=>e.jsx(ke,{metricKey:h,actual:S[h],goal:f[h],periodLabel:y},h)),(v.customerMix??!0)&&e.jsx(Ne,{newCount:l.newCustomerCount,repeatCount:l.returnCustomerCount,newGoal:f.newCustomers,repeatGoal:f.repeatCustomers})]})})()]})]})}function js({shops:s,revenueGoal:r,metricGoalsByShop:p,sectionVisibility:y,activeView:f,goalPeriodLabel:v,ownerDefaultRingCount:b}){const[l,R]=c.useState(new Set),j=h=>R(i=>{const w=new Set(i);return w.has(h)?w.delete(h):w.add(h),w});if(s.length===0)return e.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-16",style:{color:t.labelColor},"data-testid":"comparison-empty",children:[e.jsx(te,{className:"h-8 w-8"}),e.jsx("p",{className:"text-sm font-medium",children:"No shops connected"}),e.jsx("p",{className:"text-xs",children:"Connect a location to compare shops side by side."})]});const x=new Set(s.map(h=>String(h.shopId))),g=new Set([...l].filter(h=>x.has(h))),S=s.filter(h=>!g.has(String(h.shopId)));return e.jsxs("div",{"data-testid":"comparison-view",children:[s.length>1&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-4","data-testid":"compare-location-filter",children:[e.jsx("span",{className:"text-[11px] uppercase tracking-wider font-medium shrink-0",style:{color:t.labelColor},children:"Locations:"}),s.map(h=>{const i=String(h.shopId),w=!g.has(i);return e.jsx("button",{onClick:()=>j(i),"data-testid":`compare-shop-filter-${i}`,"aria-pressed":w,className:"px-3 py-1 rounded-full text-[11px] font-semibold transition-colors whitespace-nowrap",style:w?{background:t.rsx,color:"#fff"}:{background:t.cardBg,color:t.labelColor,border:`1px solid ${t.rsxBorder}`}
1,children:h.shopName??`Shop ${h.shopId}`},i)}),g.size>0&&e.jsx("button",{onClick:()=>R(new Set),"data-testid":"compare-show-all-locations",className:"px-3 py-1 rounded-full text-[11px] font-medium transition-colors whitespace-nowrap",style:{color:t.rsx,border:`1px solid ${t.rsx}`},children:"Show all"})]}),S.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-16",style:{color:t.labelColor},"data-testid":"comparison-all-hidden",children:[e.jsx(te,{className:"h-8 w-8"}),e.jsx("p",{className:"text-sm font-medium",children:"All locations hidden"}),e.jsx("p",{className:"text-xs",children:"Tap a location above to show it."})]}):e.jsx("div",{className:"grid gap-4",style:{gridTemplateColumns:"repeat(auto-fit, minmax(260px, 1fr))"},"data-testid":"comparison-columns",children:S.map(h=>e.jsx(Ss,{shop:h,revenueGoal:h.revenueGoal??r,activeView:f,goalPeriodLabel:v,metricGoals:p[String(h.shopId)]??{},sectionVisibility:y,ownerDefaultRingCount:b},h.shopId))})]})}const ks={today:"Today",this_week:"This Week",last_week:"Last Week",mtd:"This Month",this_year:"This Year"},_e="(min-width: 1024px) and (orientation: landscape)",ve=16;function Ns(s,r){if(r.terminalError||r.blocked)return;if(s)return s;const p=r.retained;if(p&&r.isError&&p.token===r.token)return p.data}function Vs(){const r=os().token,[p,y]=c.useState(void 0),[f,v]=c.useState(()=>{try{return new URLSearchParams(window.location.search).get("compare")==="1"}catch{return!1}}),[b,l]=c.useState(new Set),[R,j]=c.useState(!1),[x,g]=c.useState(Ps),[S,h]=c.useState("combined"),[i]=c.useState(()=>{try{const a=new URLSearchParams(window.location.search).get("rotate"),d=a?parseInt(a,10):NaN;return Number.isFinite(d)&&d>0?d:null}catch{return null}}),[w,O]=c.useState(!1),U=bs(),K=c.useRef(null),q=c.useRef(!1),F=c.useRef(void 0),[m,le]=c.useState(()=>{try{const a=new URLSearchParams(window.location.search).get("unlock");return a||(r?localStorage.getItem(Ce(r)):null)}catch{return null}}),[_,X]=c.useState([]),L=r?`scorecard_sales_rail_${r}`:null,W=c.useCallback(a=>{try{return a?localStorage.getItem(a)!=="0":!0}catch{return!0}},[]),[ne,ae]=c.useState(()=>W(L)),[$,n]=c.useState(!1),P=c.useCallback(()=>{n(!0),ae(a=>{const d=!a;try{L&&localStorage.setItem(L,d?"1":"0")}catch{}return d})},[L]);c.useEffect(()=>{ae(W(L)),n(!1)},[L,W]);const[H,D]=c.useState(()=>{try{return window.matchMedia?.(_e).matches??!1}catch{return!1}});c.useEffect(()=>{if(typeof window.matchMedia!="function")return;const a=window.matchMedia(_e),d=()=>D(a.matches);return d(),a.addEventListener("change",d),()=>a.removeEventListener("change",d)},[]);const A=ne&&H,k=c.useRef(null),T=c.useRef(null),[B,N]=c.useState(0);c.useEffect(()=>{if(!A){N(0);return}const a=()=>{const u=k.current;if(!u)return;const G=document.documentElement.clientWidth-u.getBoundingClientRect().left+ve;N(Math.max(0,Math.round(G)))};a();const d=new ResizeObserver(a);return k.current&&d.observe(k.current),window.addEventListener("resize",a),()=>{d.disconnect(),window.removeEventListener("resize",a)}},[A]),c.useEffect(()=>{$&&n(!1)},[A]);const[M,Z]=c.useState(0),V=c.useRef(null),xe=c.useCallback(a=>
1{if(V.current?.disconnect(),V.current=null,!a)return;const d=()=>Z(a.getBoundingClientRect().height);if(d(),typeof ResizeObserver<"u"){const u=new ResizeObserver(d);u.observe(a),V.current=u}},[]);c.useEffect(()=>{if(!A)return;let a=0;const d=()=>{a=0;const G=k.current;if(!G)return;const E=T.current,ue=E?.firstElementChild??E,Y=M+ve,be=ue?Math.max(Y,Math.round(ue.getBoundingClientRect().top)):Y;G.style.top=`${be}px`},u=()=>{a||(a=requestAnimationFrame(d))};d(),window.addEventListener("scroll",u,{passive:!0}),window.addEventListener("resize",u);const C=new ResizeObserver(u);return T.current&&C.observe(T.current),()=>{a&&cancelAnimationFrame(a),window.removeEventListener("scroll",u),window.removeEventListener("resize",u),C.disconnect()}},[A,M]);const{data:z,isLoading:ge,isError:Ve,error:ie,refetch:es,isFetching:Re,isPlaceholderData:ss,dataUpdatedAt:Pe}=as({queryKey:[`/api/live-scorecard/${r}/data`,p??"default",m??"none"],queryFn:async()=>{const a=new URLSearchParams;p&&a.set("view",p),m&&a.set("unlock",m);const d=a.toString(),u=`/api/live-scorecard/${r}/data${d?`?${d}`:""}`,C=await fetch(u);if(C.status===404)throw new ee("Scorecard not found",404);if(C.status===403){const E=(await C.json().catch(()=>null))?.accessState;if(E==="disabled"||E==="code_required")return{blocked:E};throw new ee("Failed to load scorecard",C.status)}if(!C.ok)throw new ee("Failed to load scorecard",C.status);return C.json()},retry:(a,d)=>!(d instanceof ee&&d.status===404)&&a<2,retryDelay:a=>Math.min(1e3*2**a,4e3),placeholderData:()=>F.current?.token===r?F.current.data:void 0,refetchInterval:a=>{const u=a.state.data?.shops??[];return!(u.length>0&&u.every(E=>E.kpis==null))&&u.some(E=>E.kpis==null)?15e3:6e4},staleTime:55e3,enabled:!!r}),Q=z&&typeof z=="object"&&"blocked"in z?z.blocked:null,he=z&&!("blocked"in z)?z:void 0;he&&r&&!ss&&(F.current={token:r,data:he});const o=Ns(he,{isError:Ve,terminalError:ie instanceof ee&&ie.status===404,blocked:!!Q,token:r,retained:F.current});c.useEffect(()=>{if(Q==="code_required"&&m&&r){try{localStorage.removeItem(Ce(r))}catch{}le(null)}},[Q,m,r]);const ts=c.useCallback(a=>
1{if(r)try{localStorage.setItem(Ce(r),a)}catch{}le(a)},[r]);c.useEffect(()=>{q.current||o?.activeView&&ye.includes(o.activeView)&&(q.current=!0,y(o.activeView))},[o]),c.useEffect(()=>{!o||S==="combined"||o.shops.some(a=>String(a.shopId)===S)||h("combined")},[o,S]);const De=c.useCallback(a=>{h(a),i&&O(!0)},[i]),fe=c.useCallback(()=>{rs.invalidateQueries({predicate:a=>Array.isArray(a.queryKey)&&typeof a.queryKey[0]=="string"&&a.queryKey[0].startsWith(`/api/live-scorecard/${r}/`)})},[r]);c.useEffect(()=>{if(!r||Q)return;const d=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/ws?role=scorecard&token=${encodeURIComponent(r)}${m?`&unlock=${encodeURIComponent(m)}`:""}`;let u,C=null,G=!1;function E(){if(!G){try{u=new WebSocket(d)}catch{return}K.current=u,u.onmessage=ue=>{try{const Y=JSON.parse(ue.data);Y?.type==="live-scorecard-refresh"?fe():Y?.type==="live-scorecard-celebration"&&X(be=>[...be,{advisorName:String(Y.advisorName??""),amountCents:Number(Y.amountCents??0),kpiKey:Y.kpiKey??"sales"}])}catch{}},u.onclose=()=>{G||(C=setTimeout(E,5e3))},u.onerror=()=>{try{u.close()}catch{}}}}return E(),()=>{G=!0,C&&clearTimeout(C);try{K.current?.close()}catch{}K.current=null}},[r,fe,Q,m]),c.useEffect(()=>{if(!i||w||!o?.shops||o.shops.length<=1)return;const a=["combined",...o.shops.map(u=>String(u.shopId))],d=setInterval(()=>{h(u=>{const C=a.indexOf(u);return a[(C+1)%a.length]??"combined"})},i*1e3);return()=>clearInterval(d)},[i,w,o?.shops?.length]);const $e=a=>{l(d=>{const u=new Set(d);return u.has(a)?u.delete(a):u.add(a),u})},Le=c.useCallback(a=>{v(a);try{const d=new URL(window.location.href);a?d.searchParams.set("compare","1"):d.searchParams.delete("compare"),window.history.replaceState(null,"",d.toString())}catch{}},[]),Ae=Pe?new Date(Pe).toLocaleTimeString():null;if(Q==="disabled")return e.jsxs("div",{className:"min-h-screen flex flex-col",style:{background:t.pageBg},"data-testid":"scorecard-page",children:[e.jsx(se,{}),e.jsx("div",{className:"flex flex-1 items-center justify-center",children:e.jsxs("div",{className:"text-center space-y-2 px-4","data-testid":"scorecard-access-disabled",children:[e.jsx(te,{className:"h-10 w-10 mx-auto",style:{color:t.labelColor}}),e.jsx("h2",{className:"font-semibold",style:{color:t.heading},children:"This scorecard isn't available"}),e.jsx("p",{className:"text-sm",style:{color:t.labelColor},children:"The shop owner has turned off public access to this Live Score Card."})]})})]});if(Q==="code_required"&&r)return e.jsx(Ls,{token:r,onUnlocked:ts});if(ge&&!o)return e.jsxs("div",{className:"min-h-screen flex flex-col",style:{background:t.pageBg},"data-testid":"scorecard-page",children:[e.jsx(se,{}),e.jsx("div",{className:"flex flex-1 items-center justify-center",children:e.jsxs("div",{className:"flex items-center gap-2",style:{color:t.labelColor},"data-testid":"scorecard-loading",children:[e.jsx(re,{className:"h-5 w-5 animate-spin","data-testid":"scorecard-spinner"}),e.jsx("span",{children:"Loading scorecard…"})]})})]});if(!o){const a=ie instanceof ee&&ie.status===404;return e.jsxs("div",{className:"min-h-screen flex flex-col",style:{background:t.pageBg},"data-testid":"scorecard-page",children:[e.jsx(se,{}),e.jsx("div",{className:"flex flex-1 items-center justify-center",children:e.jsxs("div",{className:"text-center space-y-2",children:[e.jsx(ys,{className:"h-10 w-10 text-red-400 mx-auto"}),e.jsx("h2",{className:"font-semibold text-white",children:a?"Scorecard not found":"Couldn’t load scorecard"}),e.jsx("p",{className:"text-sm",style:{color:t.labelColor},children:a?"This link may be invalid or has been removed.":"The scorecard is temporarily unavailable. Check your connection and try again."}),!a&&e.jsx("button",{type:"button",onClick:()=>{es()},disabled:Re,className:"mt-3 inline-flex items-center justify-center rounded-md bg-blue-600 px-4 py-2 text-sm font-medium text-white hover:bg-blue-500 disabled:cursor-not-allowed disabled:opacity-60","data-testid":"button-retry-scorecard",children:Re?"Trying again…":"Try again"})]})})]})}if(!o.shops||o.shops.length===0){const a=o.hasConnection;return e.jsxs("div",{className:"min-h-screen flex flex-col",style:{...Ie(o.displayTheme),background:t.pageBg},"data-testid":"scorecard-page",children:[e.jsx(se,{companyLogoUrl:o.companyLogoUrl,companyName:o.companyName}),e.jsx("div",{className:"flex flex-1 items-center justify-center",children:e.jsxs("div",{className:"text-center space-y-2",children:[e.jsx(te,{className:"h-10 w-10 mx-auto",style:{color:t.labelColor}}),a?e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"font-semibold",style:{color:t.heading},children:"Data syncing…"}),e.jsx("p",{className:"text-sm",style:{color:t.labelColor},children:"Tekmetric is connected. Check back in a moment."})]}):e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"font-semibold",style:{color:t.heading},children:"Tekmetric not connected"}),e.jsx("p",{className:"text-sm",style:{color:t.labelColor},children:"The shop hasn't connected a Tekmetric account yet."})]})]})})]})}const ce=o.sectionVisibility??ls,Be=o.displayTheme??"light",J=ye.includes(o.activeView)?o.activeView:p??"mtd",de=Ee[o.activeView]??Ee[J];return e.jsx(ds.Provider,{value:Be,children:e.jsxs("div",{className:"min-h-screen",style:{...Ie(Be),background:t.pageBg,color:t.heading},"data-testid":"scorecard-public",children:[_[0]&&e.jsx(ns,{advisorName:_[0].advisorName,amountCents:_[0].amountCents,kpiKey:_[0].kpiKey,onDismiss:()=>X(a=>a.slice(1))},`${_[0].advisorName}-${_[0].amountCents}`),e.jsxs("header",{className:"sticky top-0 z-10",ref:xe,"data-testid":"scorecard-header",children:[e.jsx(se,{companyLogoUrl:o.companyLogoUrl,companyName:o.companyName}),e.jsx("div",{className:"px-4 py-3 backdrop-blur",style:{background:`color-mix(in srgb, ${t.pageBg} 95%, transparent)`,borderBottom:`1px solid ${t.rsxBorder}`},children:e.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-2.5 min-w-0",children:[e.jsx(te,{className:"h-4 w-4 shrink-0",style:{color:t.rsx}}),e.jsx("h1",{className:"font-semibold text-sm truncate",style:{color:t.heading},"data-testid":"scorecard-title",children:o.scorecardName}),o.shops.length>1&&e.jsxs("span",{className:"text-xs shrink-0",style:{color:t.labelColor},children:[o.shops.length," locations"]})]}),e.jsxs("div",{className:"flex items-center gap-1 rounded-lg p-1 max-w-full overflow-x-auto",style:{background:t.cardBgDeep},"data-testid":"view-tabs",children:[ye.map(a=>e.jsx("button",{onClick:()=>{y(a),f&&Le(!1)},"data-testid":`tab-view-${a}`,className:"px-3 py-1.5 rounded-md text-xs font-medium transition-colors whitespace-nowrap",style:!f&&J===a?{background:t.rsx,color:"#fff",boxShadow:"0 1px 4px rgba(0,0,0,0.3)"}:{color:t.labelColor},children:ks[a]??a},a)),e.jsx("button",{onClick:()=>Le(!f),"data-testid":"tab-view-compare",className:"px-3 py-1.5 rounded-md text-xs font-medium transition-colors whitespace-nowrap",style:f?{background:t.rsx,color:"#fff",boxShadow:"0 1px 4px rgba(0,0,0,0.3)"}:{color:t.labelColor},"aria-pressed":f,children:"Compare"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[Ae&&e.jsxs("p",{className:"text-xs hidden sm:block",style:{color:t.labelColor},"data-testid":"text-last-updated",children:["Updated ",Ae]}),e.jsx("button",{className:"h-7 w-7 flex items-center justify-center rounded-md transition-colors",style:{color:t.labelColor},onMouseEnter:a=>a.currentTarget.style.background=t.cardHover,onMouseLeave:a=>a.currentTarget.style.background="transparent",onClick:fe,"aria-label":"Refresh","data-testid":"button-refresh",children:e.jsx(re,{className:"h-3.5 w-3.5"})})]})]})})]}),e.jsxs("div",{style:B?{paddingRight:B}:void 0,"data-testid":"scorecard-content",children:[e.jsxs("div",{className:"mx-4 mt-4 flex flex-col lg:flex-row gap-4 items-stretch",children:[!A&&e.jsx("div",{className:"flex-1 min-w-0 lg:relative lg:min-h-[300px]","data-testid":"sales-board-column",children:e.jsx(Me,{token:r,unlock:m,leaders:o.salesLeaders,showRecords:!1,containerClassName:"rounded-2xl overflow-hidden lg:absolute lg:inset-0",onToggleRail:H?P:void 0,autoFocusToggle:$})}),e.jsx("div",{className:"flex-1 min-w-0 flex flex-col",ref:T,"data-testid":"leaderboard-column",children:e.jsx($s,{shops:o.shops,approvedAdvisors:o.approvedAdvisorRows??null,ownerDefaultColumns:o.defaultLeaderboardColumns,columns:x,setColumns:g})})]}),A&&e.jsx("div",{className:"flex fixed right-4 z-20 w-[380px] max-w-[34vw]",ref:k,style:{to
1p:M+ve,bottom:16},"data-testid":"sales-board-rail",children:e.jsx(Me,{token:r,unlock:m,leaders:o.salesLeaders,variant:"rail",showRecords:!1,containerClassName:"flex-1 min-w-0 rounded-2xl overflow-hidden",onToggleRail:P,autoFocusToggle:$})}),e.jsx(us,{leaders:o.salesLeaders,className:"mx-4 mt-4 grid grid-cols-1 sm:grid-cols-2 gap-3 rounded-2xl p-3",style:{background:t.cardBg,border:`1px solid ${t.rsxBorder}`}}),f?e.jsx("div",{className:"p-4",children:e.jsx(js,{shops:o.shops,revenueGoal:o.revenueGoal,metricGoalsByShop:o.metricGoals??{},sectionVisibility:ce,activeView:J,goalPeriodLabel:de,ownerDefaultRingCount:o.defaultRingCount})}):e.jsx("div",{className:"flex flex-col gap-4 p-4","data-testid":"pillars-container",children:o.shops.length>1?(()=>{const a=e.jsxs("div",{className:"flex items-center gap-1 flex-wrap min-w-0","data-testid":"location-tabs",children:[e.jsx("button",{onClick:()=>De("combined"),"data-testid":"location-tab-combined",className:"px-3 py-1.5 rounded-md text-xs font-medium transition-colors whitespace-nowrap",style:S==="combined"?{background:t.rsx,color:"#fff",boxShadow:"0 1px 4px rgba(0,0,0,0.3)"}:{color:t.labelColor},"aria-pressed":S==="combined",children:"Combined"},"combined"),o.shops.map(u=>{const C=String(u.shopId),G=u.shopName??`Shop ${u.shopId}`;return e.jsx("button",{onClick:()=>De(C),"data-testid":`location-tab-${C}`,className:"px-3 py-1.5 rounded-md text-xs font-medium transition-colors whitespace-nowrap",style:S===C?{background:t.rsx,color:"#fff",boxShadow:"0 1px 4px rgba(0,0,0,0.3)"}:{color:t.labelColor},"aria-pressed":S===C,children:G},C)}),i&&e.jsx("button",{onClick:()=>O(u=>!u),"data-testid":"rotate-toggle","aria-label":w?"Resume auto-rotation":"Pause auto-rotation",title:w?`Auto-rotate paused — click to resume (${i}s interval)`:`Auto-rotating every ${i}s — click to pause`,className:"ml-1 h-6 w-6 flex items-center justify-center rounded-md transition-colors shrink-0",style:{color:w?t.labelColor:t.rsx,background:w?"transparent":"rgba(59,130,246,0.12)",border:`1px solid ${w?t.rsxBorder:t.rsx}`},children:w?e.jsx(vs,{className:"h-3 w-3"}):e.jsx(ws,{className:"h-3 w-3"})})]});if(S==="combined")return e.jsx(Cs,{shops:o.shops,expanded:R,onToggle:()=>j(u=>!u),combinedGoal:is(o.yearlyGoal,J),metricGoals:o.metricGoals??{}
1,sectionVisibility:ce,display:U,activeView:J,goalPeriodLabel:de,headerTabs:a,openDows:o.openDows,holidayDates:o.holidayDates,combinedGamification:o.combinedGamification,combinedMedianRo:o.combinedMedianRo??null,ownerDefaultRingCount:o.defaultRingCount,marketingSourceSettings:o.marketingSourceSettings});const d=o.shops.find(u=>String(u.shopId)===S);return d?e.jsx(Oe,{shop:d,expanded:b.has(d.shopId),onToggle:()=>$e(d.shopId),revenueGoal:d.revenueGoal??o.revenueGoal,sectionVisibility:ce,display:U,activeView:J,goalPeriodLabel:de,headerTabs:a,openDows:o.openDows,holidayDates:o.holidayDates,metricGoals:(o.metricGoals??{})[String(d.shopId)]??{},ownerDefaultRingCount:o.defaultRingCount,marketingSourceSettings:o.marketingSourceSettings},d.shopId):null})():o.shops.map(a=>e.jsx(Oe,{shop:a,expanded:b.has(a.shopId),onToggle:()=>$e(a.shopId),revenueGoal:a.revenueGoal??o.revenueGoal,sectionVisibility:ce,display:U,activeView:J,goalPeriodLabel:de,openDows:o.openDows,holidayDates:o.holidayDates,metricGoals:(o.metricGoals??{})[String(a.shopId)]??{},ownerDefaultRingCount:o.defaultRingCount,marketingSourceSettings:o.marketingSourceSettings},a.shopId))}),(o.shops[0]?.startDate||o.shops[0]?.endDate)&&e.jsx("p",{className:"text-center text-xs pb-3 -mt-1",style:{color:t.labelColor},children:o.shops[0].startDate&&o.shops[0].endDate?`${o.shops[0].startDate} – ${o.shops[0].endDate}`:o.shops[0].startDate??o.shops[0].endDate})]})]})})}const Ts={0:"🥇",1:"🥈",2:"🥉"},Rs={0:"#f59e0b",1:"#94a3b8",2:"#b45309"},we={advisorSales:{label:"Advisor Sales",source:"advisor",value:s=>s.sales,format:oe},advisorApprovedSales:{label:"Advisor Approved Sales",source:"approvedAdvisor",value:()=>null,format:oe},advisorGp:{label:"Advisor GP$",source:"advisor",value:s=>s.grossProfit??null,format:oe},advisorGpph:{label:"Advisor GP/HR",source:"advisor",value:s=>s.gpph||null,format:Ge},advisorAro:{label:"Advisor ARO",source:"advisor",value:s=>s.averageRepairOrder||null,format:oe},advisorCloseRatio:{label:"Advisor Close Ratio",source:"advisor",value:s=>s.closeRatio||null,format:fs},advisorCars:{label:"Advisor Cars",source:"advisor",value:s=>s.roCount,format:s=>String(Math.round(s))},techHours:{label:"Technician Hours",source:"tech",value:s=>s.billedHours??null,format:hs},techCars:{label:"Technician Cars",source:"tech",value:s=>s.roCount,format:s=>String(Math.round(s))},techGpph:{label:"Technician GP/HR",source:"tech",value:s=>s.gpph||null,format:Ge},techGp:{label:"GP$/Tech",source:"tech",value:s=>s.grossProfit??null,format:oe}},Ps=["advisorSales","techHours","advisorGpph","techCars"];function Ds({boardKey:s,columnIndex:r,onChangeBoard:p,advisors:y,approvedAdvisors:f,techs:v}){const b=He(),l=we[s],R=l.source==="approvedAdvisor"&&f==null,j=(l.source==="approvedAdvisor"?(f??[]).map(x=>({id:x.advisorKey,name:x.name,value:x.approvedSales})):(l.source==="advisor"?y:v).map(x=>({id:x.employeeId,name:x.name,value:l.value(x)}))).filter(x=>x.value!=null&&x.value>0).sort((x,g)=>g.value-x.value).slice(0,5);return e.jsxs("div",{className:"sm:odd:border-r lg:border-r lg:last:border-r-0",style:{borderColor:t.divider},"data-testid":`leaderboard-column-${r}`,children:[e.jsx("div",{className:"px-3 py-2",style:{borderBottom:`1px solid ${t.divider}`},children:e.jsx("select",{value:s,onChange:x=>p(x.target.value),className:"w-full rounded-md px-2 py-1.5 text-[11px] font-semibold uppercase tracking-wider cursor-pointer focus:outline-none",style:{background:t.sectionBg,color:t.valueColor,border:`1px solid ${t.rsxBorder}`,colorScheme:b==="light"?"light":"dark"},"data-testid":`select-leaderboard-${r}`,children:Object.keys(we).map(x=>e.jsx("option",{value:x,style:{backgroundColor:t.cardBg,color:t.valueColor},children:we[x].label},x))})}),R?e.jsx("p",{className:"px-4 py-4 text-xs",style:{color:t.labelColor},"data-testid":`leaderboard-unavailable-${r}`,children:"Approved Sales ranking unavailable."}):j.length===0?e.jsx("p",{className:"px-4 py-4 text-xs",style:{color:t.labelColor},children:l.source==="approvedAdvisor"?"No approved sales in this period.":"No data yet."}):e.jsx("div",{children:j.map((x,g)=>e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5","data-testid":`leaderboard-row-${r}-${g}`,style:{borderBottom:g<j.length-1?`1px solid ${t.divider}`:void 0,background:g===0?t.goldBg:"transparent",borderLeft:g===0?`3px solid ${t.gold}`:"3px solid transparent"},children:[e.jsx("span",{className:"text-base w-5 shrink-0 text-center leading-none",children:g<3?Ts[g]:e.jsx("span",{className:"text-xs font-bold tabular-nums",style:{color:Rs[g]??t.labelColor},children:g+1})}),e.jsx("span",{className:"flex-1 text-sm font-medium truncate",style:{color:t.valueColor},children:x.name}),e.jsx("span",{className:"text-sm font-semibold tabular-nums shrink-0",style:{color:g===0?t.gold:t.valueColor},children:l.format(x.value)})]},x.id))})]})}const Ue={1:"grid grid-cols-1",2:"grid grid-cols-1 sm:grid-cols-2",3:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3",4:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4"};function $s({shops:s,approvedAdvisors:r,ownerDefaultColumns:p,columns:y,setColumns:f}){const v=He(),b=Fe(s),l=ze(s),[R,j]=c.useState(p??4),x=c.useRef(!1);return c.useEffect(()=>{x.current||j(p??4)},[p]),!b.length&&!l.length&&r==null?null:e.jsxs("div",{className:"rounded-2xl overflow-hidden h-full",style:{background:t.cardBg,border:`1px solid ${t.rsxBorder}`},"data-testid":"combined-leaderboard",children:[e.jsxs("div",{className:"px-5 py-3 flex items-center gap-2",style:{background:t.sectionBg,borderBottom:`1px solid ${t.rsxBorder}`},children:[e.jsx("span",{className:"text-sm font-semibold uppercase tracking-widest",style:{color:t.valueColor},children:"Leaderboard"}),e.jsx("select",{value:R,onChange:g=>{x.current=!0,j(Number(g.target.value))},className:"ml-auto rounded-md px-2 py-1 text-[11px] font-semibold uppercase tracking-wider cursor-pointer focus:outline-none",style:{background:t.cardBg,color:t.valueColor,border:`1px solid ${t.rsxBorder}`,colorScheme:v==="light"?"light":"dark"},"data-testid":"select-leaderboard-column-count",children:[1,2,3,4].map(g=>e.jsxs("option",{value:g,style:{backgroundColor:t.cardBg,color:t.valueColor},children:[g," ",g===1?"column":"columns"]},g))})]}),e.jsx("div",{className:Ue[R]??Ue[4],"data-testid":"leaderboard-grid",children:y.slice(0,R).map((g,S)=>e.jsx(Ds,{boardKey:g,columnIndex:S,onChangeBoard:h=>f(i=>i.map((w,O)=>O===S?h:w)),advisors:b,approvedAdvisors:r,techs:l},S))})]})}function Ls({token:s,onUnlocked:r}){const[p,y]=c.useState(""),[f,v]=c.useState(null),[b,l]=c.useState(!1),R=async j=>{if(j.preventDefault(),!/^\d{4}$/.test(p)){v("Enter the 4-digit code.");return}l(!0),v(null);
1try{const x=await fetch(`/api/live-scorecard/${s}/verify-code`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:p})});if(x.ok){const g=await x.json();if(typeof g?.unlock=="string"&&g.unlock){r(g.unlock);return}v("Something went wrong. Please try again.")}else x.status===429?v("Too many attempts. Please wait a few minutes and try again."):v("Incorrect code. Please try again.");y("")}catch{v("Something went wrong. Please try again.")}finally{l(!1)}};return e.jsxs("div",{className:"min-h-screen flex flex-col",style:{background:t.pageBg},"data-testid":"scorecard-page",children:[e.jsx(se,{}),e.jsx("div",{className:"flex flex-1 items-center justify-center px-4",children:e.jsxs("form",{onSubmit:R,className:"text-center space-y-4 w-full max-w-xs","data-testid":"scorecard-code-gate",children:[e.jsx(te,{className:"h-10 w-10 mx-auto",style:{color:t.labelColor}}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{className:"font-semibold",style:{color:t.heading},children:"Enter access code"}),e.jsx("p",{className:"text-sm",style:{color:t.labelColor},children:"This scorecard is protected by a 4-digit code. Ask the shop owner for it."})]}),e.jsx("input",{value:p,onChange:j=>y(j.target.value.replace(/\D/g,"").slice(0,4)),inputMode:"numeric",autoComplete:"one-time-code",autoFocus:!0,maxLength:4,placeholder:"••••","aria-label":"4-digit access code",className:"w-40 mx-auto block rounded-lg border px-4 py-3 text-center text-2xl tracking-[0.5em] focus:outline-none focus:ring-2",style:{borderColor:t.divider,background:t.cardBg,color:t.valueColor},"data-testid":"input-scorecard-access-code"}),f&&e.jsx("p",{className:"text-sm text-red-400","data-testid":"text-code-error",children:f}),e.jsx("button",{type:"submit",disabled:b||p.length!==4,className:"w-40 mx-auto block rounded-lg px-4 py-2 text-sm font-semibold text-white disabled:opacity-50",style:{background:t.rsx},"data-testid":"button-submit-access-code",children:b?"Checking…":"Unlock"})]})})]})}function Ce(s){return`rsx_sc_unlock_${s}`}export{Vs as default,Ns as scorecardDataForRender};

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.