1import{y as He,s as h,j as e,C as b,v as G,w as Z,o as Q,m as S,x as Pe,p as ns,t as ls}from"./index-Btwe7OM_.js";import{r as f}from"./carousel-Ywnn_L1b.js";import{u as pe}from"./useQuery-XvkwiZrA.js";import{u as ye}from"./useMutation-VvhcR3px.js";import{I as os}from"./input-BSdelcww.js";import{T as Ye,a as Xe,b as B,c as ge}from"./tabs-DzCyXoLI.js";import{w as cs}from"./SentryErrorBoundary-CQ8C0IMY.js";import{E as ds,b as ms}from"./pdf-CGsjJpaq.js";import{p as Ce,s as Ee}from"./dateUtils-B345kFLA.js";import{T as us,a as hs,b as xe,c as K,d as xs,e as M}from"./table-D0jRHYTT.js";import{S as ne,a as le,b as oe,c as ce,d as z}from"./select-fPIBti7U.js";import{C as gs,a as ps,b as _s,c as Ne,d as fs}from"./context-menu-BxAYfEOx.js";import{B as C}from"./badge-DZQL15lS.js";import{i as js}from"./nycShuttle-BYGgL6fQ.js";import{D as Le,a as Me,b as bs,c as vs}from"./dialog-Dkcayg94.js";import{u as Ge}from"./use-toast-CZ-k4o9O.js";import{C as ze}from"./checkbox-DM18dQcp.js";import{L as Ze,i as es,x as ys,s as Be,r as $e,Z as Ns,D as ws,t as Cs,bP as Ss,bQ as ks,aw as Ds,F as Je,a3 as Ae,k as de,aF as Ts,H as qs,A as Re,bK as Ie,E as Fs,o as Ps,b9 as Es}from"./icons-EWXH9Ucy.js";import{f as ss}from"./format-yZRq02RC.js";import{P as Ls}from"./PickupSchedulerDialog-DnBb00xB.js";import{s as Ms}from"./startOfQuarter-BDBea39C.js";import{t as we}from"./en-US-N0Vr6b0S.js";import{b as zs,B as Bs,C as We,X as Ve,Y as Ke,T as Qe,L as Oe,d as $s,k as Js,i as As}from"./charts-B0JxqJjf.js";import{s as Rs}from"./subDays-3i9bDBr1.js";import{e as Is}from"./eachDayOfInterval-C0gW3x2w.js";import{e as Ws}from"./eachWeekOfInterval-DNXx6oFO.js";import{I as Vs}from"./InventoryTransferPreviewDialog-CznAW3n2.js";import{u as Ks}from"./useCRMPanel-D3k86e9c.js";import{s as Ue}from"./phoneUtils-zLwIw60D.js";import"./supabase-BSoIuNt1.js";import"./mapbox-gl-B7jh3gon.js";import"./index-BWnZCI9Y.js";import"./index-DJnzKn2Q.js";import"./index-yhi_i3rm.js";import"./index-BdQq_4o_.js";import"./Combination-DlbveIUj.js";import"./index-BUtf7Ub_.js";import"./index-Ilbv7smq.js";import"./index-DPpSed2U.js";import"./index-C8vZXRoo.js";import"./calendar-BfXD-lwW.js";import"./isSameDay-DyQqH76s.js";import"./addDays-DxzYTtkq.js";import"./startOfMonth-BN8AI--O.js";import"./endOfMonth-D6LcxRly.js";import"./addMonths-Bb-OV9Ki.js";import"./differenceInCalendarMonths-X2iIndw0.js";import"./isSameMonth-Dhu_SVov.js";import"./label-B1kcfWwV.js";import"./popover-DWkQuulF.js";import"./index-B3iVyTQb.js";import"./parseISO-ClQgUkVh.js";import"./alert-DfTzsRUZ.js";import"./CRMContext-1pjrmQ5S.js";function Qs(n,p){const m=we(n.start),j=we(n.end);let c=+m>+j;const x=c?+m:+j,u=c?j:m;u.setHours(0,0,0,0),u.setDate(1);let d=1;const i=[];for(;+u<=x;)i.push(we(u)),u.setMonth(u.getMonth()+d);return c?i.reverse():i}const Os=n=>{if(!n||n.length===0)return;const p=["Job Number","Customer Name","Customer Email","Customer Phone","Company Name","Status","Move Type","Origin Address","Destination Address","Scheduled Date","Crew Size","Estimated Hours","Actual Hours","Created Date","Completed Date","Special Instructions"],m=n.map(i=>[i.job_number||"",i.customers?.contact_name||"",i.customers?.email||"",i.customers?.phone||"",i.customers?.company_name||"",i.status||"",i.move_type||i.job_type||"",i.origin_address||"",i.destination_address||"",i.scheduled_date&&Ce(i.scheduled_date)?.toLocaleDateString()||"",i.crew_size?.toString()||"",i.estimated_hours?.toString()||"",i.actual_hours?.toString()||"",new Date(i.created_at).toLocaleDateString(),new Date(i.updated_at).toLocaleDateString(),i.special_instructions||""]),j=[p.join(","),...m.map(i=>i.map(N=>`"${N.replace(/"/g,'""')}"`).join(","))].join(` 2`),c=new Blob([j],{type:"text/csv;charset=utf-8;"}),x=document.createElement("a"),u=URL.createObjectURL(c),d=`closed-jobs-export-${new Date().toISOString().split("T")[0]}.csv`;x.setAttribute("href",u),x.setAttribute("download",d),x.style.visibility="hidden",document.body.appendChild(x),x.click(),document.body.removeChild(x)},Us=n=>{if(!n||n.length===0)return;const p=new ds("landscape");p.setFontSize(18),p.text("Closed Jobs Archive",14,20),p.setFontSize(10),p.text(`Export Date: ${new Date().toLocaleDateString()}`,14,28),p.text(`Total Jobs: ${n.length}`,14,34);const m=n.map(c=>[c.job_number||"",c.customers?.contact_name||"",c.status||"",c.move_type||c.job_type||"",c.origin_address||"",c.destination_address||"",c.scheduled_date&&
2Ce(c.scheduled_date)?.toLocaleDateString()||"",new Date(c.updated_at).toLocaleDateString()]);ms(p,{startY:40,head:[["Job #","Customer","Status","Type","Origin","Destination","Scheduled","Closed Date"]],body:m,styles:{fontSize:8},headStyles:{fillColor:[59,130,246]},columnStyles:{0:{cellWidth:25},1:{cellWidth:35},2:{cellWidth:20},3:{cellWidth:20},4:{cellWidth:50},5:{cellWidth:50},6:{cellWidth:25},7:{cellWidth:25}}});const j=`closed-jobs-archive-${new Date().toISOString().split("T")[0]}.pdf`;p.save(j)};function Hs({open:n,onOpenChange:p,job:m}){const[j,c]=f.useState([]),[x,u]=f.useState([]),{toast:d}=Ge(),i=He(),N=Ce(m.scheduled_date)||new Date,$=m.scheduled_date?.split("T")[0]||ss(N,"yyyy-MM-dd"),{data:_,isLoading:O}=pe({queryKey:["available-teams",$],queryFn:async()=>{const{data:r,error:l}=await h.from("teams").select(` 3 id, 4 team_name, 5 team_type, 6 team_members( 7 user_id, 8 member_role, 9 is_team_lead, 10 profiles(first_name, last_name) 11 ) 12 `).eq("is_active",!0);if(l)throw l;const{data:g,error:E}=await h.from("job_teams").select("team_id, jobs!inner(scheduled_date)").gte("jobs.scheduled_date",$).lte("jobs.scheduled_date",$+"T23:59:59");if(E)throw E;const ae=g.reduce((y,_e)=>(y[_e.team_id]=(y[_e.team_id]||0)+1,y),{});return r.map(y=>({id:y.id,team_name:y.team_name,team_type:y.team_type,members:y.team_members||[],current_jobs:ae[y.id]||0,available:(ae[y.id]||0)===0}))},enabled:n}),{data:v,isLoading:D}=pe({queryKey:["available-fleet",$],queryFn:async()=>{const{data:r,error:l}=await h.from("fleet").select("*").eq("status","available");if(l)throw l;const{data:g,error:E}=await h.from("job_fleet").select("fleet_id, jobs!inner(scheduled_date)").gte("jobs.scheduled_date",$).lte("jobs.scheduled_date",$+"T23:59:59");if(E)throw E;const ae=new Set(g.map(y=>y.fleet_id));return r.map(y=>({...y,assigned:ae.has(y.id)}))},enabled:n});f.useEffect(()=>{if(_&&v&&j.length===0){const r=_.filter(g=>g.available).slice(0,1).map(g=>g.id);c(r);const l=v.filter(g=>!g.assigned).slice(0,1).map(g=>g.id);u(l)}},[_,v]);const T=async()=>{try{if(j.length>0){const r=j.map(g=>({job_id:m.id,team_id:g})),{error:l}=await h.from("job_teams").insert(r);if(l)throw l}if(x.length>0){const r=x.map(g=>({job_id:m.id,fleet_id:g})),{error:l}=await h.from("job_fleet").insert(r);if(l)throw l}await i.invalidateQueries({queryKey:["jobs"]}),await i.invalidateQueries({queryKey:["job-teams"]}),await i.invalidateQueries({queryKey:["in-progress-jobs"]}),await i.invalidateQueries({queryKey:["pickup-calendar-jobs"]}),await i.invalidateQueries({queryKey:["available-teams"]}),await i.invalidateQueries({queryKey:["available-fleet"]}),d({title:"Success",description:`Assigned ${j.length} team(s) and ${x.length} vehicle(s) to ${m.job_number}`}),p(!1)}catch(r){d({title:"Error",description:r.message,variant:"destructive"})}},J=r=>{c(l=>l.includes(r)?l.filter(g=>g!==r):[...l,r])},k=r=>{u(l=>l.includes(r)?l.filter(g=>g!==r):[...l,r])};if(O||D)return e.jsx(Le,{open:n,onOpenChange:p,children:e.jsx(Me,{className:"max-w-3xl",children:e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(Ze,{className:"h-8 w-8 animate-spin text-primary"})})})});const P=_?.filter(r=>r.available).length||0,U=v?.filter(r=>!r.assigned).length||0;return e.jsx(Le,{open:n,onOpenChange:p,children:e.jsxs(Me,{className:"max-w-3xl max-h-[90vh] overflow-y-auto",children:[e.jsxs(bs,{children:[e.jsxs(vs,{children:["Smart Schedule - ",m.job_number]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically assign crew and vehicles based on availability"})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs(b,{children:[e.jsx(G,{className:"pb-2",children:e.jsxs(Z,{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(es,{className:"h-4 w-4"}),"Available Teams"]})}),e.jsxs(Q,{children:[e.jsx("div",{className:"text-2xl font-bold",children:P}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Ready to assign"})]})]}),e.jsxs(b,{children:[e.jsx(G,{className:"pb-2",children:e.jsxs(Z,{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(ys,{className:"h-4 w-4"}),"Available Vehicles"]})}),e.jsxs(Q,{children:[e.jsx("div",{className:"text-2xl font-bold",children:U}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Ready to assign"})]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"font-semibold",children:"Teams"}),e.jsxs(C,{variant:"outline",children:[j.length," selected"]})]}),e.jsx("div",{className:"grid gap-2",children:_&&_.length>0?_.map(r=>{const l=r.members.find(E=>E.is_team_lead),g=r.members.length;
12return e.jsx(b,{className:`cursor-pointer transition-all ${j.includes(r.id)?"ring-2 ring-primary":""}`,onClick:()=>J(r.id),children:e.jsx(Q,{className:"p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ze,{checked:j.includes(r.id),onCheckedChange:()=>J(r.id)}),e.jsxs("div",{children:[e.jsxs("div",{className:"font-medium flex items-center gap-2",children:[r.team_name,e.jsx(C,{variant:"secondary",className:"text-xs",children:r.team_type})]}),e.jsxs("div",{className:"text-sm text-muted-foreground",children:[g," member",g!==1?"s":"",l&&e.jsxs("span",{className:"ml-2",children:["⢠Lead: ",l.profiles.first_name," ",l.profiles.last_name]})]}),r.current_jobs>0&&e.jsxs("div",{className:"text-xs text-muted-foreground mt-1",children:[r.current_jobs," job(s) scheduled"]})]})]}),r.available?e.jsxs(C,{className:"bg-green-500",children:[e.jsx(Be,{className:"h-3 w-3 mr-1"}),"Available"]}):e.jsxs(C,{variant:"outline",className:"text-orange-600",children:[e.jsx($e,{className:"h-3 w-3 mr-1"}),"Busy"]})]})})},r.id)}):e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"No teams available"})})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"font-semibold",children:"Vehicles"}),e.jsxs(C,{variant:"outline",children:[x.length," selected"]})]}),e.jsx("div",{className:"grid gap-2",children:v&&v.length>0?v.map(r=>e.jsx(b,{className:`cursor-pointer transition-all ${x.includes(r.id)?"ring-2 ring-primary":""}`,onClick:()=>k(r.id),children:e.jsx(Q,{className:"p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ze,{checked:x.includes(r.id),onCheckedChange:()=>k(r.id)}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:r.truck_number}),e.jsxs("div",{className:"text-sm text-muted-foreground",children:[r.type,r.capacity_cuft&&` ⢠${r.capacity_cuft} cu ft`]})]})]}),r.assigned?e.jsxs(C,{variant:"outline",className:"text-orange-600",children:[e.jsx($e,{className:"h-3 w-3 mr-1"}),"Assigned"]}):e.jsxs(C,{className:"bg-green-500",children:[e.jsx(Be,{className:"h-3 w-3 mr-1"}),"Available"]})]})})},r.id)):e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"No vehicles available"})})]}),e.jsxs("div",{className:"flex gap-2 pt-4",children:[e.jsx(S,{variant:"outline",onClick:()=>p(!1),className:"flex-1",children:"Cancel"}),e.jsx(S,{onClick:T,className:"flex-1",disabled:j.length===0&&x.length===0,children:"Assign to Job"})]})]})]})})}const Ys=()=>{const[n,p]=f.useState("bar"),{data:m,isLoading:j}=pe({queryKey:["closed-jobs-stats"],queryFn:async()=>{const u=new Date,d=Rs(u,30),i=Ms(u),{data:N,error:$}=await h.from("jobs").select(` 13 id, 14 created_at, 15 updated_at, 16 invoices(total) 17 `).eq("status","closed");if($)throw $;const _=v=>{const D=v?N.filter(P=>new Date(P.updated_at)>=v):N,T=D.length,J=D.reduce((P,U)=>{const r=U.invoices?.[0]?.total||0;return P+Number(r)},0),k=T>0?J/T:0;return{totalJobs:T,totalRevenue:J,averageValue:k}},O=(v,D)=>{let T=[];return D==="day"?T=Is({start:v,end:u}):D==="week"?T=Ws({start:v,end:u}):T=Qs({start:v,end:u}),T.map(J=>{const k=new Date(J);D==="day"?k.setDate(k.getDate()+1):D==="week"?k.setDate(k.getDate()+7):k.setMonth(k.getMonth()+1);const P=N.filter(r=>{const l=new Date(r.updated_at);return l>=J&&l<k}),U=P.reduce((r,l)=>{const g=l.invoices?.[0]?.total||0;return r+Number(g)},0);return{date:ss(J,D==="day"||D==="week"?"MMM d":"MMM yyyy"),revenue:U,jobs:P.length}})};return{last30Days:_(d),lastQuarter:_(i),allTime:_(null),chartData30Days:O(d,"day"),chartDataQuarter:O(i,"week"),chartDataAllTime:N.length>0?O(new Date(Math.min(...N.map(v=>new Date(v.updated_at).getTime()))),"month"):[]}}});if(j)return e.jsx(b,{className:"mb-6",children:e.jsx(G,{children:e.jsx(Z,{children:"Loading Statistics..."})})});const c=u=>e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsxs(b,{children:[e.jsxs(G,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Z,{className:"text-sm font-medium",children:"Total Closed Jobs"}),e.jsx(Ns,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(Q,{children:[e.jsx("div",{className:"text-2xl font-bold",children:u.totalJobs}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Completed and archived"})]})]}),e.jsxs(b,{children:[e.jsxs(G,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Z,{className:"text-sm font-medium",children:"Total Revenue"}),e.jsx(ws,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(Q,{children:[e.jsxs("div",{className:"text-2xl font-bold",children:["$",u.totalRevenue.toLocaleStr
17ing("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"From closed jobs"})]})]}),e.jsxs(b,{children:[e.jsxs(G,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(Z,{className:"text-sm font-medium",children:"Average Job Value"}),e.jsx(Cs,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsxs(Q,{children:[e.jsxs("div",{className:"text-2xl font-bold",children:["$",u.averageValue.toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Per closed job"})]})]})]}),x=u=>e.jsxs(b,{className:"mt-4",children:[e.jsx(G,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(Z,{className:"text-base",children:"Revenue Trend"}),e.jsx(Pe,{children:"Daily revenue from closed jobs over time"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(S,{variant:n==="bar"?"default":"outline",size:"sm",onClick:()=>p("bar"),children:[e.jsx(Ss,{className:"h-4 w-4 mr-2"}),"Bar"]}),e.jsxs(S,{variant:n==="line"?"default":"outline",size:"sm",onClick:()=>p("line"),children:[e.jsx(ks,{className:"h-4 w-4 mr-2"}),"Line"]})]})]})}),e.jsx(Q,{children:e.jsx(zs,{width:"100%",height:300,children:n==="bar"?e.jsxs(Bs,{data:u,children:[e.jsx(We,{strokeDasharray:"3 3",className:"stroke-muted"}),e.jsx(Ve,{dataKey:"date",className:"text-xs",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(Ke,{className:"text-xs",tick:{fill:"hsl(var(--muted-foreground))"},tickFormatter:d=>`$${(d/1e3).toFixed(0)}k`}),e.jsx(Qe,{contentStyle:{backgroundColor:"hsl(var(--background))",border:"1px solid hsl(var(--border))",borderRadius:"6px"},formatter:(d,i)=>[i==="revenue"?`$${d.toLocaleString("en-US",{minimumFractionDigits:2})}`:d,i==="revenue"?"Revenue":"Jobs"]}),e.jsx(Oe,{}),e.jsx($s,{dataKey:"revenue",fill:"hsl(var(--primary))",name:"Revenue",radius:[4,4,0,0]})]}):e.jsxs(Js,{data:u,children:[e.jsx(We,{strokeDasharray:"3 3",className:"stroke-muted"}),e.jsx(Ve,{dataKey:"date",className:"text-xs",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(Ke,{className:"text-xs",tick:{fill:"hsl(var(--muted-foreground))"},tickFormatter:d=>`$${(d/1e3).toFixed(0)}k`}),e.jsx(Qe,{contentStyle:{backgroundColor:"hsl(var(--background))",border:"1px solid hsl(var(--border))",borderRadius:"6px"},formatter:(d,i)=>[i==="revenue"?`$${d.toLocaleString("en-US",{minimumFractionDigits:2})}`:d,i==="revenue"?"Revenue":"Jobs"]}),e.jsx(Oe,{}),e.jsx(As,{type:"monotone",dataKey:"revenue",stroke:"hsl(var(--primary))",strokeWidth:2,name:"Revenue",dot:{fill:"hsl(var(--primary))",r:4},activeDot:{r:6}})]})})})]});return e.jsxs(b,{className:"mb-6",children:[e.jsxs(G,{children:[e.jsx(Z,{children:"Closed Jobs Statistics"}),e.jsx(Pe,{children:"Revenue and performance metrics for closed jobs"})]}),e.jsx(Q,{children:e.jsxs(Ye,{defaultValue:"30days",className:"w-full",children:[e.jsxs(Xe,{className:"grid w-full grid-cols-3",children:[e.jsx(B,{value:"30days",children:"Last 30 Days"}),e.jsx(B,{value:"quarter",children:"This Quarter"}),e.jsx(B,{value:"alltime",children:"All Time"})]}),e.jsx(ge,{value:"30days",className:"space-y-4 mt-4",children:m&&e.jsxs(e.Fragment,{children:[c(m.last30Days),x(m.chartData30Days)]})}),e.jsx(ge,{value:"quarter",className:"space-y-4 mt-4",children:m&&e.jsxs(e.Fragment,{children:[c(m.lastQuarter),x(m.chartDataQuarter)]})}),e.jsx(ge,{value:"alltime",className:"space-y-4 mt-4",children:m&&e.jsxs(e.Fragment,{children:[c(m.allTime),x(m.chartDataAllTime)]})})]})})]})},Xs=()=>{const{type:n}=ns(),[p,m]=ls(),j=p.get("status"),c=p.get("source"),[x,u]=f.useState(""),[d,i]=f.useState(j||"all"),[N,$]=f.useState(()=>c&&(c==="web"||c==="manual"||c==="all")?c:localStorage.getItem("jobs-source-filter")||"all"),[_,O]=f.useState(()=>localStorage.getItem("jobs-sort-by")||"created_at"),[v,D]=f.useState(!1),[T,J]=f.useState(null),[k,P]=f.useState(!1),[U,r]=f.useState(null),[l,g]=f.useState("all"),[E,ae]=f.useState("all"),[y,_e]=f.useState(1),fe=50,[re,je]=f.useState({open:!1,booking:null,inventory:[]}),{toast:ee}=Ge(),H=He(),{openPanel:me}=Ks();f.useEffect(()=>{const s=p.get("openCRM");if(s){me("job",s);const a=new URLSearchParams(p);a.delete("openCRM"),m(a,{replace:!0})}},[p]),f.useEffect(()=>{localStorage.setItem("jobs-source-filter",N);const s=new URLSearchParams(p);N==="all"?s.delete("source"):s.set("source",N),m(s,{replace:!0})}
17,[N]),f.useEffect(()=>{localStorage.setItem("jobs-sort-by",_)},[_]);const ts=()=>n==="local"?"Local Jobs":n==="interstate"?"Interstate Jobs":n==="closed"?"Closed Jobs":n==="claims"?"Claims":"All Jobs",as=()=>n==="local"?"Manage local moving jobs and scheduling":n==="interstate"?"Manage interstate moving jobs and scheduling":n==="closed"?"View and manage closed moving jobs":n==="claims"?"Manage insurance claims and disputed jobs":"Manage all jobs and scheduling";f.useEffect(()=>{const s=h.channel("jobs-changes").on("postgres_changes",{event:"*",schema:"public",table:"jobs"},a=>{H.invalidateQueries({queryKey:["jobs"]}),H.invalidateQueries({queryKey:["calendar-jobs"]})}).subscribe();return()=>{h.removeChannel(s)}},[H]);const{data:Se,isLoading:ke,refetch:Gs}=pe({queryKey:["jobs",d,n,y,_,x.trim()],queryFn:async()=>{const s=(y-1)*fe,a=s+fe-1;if(d==="active"){const{data:F,error:X,count:te}=await h.from("jobs").select(` 18 id, job_number, vb_number, customer_id, status, job_type, move_type, source, scheduled_date, 19 origin_address, origin_city, origin_state, origin_zip, 20 destination_address, destination_city, destination_state, destination_zip, 21 estimated_hours, crew_size, special_instructions, created_at, has_claim, claim_status, claim_reason, 22 customers(contact_name), 23 job_teams(teams(team_name)), 24 job_fleet(fleet(truck_number)) 25 `,{count:"exact"}).in("status",["scheduled","in_progress"]).eq("archived",!1).order(_,{ascending:!1}).range(s,a);if(X)throw X;const{data:W,error:V,count:L}=await h.from("online_bookings").select("id, vb_number, customer_name, actual_move_date, origin_full_address, origin_zip, destination_full_address, destination_zip, estimated_hours, crew_size_requested, special_requirements, created_at, status",{count:"exact"}).in("status",["accepted","paid","booked"]).is("job_id",null).eq("archived",!1).order("created_at",{ascending:!1}).range(s,a);if(V)throw V;const w=(W||[]).map(q=>({id:q.id,job_number:q.vb_number,vb_number:q.vb_number,customer_id:null,status:"Website Booking",job_type:"interstate",scheduled_date:q.actual_move_date,origin_address:q.origin_full_address||`${q.origin_zip}`,destination_address:q.destination_full_address||`${q.destination_zip}`,estimated_hours:q.estimated_hours,crew_size:q.crew_size_requested,special_instructions:q.special_requirements,created_at:q.created_at,customers:{contact_name:q.customer_name},_isWebsiteBooking:!0})),ve=(te||0)+(L||0);return{jobs:[...F||[],...w],totalCount:ve}}if(d==="completed"){const{data:F,error:X}=await h.from("job_payments").select("job_id").eq("stage","pickup").not("job_id","is",null);if(X)throw X;const te=F?.map(ve=>ve.job_id)||[];let W=h.from("jobs").select(` 26 id, job_number, vb_number, customer_id, status, job_type, move_type, source, scheduled_date, 27 origin_address, origin_city, origin_state, origin_zip, 28 destination_address, destination_city, destination_state, destination_zip, 29 estimated_hours, crew_size, special_instructions, created_at, has_claim, claim_status, claim_reason, 30 customers(contact_name), 31 job_teams(teams(team_name)), 32 job_fleet(fleet(truck_number)) 33 `,{count:"exact"}).eq("archived",!1).eq("status","completed").in("id",te.length>0?te:["00000000-0000-0000-0000-000000000000"]).order(_,{ascending:!1}).range(s,a);n==="local"?W=W.eq("job_type","local"):n==="interstate"&&(W=W.eq("job_type","long_distance"));const{data:V,error:L,count:w}=await W;if(L)throw L;return{jobs:V,totalCount:w||0}}const t=x.trim(),R=t.length>0;let o=h.from("jobs").select(` 34 id, job_number, vb_number, customer_id, status, job_type, move_type, source, scheduled_date, 35 origin_address, origin_city, origin_state, origin_zip, 36 destination_address, destination_city, destination_state, destination_zip, 37 estimated_hours, crew_size, special_instructions, created_at, has_claim, claim_status, claim_reason, 38 customers(contact_name), 39 job_teams(teams(team_name)), 40 job_fleet(fleet(truck_number)) 41 `,{count:"exact"}).eq("archived",!1).order(_,{ascending:!1});if(R||(o=o.range(s,a)),d!=="all"&&(o=o.eq("status",d)),n==="local"?(o=o.eq("move_type","local"),o=o.not("status","in",'("closed","claim","cancelled")')):n==="interstate"?(o=o.eq("move_type","interstate"),o=o.not("status","in",'("closed","claim","cancelled")')):n==="closed"?o=o.eq("status","closed"):n==="claims"&&(o=o.eq("status","claim")),R){const F=t.replace(/[%,()]/g,"");o=o.or(`vb_number.ilike.%${F}%,job_number.ilike.%${F}%`)}const{data:I,error:Y,count:be}=await o;
41if(Y)throw Y;return{jobs:I,totalCount:be||0}}}),se=Se?.jobs||[];Math.ceil((Se?.totalCount||0)/fe),ye({mutationFn:async s=>{const{error:a}=await h.from("jobs").update({archived:!0}).eq("id",s);if(a)throw a;return s},onSuccess:()=>{H.invalidateQueries({queryKey:["jobs"]}),ee({title:"Success",description:"Job archived successfully"})},onError:s=>{ee({title:"Error",description:s.message,variant:"destructive"})}}),ye({mutationFn:async s=>{const{data:a}=await h.from("invoices").select("id, invoice_number, vb_number").eq("job_id",s.id).maybeSingle();if(a)throw new Error(`Invoice ${a.vb_number||a.invoice_number} already exists for this job`);let t=s.vb_number;if(!t){const{data:I}=await h.rpc("generate_vb_number");t=I}const{data:R,error:o}=await h.from("invoices").insert({vb_number:t,invoice_number:t,job_id:s.id,customer_id:s.customer_id,status:"draft",subtotal:0,tax:0,total:0,notes:`Invoice for Job ${s.vb_number||s.job_number}`}).select().single();if(o)throw o;return R},onSuccess:s=>{H.invalidateQueries({queryKey:["invoices"]}),ee({title:"Success",description:`Invoice ${s.vb_number||s.invoice_number} created successfully`})},onError:s=>{ee({title:"Error",description:s.message,variant:"destructive"})}});const De=async s=>{const{data:a,error:t}=await h.from("booking_inventory").select("*").eq("booking_id",s.id);if(t){console.error("Error fetching inventory:",t),ee({title:"Error",description:"Failed to load inventory for preview",variant:"destructive"});return}je({open:!0,booking:s,inventory:a||[]})},rs=s=>{re.booking&&(ue.mutate({booking:re.booking,modifiedInventory:s}),je({open:!1,booking:null,inventory:[]}))},ue=ye({mutationFn:async({booking:s,modifiedInventory:a})=>{const{data:t,error:R}=await h.from("online_bookings").select("*").eq("id",s.id).single();if(R)throw R;if(t.job_id)throw new Error("This booking has already been converted to a job");let o=null;const{data:I}=await h.from("customers").select("id, contact_name").eq("email",t.customer_email).maybeSingle(),Y=t.move_type||(t.origin_state===t.destination_state&&t.origin_state==="IL"?"local":"interstate"),be=Y==="interstate"?"long_distance":"local";if(I){const V=I.contact_name?.toLowerCase().trim()||"",L=t.customer_name?.toLowerCase().trim()||"";V===L?(o=I.id,console.log(`[Manual Conversion] Reusing existing customer ${o} for ${t.customer_name} (${t.customer_email})`)):console.log(`[Manual Conversion] Email match but different names: "${I.contact_name}" vs "${t.customer_name}" - creating new customer`)}if(!o){const{data:V,error:L}=await h.from("customers").insert({contact_name:t.customer_name,email:t.customer_email,phone:t.customer_phone,address:t.origin_full_address,city:t.origin_city,state:t.origin_state,zip:t.origin_zip,move_type:Y}).select().single();if(L)throw L;o=V.id}const{data:F,error:X}=await h.from("jobs").insert({vb_number:t.vb_number,job_number:t.vb_number,customer_id:o,status:"scheduled",job_type:be,move_type:Y,scheduled_date:t.actual_move_date,origin_address:t.origin_full_address,origin_full_address:t.origin_full_address,origin_city:t.origin_city,origin_state:t.origin_state,origin_zip:t.origin_zip,origin_property_type:t.origin_property_type,origin_unit_number:t.origin_unit_number,destination_address:t.destination_full_address,destination_full_address:t.destination_full_address,destination_city:t.destination_city,destination_state:t.destination_state,destination_zip:t.destination_zip,destination_property_type:t.destination_property_type,destination_unit_number:t.destination_unit_number,estimated_hours:t.estimated_hours,crew_size:t.crew_size_requested,special_instructions:t.special_requirements,total_amount:t.quote_total,cubic_feet:t.quote_cubic_feet}).select().single();if(X)throw X;const{error:te}=await h.from("online_bookings").update({job_id:F.id,status:"booked",converted_to_job_at:new Date().toISOString()}).eq("id",s.id);if(te)throw te;let W=0;if(a&&a.length>0){const V=a.map(w=>({job_id:F.id,inventory_item_id:w.inventory_item_id,item_name:w.item_name,quantity:w.quantity,volume_cuft:w.volume_cuft,fragile:w.fragile,room:w.room??null,notes:w.notes})),{error:L}=await h.from("job_inventory").insert(V);L||(W=a.length,await h.from("inventory_transfer_log").insert({source_record_type:"booking",source_record_id:s.id,destination_record_type:"job",destination_record_id:F.id,items_transferred:a.length,transfer_details:a.map(w=>({item_name:w.item_name,quantity:w.quantity,volume_cuft:w.volume_cuft,fragile:w.fragile,inventory_item_id:w.inventory_item_id})),transferred_by:(await h.auth.getUser()).data.user?.id,notes:`Booking ${t.vb_number} converted to Job ${F.vb_number}`}))}return{job:F,inventoryCount:W}},onSuccess:({job:s,inventoryCount:a})=>{H.invalidateQueries({queryKey:["jobs"]}),H.invalidateQueries({queryKey:["dashboard-stats"]});const t=a>0?` ${a} inventory items transferred.`:"";ee({title:"Success",description:`Booking ${s.vb_number} converted to job successfully.${t}`})},onError:s=>{ee({title:"Error",description:s.message,variant:"destructive"})}}),A=se?.filter(s=>{const a=x.toLowerCase(),t=Ue(x),R=s.vb_number?.toLowerCase().includes(a)||s.job_number?.toLowerCase().includes(a)||s.customers?.contact_name?.toLowerCase().includes(a)||s.customers?.email?.toLowerCase().includes(a)||t.length>=3&&Ue(s.customers?.phone||"").includes(t);if(d!=="active")return R;const o=N==="all"?!0:N==="web"?s._isWebsiteBooking:N==="manual"?!s._isWebsiteBooking:!0,I=l==="all"||s.origin_state===l,Y=E==="all"||s.destination_state===E;return R&&o&&I&&Y}),ie={total:se?.length||0,pending:se?.filter(s=>s.status==="pending").length||0,scheduled:se?.filter(s=>s.status==="scheduled").length||0,inProgress:se?.filter(s=>s.status==="in_progress").length||0,followUpsDue:0},Te=s=>{const t={pending:{variant:"outline",className:"border-amber-500 text-amber-700 bg-amber-50"},scheduled:{variant:"outline",className:"border-blue-500 text-blue-700 bg-blue-50"},on_hold:{variant:"outline",className:"border-yellow-500 text-yellow-700 bg-yellow-50"},in_progress:{variant:"outline",className:"border-purple-500 text-purple-700 bg-purple-50"},completed:{variant:"outline",className:"border-green-500 text-green-700 bg-green-50"},cancelled:{variant:"outline",className:"border-red-500 text-red-700 bg-red-50"},closed:{variant:"outline",className:"border-gray-500 text-gray-700 bg-gray-50"},claim:{variant:"outline",className:"border-orange-500 text-orange-700 bg-orange-50"},"Website Booking":{variant:"outline",className:"border-purple-500 text-purple-700 bg-purple-50"}}[s]||{variant:"outline"};return e.jsx(C,{...t,children:s.replace("_"," ")})},he=s=>{r(s),P(!0)},[qe,Fe]=f.useState(!1),is=async()=>{Fe(!0),await H.invalidateQueries({queryKey:["jobs"]}),setTimeout(()=>Fe(!1),500)};return e.jsxs("div",{className:"max-w-full p-4 sm:p-6 space-y-4 sm:sp
41ace-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:ts()}),e.jsx("p",{className:"text-sm sm:text-base text-muted-foreground",children:as()})]}),e.jsx(S,{variant:"outline",size:"icon",onClick:is,disabled:qe,title:"Refresh data",children:e.jsx(Ds,{className:`h-4 w-4 ${qe?"animate-spin":""}`})})]}),n==="closed"&&A&&A.length>0&&e.jsxs("div",{className:"flex gap-2 mr-60",children:[e.jsxs(S,{variant:"outline",onClick:()=>Os(A),children:[e.jsx(Je,{className:"mr-2 h-4 w-4"}),"Export CSV"]}),e.jsxs(S,{variant:"outline",onClick:()=>Us(A),children:[e.jsx(Je,{className:"mr-2 h-4 w-4"}),"Export PDF"]})]})]}),n==="closed"&&e.jsx(Ys,{}),n!=="closed"&&e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-5 gap-4",children:[e.jsx(b,{className:"p-3 sm:p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Total Jobs"}),e.jsx("p",{className:"text-2xl font-bold",children:ie.total})]}),e.jsx(es,{className:"h-6 w-6 sm:h-8 sm:w-8 text-primary"})]})}),e.jsx(b,{className:"p-3 sm:p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Pending"}),e.jsx("p",{className:"text-2xl font-bold",children:ie.pending})]}),e.jsx(Ae,{className:"h-6 w-6 sm:h-8 sm:w-8 text-amber-500"})]})}),e.jsx(b,{className:"p-3 sm:p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Scheduled"}),e.jsx("p",{className:"text-2xl font-bold",children:ie.scheduled})]}),e.jsx(de,{className:"h-6 w-6 sm:h-8 sm:w-8 text-blue-500"})]})}),e.jsx(b,{className:"p-3 sm:p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"In Progress"}),e.jsx("p",{className:"text-2xl font-bold",children:ie.inProgress})]}),e.jsx(Ts,{className:"h-6 w-6 sm:h-8 sm:w-8 text-purple-500"})]})}),e.jsx(b,{className:"p-3 sm:p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Follow-ups Due"}),e.jsx("p",{className:"text-2xl font-bold",children:ie.followUpsDue})]}),e.jsx(Ae,{className:"h-6 w-6 sm:h-8 sm:w-8 text-warning"})]})})]}),e.jsx(b,{className:"p-3 sm:p-4",children:e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-6 gap-3 sm:gap-4",children:[e.jsxs("div",{className:"relative",children:[e.jsx(qs,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(os,{placeholder:"Search VB#, name, email...",value:x,onChange:s=>u(s.target.value),onDoubleClick:()=>u(""),className:"pl-9"})]}),e.jsxs(ne,{value:l,onValueChange:g,children:[e.jsx(le,{children:e.jsx(oe,{placeholder:"Origin State"})}),e.jsxs(ce,{children:[e.jsx(z,{value:"all",children:"All Origin States"}),(()=>{const s={};return se?.forEach(a=>{a.origin_state&&(s[a.origin_state]=(s[a.origin_state]||0)+1)}),Object.entries(s).sort(([a],[t])=>a.localeCompare(t)).map(([a,t])=>e.jsxs(z,{value:a,children:[a," (",t,")"]},a))})()]})]}),e.jsxs(ne,{value:E,onValueChange:ae,children:[e.jsx(le,{children:e.jsx(oe,{placeholder:"Destination State"})}),e.jsxs(ce,{children:[e.jsx(z,{value:"all",children:"All Destination States"}),(()=>{const s={};return se?.forEach(a=>{a.destination_state&&(s[a.destination_state]=(s[a.destination_state]||0)+1)}),Object.entries(s).sort(([a],[t])=>a.localeCompare(t)).map(([a,t])=>e.jsxs(z,{value:a,children:[a," (",t,")"]},a))})()]})]}),e.jsxs(ne,{value:_,onValueChange:s=>O(s),children:[e.jsx(le,{children:e.jsx(oe,{placeholder:"Sort by"})}),e.jsxs(ce,{children:[e.jsx(z,{value:"created_at",children:"Newest First"}),e.jsx(z,{value:"scheduled_date",children:"Move Date"}),e.jsx(z,{value:"vb_number",children:"VB Number"})]})]}),e.jsxs(ne,{value:"all",onValueChange:()=>{},children:[e.jsx(le,{children:e.jsx(oe,{placeholder:"Assigned Team"})}),e.jsx(ce,{children:e.jsx(z,{value:"all",children:"All Teams"})})]}),e.jsxs(ne,{value:"all",onValueChange:()=>{},children:[e.jsx(le,{children:e.jsx(oe,{placeholder:"Has Tasks"})}),e.jsxs(ce,{children:[e.jsx(z,{value:"all",children:"All"}),e.jsx(z,{value:"yes",children:"Has Tasks"}),e.jsx(z,{value:"no",children:"No Tasks"})]})]})]})}),e.jsxs(Ye,{value:d,onValueChange:i,children:[e.jsx("div",{className:"overflow-x-auto pb-2",children:e.jsxs(Xe,{className:"w-full sm:w-auto inline-flex flex-nowrap min-w-min",children:[e.jsx(B,{value:"all",children:"All Jobs"}),e.jsx(B,{value:"pending",children:"Pending"}),e.jsx(B,{value:"scheduled",children:"Scheduled"}),e.jsx(B,{value:"on_hold",children:"On Hold"}),e.jsx(B,{value:"in_progress",children:"In Progress"}),e.jsx(B,{value:"completed",children:"Completed"}),e.jsx(B,{value:"closed",children:"Closed"}),e.jsx(B,{value:"cancelled",children:"Cancelled"})]})}),e.jsxs(ge,{value:d,className:"mt-4",children:[e.jsx(b,{className:"hidden md:block",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(us,{className:"min-w-[900px]",children:[e.jsx(hs,{children:e.jsxs(xe,{children:[e.jsx(K,{className:"w-32",children:"VB # / Type"}),e.jsx(K,{children:"Customer"}),e.jsx(K,{children:"Route"}),e.jsx(K,{className:"w-28",children:"Move Type"}),e.jsxs(K,{className:"w-28 cursor-pointer hover:text-foreground select-none",onClick:()=>O(_==="source"?"created_at":"source"),children:["Source ",_==="source"&&"â"]}),e.jsx(K,{className:"w-28",children:"Status"}),e.jsx(K,{className:"w-32",children:"Activity"}),e.jsx(K,{className:"w-24",children:"Move Date"}),e.jsx(K,{className:"w-32 text-center",children:"Actions"})]})}),e.jsx(xs,{children:ke?e.jsx(xe,{children:e.jsx(M,{colSpan:9,className:"text-center py-8",children:e.jsx(Ze,{className:"h-8 w-8 animate-spin mx-auto text-primary"})})}):A&&A.length>0?A.map(s=>!s||!s.id?null:e.jsxs(gs,{children:[e.jsx(ps,{asChild:!0,children:e.jsxs(xe,{className:"cursor-pointer hover:bg-muted/50",onClick:()=>me(s?._isWebsiteBooking?"booking":"job",s.id),children:[e.jsx(M,{className:"font-medium",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"truncate",children:s?.vb_number||s?.job_number||"-"}),e.jsx(C,{variant:"outline",className:"text-xs shrink-0",children:s?._isWebsiteBooking?"booking":"job"})]})}),e.jsx(M,{children:e.jsxs("div",{children:[e.jsx("p",{className:"font-medium truncate",children:s?.customers?.contact_name||"-"}),e.jsx("p",{className:"text-xs text-muted-foreground truncate",children:"-"})]})}),e.jsx(M,{children:e.jsxs("div",{className:"text-sm text-muted-foreground",children:[s?.origin_city||s?.origin_state||s?.destination_city||s?.destination_state?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"font-medium text-foreground",children:[s?.origin_city,s?.origin_state].filter(
41Boolean).join(", ")||"â"}),e.jsx("span",{className:"mx-1",children:"â"}),e.jsx("span",{className:"font-medium text-foreground",children:[s?.destination_city,s?.destination_state].filter(Boolean).join(", ")||"â"})]}):e.jsx("span",{children:"â"}),js(s)&&e.jsx(C,{variant:"destructive",className:"ml-2 text-[10px] py-0",children:"NYC SHUTTLE"})]})}),e.jsx(M,{children:e.jsx(C,{variant:s?.move_type==="local"?"default":"secondary",children:s?.move_type||"-"})}),e.jsx(M,{children:e.jsx(C,{variant:"outline",className:"capitalize text-xs",children:s?.source?.replace(/-/g," ")||"N/A"})}),e.jsx(M,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[Te(s?.status||"unknown"),s?.has_claim&&e.jsx(C,{variant:"outline",className:"border-orange-500 text-orange-700 text-xs",children:"Claim"})]})}),e.jsx(M,{children:e.jsx("div",{className:"text-xs",children:e.jsx("span",{className:"text-muted-foreground",children:"-"})})}),e.jsx(M,{children:e.jsx("span",{className:"text-sm whitespace-nowrap",children:s.scheduled_date?Ee(s.scheduled_date,"MMM d"):"-"})}),e.jsx(M,{onClick:a=>a.stopPropagation(),children:e.jsx("div",{className:"flex justify-center gap-2",children:s?._isWebsiteBooking?e.jsxs(S,{variant:"default",size:"sm",onClick:()=>De(s),disabled:ue.isPending,children:[e.jsx(Re,{className:"h-4 w-4 mr-1"}),"Convert"]}):s?.status==="pending"?e.jsx(S,{variant:"ghost",size:"sm",onClick:()=>he(s),title:"Schedule Pickup",children:e.jsx(de,{className:"h-4 w-4"})}):s?.scheduled_date?e.jsx(S,{variant:"ghost",size:"sm",onClick:()=>he(s),title:"View Schedule",children:e.jsx(de,{className:"h-4 w-4 text-green-600"})}):e.jsx(S,{variant:"ghost",size:"sm",onClick:()=>{},title:"Schedule Follow-Up",children:e.jsx(Ie,{className:"h-4 w-4"})})})})]})}),e.jsxs(_s,{className:"w-56",children:[e.jsxs(Ne,{onClick:a=>{a.stopPropagation(),me(s?._isWebsiteBooking?"booking":"job",s.id)},children:[e.jsx(Fs,{className:"mr-2 h-4 w-4"}),"View Details"]}),e.jsxs(Ne,{onClick:a=>{a.stopPropagation()},children:[e.jsx(Ps,{className:"mr-2 h-4 w-4"}),"Send Email"]}),e.jsx(fs,{}),e.jsxs(Ne,{onClick:a=>{a.stopPropagation()},className:"text-orange-600 focus:text-orange-600",children:[e.jsx(Es,{className:"mr-2 h-4 w-4"}),"Archive"]})]})]},s.id)).filter(Boolean):e.jsx(xe,{children:e.jsx(M,{colSpan:7,className:"text-center py-8 text-muted-foreground",children:"No jobs found"})})})]})})}),e.jsx("div",{className:"md:hidden space-y-3",children:ke?e.jsx(b,{className:"p-4",children:e.jsx("p",{className:"text-center text-muted-foreground",children:"Loading jobs..."})}):A&&A.length>0?A.map(s=>!s||!s.id?null:e.jsxs(b,{className:"p-3 cursor-pointer hover:shadow-md transition-shadow",onClick:()=>me(s?._isWebsiteBooking?"booking":"job",s.id),children:[e.jsxs("div",{className:"flex items-start justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium",children:s?.vb_number||s?.job_number||"-"}),e.jsx(C,{variant:"outline",className:"text-xs",children:s?._isWebsiteBooking?"booking":"job"})]}),e.jsx(C,{variant:s?.job_type==="local"?"default":"secondary",className:"text-xs",children:s?.job_type||"-"})]}),e.jsxs("div",{className:"space-y-1 mb-3",children:[e.jsx("p",{className:"font-medium",children:s?.customers?.contact_name||"-"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"-"})]}),e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[Te(s?.status||"unknown"),s?.has_claim&&e.jsx(C,{variant:"outline",className:"border-orange-500 text-orange-700 text-xs",children:"Claim"})]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:s.scheduled_date?Ee(s.scheduled_date,"MMM d, yyyy"):"Not scheduled"})]}),e.jsx("div",{onClick:a=>a.stopPropagation(),children:s?._isWebsiteBooking?e.jsxs(S,{variant:"outline",size:"sm",className:"w-full",onClick:()=>De(s),disabled:ue.isPending,children:[e.jsx(Re,{className:"h-4 w-4 mr-2"}),"Convert to Job"]}):s?.status==="pending"?e.jsxs(S,{variant:"outline",size:"sm",className:"w-full",onClick:()=>he(s),children:[e.jsx(de,{className:"h-4 w-4 mr-2"}),"Schedule Pickup"]}):s?.scheduled_date?e.jsxs(S,{variant:"outline",size:"sm",className:"w-full",onClick:()=>he(s),children:[e.jsx(de,{className:"h-4 w-4 mr-2 text-green-600"}),"View Schedule"]}):e.jsxs(S,{variant:"outline",size:"sm",className:"w-full",onClick:()=>{},children:[e.jsx(Ie,{className:"h-4 w-4 mr-2"}),"Schedule Follow-Up"]})})]},s.id)):e.jsx(b,{className:"p-4",children:e.jsx("p",{className:"text-center text-muted-foreground",children:"No jobs found"})})})]})]}),T&&e.jsx(Hs,{open:v,onOpenChange:D,job:T}),U&&e.jsx(Ls,{open:k,onOpenChange:P,job:U}),e.jsx(Vs,{open:re.open,onOpenChange:s=>je({...re,open:s}),onConfirm:rs,bookingNumber:re.booking?.vb_number||"",inventory:re.inventory,isLoading:ue.isPending})]})},Zt=cs(Xs,{context:"Jobs",tags:{page:"jobs",section:"admin",feature:"scheduling"},level:"page"});export{Zt as default}; 42//# sourceMappingURL=Jobs-DISOJOPI.js.map
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.