1import{a as w,c as L,j as e}from"./vendor-query-BxlSJxfF.js";import{u as M,a as R,q as E,r as q,s as p}from"./index-DO0aGFYL.js";import{a as P}from"./use-profile-summary-pcsmjbRV.js";import{H as G}from"./Head-CFjoxvyt.js";import{u as H}from"./vendor-react-DdNhUK9-.js";import{C as K}from"./chevron-left-Bpy2VrDY.js";import{S as D}from"./send-C6vNENnO.js";import{G as F}from"./gavel-C8K741vS.js";import"./vendor-supabase-Csx7YFID.js";function Z(){const c=H(),{user:o}=M(),{t:k,lang:I}=R(),m=k.inviteToBid,a=m.proposals,[d,$]=w.useState("requests"),{data:n,isLoading:B}=L({queryKey:["contractor-proposals",o==null?void 0:o.id],enabled:!!(o!=null&&o.id),staleTime:3e4,queryFn:async()=>{const{data:t}=await p.from("jobs").select("id, title").eq("contractor_id",o.id).eq("job_type","sub_package").is("deleted_at",null).order("created_at",{ascending:!1}).limit(100),r=t??[],f=new Map(r.map(s=>[s.id,s.title??""])),u=r.map(s=>s.id);if(u.length===0)return{requests:[],bids:[],names:new Map};const[T,C]=await Promise.all([p.from("job_invitations").select("id, job_id, worker_id, status, invited_at, bid_scope_note, bid_budget, bid_respond_by").eq("contractor_id",o.id).in("job_id",u).order("invited_at",{ascending:!1}),p.from("applications").select("id, job_id, worker_id, status, created_at, bid_amount, bid_note, bid_recorded_by").in("job_id",u).order("created_at",{ascending:!1})]),j=(T.data??[]).map(s=>({id:s.id,jobId:s.job_id,jobTitle:f.get(s.job_id)??"",subId:s.worker_id,status:String(s.status??"pending"),invitedAt:s.invited_at,scopeNote:s.bid_scope_note??null,budget:s.bid_budget!=null?Number(s.bid_budget):null,respondBy:s.bid_respond_by??null})),h=(C.data??[]).map(s=>({id:s.id,jobId:s.job_id,jobTitle:f.get(s.job_id)??"",subId:s.worker_id,amount:s.bid_amount!=null?Number(s.bid_amount):null,note:s.bid_note??null,status:String(s.status??"pending"),createdAt:s.created_at,recorded:!!s.bid_recorded_by})),_=[...new Set([...j.map(s=>s.subId),...h.map(s=>s.subId)])],A=_.length?await P(_):[],y=new Map;return(A??[]).forEach(s=>{var N,v;y.set(s.userId,((v=(N=s.sub)==null?void 0:N.companyName)==null?void 0:v.trim())||s.displayName||"")}),{requests:j,bids:h,names:y}}}),i=(n==null?void 0:n.requests)??[],l=(n==null?void 0:n.bids)??[],b=(n==null?void 0:n.names)??new Map,x=t=>`$${Math.round(t).toLocaleString()}`,g=t=>{var r;return((r=a.status)==null?void 0:r[t])??t},S=w.useMemo(()=>d==="requests"?i:l,[d,i,l]);return e.jsxs("div",{className:"px-4 pt-3 pb-[calc(env(safe-area-inset-bottom)+96px)] max-w-2xl mx-auto",children:[e.jsx(G,{title:`${a.title} · Knuckl`,description:a.subtitle}),e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx("button",{type:"button",onClick:()=>c(-1),"aria-label":m.back,className:"p-1.5 -ml-1.5 rounded-md text-muted-foreground hover:bg-secondary",children:e.jsx(K,{className:"w-5 h-5"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"font-display text-lg text-foreground leading-tight",children:a.title}),e.jsx("p",{className:"text-label text-muted-foreground",children:a.subtitle})]})]}),e.jsx("div",{className:"grid grid-cols-2 gap-1 p-1 rounded-full bg-secondary/60 mb-4",children:["requests","bids"].map(t=>e.jsx("button",{type:"button",onClick:()=>$(t),className:`h-9 rounded-full text-small font-semibold transition-colors ${d===t?"bg-background text-foreground shadow-sm":"text-muted-foreground"}`,children:t==="requests"?`${a.tabRequests} (${i.length})`:`${a.tabBids} (${l.length})`},t))}),B?e.jsx("div",{className:"space-y-2",children:[0,1,2].map(t=>e.jsx("div",{className:"h-20 rounded-xl bg-card/60 border border-border/60 animate-pulse"},t))}):S.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-10",children:d==="requests"?a.emptyRequests:a.emptyBids}):e.jsx("div",{className:"space-y-2",children:d==="requests"?i.map(t=>e.jsx("button",{type:"button",onClick:()=>c(`/contractor/jobs/${t.jobId}`),className:"w-full text-left rounded-xl border border-border bg-card p-3 active:scale-[0.99] transition-transform",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(D,{className:"w-4 h-4 text-primary mt-0.5 shrink-0"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-sm font-semibold text-foreground truncate",children:b.get(t.subId)||"â"}),e.jsx("p",{className:"text-label text-muted-foreground truncate",children:t.jobTitle}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mt-1 text-caption text-muted-foreground",children:[e.jsx("span",{className:"px-1.5 py-0.5 rounded-full bg-secondary text-foreground font-medium",children:g(t.status)}),t.budget!=null&&e.jsx("span",{children:a.budget(x(t.budget))}),t.respondBy&&e.jsx("span",{children:a.respondBy(E(t.respondBy,I,{month:"short",day:"numeric"}))}),e.jsx("span",{children:q(t.invitedAt)})]}),t.scopeNote&&e.jsx("p",{className:"mt-1.5 text-label text-foreground
1/80 line-clamp-2",children:t.scopeNote})]})]})},t.id)):l.map(t=>e.jsx("button",{type:"button",onClick:()=>c(`/contractor/applicants?job=${t.jobId}`),className:"w-full text-left rounded-xl border border-border bg-card p-3 active:scale-[0.99] transition-transform",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(F,{className:"w-4 h-4 text-primary mt-0.5 shrink-0"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-sm font-semibold text-foreground truncate",children:b.get(t.subId)||"â"}),t.amount!=null&&e.jsx("span",{className:"text-sm font-bold text-primary shrink-0",children:x(t.amount)})]}),e.jsx("p",{className:"text-label text-muted-foreground truncate",children:t.jobTitle}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mt-1 text-caption text-muted-foreground",children:[e.jsx("span",{className:"px-1.5 py-0.5 rounded-full bg-secondary text-foreground font-medium",children:g(t.status)}),t.recorded&&e.jsx("span",{className:"px-1.5 py-0.5 rounded-full bg-primary/10 text-primary font-medium",children:m.recordedBadge}),e.jsx("span",{children:q(t.createdAt)})]}),t.note&&e.jsx("p",{className:"mt-1.5 text-label text-foreground/80 line-clamp-2",children:t.note})]})]})},t.id))})]})}export{Z 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.