1import{u as F,a as u,c as y,i as $,j as e}from"./vendor-query-BxlSJxfF.js";import{u as K,a as O,a0 as Q,a1 as H,a2 as J,a3 as V,e as N,s as c}from"./index-DO0aGFYL.js";import{T as B}from"./textarea-CY9O0h4D.js";import{C as U,W as h,b as _,c as z,s as G}from"./submit-review-DKPhkcxU.js";import{H as X}from"./Head-CFjoxvyt.js";import{M as Y}from"./MomentSharePrompt-D_sKPhPX.js";import{R as k,a as Z}from"./review-window-bRPqN3sJ.js";import{u as ee}from"./vendor-react-DdNhUK9-.js";import{A as te}from"./arrow-left-DNK6fh5x.js";import{S as R}from"./star-B2GJQJHh.js";import{C as re}from"./clock-TDYRjmmL.js";import{C as se}from"./chevron-right-n5eCbV2c.js";import"./vendor-supabase-Csx7YFID.js";import"./moment-share-CYblPAFV.js";import"./vendor-motion-CdL2ySym.js";import"./party-popper-CcTxkyfz.js";import"./share-2-0UyL2gfq.js";function ve(){const j=ee(),{user:s}=K(),p=F(),{t:i}=O(),[o,x]=u.useState(null),[v,w]=u.useState(""),[n,b]=u.useState({}),[C,I]=u.useState(!1),{data:S=0}=y({queryKey:["contractor-prior-review-count",s==null?void 0:s.id],enabled:!!s,queryFn:async()=>{const{count:t}=await c.from("reviews").select("id",{count:"exact",head:!0}).eq("reviewer_id",s.id);return t??0}}),{data:l=[],isLoading:T}=y({queryKey:["contractor-reviewable-workers",s==null?void 0:s.id],enabled:!!s,queryFn:async()=>{const{data:t}=await c.from("jobs").select("id, title, closed_at, job_type").eq("contractor_id",s.id).eq("status","closed").is("deleted_at",null);if(!t||t.length===0)return[];const a=new Date,d=t.filter(r=>r.closed_at?a.getTime()-new Date(r.closed_at).getTime()<=k:!1);if(d.length===0)return[];const E=d.map(r=>r.id),{data:m}=await c.from("applications").select("job_id, worker_id").in("job_id",E).in("status",[...Z]);if(!m||m.length===0)return[];const{data:q}=await c.from("reviews").select("job_id, worker_id").eq("reviewer_id",s.id),M=new Set((q??[]).map(r=>`${r.job_id}:${r.worker_id}`)),P=[...new Set(m.map(r=>r.worker_id))],{data:W}=await c.from("profiles_public").select("user_id, full_name").in("user_id",P),A=new Map((W??[]).map(r=>[r.user_id,r.full_name??"Worker"])),L=new Map(d.map(r=>[r.id,r]));return m.filter(r=>!M.has(`${r.job_id}:${r.worker_id}`)).map(r=>{const f=L.get(r.job_id),D=new Date(f.closed_at);return{jobId:r.job_id,workerId:r.worker_id,workerName:A.get(r.worker_id)??"Worker",title:f.title,jobType:f.job_type,daysLeft:Math.max(0,Math.ceil((D.getTime()+k-a.getTime())/(24*60*60*1e3)))}})}}),g=$({mutationFn:async()=>{const t=z(n);if(!s||!o||!_(h,n))throw new Error("Invalid");const a=await G({jobId:o.jobId,jobType:o.jobType??"day_labor",reviewerId:s.id,revieweeId:o.workerId,reviewerIsJobPoster:!0,rating:t,comment:v,categories:n});if(a.ok===!1)throw new Error(a.error)},onSuccess:()=>{N.success("Review submitted!"),S===0&&I(!0),x(null),b({}),w(""),p.invalidateQueries({queryKey:["contractor-reviewable-workers"]}),p.invalidateQueries({queryKey:["contractor-prior-review-count"]}),p.invalidateQueries({queryKey:["contractor-pending-review-count"]})},onError:t=>N.error(t.message||"Failed to submit review")});return e.jsxs(e.Fragment,{children:[e.jsx(X,{title:"Pending Reviews",description:"Review workers from your completed jobs"}),e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx("div",{className:"sticky top-0 z-10 bg-background/95 backdrop-blur-md border-b border-border/60 px-4 py-3",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{onClick:()=>j(-1),className:"p-1.5 rounded-lg hover:bg-muted/60 transition-colors",children:e.jsx(te,{className:"w-5 h-5 text-foreground"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-lg font-display font-semibold text-foreground",children:"Pending Reviews"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[l.length," worker",l.length!==1?"s":""," awaiting your review"]})]})]})}),e.jsxs("div",{className:"p-4 space-y-3",children:[e.jsx(Y,{event:"contractor_first_review",active:C,title:i.pass3.momentContractorTitle,body:i.pass3.momentContractorBody,shareLabel:i.pass3.momentContractorShare}),T?e.jsx("div",{className:"space-y-2","aria-busy":"true",children:[0,1,2].map(t=>e.jsx("div",{className:"h-20 rounded-card border border-border/60 bg-card/60 animate-pulse"},t))}):l.length===0?e.jsxs("div",{className:"text-center py-16 space-y-3",children:[e.jsx("div",{className:"w-14 h-14 roun
1ded-card bg-primary/10 mx-auto flex items-center justify-center",children:e.jsx(R,{className:"w-7 h-7 text-primary"})}),e.jsx("p",{className:"text-foreground text-sm font-semibold",children:i.pass3.noPendingReviews}),e.jsx("p",{className:"text-muted-foreground/80 text-xs",children:i.pass3.allCaughtUp}),e.jsx("button",{type:"button",onClick:()=>j("/home"),className:"mt-2 inline-flex items-center gap-1.5 px-4 py-2 rounded-xl bg-primary text-primary-foreground text-xs font-semibold hover:bg-primary/90 transition-colors",children:i.pass3.backToHome})]}):l.map((t,a)=>e.jsx("button",{onClick:()=>x({jobId:t.jobId,workerId:t.workerId,workerName:t.workerName,jobType:t.jobType}),className:"w-full text-left p-4 rounded-xl bg-card/80 backdrop-blur-md border border-border/60 hover:border-warning/40 transition-all group",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"font-medium text-foreground text-sm truncate",children:t.workerName}),e.jsx("p",{className:"text-xs text-muted-foreground truncate",children:t.title}),e.jsxs("div",{className:"flex items-center gap-1.5 mt-1",children:[e.jsx(re,{className:"w-3 h-3 text-warning"}),e.jsxs("span",{className:"text-xs text-warning font-medium",children:[t.daysLeft," day",t.daysLeft!==1?"s":""," left to review"]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(R,{className:"w-4 h-4 text-warning"}),e.jsx(se,{className:"w-4 h-4 text-muted-foreground group-hover:text-foreground transition-colors"})]})]})},`${t.jobId}-${t.workerId}-${a}`))]})]}),e.jsx(Q,{open:!!o,onOpenChange:t=>{t||(x(null),b({}),w(""))},children:e.jsxs(H,{className:"max-w-md",children:[e.jsx(J,{children:e.jsxs(V,{className:"font-display",children:["Rate ",o==null?void 0:o.workerName]})}),e.jsxs("div",{className:"space-y-4 pt-2",children:[e.jsx(U,{categories:h,values:n,onChange:(t,a)=>b(d=>({...d,[t]:a}))}),e.jsx(B,{placeholder:"Leave a comment (optional)",value:v,onChange:t=>w(t.target.value),className:"min-h-[80px]"}),e.jsx("button",{onClick:()=>g.mutate(),disabled:!_(h,n)||g.isPending,className:"w-full py-2.5 rounded-lg bg-primary text-primary-foreground font-medium text-sm disabled:opacity-50 transition-opacity",children:g.isPending?"Submittingâ¦":"Submit Review"})]})]})})]})}export{ve 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.