1import{u as A,j as e}from"./vendor-data-_Pz25YLs.js";import{a6 as O,u as $,s as w,B as C,i as D,I as W,e as S,X,a7 as G,a8 as H,a9 as M,aa as J,K as U,N as Y,O as Z,Q as ee,R as i,t as se,r as te}from"./index-C15KveKt.js";import{C as f,c as g}from"./card-DKtZ9FmL.js";import{JobsMap as ae}from"./JobsMap-27-UUhdm.js";import{h as re,r as o,d as le,L as ce}from"./vendor-react-C5ET9VRQ.js";import{L as de}from"./list-Bi5abceb.js";import{M as ie}from"./map-C9FM-jaO.js";import{C as ne}from"./clock-ByM7PWKN.js";import{f as oe}from"./format-Bo4AVCK2.js";import"./mapbox-gl-D5opnLfI.js";function ye(){var q,F;const{user:a}=O(),{effectiveContractorId:m}=$(),[j,I]=re(),n=j.get("project"),u=j.get("tab"),V=j.get("status"),[v,L]=o.useState("list"),[h,Q]=o.useState(V||"all"),[x,b]=o.useState(""),z=le(),{data:r}=A({queryKey:["contractor-profile",m,a==null?void 0:a.id],queryFn:async()=>{if(m){const{data:d,error:l}=await w.from("contractors").select("*").eq("id",m).single();if(l)throw l;return d}const{data:s,error:t}=await w.from("contractors").select("*").eq("user_id",a==null?void 0:a.id).single();if(t)throw t;return s},enabled:!!m||!!(a!=null&&a.id)}),{data:p=[],isLoading:B}=A({queryKey:["contractor-all-jobs",r==null?void 0:r.id],queryFn:async()=>{const{data:s,error:t}=await w.from("jobs").select(` 2 *, 3 customers (name, address, phone), 4 projects:project_id (name) 5 `).eq("contractor_id",r==null?void 0:r.id).order("scheduled_date",{ascending:!0});if(t)throw t;return s},enabled:!!(r!=null&&r.id)}),c=o.useMemo(()=>{let s=n?p.filter(t=>t.project_id===n):p;if(x.trim()){const t=x.toLowerCase();s=s.filter(d=>{var l,P,T;return((l=d.title)==null?void 0:l.toLowerCase().includes(t))||((T=(P=d.projects)==null?void 0:P.name)==null?void 0:T.toLowerCase().includes(t))})}return s},[p,n,x]),k=n?(F=(q=p.find(s=>s.project_id===n))==null?void 0:q.projects)==null?void 0:F.name:null,N=o.useMemo(()=>{const s=c.filter(t=>["pending","scheduled","in-progress","won","overdue"].includes(t.status||""));return h==="all"?s:s.filter(t=>t.status===h)},[c,h]),y=c.filter(s=>s.status==="complete"),K=s=>{switch(s){case"complete":return"default";case"in-progress":return"secondary";case"scheduled":return"outline";case"pending":return"outline";default:return"outline"}},_=({job:s})=>{var t,d,l;return e.jsx(ce,{to:`/contractor/jobs/${s.id}`,className:"block",children:e.jsx(f,{className:"hover:bg-accent/50 transition-colors cursor-pointer",children:e.jsxs(g,{className:"p-4",children:[e.jsxs("div",{className:"flex justify-between items-start",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"font-semibold text-lg",children:s.title}),e.jsx("p",{className:"text-sm text-muted-foreground",children:(t=s.customers)==null?void 0:t.name}),(s.address||((d=s.customers)==null?void 0:d.address))&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(se,{className:"h-4 w-4"}),e.jsx("span",{children:s.address||((l=s.customers)==null?void 0:l.address)})]}),s.scheduled_date&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(te,{className:"h-4 w-4"}),e.jsx("span",{children:oe(new Date(s.scheduled_date),"MMM d, yyyy")}),s.scheduled_time&&e.jsxs(e.Fragment,{children:[e.jsx(ne,{className:"h-4 w-4 ml-2"}),e.jsx("span",{children:s.scheduled_time})]})]})]}),e.jsxs("div",{className:"flex flex-col items-end gap-2",children:[e.jsx(S,{variant:K(s.status||"pending"),children:s.status}),s.priority&&e.jsx(S,{variant:s.priority==="urgent"?"destructive":s.priority==="high"?"secondary":"outline",children:s.priority})]})]}),s.description&&e.jsx("p",{className:"mt-3 text-sm text-muted-foreground line-clamp-2",children:s.description})]})})})};
5if(B)return e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-primary"})});const R=s=>s.map(t=>({id:t.id,title:t.title,description:t.description,status:t.status,priority:t.priority,address:t.address,address_lat:t.address_lat,address_lng:t.address_lng,scheduled_date:t.scheduled_date,scheduled_time:t.scheduled_time,due_date:t.due_date,customer_id:t.customer_id,project_id:t.project_id,contractor_id:t.contractor_id,created_at:t.created_at,updated_at:t.updated_at,customer:t.customers?{id:t.customer_id,name:t.customers.name}:void 0,project:t.projects?{id:t.project_id,name:t.projects.name}:void 0})),E=s=>{z(`/contractor/jobs/${s.id}`)};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold text-foreground",children:"My Jobs"}),e.jsx("p",{className:"text-muted-foreground mt-1",children:"View and manage your assigned jobs"})]}),e.jsxs("div",{className:"flex items-center gap-1 bg-muted p-1 rounded-lg",children:[e.jsxs(C,{variant:v==="list"?"default":"ghost",size:"sm",onClick:()=>L("list"),className:"gap-2",children:[e.jsx(de,{className:"h-4 w-4"}),"List"]}),e.jsxs(C,{variant:v==="map"?"default":"ghost",size:"sm",onClick:()=>L("map"),className:"gap-2",children:[e.jsx(ie,{className:"h-4 w-4"}),"Map"]})]})]}),e.jsxs("div",{className:"relative max-w-sm",children:[e.jsx(D,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(W,{placeholder:"Search by job title or projectâ¦",value:x,onChange:s=>b(s.target.value),className:"pl-9"})]}),k&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Filtered by project:"}),e.jsxs(S,{variant:"secondary",className:"gap-1",children:[k,e.jsx(C,{variant:"ghost",size:"icon",className:"h-4 w-4 p-0 hover:bg-transparent",onClick:()=>I({}),children:e.jsx(X,{className:"h-3 w-3"})})]})]}),v==="map"?e.jsx(ae,{jobs:R(c),onJobClick:E}):e.jsxs(G,{defaultValue:u==="active"||u==="completed"||u==="all"?u:"active",className:"w-full",children:[e.jsxs(H,{
5children:[e.jsxs(M,{value:"active",children:["Active (",N.length,")"]}),e.jsxs(M,{value:"completed",children:["Completed (",y.length,")"]}),e.jsxs(M,{value:"all",children:["All (",c.length,")"]})]}),e.jsxs(J,{value:"active",className:"mt-6",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:"Status:"}),e.jsxs(U,{value:h,onValueChange:Q,children:[e.jsx(Y,{className:"w-[180px]",children:e.jsx(Z,{placeholder:"All statuses"})}),e.jsxs(ee,{children:[e.jsx(i,{value:"all",children:"All"}),e.jsx(i,{value:"won",children:"Won"}),e.jsx(i,{value:"pending",children:"Pending"}),e.jsx(i,{value:"in-progress",children:"In Progress"}),e.jsx(i,{value:"scheduled",children:"Scheduled"}),e.jsx(i,{value:"overdue",children:"Overdue"})]})]})]}),N.length===0?e.jsx(f,{children:e.jsx(g,{className:"py-12 text-center text-muted-foreground",children:"No active jobs assigned to you"})}):e.jsx("div",{className:"space-y-4",children:N.map(s=>e.jsx(_,{job:s},s.id))})]}),e.jsx(J,{value:"completed",className:"mt-6",children:y.length===0?e.jsx(f,{children:e.jsx(g,{className:"py-12 text-center text-muted-foreground",children:"No completed jobs yet"})}):e.jsx("div",{className:"space-y-4",children:y.map(s=>e.jsx(_,{job:s},s.id))})}),e.jsx(J,{value:"all",className:"mt-6",children:c.length===0?e.jsx(f,{children:e.jsx(g,{className:"py-12 text-center text-muted-foreground",children:"No jobs assigned to you"})}):e.jsx("div",{className:"space-y-4",children:c.map(s=>e.jsx(_,{job:s},s.id))})})]})]})}export{ye 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.