PageSourceSearch

https://restaurant-app-production.web.app/assets/LaborSchedulingHub-_CN1_KDn.js

js restaurant-app-production.web.app collected 2026-10-03 12:35:47 UTC 65,549 bytes, 1 lines download raw bytes

1import{r as aa}from"./rolldown-runtime-b3L32Ng1.js";import{_ as qe,a as Ze,p as Ft}from"./app-DWbpOmbp.js";import{Cn as _e,Ct as ra,En as na,F as la,Kt as ia,Lt as q,S as Ps,Sn as ms,Xt as oa,bn as le,cn as Je,fn as Fs,h as $,hn as ca,in as da,kn as D,nr as ua,qt as ke,rn as ma,u as ba,xn as $s}from"./module-B8BOkXXh.js";import{A as ha,L as xa,S as pa,U as bs,W as Bt,i as ie,n as hs,p as ga,v as Os}from"./dashboardFilterState-C5qGIQV9.js";import{n as fa}from"./dashboardTenantTimeZone-BQw3VcsB.js";import{C as ya,E as Sa,S as xs,T as wa,_ as ja,a as va,b as Na,c as de,d as za,f as ka,g as ps,h as Qe,l as Ca,m as Aa,o as La,p as gs,s as Da,u as Ea,v as Ra,w as Ta,y as Ia}from"./moduleDeepLinks-CTVFNwbL.js";import{On as Pa,cn as fs}from"./main-BpGFkDZX.js";import{i as Fa}from"./aiSupportBridge-8U84gl9A.js";import{g as ys,h as Oe,n as $a,r as _s,y as Ss}from"./DashboardV3Cards-BziSy3V9.js";import{C as Oa,D as _a,E as Ba,S as Bs,T as Wa,b as Ha,c as Ma,n as Va,o as Ua,w as $t,x as Ka}from"./DashboardFilterBar-BPBQRTja.js";import{_ as Ga,a as Ya,d as St,f as qa,i as Qa,l as ws,n as Ja,o as Xa,p as Za,r as Ot,s as er,u as tr,v as sr,w as ar,x as Be}from"./aiWeeklyCoach-Cw1BoyKH.js";import{c as rr,n as nr,t as lr}from"./forecasting-DASO0nGJ.js";import{t as ir}from"./ai-support-context-rhy2ruQZ.js";var i=aa(ua(),1);function or({queryStoreNames:t=[],hubCanSeeAllStores:s=!1,selectedStore:a=""}={}){const l=(Array.isArray(t)?t:[]).map(r=>String(r||"").trim()).filter(Boolean);if(l.length>0)return fs(l);if(s!==!0){const r=String(a||"").trim();if(r)return fs([r])}return[]}function cr({db:t,collectionName:s,constraints:a=[],extras:l=[],storeScope:r=[]}={}){const d=Je(t,s),n=Array.isArray(r)?r:[],x=Array.isArray(a)?a:[],o=Array.isArray(l)?l:[];return n.length===0?[_e(d,...x,...o)]:n.map(b=>_e(d,...x,D(b.field,b.op,b.value),...o))}function dr({tenantId:t,selectedStore:s="",canSeeAllStores:a=!1,canReadScheduling:l=!1,emptyStoreSelection:r=!1}={}){const[d,n]=(0,i.useState)([]),[x,o]=(0,i.useState)(!1),[b,u]=(0,i.useState)(!1),[S,v]=(0,i.useState)(!1);return(0,i.useEffect)(()=>{if(!t||!l||r===!0){n([]),o(!1),u(!1),v(!1);return}const k=[D("tenantId","==",t),D("payType","==","salaried")];return!a&&s&&k.push(D("store","==",s)),$s(_e(Je(ke,q.employees),...k,le(250)),C=>{const g=(Array.isArray(C?.docs)?C.docs:[]).map(j=>({id:j.id,...j.data()})),f=!Aa(g,250);o(f),n(f?[]:g),v(!1),u(!0)},()=>{n([]),o(!1),v(!0),u(!1)})},[l,a,r,s,t]),{liveSalariedEmployees:d,liveSalariedReady:b,liveSalariedTruncated:x,liveSalariedFailed:S}}var e=ra(),ur=["late","left_early","call_out","sick","no_show"];function mr({summary:t,canSeeNames:s=!1,unavailable:a=!1,loading:l=!1}){const{t:r}=Ze(),[d,n]=(0,i.useState)(!1);if(!t)return null;const x=t.countsByStatus||{};let o=r("scheduling.attendance.summary.empty");return a?o=r("scheduling.attendance.summary.unavailable"):l?o=r("scheduling.attendance.summary.loading"):t.total>0&&(o=r("scheduling.attendance.summary.counts",{count:t.total})),(0,e.jsxs)("section",{"data-testid":"attendance-summary",className:"rounded-[24px] border border-zinc-200 bg-white p-4 shadow-sm sm:p-5",children:[(0,e.jsx)("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:(0,e.jsxs)("div",{children:[(0,e.jsx)("p",{className:"text-xs font-semibold uppercase tracking-wide text-zinc-500",children:r("scheduling.attendance.history.title")}),(0,e.jsx)("h3",{className:"mt-1 text-base font-bold text-zinc-900",children:r("scheduling.attendance.last30Days")}),(0,e.jsx)("p",{className:"mt-1 text-sm text-zinc-600","data-testid":"attendance-summary-line",children:o})]})}),!a&&!l&&t.total>0&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("dl",{className:"mt-4 grid grid-cols-2 gap-2 sm:grid-cols-5",children:ur.map(b=>(0,e.jsxs)("div",{className:"rounded-xl border border-zinc-200 bg-zinc-50 px-3 py-2.5",children:[(0,e.jsx)("dt",{className:"text-[11px] font-semibold uppercase tracking-wide text-zinc-500",children:r(`scheduling.attendance.status.${b}`)}),(0,e.jsx)("dd",{className:"mt-1 text-sm font-semibold text-zinc-900",children:Number(x[b]||0)})]},b))}),t.topReasonCodes?.length>0&&(0,e.jsxs)("div",{className:"mt-3",children:[(0,e.jsx)("p",{className:"text-xs font-semibold uppercase tracking-wide text-zinc-500",children:r("scheduling.attendance.summary.topReasons")}),(0,e.jsx)("div",{className:"mt-2 flex flex-wrap gap-1","data-testid":"attendance-top-reasons",children:t.topReasonCodes.map(b=>(0,e.jsxs)("span",{className:"inline-flex items-center rounded-full border border-zinc-200 bg-white px-2.5 py-1 text-xs font-semibold text-zinc-700",children:[r(`scheduling.attendance.reason.${b.code}`)," · ",b.count]},b.code))})]}),s&&t.employees?.length>0&&(0,e.jsxs)("div",{className:"mt-4",children:[(0,e.jsxs)("button",{type:"button","data-testid":"attendance-drilldown-toggle",onClick:()=>n(b=>!b),className:"inline-flex min-h-[44px] items-center gap-2 rounded-xl border border-zinc-200 bg-white px-3 py-2 text-sm font-semibold text-zinc-700 hover:bg-zinc-50",children:[(0,e.jsx)($,{name:d?"ChevronUp":"ChevronDown",size:16}),r("scheduling.attendance.drilldown")]}),d&&(0,e.jsx)("ul",{className:"mt-3 divide-y divide-zinc-100 rounded-xl border border-zinc-200","data-testid":"attendance-drilldown",children:t.employees.map(b=>(0,e.jsxs)("li",{className:"flex items-center justify-between gap-3 px-3 py-2 text-sm",children:[(0,e.jsx)("span",{className:"truncate font-medium text-zinc-900",children:b.employeeName}),(0,e.jsx)("span",{className:"shrink-0 text-zinc-500",children:b.total})]},b.employeeId))})]})]})]})}function br({period:t,startDate:s,endDate:a,selectedStores:l,availableStores:r,emptySelection:d=!1}={}){const n=Os({availableStores:r,selectedStores:d===!0?[]:l});return Wa({periodKind:t,startIso:s,endIso:a,stores:n.selectedStores,allStores:n.isAll})}function hr(t){const s=Ka(t?.periodKind),a={period:s,stores:[...t?.stores||[]],allStores:t?.allStores===!0,dayValue:t?.startIso,weekStart:t?.startIso,customStart:t?.startIso,customEnd:t?.endIso};return s===ie.DAY&&(a.dayValue=t?.startIso),s===ie.WEEK&&(a.weekStart=t?.startIso),s===ie.CUSTOM&&(a.customStart=t?.startIso,a.customEnd=t?.endIso),a}function xr({patch:t={},moduleContext:s,navigationScope:a,now:l,timeZone:r="",resolvedWindow:d}={}){const n=String(t.period||ie.THIS_WEEK).trim(),x=d||Bs({startIso:t.customStart||t.dayValue||"",endIso:t.customEnd||t.dayValue||"",periodKind:n}),o=ha({period:n,dayValue:t.dayValue,weekStart:t.weekStart,customStart:t.customStart,customEnd:t.customEnd,now:l instanceof Date&&!Number.isNaN(l.getTime())?l:Bt(r),timeZone:r,resolvedWindow:x}),b={...s||{}
1,period:n,weekStart:pa(o.startDate),startDate:o.startDate,endDate:o.endDate};return pr(b,n,t,o),gr(b,t,a),b}function pr(t,s,a,l){if(s===ie.DAY?t.dayValue=a.dayValue||l.startDate:delete t.dayValue,s===ie.WEEK&&(t.weekStart=a.weekStart||l.startDate),s===ie.CUSTOM){t.customStart=a.customStart||l.startDate,t.customEnd=a.customEnd||l.endDate;return}delete t.customStart,delete t.customEnd}function gr(t,s,a){if(s.allStores===!0){delete t.stores;return}if(Array.isArray(s.stores)){t.stores=s.stores;return}if(a?.hasExplicitStores){t.stores=a.selectedStores;return}delete t.stores}var fr="labor-filter";function yr(t,s,a){return{dayValue:String(s?.dayValue||(t===ie.DAY?a.startDate:"")).trim(),weekStart:String(s?.weekStart||a.weekStart||"").trim(),customStart:String(s?.customStart||(t===ie.CUSTOM?a.startDate:"")).trim(),customEnd:String(s?.customEnd||(t===ie.CUSTOM?a.endDate:"")).trim()}}function Sr({moduleContext:t,navigationScope:s,authorizedStores:a,now:l,timeZone:r="",onNavigate:d,isManagerOnly:n=!1,canSeeAllStores:x=!1,tenantId:o="",userKey:b=""}={}){const u=s.period||ie.THIS_WEEK,S=(0,i.useCallback)(()=>br({period:u,startDate:s.startDate,endDate:s.endDate,selectedStores:s.selectedStores,availableStores:a,emptySelection:s.emptySelection}),[a,s.emptySelection,s.endDate,s.selectedStores,s.startDate,u]),v=(0,i.useCallback)(p=>{const E=Ma(Ha(p,null,{...bs(r,l),limits:hs}),a);E&&(_a(E,S())||d("laborSchedulingHub",xr({patch:hr(E),moduleContext:t,navigationScope:s,now:Bt(r),timeZone:r,resolvedWindow:Bs(E)})))},[a,t,s,l,d,S,r]),k=(0,i.useCallback)((p,E)=>{v(Ba(p,S(),E||bs(r,l)))},[v,l,S,r]),C=Ua(S,v,{tenantId:o,uid:b,screen:fr,catalogStores:a}),g=Os({availableStores:a,selectedStores:s.selectedStores}),f=S(),j=yr(u,t,s);return(0,i.useMemo)(()=>({period:u,mode:ga(u)||Oa(f),startDate:s.startDate,endDate:s.endDate,selectedStores:g.selectedStores,selectedStoresKey:$t(g.selectedStores),availableStores:a,isEmptyStoreSet:s.emptySelection,isStoreSetLocked:n||!x,isAllStoresSelected:g.isAll,dayValue:j.dayValue,weekStart:j.weekStart,customStart:j.customStart,customEnd:j.customEnd,now:l,timeZone:r,filterDraftLimits:hs,readFilterSelection:S,applyFilterSelection:v,applyPreset:k,...C}),[k,a,x,g.isAll,g.selectedStores,n,s.emptySelection,s.endDate,s.startDate,l,u,S,v,C,f,r,j.customEnd,j.customStart,j.dayValue,j.weekStart])}var Et=Object.freeze([]);function wr(t,s){const[a]=(0,i.useState)(()=>Bt(s));return t instanceof Date&&!Number.isNaN(t.getTime())?t:a}function jr(t){const s=(0,i.useRef)(Et),a=Array.isArray(t)?t:Et;return $t(s.current)!==$t(a)&&(s.current=a.length===0?Et:Object.freeze([...a])),s.current}var Rt="unverified",vr="Could not verify your session — try again";function Nr(t){return t.exists()}function zr(t){return t.data()||{}}async function kr({profile:t=null,user:s=null}={}){if(qe(t)||qe(s)||qe(s&&s.token))return!0;let a=s||null;if(!a)try{a=ia.currentUser||null}catch{a=null}try{const r=await a.getIdTokenResult();if(qe(r&&r.claims))return!0}catch{return!0}const l=String(t&&t.uid||a&&a.uid||"").trim();if(!l)return Rt;try{const r=await ca(Fs(ke,q.users,l));return Nr(r)?qe(zr(r)):Rt}catch{return Rt}}function Cr(t){const s=new Date(t);return Number.isNaN(s.getTime())?"":s.toLocaleString("en-US",{timeZone:"UTC",month:"short",day:"numeric",hour:"numeric",minute:"2-digit",hour12:!0})}function js(t={}){if(typeof window>"u")return null;try{const s=window.sessionStorage?.getItem(qa(t)),a=s?JSON.parse(s):null,l=Number(a?.cachedAt),r=Number.isFinite(l)&&l>0?new Date(l).toISOString():"",d=a?.attendance;if(!d||typeof d!="object")return typeof a?.copy=="string"&&a.copy.trim()&&r?{status:"fresh",verifiedAt:r}:null;const n=String(d.status||"").trim().toLowerCase();return n!=="stale"&&n!=="unavailable"?null:{status:n,verifiedAt:String(d.verifiedAt||"").trim()}}catch{return null}}function vs(t){const s=Date.parse(String(t||"").trim());return Number.isFinite(s)?s:0}function Ar({copy:t="",attendance:s=null,cached:a="",cachedAttendance:l=null}={}){const r=String(s?.status||"").trim().toLowerCase(),d=String(t||"").trim(),n=String(a||"").trim(),x=String(s?.verifiedAt||"").trim(),o=String(l?.verifiedAt||"").trim();if(r!=="stale"&&r!=="unavailable")return{retained:d,resolvedAttendance:s}
1;const b=vs(x),u=vs(o);return d&&b>0&&b>u?{retained:d,resolvedAttendance:{...s,status:r,verifiedAt:x}}:n?{retained:n,resolvedAttendance:{...s,status:r,verifiedAt:o||x}}:{retained:d,resolvedAttendance:{...s,status:r,verifiedAt:x}}}var Ns=Object.freeze({neutral:"border-zinc-200 bg-zinc-50 text-zinc-700",success:"border-emerald-200 bg-emerald-50 text-emerald-700",warning:"border-amber-200 bg-amber-50 text-amber-700",danger:"border-red-200 bg-red-50 text-red-700"}),zs=Object.freeze({neutral:"zinc",success:"emerald",warning:"amber",danger:"red"}),ks=Object.freeze({neutral:"Watch",success:"Clear",warning:"Watch",danger:"Needs attention"}),Lr=Object.freeze({"planned-labor":"Percent","schedule-status":"CalendarDays","roster-status":"Users","payroll-status":"ClipboardCheck"}),h=Object.freeze({pending:"pending",loaded:"loaded",error:"error",unavailable:"unavailable",incomplete:"incomplete"}),gt=">=",ft="<=",yt=50,Dr="Some labor signals could not be loaded. Available data remains shown; try again to check the current week.",Cs=t=>{try{return da[t]}catch{return}},Tt=({canReadScheduling:t=!1,canReadCompleteSalaryBasis:s=!1,shouldLoadForecastRows:a=!1,canReadPayrollRecon:l=!1,shouldLoadToastSales:r=!1,aiWeeklyCoachEnabled:d=!1}={})=>({employees:t?h.pending:h.unavailable,salaryBasis:s?h.pending:h.unavailable,schedule:t?h.pending:h.unavailable,forecast:a?h.pending:h.unavailable,payroll:l?h.pending:h.unavailable,toastSales:r?h.pending:h.unavailable,toastTime:d?h.pending:h.unavailable}),As=Object.freeze({neutral:"Circle",success:"CheckCircle2",warning:"AlertTriangle",danger:"AlertCircle"}),Er=({tenant:t,profile:s})=>String(s?.tenantId||t?.id||t?.tenantId||"").trim(),Ls=t=>{const s=String(t??"").trim();if(!s)return"";const a=Number(s);return Number.isFinite(a)&&a>0?String(a):s},Xe=t=>{const s=String(t??"").trim();if(!s)return null;const a=Number(s);return Number.isFinite(a)&&a>0?a:null},Rr=({tenant:t,storeOptions:s})=>{const a=t?.settings&&typeof t.settings=="object"?t.settings:{},l=Array.isArray(a.stores)?a.stores:[],r=new Map;l.forEach(n=>{const x=String(n?.name||n?.store||n?.storeName||"").trim();x&&r.set(Q(x),{...n,name:x,laborPct:Ls(n?.laborPct)})}),(Array.isArray(s)?s:[]).forEach(n=>{const x=String(n||"").trim();if(!x||wt(x))return;const o=Q(x);r.has(o)||r.set(o,{name:x,active:!0,laborPct:""})});const d=a.labor&&typeof a.labor=="object"?a.labor:{};return{laborGoalPct:Ls(a.laborGoalPct??t?.laborGoalPct??a.targetLaborPct??""),includeSalariedInLaborPct:d.includeSalariedInLaborPct!==!1,stores:Array.from(r.values()),attendance:Be(a.attendance)}},Ws=(t={})=>JSON.stringify({laborGoalPct:t.laborGoalPct??"",includeSalariedInLaborPct:t.includeSalariedInLaborPct!==!1,stores:(t.stores||[]).map(s=>({name:s.name,id:s.id||"",slug:s.slug||"",laborPct:s.laborPct??""})),attendance:Be(t.attendance)}),Tr=(t={},s={})=>({...t||{},settings:{...t&&t.settings||{},laborGoalPct:Xe(s.laborGoalPct),labor:{...t&&t.settings&&t.settings.labor||{},includeSalariedInLaborPct:s.includeSalariedInLaborPct!==!1},stores:Array.isArray(s.stores)?s.stores:[],attendance:Be(s.attendance)}}),Ir=t=>Q(t).replace(/[^a-z0-9]+/g,"-"),Ds=(t={})=>({laborGoalPct:Xe(t.laborGoalPct),stores:(Array.isArray(t.stores)?t.stores:[]).map(s=>({...s,name:String(s?.name||"").trim(),laborPct:Xe(s?.laborPct)})).filter(s=>s.name),attendance:Be(t.attendance)}),wt=t=>/^all\s+stores$/i.test(String(t||"").trim()),Pr=({canSeeAllStores:t,selectedStore:s,storeOptions:a})=>(t?a:[s,...a]).map(l=>String(l||"").trim()).find(l=>l&&!wt(l))||"",Fr=(t,s)=>t.reduce((a,l)=>{const r=s.map(d=>Number(l?.[d])).find(d=>Number.isFinite(d));return a+(Number.isFinite(r)?r:0)},0),Q=t=>String(t||"").trim().toLowerCase(),$r=t=>{const s=t instanceof Date?new Date(t):new Date(t||Date.now());return Number.isNaN(s.getTime())?"":`${s.getFullYear()}-${String(s.getMonth()+1).padStart(2,"0")}-${String(s.getDate()).padStart(2,"0")}`},Es=(t,s)=>{const a=new Date(`${t}T00:00:00`);return Number.isNaN(a.getTime())?t:(a.setDate(a.getDate()+s),$r(a))},We=t=>{const s=Number(t);return Number.isFinite(s)?s.toLocaleString("en-US",{style:"currency",currency:"USD",maximumFractionDigits:0}):"n/a"},Wt=t=>{const s=Number(t);return Number.isFinite(s)?`${s>0?"+":""}${We(s)}`:"n/a"},jt=t=>{const s=Number(t);return Number.isFinite(s)?`${(s*100).toFixed(1)}%`:"n/a"},Ht=t=>{const s=Number(t);return Number.isFinite(s)?`${s>0?"+":""}${s.toFixed(1)} pts`:"n/a"},Or=(t={})=>{const s=Number(t.value);return Number.isFinite(s)?t.format==="money"?We(s):t.format==="signedMoney"?Wt(s):t.format==="percent"?jt(s):t.format==="points"?Ht(s):t.format==="hours"?`${s.toFixed(1)}h`:String(t.value):"n/a"},Rs=Object.freeze({none:"border-zinc-200 bg-white hover:bg-zinc-50",watch:"border-amber-200 bg-amber-50 hover:bg-amber-100/70",warning:"border-orange-200 bg-orange-50 hover:bg-orange-100/70",urgent:"border-red-200 bg-red-50 hover:bg-red-100/70"}),_t=(t={})=>{const s=String(t.weekProgressLabel||"").trim();if(s)return s;const a=Number(t.weekElapsedDays||0);return t.weekInProgress&&a>0?`Week in progress, ${a} day${a===1?"":"s"} in`:"Completed week"},Ts=(t={})=>t.weekInProgress?`Sales and labor are compared through ${t.asOfDate}, not against the full week.`:"This is the full completed week.",_r=t=>String(t?.store||t?.storeName||t?.location||"").trim(),Br=({canSeeAllStores:t,selectedStore:s,storeOptions:a,rows:l})=>
1{if(!t)return[s].map(n=>String(n||"").trim()).filter(Boolean);const r=a.map(n=>String(n||"").trim()).filter(n=>n&&!wt(n));if(r.length)return[...new Set(r)];const d=(Array.isArray(l)?l.map(_r):[]).map(n=>String(n||"").trim()).filter(n=>n&&!wt(n));return[...new Set(d)]},Wr=()=>(0,e.jsx)("div",{className:"mg-loading-panel flex min-h-[220px] items-center justify-center rounded-[24px] border border-zinc-200 bg-white p-6 shadow-card",children:(0,e.jsx)(Ps,{size:"md"})});function It({laborFilter:t,hubPeriod:s,storesAttr:a="",empty:l=!1,loading:r=!1,children:d}){return(0,e.jsxs)("main",{"data-testid":"labor-scheduling-hub","data-hub-stores":a,"data-hub-week":s.weekStart,"data-hub-start":s.startDate,"data-hub-end":s.endDate,"data-hub-period":s.period||"","data-hub-empty":l?"true":void 0,"data-hub-loading":r?"true":void 0,className:"labor-scheduling-hub space-y-4 sm:space-y-5",children:[(0,e.jsx)(Va,{filter:t}),d]})}var Hr=t=>zs[t]||zs.neutral,Mr=t=>ks[t]||ks.neutral,Vr=t=>t.salariedPayUnavailable||t.includeSalariedInLaborPct===!1?"labor.costBasis.hourlyOnly":"labor.costBasis.allIn",Ur=({metric:t})=>{const{t:s}=Ze(),a=t.id==="planned-labor"&&t.hasForecast&&t.targetSource==="blended"&&Number(t.storeCount)>0&&Number(t.targetLaborPct)>0&&t.usesCoverageNote!==!0,l=t.id==="planned-labor"&&t.hasForecast&&t.targetSource==="store"&&Number(t.storeCount)>1&&Number(t.targetLaborPct)>0&&t.usesCoverageNote!==!0,r=(Array.isArray(t.missingSalesStores)?t.missingSalesStores:[]).map(o=>String(o||"").trim()).filter(Boolean).join(" and "),d=t.salesCoverageIncomplete?s("laborHub.salesCoverage.missingStore",{store:r}):a?`${s("laborTarget.blendedAcrossStores",{count:Number(t.storeCount)})}: ${Number(t.targetLaborPct).toFixed(1)}%`:l?`${s("laborTarget.selectedStores")}: ${Number(t.targetLaborPct).toFixed(1)}%`:t.helper,n=t.id==="planned-labor"&&(t.salariedPayUnavailable||t.includeSalariedInLaborPct===!1||t.hasSalariedEmployees===!0),x=n?s(Vr(t)):"";return(0,e.jsx)($a,{testId:`labor-hub-metric-${t.id}`,label:t.label,value:t.salesCoverageIncomplete?s("laborHub.salesCoverage.incompleteValue"):t.value,helper:d,caption:x,captionTestId:n?"labor-cost-basis-caption":"",icon:Lr[t.id]||"Activity",tone:Hr(t.tone),badge:Mr(t.tone),featured:t.id==="planned-labor",compact:!0})},Kr=(t,s)=>({...t,title:t.titleKey?s(t.titleKey):t.title,detail:t.detailKey?s(t.detailKey,t.detailParams):t.detail}),Gr=({item:t,onNavigate:s})=>(0,e.jsxs)("button",{type:"button","data-testid":`labor-hub-attention-${t.id}`,onClick:()=>s(t.moduleId,t.context),className:"mg-action-row flex min-h-[64px] w-full items-start gap-3 rounded-2xl border border-zinc-200 bg-white px-4 py-3 text-left hover:bg-zinc-50 focus:outline-none focus:ring-4 focus:ring-brand-500/15",children:[(0,e.jsx)("span",{className:`mt-0.5 inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-xl border ${Ns[t.tone]||Ns.neutral}`,children:(0,e.jsx)($,{name:As[t.tone]||As.neutral,size:17})}),(0,e.jsxs)("span",{className:"min-w-0 flex-1",children:[(0,e.jsx)("span",{className:"block text-sm font-semibold text-zinc-900",children:t.title}),(0,e.jsx)("span",{className:"mt-1 block text-sm text-zinc-600",children:t.detail})]}),(0,e.jsx)($,{name:"ChevronRight",size:16,className:"mt-2 text-zinc-400"})]}),Yr=({link:t,onNavigate:s})=>(0,e.jsx)("button",{type:"button","data-testid":`labor-hub-link-${t.id}`,onClick:()=>s(t.moduleId,t.context),className:"mg-action-row min-h-[64px] rounded-2xl border border-zinc-200 bg-white px-4 py-3 text-left hover:bg-zinc-50 focus:outline-none focus:ring-4 focus:ring-brand-500/15",children:(0,e.jsxs)("span",{className:"flex items-center justify-between gap-3",children:[(0,e.jsxs)("span",{children:[(0,e.jsx)("span",{className:"block text-sm font-semibold text-zinc-900",children:t.label}),(0,e.jsx)("span",{className:"mt-1 block text-sm text-zinc-600",children:t.helper})]}),(0,e.jsx)($,{name:"ArrowRight",size:16,className:"text-zinc-400"})]})}),qr=({facts:t=[],selectedStore:s="",onSelectStore:a=()=>{}})=>{const l=Xa(t);if(!l.length)return null;const r=l.filter(n=>n.severity!=="none").length,d=l[0]?.fact||{};return(0,e.jsxs)("section",{"data-testid":"weekly-coach-rollup",className:"rounded-[24px] border border-zinc-200 bg-white p-4 shadow-sm sm:p-5","aria-labelledby":"weekly-coach-rollup-title",children:[(0,e.jsxs)("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("p",{className:"text-xs font-semibold uppercase tracking-wide text-zinc-500",children:"Weekly Coach"}),(0,e.jsx)("h3",{id:"weekly-coach-rollup-title",className:"mt-1 text-base font-bold text-zinc-900",children:r>0?`${r} store${r===1?"":"s"} need a calm review`:"All stores are close to plan"}),(0,e.jsx)("p",{className:"mt-1 text-sm text-zinc-600",children:"Sales are compared to the same elapsed part of the week, then paired with labor target."})]}),(0,e.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,e.jsxs)("span",{className:"inline-flex w-fit items-center gap-1 rounded-full border border-sky-200 bg-sky-50 px-2.5 py-1 text-xs font-semibold text-sky-800",children:[(0,e.jsx)($,{name:"CalendarClock",size:13}),_t(d)]}),(0,e.jsxs)("span",{className:"inline-flex w-fit items-center gap-1 rounded-full border border-zinc-200 bg-zinc-50 px-2.5 py-1 text-xs font-semibold text-zinc-600",children:[(0,e.jsx)($,{name:"Building2",size:13}),"All-store view"]})]})]}),(0,e.jsx)("div",{className:"mt-4 space-y-2",children:l.map(({fact:n,store:x,severity:o})=>{const b=Q(x).replace(/[^a-z0-9]+/g,"-"),u=Q(s)===Q(x),S=n.actualLaborPct!==null&&!n.missingInputs.includes("timeEntries");return(0,e.jsxs)("button",{type:"button","data-testid":`weekly-coach-rollup-row-${b}`,"aria-pressed":u,onClick:()=>a(x),className:`w-full rounded-xl border p-3 text-left transition focus:outline-none focus:ring-4 focus:ring-brand-500/15 sm:p-4 ${Rs[o]||Rs.none} ${u?"ring-2 ring-brand-500/30":""}`,children:[(0,e.jsxs)("span",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[(0,e.jsxs)("span",{className:"min-w-0",children:[(0,e.jsx)("span",{className:"block text-sm font-bold text-zinc-900",children:x}),(0,e.jsxs)("span",{className:"mt-1 block text-xs text-zinc-600",children:[We(n.actualSalesWtd)," actual · ",We(n.forecastSalesWtd)," forecast to date · ",S?`${jt(n.actualLaborPct)} labor`:"labor waiting"]})]}),(0,e.jsxs)("span",{className:"flex shrink-0 flex-wrap items-center gap-2",children:[(0,e.jsx)(_s,{tone:o==="urgent"?"red":o==="none"?"emerald":"amber",children:o==="none"?"Clear":o==="urgent"?"Needs attention":"Watch"}),(0,e.jsxs)("span",{className:"inline-flex items-center gap-1 text-xs font-semibold text-zinc-600",children:["Open store",(0,e.jsx)($,{name:"ChevronRight",size:14})]})]})]}),(0,e.jsxs)("span",{className:"mt-3 grid grid-cols-1 gap-2 sm:grid-cols-3",children:[(0,e.jsxs)("span",{className:"rounded-lg border border-white/70 bg-white/80 p-2",children:[(0,e.jsx)("span",{className:"block text-[11px] font-semibold uppercase tracking-wide text-zinc-500",children:"Sales gap"}),(0,e.jsx)("span",{className:"mt-1 block text-sm font-bold text-zinc-900",children:Wt(n.salesVarianceDollars)}),(0,e.jsx)("span",{className:"mt-0.5 block text-[11px] text-zinc-500",children:"So far this week"})]}),(0,e.jsxs)("span",{className:"rounded-lg border border-white/70 bg-white/80 p-2",children:[(0,e.jsx)("span",{className:"block text-[11px] font-semibold uppercase tracking-wide text-zinc-500",children:"Labor gap"}),(0,e.jsx)("span",{className:"mt-1 block text-sm font-bold text-zinc-900",children:S?Ht(n.laborVariancePoints):"Waiting"})]}),(0,e.jsxs)("span",{className:"rounded-lg border border-white/70 bg-white/80 p-2",children:[(0,e.jsx)("span",{className:"block text-[11px] font-semibold uppercase tracking-wide text-zinc-500",children:"Staffing move"}),(0,e.jsx)("span",{className:"mt-1 block text-sm font-bold text-zinc-900",children:Number(n.suggestedHoursDelta||0)>0?`Reduce up to ${Number(n.suggestedHoursDelta).toFixed(1)}h`:"No cut"})]})]})]},`${x}_${n.weekStart}`)})})]})},Qr=t=>{const s=Number(t);return!Number.isFinite(s)||s===0?"bg-zinc-50 text-zinc-600":s>0?"bg-amber-50 text-amber-800":"bg-sky-50 text-sky-800"},Jr=t=>{const s=Number(t);return!Number.isFinite(s)||s===0?"0":`${s>0?"+":""}${s.toFixed(1)}`},Pt=({facts:t=[],lang:s="en",t:a,onOpenSchedule:l})=>
1{if(!t.length)return null;const r=String(s||"en").toLowerCase().startsWith("es");return(0,e.jsxs)("section",{"data-testid":"scheduled-vs-actual",className:"rounded-[24px] border border-zinc-200 bg-white p-4 shadow-sm sm:p-5","aria-labelledby":"scheduled-vs-actual-title",children:[(0,e.jsxs)("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("p",{className:"text-xs font-semibold uppercase tracking-wide text-zinc-500",children:a("scheduling.hub.varianceEyebrow")}),(0,e.jsx)("h3",{id:"scheduled-vs-actual-title",className:"mt-1 text-lg font-bold leading-tight text-zinc-950",children:a("scheduling.hub.varianceTitle")})]}),(0,e.jsxs)("span",{className:"inline-flex w-fit items-center gap-1 rounded-full border border-zinc-200 bg-zinc-50 px-2.5 py-1 text-xs font-semibold text-zinc-600",children:[(0,e.jsx)($,{name:"ShieldCheck",size:13}),a("scheduling.hub.readOnly")]})]}),(0,e.jsx)("div",{className:"mt-5 space-y-5",children:t.map(d=>{const n=d?.laborVariance&&typeof d.laborVariance=="object"?d.laborVariance:{},x=Array.isArray(n.weekStarts)?n.weekStarts:[],o=Array.isArray(n.dayparts)?n.dayparts:[],b=Array.isArray(n.days)?n.days:[],u=Array.isArray(n.cells)?n.cells:[],S=Array.isArray(d.laborVariancePatterns)?d.laborVariancePatterns:[],v=n.hasData===!0&&u.length>0,k=Q(d.store).replace(/[^a-z0-9]+/g,"-"),C=new Map(u.map(g=>[`${g.weekStart}|${g.day}|${g.daypart}`,g]));return(0,e.jsxs)("article",{"data-testid":`scheduled-vs-actual-store-${k}`,className:"rounded-xl border border-zinc-200 bg-white p-3 sm:p-4",children:[(0,e.jsx)("h4",{className:"text-base font-bold text-zinc-950",children:d.store||a("scheduling.hub.currentStore")}),v?(0,e.jsx)("div",{className:"mt-4 space-y-4",children:x.map(g=>(0,e.jsxs)("div",{className:"space-y-2",children:[(0,e.jsx)("p",{className:"text-xs font-semibold uppercase tracking-wide text-zinc-500",children:a("scheduling.hub.varianceWeekOf",{weekStart:g})}),(0,e.jsx)("div",{className:"overflow-x-auto",children:(0,e.jsxs)("table",{className:"min-w-full border-collapse text-left text-xs","aria-label":a("scheduling.hub.varianceAria"),children:[(0,e.jsx)("thead",{children:(0,e.jsxs)("tr",{children:[(0,e.jsx)("th",{className:"sticky left-0 bg-white px-2 py-2 font-semibold text-zinc-500",children:a("scheduling.hub.varianceDay")}),o.map(f=>(0,e.jsx)("th",{className:"px-2 py-2 font-semibold text-zinc-500",children:a(`scheduling.hub.daypart.${f.id}`)},f.id))]})}),(0,e.jsx)("tbody",{children:b.map(f=>(0,e.jsxs)("tr",{className:"border-t border-zinc-100",children:[(0,e.jsx)("th",{className:"sticky left-0 bg-white px-2 py-2 font-semibold text-zinc-700",children:a(`scheduling.hub.day.${f}`)}),o.map(j=>{const p=C.get(`${g}|${f}|${j.id}`),E=Number(p?.varianceHours)||0;return(0,e.jsx)("td",{className:`px-2 py-2 text-right font-semibold tabular-nums ${Qr(E)}`,children:Jr(E)},`${g}_${f}_${j.id}`)})]},`${g}_${f}`))})]})})]},g))}):(0,e.jsx)("p",{"data-testid":`scheduled-vs-actual-empty-${k}`,className:"mt-3 text-sm leading-6 text-zinc-600",children:a("scheduling.hub.varianceEmpty")}),S.length?(0,e.jsx)("ul",{className:"mt-4 space-y-3","data-testid":`scheduled-vs-actual-patterns-${k}`,children:S.map(g=>(0,e.jsxs)("li",{className:"flex flex-col gap-2 rounded-xl border border-zinc-200 bg-zinc-50 px-3 py-3 sm:flex-row sm:items-start sm:justify-between",children:[(0,e.jsx)("p",{className:"text-sm leading-6 text-zinc-800",children:r?g.guidanceEs||g.guidanceEn||"":g.guidanceEn||g.guidance||""}),(0,e.jsx)("button",{type:"button","data-testid":`scheduled-vs-actual-open-${k}-${String(g.key||"").replace(/[^a-z0-9]+/g,"-")}`,onClick:()=>l?.(g.weekStart||d.weekStart,d.store),className:"mg-button mg-button--outline inline-flex min-h-[44px] w-fit shrink-0 items-center gap-2 rounded-xl border border-zinc-200 bg-white px-3 py-2 text-sm text-zinc-700 hover:bg-zinc-50 focus:outline-none focus:ring-4 focus:ring-brand-500/15",children:a("scheduling.hub.varianceOpenSchedule")})]},g.key||`${g.day}_${g.daypart}`))}):null]},`${d.store}_${d.weekStart}_variance`)})})]})},Is=({facts:t=[],copyByKey:s={},attendanceByKey:a={}})=>{const{t:l,lang:r}=Ze(),[d,n]=(0,i.useState)("");if(!t.length)return null;const x=[...t].sort((u,S)=>{const v={urgent:0,warning:1,watch:2,none:3};return(v[u.severity]??4)-(v[S.severity]??4)||String(u.store||"").localeCompare(String(S.store||""))}),o=x.filter(u=>u.severity!=="none").length,b=x[0]||{};return(0,e.jsxs)("section",{"data-testid":"weekly-coach-card",className:"rounded-[24px] border border-zinc-200 bg-white p-4 shadow-sm sm:p-5","aria-labelledby":"weekly-coach-title",children:[(0,e.jsxs)("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("p",{className:"text-xs font-semibold uppercase tracking-wide text-zinc-500",children:"Weekly Coach"}),(0,e.jsx)("h3",{id:"weekly-coach-title",className:"mt-1 text-lg font-bold leading-tight text-zinc-950",children:o>0?`${o} store${o===1?"":"s"} need a calm review`:"Sales and labor are close to plan"}),(0,e.jsxs)("p",{className:"mt-2 max-w-2xl text-sm leading-6 text-zinc-600",children:[Ts(b)," Use this as a review guide before changing any published hours."]})]}),(0,e.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,e.jsxs)("span",{className:"inline-flex w-fit items-center gap-1 rounded-full border border-sky-200 bg-sky-50 px-2.5 py-1 text-xs font-semibold text-sky-800",children:[(0,e.jsx)($,{name:"CalendarClock",size:13}),_t(b)]}),(0,e.jsxs)("span",{className:"inline-flex w-fit items-center gap-1 rounded-full border border-zinc-200 bg-zinc-50 px-2.5 py-1 text-xs font-semibold text-zinc-600",children:[(0,e.jsx)($,{name:"ShieldCheck",size:13}),"Read only"]})]})]}),(0,e.jsx)("div",{className:"mt-5 grid grid-cols-1 gap-3",children:x.map(u=>{const S=Number(u.suggestedHoursDelta||0),v=Array.isArray(u.missingInputs)?u.missingInputs:[],k=u.actualLaborPct!==null&&!v.includes("timeEntries"),C=St(u),g=String(s[C]||Ot(u,r)).trim(),f=Q(u.store).replace(/[^a-z0-9]+/g,"-"),j=d===C,p=a[C]||{},E=String(p.status||"").trim().toLowerCase(),J=E==="stale"||E==="unavailable"?Cr(p.verifiedAt):"",ue=J&&E==="stale"?l("scheduling.attendance.coach.lastVerified",{time:J}):"",K=E==="unavailable"?J?l("scheduling.attendance.coach.unavailable",{time:J}):l("scheduling.attendance.coach.unavailableNow"):"";return(0,e.jsxs)("article",{"data-testid":`weekly-coach-row-${f}`,className:"rounded-xl border border-zinc-200 bg-white p-3 transition sm:p-4",children:[(0,e.jsxs)("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[(0,e.jsxs)("div",{className:"flex min-w-0 gap-3",children:[(0,e.jsx)("span",{className:"inline-flex h-11 w-11 shrink-0 items-center justify-center rounded-xl border border-zinc-200 bg-zinc-50 text-zinc-600",children:(0,e.jsx)($,{name:u.severity==="none"?"CheckCircle2":"ClipboardCheck",size:18})}),(0,e.jsxs)("div",{className:"min-w-0",children:[(0,e.jsx)("h4",{className:"text-base font-bold text-zinc-950",children:u.store||"Current store"}),(0,e.jsxs)("p",{className:"mt-1 text-sm leading-5 text-zinc-600",children:[_t(u)," · as of ",u.asOfDate]})]})]}),(0,e.jsx)(_s,{tone:u.severity==="urgent"?"red":u.severity==="none"?"emerald":"amber",children:u.severity==="none"?"Clear":u.severity==="urgent"?"Needs attention":"Watch"})]}),(0,e.jsx)("p",{"data-testid":`weekly-coach-copy-${f}`,className:"mt-4 rounded-xl border border-zinc-200 bg-zinc-50 px-3 py-3 text-sm font-semibold leading-6 text-zinc-800",children:g}),ue?(0,e.jsx)("p",{"data-testid":`weekly-coach-attendance-stale-${f}`,className:"mt-2 text-xs font-semibold text-zinc-500",role:"status","aria-live":"polite",children:ue}):null,K?(0,e.jsx)("p",{"data-testid":`weekly-coach-attendance-unavailable-${f}`,className:"mt-2 text-xs font-semibold text-amber-700",role:"status","aria-live":"polite",children:K}):null,(0,e.jsxs)("div",{className:"mt-3 grid grid-cols-1 gap-2 sm:grid-cols-3",children:[(0,e.jsxs)("div",{className:"rounded-xl border border-zinc-200 bg-white p-3",children:[(0,e.jsx)("p",{className:"text-xs font-semibold text-zinc-500",children:"Sales so far"}),(0,e.jsx)("p",{className:"mt-1 text-lg font-bold text-zinc-950",children:Wt(u.salesVarianceDollars)}),(0,e.jsxs)("p",{className:"mt-1 text-xs leading-5 text-zinc-600",children:[We(u.actualSalesWtd)," actual · ",We(u.forecastSalesWtd)," forecast to date"]})]}),(0,e.jsxs)("div",{className:"rounded-xl border border-zinc-200 bg-white p-3",children:[(0,e.jsx)("p",{className:"text-xs font-semibold text-zinc-500",children:"Labor so far"}),(0,e.jsx)("p",{className:"mt-1 text-lg font-bold text-zinc-950",children:k?Ht(u.laborVariancePoints):"Waiting"}),(0,e.jsx)("p",{className:"mt-1 text-xs leading-5 text-zinc-600",children:k?`${jt(u.actualLaborPct)}
1 actual · ${jt(u.targetLaborPct)} target`:"Sales-only watch until labor imports arrive"})]}),(0,e.jsxs)("div",{className:"rounded-xl border border-zinc-200 bg-white p-3",children:[(0,e.jsx)("p",{className:"text-xs font-semibold text-zinc-500",children:"Staffing move"}),(0,e.jsx)("p",{className:"mt-1 text-lg font-bold text-zinc-950",children:S>0?`Reduce up to ${S.toFixed(1)}h`:"No cut recommended"}),(0,e.jsx)("p",{className:"mt-1 text-xs leading-5 text-zinc-600",children:"Protect required meal/rest breaks and service coverage."})]})]}),(0,e.jsx)("ul",{className:"mt-3 space-y-1 text-sm leading-6 text-zinc-700",children:(Array.isArray(u.reasons)?u.reasons:[]).slice(0,3).map(y=>(0,e.jsxs)("li",{className:"flex gap-2",children:[(0,e.jsx)($,{name:"CheckCircle2",size:14,className:"mt-0.5 shrink-0 text-zinc-400"}),(0,e.jsx)("span",{children:y})]},y))}),(0,e.jsx)("div",{className:"mt-3",children:(0,e.jsxs)("button",{type:"button","data-testid":`weekly-coach-explain-${f}`,onClick:()=>n(j?"":C),className:"inline-flex min-h-[44px] items-center gap-2 rounded-xl border border-zinc-200 bg-white px-3 py-2 text-sm font-semibold text-zinc-700 hover:bg-zinc-50 focus:outline-none focus:ring-4 focus:ring-brand-500/15","aria-expanded":j,children:[(0,e.jsx)($,{name:j?"ChevronUp":"Info",size:16}),"Show how this was calculated"]})}),j?(0,e.jsxs)("div",{"data-testid":`weekly-coach-explanation-${f}`,className:"mt-3 rounded-xl border border-zinc-200 bg-white p-3",children:[(0,e.jsxs)("div",{className:"flex items-start gap-2",children:[(0,e.jsx)($,{name:"Calculator",size:16,className:"mt-0.5 shrink-0 text-zinc-500"}),(0,e.jsxs)("div",{children:[(0,e.jsx)("p",{className:"text-sm font-bold text-zinc-900",children:"How this was calculated"}),(0,e.jsxs)("p",{className:"mt-1 text-xs leading-5 text-zinc-600",children:[Ts(u)," Opening this section does not send a message or change the schedule."]})]})]}),(0,e.jsx)("dl",{className:"mt-3 grid grid-cols-1 gap-2 sm:grid-cols-2",children:Ya(u).map(y=>(0,e.jsxs)("div",{className:"rounded-lg border border-zinc-200 bg-zinc-50 p-2.5",children:[(0,e.jsx)("dt",{className:"text-[11px] font-semibold uppercase tracking-wide text-zinc-500",children:y.label}),(0,e.jsx)("dd",{className:"mt-1 text-sm font-bold text-zinc-900",children:Or(y)}),(0,e.jsx)("dd",{className:"mt-1 text-xs text-zinc-600",children:y.source})]},y.id))})]}):null]},`${u.store}_${u.weekStart}`)})})]})},Xr=({tenantId:t="",settings:s,canEdit:a=!1,onSaved:l=()=>{},operatingTarget:r=null,canSeeAllStores:d=!1,profile:n={},user:x})=>{const{t:o}=Ze(),[b,u]=(0,i.useState)(()=>s),[S,v]=(0,i.useState)(!1),[k,C]=(0,i.useState)(""),[g,f]=(0,i.useState)(!1),j=Ws(s),p=(()=>{try{return Ft({user:x,profile:n}),!1}catch{return!0}})();(0,i.useEffect)(()=>{u(s)},[j,s]);const E=(y,L)=>{u(me=>({...me,stores:(me.stores||[]).map(w=>Q(w.name)===Q(y)?{...w,laborPct:L}:w)}))},J=async()=>{if(!t)return;try{Ft({user:x,profile:n})}catch{return}const y=await kr({profile:n,user:x});if(y==="unverified"){C(vr);return}if(y){C(o("scheduling.hub.viewAsUnavailable"));return}if(!a)return;const L=Ds(b);if(!(Number(L.laborGoalPct)>0)){C("Add a tenant default labor target before saving.");return}const me=Ds(s);if(JSON.stringify(L)===JSON.stringify(me)){C("Labor targets saved."),f(!1);return}v(!0),C("");try{await na(Fs(ke,q.tenants,t),{settings:L},{merge:!0}),l({laborGoalPct:L.laborGoalPct,includeSalariedInLaborPct:s.includeSalariedInLaborPct!==!1,stores:L.stores.map(w=>({...w,laborPct:w.laborPct??""})),attendance:L.attendance}),C("Labor targets saved."),f(!1)}catch(w){C(la(w,"Could not save labor targets."))}finally{v(!1)}},ue=()=>{f(y=>!y),C("")},K=(b?.stores||[]).filter(y=>Xe(y?.laborPct)!==null).length;return(0,e.jsxs)("section",{"data-testid":"labor-target-settings",className:"rounded-[24px] border border-zinc-200 bg-white p-4 shadow-sm sm:p-5","aria-labelledby":"labor-target-settings-title",children:[(0,e.jsxs)("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("p",{className:"text-xs font-semibold uppercase tracking-wide text-zinc-500",children:"Settings"}),(0,e.jsx)("h3",{id:"labor-target-settings-title",className:"mt-1 text-base font-bold text-zinc-900",children:"Labor targets"}),(0,e.jsx)("p",{className:"mt-1 max-w-2xl text-sm leading-6 text-zinc-600",children:"These targets power the Hub and Weekly Coach. Store targets override the tenant default."})]}),a?(0,e.jsxs)("button",{type:"button","data-testid":"labor-target-edit","aria-expanded":g,"aria-controls":"labor-target-settings-form",onClick:ue,className:"mg-button mg-button--outline inline-flex min-h-[44px] w-fit items-center justify-center gap-2 rounded-xl border border-zinc-200 bg-white px-3 py-2 text-sm font-semibold text-zinc-700 hover:bg-zinc-50 focus:outline-none focus:ring-4 focus:ring-brand-500/15",children:[(0,e.jsx)($,{name:g?"ChevronUp":"Settings2",size:16}),g?"Close editor":"Edit labor targets"]}):(0,e.jsxs)("span",{className:"inline-flex w-fit items-center gap-1 rounded-full border border-zinc-200 bg-zinc-50 px-2.5 py-1 text-xs font-semibold text-zinc-600",children:[(0,e.jsx)($,{name:"Lock",
1size:13}),o("scheduling.hub.readOnly")]})]}),(0,e.jsxs)("dl",{"data-testid":"labor-target-summary",className:"mt-4 grid grid-cols-1 gap-2 sm:grid-cols-2",children:[d&&r&&Number(r.targetLaborPct)>0?(0,e.jsxs)("div",{className:"rounded-xl border border-zinc-200 bg-zinc-50 px-3 py-2.5","data-testid":"labor-target-operating",children:[(0,e.jsx)("dt",{className:"text-xs font-semibold uppercase tracking-wide text-zinc-500",children:r.source==="blended"?o("laborTarget.blendedAcrossStores",{count:Number(r.storeCount)||0}):r.source==="store"?o("laborTarget.storeTarget"):o("laborTarget.tenantDefault")}),(0,e.jsxs)("dd",{className:"mt-1 text-sm font-semibold text-zinc-900",children:[Number(r.targetLaborPct).toFixed(1),"%"]})]}):null,(0,e.jsxs)("div",{className:"rounded-xl border border-zinc-200 bg-zinc-50 px-3 py-2.5",children:[(0,e.jsx)("dt",{className:"text-xs font-semibold uppercase tracking-wide text-zinc-500",children:o("scheduling.hub.tenantDefault")}),(0,e.jsx)("dd",{className:"mt-1 text-sm font-semibold text-zinc-900",children:Xe(b?.laborGoalPct)!==null?`${b.laborGoalPct}%`:"Not set"})]}),(0,e.jsxs)("div",{className:"rounded-xl border border-zinc-200 bg-zinc-50 px-3 py-2.5",children:[(0,e.jsx)("dt",{className:"text-xs font-semibold uppercase tracking-wide text-zinc-500",children:o("scheduling.hub.storeOverrides")}),(0,e.jsxs)("dd",{className:"mt-1 text-sm font-semibold text-zinc-900",children:[K," configured"]})]})]}),k?(0,e.jsx)("p",{className:"mt-3 text-sm text-zinc-600",role:"status","aria-live":"polite",children:k}):null,g?(0,e.jsxs)("div",{id:"labor-target-settings-form",className:"mt-4 border-t border-zinc-200 pt-4",children:[(0,e.jsxs)("div",{className:"grid grid-cols-1 gap-3 lg:grid-cols-[minmax(220px,0.4fr)_minmax(0,1fr)]",children:[(0,e.jsxs)("div",{className:"space-y-3",children:[(0,e.jsxs)("label",{className:"block rounded-xl border border-zinc-200 bg-zinc-50 p-3",children:[(0,e.jsx)("span",{className:"text-sm font-semibold text-zinc-800",children:"Tenant default %"}),(0,e.jsx)("input",{"data-testid":"labor-target-default-input",type:"number",min:"1",max:"100",step:"0.5",value:b?.laborGoalPct??"",disabled:!a||S,onChange:y=>u(L=>({...L,laborGoalPct:y.target.value})),className:"mt-2 min-h-[44px] w-full rounded-xl border border-zinc-200 bg-white px-3 py-2 text-base text-zinc-900 shadow-sm focus:border-brand-400 focus:outline-none focus:ring-4 focus:ring-brand-500/15 disabled:bg-zinc-100 disabled:text-zinc-500","aria-label":"Tenant default labor target percent"}),(0,e.jsx)("span",{className:"mt-1 block text-xs leading-5 text-zinc-500",children:"Used when a store has no override."})]}),(0,e.jsxs)("div",{className:"rounded-xl border border-zinc-200 bg-zinc-50 p-3",children:[(0,e.jsxs)("label",{className:"flex items-start gap-3",children:[(0,e.jsx)("input",{"data-testid":"labor-include-salaried-toggle",type:"checkbox",className:"mt-1 h-5 w-5 rounded border-zinc-300 text-brand-600 focus:ring-brand-500/30",checked:b?.includeSalariedInLaborPct!==!1,disabled:!0,readOnly:!0,"aria-label":o("scheduling.hub.includeSalariedInLaborPct")}),(0,e.jsxs)("span",{children:[(0,e.jsx)("span",{className:"block text-sm font-semibold text-zinc-800",children:o("scheduling.hub.includeSalariedInLaborPct")}),(0,e.jsx)("span",{className:"mt-1 block text-xs leading-5 text-zinc-500",children:o("scheduling.hub.includeSalariedHelp")})]})]}),(0,e.jsx)("p",{"data-testid":"labor-include-salaried-settings-writer-note",className:"mt-2 text-xs leading-5 text-zinc-500",children:o("scheduling.hub.includeSalariedSettingsWriterNote")})]})]}),(0,e.jsxs)("label",{className:"block rounded-xl border border-zinc-200 bg-zinc-50 p-3",children:[(0,e.jsx)("span",{className:"text-sm font-semibold text-zinc-800",children:o("scheduling.attendance.settingsTitle")}),(0,e.jsx)("span",{className:"mt-2 block text-xs font-semibold text-zinc-700",children:o("scheduling.attendance.lateAfter")}),(0,e.jsx)("input",{"data-testid":"attendance-late-after-input",type:"number",min:"0",max:"240",step:"1",value:b?.attendance?.lateAfterMinutes??10,disabled:!a||S,onChange:y=>u(L=>({...L,attendance:{...Be(L.attendance),lateAfterMinutes:y.target.value}})),className:"mt-1 min-h-[44px] w-full rounded-xl border border-zinc-200 bg-white px-3 py-2 text-base text-zinc-900 shadow-sm focus:border-brand-400 focus:outline-none focus:ring-4 focus:ring-brand-500/15 disabled:bg-zinc-100 disabled:text-zinc-500","aria-label":o("scheduling.attendance.lateAfter")}),(0,e.jsx)("span",{className:"mt-1 block text-xs leading-5 text-zinc-500",children:o("scheduling.attendance.lateAfterHelp")}),(0,e.jsx)("span",{className:"mt-3 block text-xs font-semibold text-zinc-700",children:o("scheduling.attendance.earlyOutBefore")}),(0,e.jsx)("input",{"data-testid":"attendance-early-out-input",type:"number",min:"0",max:"240",step:"1",value:b?.attendance?.earlyOutBeforeMinutes??10,disabled:!a||S,onChange:y=>u(L=>({...L,attendance:{...Be(L.attendance),earlyOutBeforeMinutes:y.target.value}})),className:"mt-1 min-h-[44px] w-full rounded-xl border border-zinc-200 bg-white px-3 py-2 text-base text-zinc-900 shadow-sm focus:border-brand-400 focus:outline-none focus:ring-4 focus:ring-brand-500/15 disabled:bg-zinc-100 disabled:text-zinc-500","aria-label":o("scheduling.attendance.earlyOutBefore")}),(0,e.jsx)("span",{className:"mt-1 block text-xs leading-5 text-zinc-500",children:o("scheduling.attendance.earlyOutHelp")})]}),(0,e.jsx)("div",{className:"grid grid-cols-1 gap-2 md:grid-cols-2 xl:grid-cols-3",children:(b?.stores||[]).map(y=>(0,e.jsxs)("label",{"data-testid":`labor-target-store-row-${Ir(y.name)}`,className:"block rounded-xl border border-zinc-200 bg-white p-3",children:[(0,e.jsx)("span",{className:"block truncate text-sm font-semibold text-zinc-900",children:y.name}),(0,e.jsx)("input",{type:"number",min:"1",max:"100",step:"0.5",value:y.laborPct??"",disabled:!a||S,onChange:L=>E(y.name,L.target.value),className:"mt-2 min-h-[44px] w-full rounded-xl border border-zinc-200 bg-white px-3 py-2 text-base text-zinc-900 shadow-sm focus:border-brand-400 focus:outline-none focus:ring-4 focus:ring-brand-500/15 disabled:bg-zinc-100 disabled:text-zinc-500","aria-label":`${y.name} labor target percent`,placeholder:"Use default"}),(0,e.jsx)("span",{className:"mt-1 block text-xs leading-5 text-zinc-500",children:"Blank uses tenant default."})]},y.name))})]}),(0,e.jsx)("div",{className:"mt-4 flex justify-end",children:(0,e.jsxs)("button",{type:"button","data-testid":"labor-target-save",onClick:J,disabled:S,className:"mg-button mg-button--primary inline-flex min-h-[44px] items-center justify-center gap-2 rounded-xl px-4 py-2 text-sm text-white focus:outline-none focus:ring-4 focus:ring-brand-500/20 disabled:cursor-not-allowed disabled:bg-zinc-300",children:[S?(0,e.jsx)(Ps,{size:"sm"}):(0,e.jsx)($,{name:"Save",size:16}),"Save labor targets"]})})]}):null,p?(0,e.jsx)("p",{className:"mt-3 text-sm text-zinc-600","data-testid":"labor-target-view-as-notice",role:"status",children:o("scheduling.attendance.viewAsUnavailable")}):null,!p&&!a?(0,e.jsx)("p",{className:"mt-3 text-sm text-zinc-600",children:"Ask an owner or admin to change these targets."}):null]})};function bn({profile:t,user:s,tenant:a,userStore:l="",canSeeAllStores:r=!1,isOwner:d=!1,isAdmin:n=!1,isCorporate:x=!1,isManagerOnly:o=!1,isSuperAdmin:b=!1,isTeamLead:u=!1,isTeamMember:S=!1,isModuleAllowed:v=()=>!1,moduleContext:k=null,onNavigate:C=()=>{},now:g}){const{t:f,lang:j}=Ze(),p=Er({tenant:a,profile:t}),E=fa(a),J=wr(g,E),ue=(0,i.useMemo)(()=>xa(J,E),[J,E]),K=(0,i.useMemo)(()=>Ea({tenant:a,userStore:l}),[a,l]),y=(0,i.useMemo)(()=>Ra({storeOptions:K,userStore:l,canSeeAllStores:r,isManagerOnly:o}),[r,o,K,l]),L=(0,i.useMemo)(()=>Ia({moduleContext:k,authorizedStores:y,now:J,timeZone:E}),[y,k,k?.endDate,k?.period,k?.startDate,k?.stores,k?.weekStart,J,E]),me=Sr({moduleContext:k,navigationScope:L,authorizedStores:y,now:g,timeZone:E,onNavigate:C,isManagerOnly:o,canSeeAllStores:r,tenantId:p,userKey:String(t?.uid||s?.uid||"").trim()}),w=L,N=w.weekStart,Mt=(0,i.useMemo)(()=>Es(N,6),[N]),et=(0,i.useMemo)(()=>Es(N,-21),[N]),Ce=w.startDate,Ae=w.endDate,Le=(0,i.useMemo)(()=>gs(Ce,Ae),[Ae,Ce]),tt=Le[Le.length-1]||N,oe=L.emptySelection===!0,Hs=za({emptySelection:oe,hasExplicitStores:L.hasExplicitStores,canSeeAllStores:r}),Ms=o?String(l||"").trim():"",F=r&&Hs&&!Ms,G=jr(oe||F?[]:L.selectedStores),st=(0,i.useMemo)(()=>Rr({tenant:a,storeOptions:K}),[a,K]),Vs=Ws(st),[pe,Vt]=(0,i.useState)(st);(0,i.useEffect)(()=>{Vt(st)},[Vs,st]);const se=(0,i.useMemo)(()=>Tr(a,pe),[a,pe]),V=Na({emptySelection:oe,queryStoreNames:G,hubCanSeeAllStores:F,userStore:l,storeOptions:K}),be=G.length>0?G:K,Ut=(0,i.useMemo)(()=>Pr({canSeeAllStores:r,selectedStore:V,storeOptions:K}),[r,V,K]),Y=v("scheduling")===!0,{liveSalariedEmployees:vt,liveSalariedReady:at,liveSalariedTruncated:Kt,liveSalariedF
1ailed:Gt}=dr({tenantId:p,selectedStore:V,canSeeAllStores:r,canReadScheduling:Y,emptyStoreSelection:oe}),rt=v("payrollRecon")===!0,Nt=Y&&v("decliningBalance")===!0,Z=Y&&nr({tenantId:rr({tenant:a,profile:t}),tenant:se||{},profile:t||{}}),zt=(0,i.useMemo)(()=>lr(se||{}),[se]),Yt=!S&&(d||n||o||b||u),qt=!!(d||n||b||x||o&&!u&&!S),Us=!S&&(d||n||b),[ae,De]=(0,i.useState)([]),[Ks,Gs]=(0,i.useState)(0),[Qt,Jt]=(0,i.useState)([]),[ge,fe]=(0,i.useState)([]),[Xt,Zt]=(0,i.useState)([]),[kt,ye]=(0,i.useState)([]),[es,He]=(0,i.useState)([]),[Ys,Ee]=(0,i.useState)([]),[Ct,Re]=(0,i.useState)([]),[Te,Se]=(0,i.useState)([]),[At,we]=(0,i.useState)([]),[nt,lt]=(0,i.useState)(!0),[ts,ss]=(0,i.useState)(""),[R,je]=(0,i.useState)(()=>Tt()),[as,it]=(0,i.useState)({}),[rs,ot]=(0,i.useState)({}),[ve,ct]=(0,i.useState)(""),Lt=(0,i.useRef)(new Set),Ne=(0,i.useRef)("");(0,i.useEffect)(()=>{const m={selectedStores:G,unconstrainedAllStores:F},P=or({queryStoreNames:G,hubCanSeeAllStores:F,selectedStore:V}),O=(c,_,B=[])=>cr({db:ke,collectionName:c,constraints:_,extras:B,storeScope:P}),W=Nt||Z,A=Z||r&&Y,T=Tt({canReadScheduling:Y,shouldLoadForecastRows:W,canReadPayrollRecon:rt,shouldLoadToastSales:A,aiWeeklyCoachEnabled:Z});if(!p||oe){Ne.current="",De([]),fe([]),ye([]),Ee([]),Re([]),He([]),Se([]),we([]),je(Tt()),lt(!1);return}const H=p;Ne.current=H,De(c=>de(c,m)),fe(c=>de(c,m)),ye(c=>de(c,m)),Ee(c=>de(c,m)),Re(c=>de(c,m)),Se(c=>de(c,m)),we(c=>de(c,m)),lt(!0),ss(""),je(c=>({...T,salaryBasis:c.salaryBasis}));const I=[];let X=!1,Ue=(Y?2:0)+(W?1:0)+(rt?1:0)+(A?1:0)+(Z?1:0);if(Ue===0){De([]),fe([]),ye([]),Ee([]),Re([]),He([]),Se([]),we([]),je(c=>({...T,salaryBasis:c.salaryBasis})),lt(!1);return}const Ke=new Set,ee={schedule:{},toastSales:{},toastTime:{}},te=(c,_)=>{X||(je(B=>({...B,[c]:_})),!Ke.has(c)&&(Ke.add(c),Ue-=1,(Ue<=0||Ke.size>0)&&lt(!1)))},Ge=c=>{c==="employees"&&De([]),c==="schedule"&&(ee.schedule={},fe([]),ye([])),c==="forecast"&&(Ee([]),Re([])),c==="payroll"&&He([]),c==="toastSales"&&(ee.toastSales={},Se([])),c==="toastTime"&&(ee.toastTime={},we([]))},bt=()=>console.error({code:"labor_hub_roster_failed",tenantId:p,store:V}),M=c=>{X||(c==="employees"?bt():console.error({code:`labor_hub_${c}_failed`,tenantId:p,store:V}),Ge(c),ss(Dr),te(c,h.error))};if(Y){I.push(Oe(O(q.employees,[D("tenantId","==",p)],[le(250)]),U=>{if(X||Ne.current!==H)return;const ne=U.docs.map($e=>({id:$e.id,...$e.data()}));De(de(ne,m)),ne.length>=250&&Gs($e=>$e+1),te("employees",h.loaded)},U=>{Ne.current===H&&M("employees",U)},{limitCount:250}));const c=Math.max((F?y.length:G.length)||0,1),_=Ss({unitCount:Math.max(Le.length,1),storeCount:c}),B=Ss({unitCount:Math.max(gs(et,tt).length,1),storeCount:c}),Fe=(U=[])=>(Array.isArray(U)?U:[]).map(ne=>({id:ne.id,...ne.data()})),ds=(U,ne,{incomplete:$e=!1,settle:ta=!1}={})=>{if(X||Ne.current!==H)return;if($e){ee.schedule={},fe([]),ye([]),te("schedule",h.incomplete);return}const sa=Fe(ne),us=Qe(Object.assign(ee.schedule,{[U]:sa}),m);fe(us),ye(us),ta&&te("schedule",h.loaded)},pt=[D("tenantId","==",p)];Le.length>1?(pt.push(D("weekStart",gt,Le[0])),pt.push(D("weekStart",ft,tt))):pt.push(D("weekStart","==",N)),I.push(ys(O(q.schedules,pt,[le(yt)]),{pageSize:yt,maxDocs:_,onDocs:(U,{incomplete:ne}={})=>{ds("week",U,{incomplete:ne,settle:!0})},onError:U=>{Ne.current===H&&M("schedule",U)}}));const ea=[D("tenantId","==",p),D("weekStart",gt,et),D("weekStart",ft,tt)];I.push(ys(O(q.schedules,ea,[le(yt)]),{pageSize:yt,maxDocs:B,onDocs:(U,{incomplete:ne}={})=>{ds("variance",U,{incomplete:ne,settle:!1})},onError:U=>{Ne.current===H&&M("schedule",U)}}))}else De([]),fe([]),ye([]);if(W){const c=F?100:25;I.push(Oe(O(q.decliningBalance,[D("tenantId","==",p),D("weekOf","==",N)],[le(c)]),_=>{if(X)return;const B=ka(_.docs.map(Fe=>({id:Fe.id,...Fe.data()})).filter(Fe=>Fe.isDeleted!==!0));Ee(Nt?B:[]),Re(Z?B:[]),te("forecast",h.loaded)},_=>M("forecast",_),{limitCount:c}))}else Ee([]),Re([]);const Ye=[D("tenantId","==",p),D("businessDate",gt,Ce),D("businessDate",ft,Ae),ms("businessDate","desc")],cs=[D("tenantId","==",p),D("businessDate",gt,et),D("businessDate",ft,Mt),ms("businessDate","desc")],ht=F?100:20,xt=F?400:Math.max(G.length*32,32);return A?(I.push(Oe(O(q.toastDailySummary,Ye,[le(ht)]),c=>{if(X)return;const _=c.docs.map(B=>({id:B.id,...B.data()}));Se(Qe(Object.assign(ee.toastSales,{period:_}),m)),te("toastSales",h.loaded)},c=>M("toastSales",c),{limitCount:ht})),I.push(Oe(O(q.toastDailySummary,cs,[le(xt)]),c=>{if(X)return;const _=c.docs.map(B=>({id:B.id,...B.data()}));Se(Qe(Object.assign(ee.toastSales,{variance:_}),m))},c=>M("toastSales",c),{limitCount:xt}))):Se([]),Z?(I.push(Oe(O(q.toastTimeEntries,Ye,[le(ht)]),c=>{if(X)return;const _=c.docs.map(B=>({id:B.id,...B.data()}));we(Qe(Object.assign(ee.toastTime,{period:_}),m)),te("toastTime",h.loaded)},c=>M("toastTime",c),{limitCount:ht})),I.push(Oe(O(q.toastTimeEntries,cs,[le(xt)]),c=>{if(X)return;const _=c.docs.map(B=>({id:B.id,...B.data()}));we(Qe(Object.assign(ee.toastTime,{variance:_}),m))},c=>M("toastTime",c),{limitCount:xt}))):we([]),rt?I.push($s(_e(Je(ke,q.payrollRecon),D("tenantId","==",p),le(25)),c=>{X||(He(c.docs.map(_=>({id:_.id,..._.data()}))),te("payroll",h.loaded))},c=>M("payroll",c))):He([]),()=>{X=!0,I.forEach(c=>{try{c()}catch{}})}},[Z,y,Nt,rt,Y,r,oe,F,Le,G,Ae,Ce,tt,V,p,et,Mt,N]);const ce=(0,i.useMemo)(()=>R.schedule===h.loaded?de(Ca({rows:ge,startDate:Ce,endDate:Ae,weekStart:N}),{selectedStores:G,unconstrainedAllStores:F}):[],[F,G,Ae,Ce,ge,R.schedule,N]),Ie=R.forecast===h.loaded?Ys:[],dt=Cs("getDocs"),ns=Cs("startAfter"),he=Y&&typeof dt=="function",ls=(R.employees===h.loaded||R.employees===h.error)&&(R.schedule===h.loaded||R.schedule===h.error),qs=(0,i.useMemo)(()=>Da({employees:ae,scheduleRows:ce,weekStart:N}),[ae,ce,N]);(0,i.useEffect)(()=>{const m=O=>{je(W=>W.salaryBasis===O?W:{...W,salaryBasis:O})};if(!p||oe||!Y||!he){m(h.unavailable);return}if(!ls){m(h.pending);return}let P=!1;return m(h.pending),(async()=>{const O=await Pa({db:ke,collection:Je,query:_e,where:D,limit:le,startAfter:ns,getDocs:dt,collectionName:q.employees,tenantId:p});if(P)return;
1if(O.status!==h.loaded)throw new Error("salary roster incomplete");const W=await dt(_e(Je(ke,q.schedules),D("tenantId","==",p),D("weekStart","==",N)));P||(Jt(O),Zt(W.docs.map(A=>({id:A.id,...A.data()}))),je(A=>({...A,salaryBasis:h.loaded})))})().catch(()=>{P||(console.error({code:"labor_hub_roster_failed",tenantId:p,store:V}),Jt([]),Zt([]),je(O=>({...O,salaryBasis:h.error})))}),()=>{P=!0}},[he,Y,oe,ls,dt,ns,ya({snapshotVersion:(0,i.useMemo)(()=>La(ae),[ae]),liveEmployees:ae,liveEpoch:Ks,liveSalariedEmployees:vt}),V,p,N]);const ut=(0,i.useMemo)(()=>ps(ps(he?Qt:ae,vt),ae),[he,ae,vt,Qt]),mt=(0,i.useMemo)(()=>ja(he?Xt:ce,ce,{weekStart:N}),[ce,he,Xt,N]),Me=(0,i.useMemo)(()=>Ta({rows:ce,tenantId:p,weekStart:N,forecastRows:Ie}),[Ie,ce,p,N]),xe=(0,i.useMemo)(()=>xs({tenant:se,canSeeAllStores:F,selectedStore:V,selectedStores:G,userStore:l,storeOptions:be,storeNames:be,salesRows:Te}),[se,F,be,G,V,Te,l]),is=xe.targetLaborPct,Qs=(0,i.useMemo)(()=>{if(F||G.length>1)return Fr(Ie,["forecastSales"]);const m=Ie[0];return Number(m?.forecastSales||0)},[Ie,F,G.length]),Js=wa({period:w.period,startDate:w.startDate,endDate:w.endDate,weekStart:w.weekStart}),os=Number(R.schedule===h.loaded?Js?Me?.projectedSales||Me?.salesForecast||(R.forecast===h.loaded?Qs:R.forecast===h.unavailable?a?.settings?.weeklySalesForecast:0):Sa({schedule:Me,forecastRows:Ie,startDate:w.startDate,endDate:w.endDate}):0),Ve=(0,i.useMemo)(()=>!Y||R.employees===h.error?R:Gt||!at||Kt?{...R,salaryBasis:h.pending}:R,[Y,Gt,at,Kt,R]),z=(0,i.useMemo)(()=>va({now:J,weekStart:w.weekStart,startDate:w.startDate,endDate:w.endDate,period:w.period,store:V,stores:F?[]:be,navigationStore:Ut,canSeeAllStores:F,canManageSchedule:Yt,employees:ae,salaryEmployees:ut,schedule:Me,salaryScheduleRows:mt,liveScheduleRows:ce,payrollRows:es,targetLaborPct:is,targetLaborSource:xe.source,targetLaborSourceLabel:xe.sourceLabel,storeCount:xe.storeCount||0,projectedSales:os,sourceStatuses:Ve,salaryBasisLiveReady:at,isModuleAllowed:v,tenant:se,includeSalariedInLaborPct:pe?.includeSalariedInLaborPct!==!1}),[Yt,F,be,ae,ut,v,J,es,os,Me,mt,ce,qs,V,Ut,xe.source,xe.sourceLabel,xe.storeCount,w.endDate,w.period,w.startDate,w.weekStart,Ve,at,R,is,N,se,pe?.includeSalariedInLaborPct]),re=(0,i.useMemo)(()=>{if(!Z||["schedule","forecast","toastSales","toastTime"].some(W=>R[W]!==h.loaded))return[];const m=pe?.includeSalariedInLaborPct!==!1&&(R.employees===h.error||R.employees===h.pending||Ve.salaryBasis===h.error||Ve.salaryBasis===h.pending),P=ut,O=he?[...ge.filter(W=>String(W?.weekStart||"").slice(0,10)!==N),...mt]:ge;return er(Br({canSeeAllStores:F,selectedStore:V,storeOptions:be,rows:[...Te,...At,...Ct,...ge]}),zt).map(W=>{const A=tr({tenantId:p,store:W,weekStart:N,asOfDate:ue,actualSalesRows:Te}),T=xs({tenant:se,store:W});return Qa({tenantId:p,store:W,weekStart:N,asOfDate:A,tenant:se,storeConfigs:se?.settings?.stores||[],actualSalesRows:Te,forecastRows:Ct,timeEntryRows:At,scheduleRows:ar([...ge,...kt]),employees:P,salaryEmployees:P,salaryScheduleRows:O,salaryBasisIncomplete:m,targetLaborPct:T.targetLaborPct,targetLaborSource:T.source,targetLaborSourceLabel:T.sourceLabel,settings:zt,sourceLabels:{laborTarget:T.sourceLabel},permissionScope:r?"all-stores":"single-store"})})},[Z,zt,ue,r,Ct,ut,mt,he,se,pe?.includeSalariedInLaborPct,kt,ge,V,R,Ve,K,p,Te,At,N]),Dt=Z&&r&&(d||n||x||b),ze=(0,i.useMemo)(()=>ve&&re.find(m=>Q(m.store)===Q(ve))||null,[ve,re]);(0,i.useEffect)(()=>{if(!Dt){ve&&ct("");return}ve&&!ze&&ct("")},[Dt,ze,ve]),(0,i.useEffect)(()=>{if(nt||!Z||re.length===0){it({}),ot({}),nt||(Lt.current=new Set);return}let m=!1;const P=re.reduce((A,T)=>{const H=St(T);return A[H]=ws(T)||Ot(T,j),A},{}),O=re.reduce((A,T)=>{const H=St(T),I=js(T);return I&&(A[H]=I),A},{});it(P),ot(O);try{Ft({user:s,profile:t})}catch{return()=>{m=!0}}const W=ma(oa,"buildAiWeeklyCoach");return re.forEach(A=>{const T=St(A);Lt.current.has(T)||(Lt.current.add(T),W({fact:Ja(A)}).then(H=>{const I=H?.data&&typeof H.data=="object"?H.data:{}
1,X=typeof I.copy=="string"?I.copy.trim():"",Ue=!I.store||Q(I.store)===Q(A.store),Ke=!I.weekStart||String(I.weekStart)===String(A.weekStart);if(!Ue||!Ke||m)return;const ee=I.attendance&&typeof I.attendance=="object"?I.attendance:null,te=String(ee?.status||"").trim().toLowerCase(),{retained:Ge,resolvedAttendance:bt}=Ar({copy:X,attendance:ee,cached:ws(A),cachedAttendance:js(A)});Ge&&(Za(A,Ge,bt),it(M=>({...M,[T]:Ge})),ot(te==="stale"||te==="unavailable"?M=>({...M,[T]:{status:te,verifiedAt:String(bt?.verifiedAt||"").trim()}}):M=>{if(!M[T])return M;const Ye={...M};return delete Ye[T],Ye}))}).catch(()=>{m||it(H=>({...H,[T]:H[T]||Ot(A,j)}))}))}),()=>{m=!0}},[Z,nt,re,j,s,t]);const Pe=(0,i.useCallback)((m,P)=>{!m||!v(m)||C(m,P||null)},[v,C]),Xs=(0,i.useCallback)(()=>{Fa({message:z.aiAssist.message,activeContext:ir(z.aiAssist.context)})},[z.aiAssist.context,z.aiAssist.message]);if(!p)return(0,e.jsxs)("div",{className:"mg-empty-state rounded-[24px] border border-zinc-200 bg-white p-6 text-center shadow-card",children:[(0,e.jsx)("p",{className:"text-sm font-semibold text-zinc-900",children:"Labor & Scheduling Hub needs a tenant workspace."}),(0,e.jsx)("p",{className:"mt-1 text-sm text-zinc-600",children:"Open Dashboard or ask an admin to confirm your workspace access."})]});if(oe)return(0,e.jsx)(It,{laborFilter:me,hubPeriod:w,storesAttr:"",empty:!0,children:(0,e.jsxs)("section",{"data-testid":"labor-hub-empty-stores",role:"status",className:"rounded-[24px] border border-amber-200 bg-amber-50/80 px-4 py-6 text-center shadow-sm sm:px-6",children:[(0,e.jsx)("h2",{className:"text-base font-bold text-zinc-950",children:f("scheduling.hub.noStoresSelected")}),(0,e.jsx)("p",{className:"mt-1 text-sm text-zinc-600",children:f("scheduling.hub.noStoresSelectedHint")})]})});if(nt)return(0,e.jsx)(It,{laborFilter:me,hubPeriod:w,storesAttr:F?"":be.join("|"),loading:!0,children:(0,e.jsx)(Wr,{})});const Zs=w.period==="today"?f("scheduling.hub.scopeToday"):f("scheduling.hub.scopeWeek",{weekStart:w.weekStart});return(0,e.jsxs)(It,{laborFilter:me,hubPeriod:w,storesAttr:F?"":be.join("|"),children:[(0,e.jsxs)("section",{className:"mg-hub-header rounded-[28px] border border-zinc-200 bg-white p-4 shadow-sm sm:p-6",children:[(0,e.jsxs)("div",{className:"flex flex-col gap-4 lg:flex-row lg:items-start lg:justify-between",children:[(0,e.jsxs)("div",{className:"min-w-0",children:[(0,e.jsx)("p",{className:"mg-eyebrow text-zinc-500",children:"Labor & Scheduling Hub"}),(0,e.jsx)("h2",{"data-testid":"labor-hub-answer",className:"mt-2 text-2xl font-bold leading-tight text-zinc-900 sm:text-3xl",children:z.state==="incomplete"?f(`laborHub.salesCoverage.answer.${z.salesCoverageScope||"day"}`,{store:(z.metrics.find(m=>m.id==="planned-labor")?.missingSalesStores||[]).join(" and ")}):z.answerKey?f(z.answerKey):z.answer}),(0,e.jsxs)("p",{"data-testid":"labor-hub-scope",className:"mt-2 text-sm text-zinc-600",children:[z.storeLabel," · ",Zs]})]}),(0,e.jsx)("button",{type:"button","data-testid":"labor-hub-primary-action",onClick:()=>Pe(z.primaryAction.moduleId,z.primaryAction.context),disabled:!z.primaryAction.moduleId,className:"mg-button mg-button--primary min-h-[52px] w-full rounded-2xl px-5 py-3 text-sm text-white focus:outline-none focus:ring-4 focus:ring-brand-500/20 disabled:cursor-not-allowed disabled:bg-zinc-300 sm:w-auto",children:(0,e.jsxs)("span",{className:"inline-flex items-center justify-center gap-2",children:[z.state==="incomplete"?f("laborHub.salesCoverage.action"):z.primaryAction.label,(0,e.jsx)($,{name:"ArrowRight",size:16})]})})]}),(0,e.jsx)("p",{"data-testid":"labor-hub-primary-helper",className:"mt-3 text-sm text-zinc-600",children:z.state==="incomplete"?f("laborHub.salesCoverage.actionHelper"):z.primaryAction.helper}),ts&&(0,e.jsx)("div",{className:"mt-4 rounded-xl border border-amber-200 bg-amber-50 px-3 py-2 text-sm text-amber-800",children:ts})]}),(0,e.jsx)("section",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2 xl:grid-cols-4","aria-label":f("scheduling.hub.summaryAria"),children:z.metrics.map(m=>(0,e.jsx)(Ur,{metric:m},m.id))}),(0,e.jsx)(Xr,{tenantId:p,settings:pe,canEdit:Us,onSaved:Vt,operatingTarget:xe,canSeeAllStores:r,profile:t,user:s}),Y?(0,e.jsx)(mr,{summary:Ga({asOfDate:ue,includeNames:qt,employeeById:new Map(ae.filter(m=>String(m?.tenantId||"")===p).map(m=>[m.id,m])),incidents:(R.schedule===h.loaded?kt.filter(m=>String(m?.tenantId||"")===p):[]).flatMap(m=>sr(m.id,m,r?"":V))}),canSeeNames:qt,loading:R.schedule===h.pending,unavailable:R.schedule===h.error},p):null,Dt?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(qr,{facts:re,selectedStore:ve,onSelectStore:ct}),ze?null:(0,e.jsx)(Pt,{facts:re,lang:j,t:f,onOpenSchedule:(m,P)=>Pe("scheduling",{source:"laborSchedulingHub",tab:"schedule",weekStart:m||N,store:P,selectedStore:P})}),ze?(0,e.jsxs)("section",{"data-testid":"weekly-coach-drilldown",className:"space-y-3",children:[(0,e.jsxs)("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("p",{className:"text-xs font-semibold uppercase tracking-wide text-zinc-500",children:"Store detail"}),(0,e.jsx)("h3",{className:"text-base font-bold text-zinc-900",children:ze.store})]}),(0,e.jsxs)("button",{type:"button","data-testid":"weekly-coach-rollup-back",onClick:()=>ct(""),className:"mg-button mg-button--outline inline-flex min-h-[44px] w-fit items-center gap-2 rounded-xl border border-zinc-200 bg-white px-3 py-2 text-sm text-zinc-700 hover:bg-zinc-50 focus:outline-none focus:ring-4 focus:ring-brand-500/15",children:[(0,e.jsx)($,{name:"ChevronLeft",size:16}),"Back to all stores"]})]}),(0,e.jsx)(Is,{facts:[ze],copyByKey:as,attendanceByKey:rs}),(0,e.jsx)(Pt,{facts:[ze],lang:j,t:f,onOpenSchedule:(m,P)=>Pe("scheduling",{source:"laborSchedulingHub",tab:"schedule",weekStart:m||N,store:P,selectedStore:P})})]}):null]}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(Is,{facts:re,copyByKey:as,attendanceByKey:rs}),(0,e.jsx)(Pt,{facts:re,lang:j,t:f,onOpenSchedule:(m,P)=>Pe("scheduling",{source:"laborSchedulingHub",tab:"schedule",weekStart:m||N,store:P,selectedStore:P})})]}),(0,e.jsxs)("div",{className:"grid grid-cols-1 gap-4 xl:grid-cols-[minmax(0,1.3fr)_minmax(320px,0.7fr)]",children:[(0,e.jsxs)("section",{className:"rounded-[24px] border border-zinc-200 bg-white p-4 shadow-card sm:p-5",children:[(0,e.jsxs)("div",{className:"mb-3 flex items-center justify-between gap-3",children:[(0,e.jsx)("h3",{className:"mg-heading-section text-base font-bold text-zinc-900",children:"Needs attention"}),(0,e.jsxs)("span",{className:"mg-chip rounded-full border border-zinc-200 bg-zinc-50 px-2.5 py-1 text-xs text-zinc-600",children:[z.attentionItems.length," item",z.attentionItems.length===1?"":"s"]})]}),(0,e.jsx)("div",{className:"space-y-3",children:z.attentionItems.map(m=>(0,e.jsx)(Gr,{item:Kr(m,f),onNavigate:Pe},m.id))})]}),(0,e.jsxs)("aside",{className:"space-y-4",children:[(0,e.jsxs)("section",{className:"rounded-[24px] border border-brand-200 bg-brand-50 p-4 shadow-card sm:p-5",children:[(0,e.jsxs)("div",{className:"flex items-start gap-3",children:[(0,e.jsx)("span",{className:"inline-flex h-10 w-10 shrink-0 items-center justify-center rounded-xl bg-brand-500 text-white",children:(0,e.jsx)($,{name:"Sparkles",size:18})}),(0,e.jsxs)("div",{className:"min-w-0",children:[(0,e.jsx)("h3",{className:"text-base font-bold text-zinc-900",children:z.aiAssist.title}),(0,e.jsx)("p",{className:"mt-1 text-sm text-zinc-700",children:z.aiAssist.detail})]})]}),(0,e.jsxs)(ba,{"data-testid":"labor-hub-ai-assist",onClick:Xs,className:"mt-4 w-full justify-center",children:[(0,e.jsx)($,{name:"Sparkles",size:16}),z.aiAssist.buttonLabel]})]}),(0,e.jsxs)("section",{className:"rounded-[24px] border border-zinc-200 bg-white p-4 shadow-card sm:p-5",children:[(0,e.jsx)("h3",{className:"mg-heading-section text-base font-bold text-zinc-900",children:"Qu
1ick access"}),(0,e.jsx)("div",{className:"mt-3 grid grid-cols-1 gap-3",children:z.deepLinks.map(m=>(0,e.jsx)(Yr,{link:m,onNavigate:Pe},m.id))})]})]})]})]})}export{bn 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.