1import{al as K,r as g,ac as F,c1 as P,ad as b,ap as j,K as x,j as e,a6 as R,bB as T,f as B,m as y,U as Q,T as _,q as M,k as U,b1 as N,M as W,C as H}from"./index-B01jGDSO.js";import{u as $}from"./useLiveBoardSettings-CpPzpzwQ.js";import{H as z}from"./house-BstGMZ7_.js";import{C as v}from"./circle-play-BDKAxBly.js";import{R as G}from"./refresh-cw-DwcaIqPh.js";import{C as V}from"./circle-pause-Bnr0_pyu.js";import{p as Y}from"./parseISO-Vp8wWM8k.js";const D={scheduled:{label:"Not Started",icon:e.jsx(H,{className:"h-3.5 w-3.5"}),className:"bg-muted text-muted-foreground border-border"},in_progress:{label:"In Progress",icon:e.jsx(v,{className:"h-3.5 w-3.5"}),className:"bg-primary/10 text-primary border-primary/30"},completed:{label:"Complete",icon:e.jsx(M,{className:"h-3.5 w-3.5"}),className:"bg-green-100 text-green-800 border-green-200 dark:bg-green-900/30 dark:text-green-400 dark:border-green-800"},on_hold:{label:"Issue Flagged",icon:e.jsx(_,{className:"h-3.5 w-3.5"}),className:"bg-orange-100 text-orange-800 border-orange-200 dark:bg-orange-900/30 dark:text-orange-400 dark:border-orange-800"},cancelled:{label:"Cancelled",icon:e.jsx(V,{className:"h-3.5 w-3.5"}),className:"bg-destructive/10 text-destructive border-destructive/20"}};function X({job:r,index:c,showAddress:u,showTime:t,showNumber:d}){const i=D[r.status]||D.scheduled,o=r.scheduled_start?j(Y(r.scheduled_start),"h:mm a"):"â";return e.jsxs("div",{className:N("flex-shrink-0 w-[220px] rounded-lg border-2 p-3 transition-all",i.className,r.status==="in_progress"&&"ring-2 ring-primary/40 shadow-md"),children:[e.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[e.jsxs("span",{className:"text-xs font-bold opacity-60",children:["Job ",c+1]}),e.jsxs("div",{className:"flex items-center gap-1 text-xs font-medium",children:[i.icon,i.label]})]}),e.jsx("p",{className:"text-sm font-semibold truncate",children:r.project_name}),u!==!1&&r.project_address&&e.jsxs("p",{className:"text-xs opacity-70 truncate flex items-center gap-1 mt-0.5",children:[e.jsx(W,{className:"h-3 w-3 shrink-0"}),r.project_address]}),e.jsxs("div",{className:"flex items-center justify-between mt-2 text-xs opacity-60",children:[t!==!1?e.jsx("span",{children:o}):e.jsx("span",{}),d!==!1&&e.jsxs("span",{children:["#",r.job_number]})]})]})}function Z({name:r,jobs:c,clockedIn:u,showAddress:t,showTime:d,showNumber:i}){const o=c.find(n=>n.status==="in_progress"),w=c.filter(n=>n.status==="completed").length,m=c.some(n=>n.status==="on_hold");return e.jsxs("div",{className:"border rounded-xl bg-card overflow-hidden",children:[e.jsxs("div",{className:N("flex items-center justify-between px-4 py-3 border-b",m?"bg-orange-50 dark:bg-orange-950/20":"bg-muted/40"),children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:N("h-3 w-3 rounded-full",u?"bg-green-500 animate-pulse":"bg-muted-foreground/30")}),e.jsx("h3",{className:"font-semibold text-sm",children:r}),m&&e.jsxs(y,{variant:"outline",className:"text-[10px] bg-orange-100 text-orange-800 border-orange-200",children:[e.jsx(_,{className:"h-2.5 w-2.5 mr-0.5"})," Issue"]})]}),e.jsxs("div",{className:"flex items-center gap-3 text-xs text-muted-foreground",children:[e.jsxs("span",{children:[w,"/",c.length," done"]}),o&&e.jsxs(y,{variant:"outline",className:"text-[10px] bg-primary/10 text-primary border-primary/30",children:[e.jsx(v,{className:"h-2.5 w-2.5 mr-0.5"})," Active"]})]})]}),e.jsx("div",{className:"flex gap-3 p-3 overflow-x-auto",children:c.length===0?e.jsx("p",{className:"text-xs text-muted-foreground py-4 px-2",children:"No jobs scheduled"}):c.map((n,f)=>e.jsx(X,{job:n,index:f,showAddress:t,showTime:d,showNumber:i},n.id))})]})}function oe(){const r=K(),[c,u]=g.useState(new Date),{isVisible:t}=$("crew_board");g.useEffect(()=>{const s=setInterval(()=>u(new Date),3e4);return()=>clearInterval(s)},[]);const d=F(new Date).toISOString(),i=P(new Date).toISOString(),{data:o=[],isLoading:w}=b({queryKey:["crew-dashboard-jobs",j(new Date,"yyyy-MM-dd")],queryFn:async()=>{const{data:s,error:a}=await x.from("jobs").select(` 2 *, 3 client:clients(name), 4 assigned_to_profile:profiles!jobs_assigned_to_fkey(full_name, id) 5 `).or(`scheduled_start.gte.${d},status.eq.in_progress`).lte("scheduled_start",i).order("scheduled_start",{ascending:!0});if(a)throw a;return s||[]},refetchInterval:3e4}),{data:m=[]}=b({queryKey:["crew-dashboard-time",j(new Date,"yyyy-MM-dd")],queryFn:async()=>{const{data:s,error:a}=await x.from("time_entries").select("id, employee_id, clock_in, clock_out, job_id").gte("clock_in",d).is("clock_out",null);if(a)throw a;return s||[]},refetchInterval:3e4}),{data:n=[]}=b({queryKey:["crew-definitions"],queryFn:async()=>{const{data:s,error:a}=await x.from("crew_definitions_legacy").select("*").order("sort_order",{ascending:!0});if(a)throw a;return s||[]}});b({queryKey:["profiles-all"],queryFn:async()=>{const{data:s,error:a}=await x.from("profiles").select("id, full_name, user_id");if(a)throw a;return s||[]}}),g.useEffect(()=>{const s=x.channel("crew-dashboard-realtime").on("postgres_changes",{event:"*",schema:"public",table:"jobs"},()=>{r.invalidateQueries({queryKey:["crew-dashboard-jobs"]})}).on("postgres_changes",{event:"*",schema:"public",table:"time_entries"},()=>{r.invalidateQueries({queryKey:["crew-dashboard-time"]})}).subscribe();return()=>{x.removeChannel(s)}},[r]);const f=g.useMemo(()=>{const s=new Set(m.map(l=>l.employee_id)),a=new Map;
5n.forEach(l=>{a.set(`crew-${l.id}`,{name:l.crew_name,jobs:[],clockedIn:!1})}),o.forEach(l=>{var E,q;const h=(E=l.assigned_to_profile)==null?void 0:E.id,O=((q=l.assigned_to_profile)==null?void 0:q.full_name)||"Unassigned",p=h||"unassigned";a.has(p)||a.set(p,{name:O,jobs:[],clockedIn:h?s.has(h):!1}),a.get(p).jobs.push(l),h&&s.has(h)&&(a.get(p).clockedIn=!0)});const I=Array.from(a.values()),S=I.filter(l=>l.jobs.length>0);return S.length>0?S:I},[o,m,n]),J=o.length,L=o.filter(s=>s.status==="completed").length,k=o.filter(s=>s.status==="in_progress").length,C=o.filter(s=>s.status==="on_hold").length,A=new Set(m.map(s=>s.employee_id)).size;return w?e.jsx("div",{className:"h-screen w-screen flex items-center justify-center bg-background",children:e.jsx(R,{className:"h-10 w-10 animate-spin text-primary"})}):e.jsxs("div",{className:"h-screen w-screen flex flex-col bg-background overflow-hidden select-none",children:[e.jsxs("header",{className:"flex items-center justify-between px-6 py-3 border-b bg-card shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(T,{to:"/dashboard",className:"flex items-center gap-2 hover:opacity-70 transition-opacity",title:"Back to Dashboard",children:e.jsx(z,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(B,{className:"h-5 w-5 text-primary"}),e.jsx("h1",{className:"text-lg font-bold tracking-tight",children:"CREW BOARD"})]}),t("header_date")&&e.jsx(y,{variant:"outline",className:"text-xs",children:j(c,"EEEE, MMM d · h:mm a")})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[t("clocked_in_count")&&e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx(Q,{className:"h-4 w-4"}),e.jsxs("span",{className:"font-medium",children:[A," clocked in"]})]}),t("clocked_in_count")&&(t("active_jobs")||t("flagged_issues")||t("completion_count"))&&e.jsx("div",{className:"h-4 w-px bg-border"}),e.jsxs("div",{className:"flex items-center gap-3 text-xs",children:[t("active_jobs")&&k>0&&e.jsxs("span",{className:"flex items-center gap-1 text-primary font-medium",children:[e.jsx(v,{className:"h-3.5 w-3.5"})," ",k," active"]}),t("flagged_issues")&&C>0&&e.jsxs("span",{className:"flex items-center gap-1 text-orange-600 font-medium",children:[e.jsx(_,{className:"h-3.5 w-3.5"})," ",C," flagged"]}),t("completion_count")&&e.jsxs("span",{className:"flex items-center gap-1 text-muted-foreground",children:[e.jsx(M,{className:"h-3.5 w-3.5"})," ",L,"/",J]})]}),e.jsx("div",{className:"h-4 w-px bg-border"}),t("live_indicator")&&e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground",children:[e.jsx(G,{className:"h-3 w-3 animate-spin",style:{animationDuration:"4s"}}),"Live"]})]})]}),t("crew_lanes")&&e.jsx("main",{className:"flex-1 overflow-y-auto p-4 space-y-3",children:f.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-muted-foreground",children:[e.jsx(U,{className:"h-16 w-16 mb-4 opacity-30"}),e.jsx("p",{className:"text-lg font-medium",children:"No jobs scheduled for today"}),e.jsx("p",{className:"text-sm",children:"Jobs will appear here when dispatched from the Schedule."})]}):f.map((s,a)=>e.jsx(Z,{name:s.name,jobs:s.jobs,clockedIn:s.clockedIn,showAddress:t("job_addresses"),showTime:t("job_time_windows"),showNumber:t("job_numbers")},a))}),!t("crew_lanes")&&e.jsx("main",{className:"flex-1"}),e.jsx("footer",{className:"flex items-center justify-center px-6 py-2 border-t bg-card text-[10px] text-muted-foreground shrink-0",children:"READ-ONLY · Auto-updates from dispatch and crew actions · No manual edits"})]})}export{oe 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.