1import{a as p,j as e,u as Mt,c as re,i as Re}from"./vendor-query-BxlSJxfF.js";import{o as ss}from"./post-job-sheet-BxL-Oe-u.js";import{B as be}from"./badge-4jZnSn2H.js";import{p as Kt,m as Nt,L as ie,u as Ue,s as b,a as Oe,a0 as Ft,a1 as Qt,a2 as It,a3 as Lt,q as rs,r as kt,e as R,I as as}from"./index-DO0aGFYL.js";import{a as Ge}from"./use-profile-summary-pcsmjbRV.js";import{A as os,a as is,b as ns,c as ls,d as ds,e as cs,f as ms,g as us}from"./alert-dialog-WBQzXKSB.js";import{S as ps,a as fs,b as xs,c as gs,d as Ye}from"./select-B9JmKruI.js";import{p as St}from"./parse-local-date-CGCN6Dtg.js";import{s as hs}from"./share-job-Dw7dHJvf.js";import{o as bs,u as ys}from"./application-status-OYVIyYV9.js";import{i as Ct,a as ws,b as vs}from"./job-lifecycle-luKOFqVS.js";import{u as st,a as _s,d as js}from"./vendor-react-DdNhUK9-.js";import{f as Ns,b as ks,a as Ss}from"./schedule-utils-D9oAnoFZ.js";import{a as qt}from"./route-prefetch-DBHlz2eE.js";import{t as Bt}from"./image-url-_sEuZELz.js";import{j as Cs,b as qs,n as Js,A as Ps}from"./job-status-display-C9X_vakp.js";import{m as Pe,A as Jt}from"./vendor-motion-CdL2ySym.js";import{C as $e}from"./circle-check-big-S3OQIQmC.js";import{Z as Ze}from"./zap-3WSssjod.js";import{M as Es}from"./map-pin-Clc12hBl.js";import{C as Ds}from"./calendar-bL1Vkweo.js";import{p as Pt}from"./parseISO-B5tfR1s8.js";import{C as Ie}from"./clock-TDYRjmmL.js";import{B as Wt}from"./briefcase-DprwYuVO.js";import{A as Le}from"./arrow-right-Cxpw4wQL.js";import{U as We}from"./users-4wDC2oQA.js";import{S as Et}from"./share-2-0UyL2gfq.js";import{M as Be}from"./message-square-CLxZQpIa.js";import{H as $s}from"./heart-BHSL6QMs.js";import{S as Me}from"./star-B2GJQJHh.js";import{R as Ts}from"./repeat-B20BXHly.js";import{E as As}from"./eye-zwjnFLuE.js";import{R as Dt}from"./rotate-ccw-CaM1lpMX.js";import{E as Rs}from"./ellipsis-CfLXW49T.js";import{P as et}from"./pencil-B-NCVQLG.js";import{C as Xe}from"./copy-0DH5VK1i.js";import{T as tt}from"./trash-2-EocM2Uxl.js";import{P as Ms}from"./play-CI91lpXO.js";import{C as Ks}from"./CloseJobDialog-BhDtCIzH.js";import{u as Fs,N as Qs,P as Is}from"./PendingApplicantsStrip-BPAY3Z_9.js";import{u as Ls,A as Bs}from"./AttentionSection-BdU1R4Ht.js";import{u as Ws}from"./use-shortlist-RQmgZicA.js";import{T as Us}from"./TrackerViewSwitch-EaPPnucF.js";import{u as Os,p as Hs,E as zs}from"./application-status-badge-DzzV56B5.js";import{c as Vs,b as Gs,W as $t,C as Ys,s as Zs}from"./submit-review-DKPhkcxU.js";import{T as Ut}from"./textarea-CY9O0h4D.js";import{B as Ot}from"./ban-D47cmeaL.js";import{R as Xs}from"./review-window-bRPqN3sJ.js";import{C as er}from"./circle-x-DfUR7P0J.js";import{S as Ht}from"./send-C6vNENnO.js";import{m as tr,p as sr}from"./tier-error-C6TW3of0.js";import{u as rr}from"./use-feature-gate-D2hKRPw6.js";import{P as Tt}from"./plus-Cn9YMeBw.js";import{S as ar}from"./search-BkqYkxAv.js";import"./vendor-supabase-Csx7YFID.js";import"./index-D17hSi50.js";import"./index-Ce1IEqmK.js";import"./index-Bidgsva9.js";import"./chevron-down-Bc6tfcMh.js";import"./check-BTT3mgzE.js";import"./chevron-up-EG6HBK1O.js";import"./QuickJobDialog-DPtlmgFx.js";import"./switch-CdLpmXwy.js";import"./use-pending-review-count-DlV_gBvd.js";import"./LocationAutocomplete-BSme0mji.js";import"./geocode-CX448-fu.js";import"./locate-fixed-DXW6AJ3Q.js";import"./MiniMapPreview-BDdJ0hjB.js";import"./MapUnavailable-B-QP0qIy.js";import"./external-link-BMHb0t-K.js";import"./MarketRateWarning-ClC-iQuU.js";import"./use-geolocation-CF3oDqXg.js";import"./trending-up-DS_OYcrn.js";import"./dollar-sign-4OmuIJls.js";import"./file-text-CHUqxuo4.js";import"./car-DO0yWu1G.js";import"./feedback-Bgf_c1TA.js";import"./appReview-CW1-s-M2.js";import"./undo-2-DbTqGnAe.js";import"./user-x-CO5rZhsv.js";import"./user-plus-e-panZql.js";import"./chevron-right-n5eCbV2c.js";import"./phase-status-C8GaQkLu.js";import"./flag-iQDr95MH.js";import"./circle-check-BzeG-ygw.js";import"./flash-prefill-CtQFfO_E.js";import"./sheet-KxRpZ2qz.js";import"./JobSkillPicker-BUap6frS.js";import"./skill-catalog-CiwHrT6-.js";import"./sparkles-B9Io74C_.js";import"./JobMediaUpload-D4RefLCq.js";import"./image-resize-D0CnxHUe.js";import"./camera-vAyeR-gp.js";import"./use-subscription-OP_b8dLc.js";import"./bid-deadline-BsuXNHJh.js";import"./shield-RTfo1DTu.js";import"./lock-CWPApfun.js";import"./info-CrnkT6_5.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const At=Kt("Pause",[["rect",{x:"14",y:"4",width:"4",height:"16",rx:"1",key:"zuxfzm"}],["rect",{x:"6",y:"4",width:"4",height:"16",rx:"1",key:"1okwgv"}]]);/** 7 * @license lucide-react v0.462.0 - ISC 8 * 9 * This source code is licensed under the ISC license. 10 * See the LICENSE file in the root directory of this source tree. 11 */const Rt=Kt("Pin",[["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7
11a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z",key:"1nkz8b"}]]);function or({job:s,index:k,applicantCount:E,pendingAppCount:r,jobUnread:h,shortlistedCount:n,needsReview:B,reviewInfo:W,skillCoverage:I,acceptedWorkers:y,acceptedWorkerCount:D,applicantPreview:M=[],isExpanded:ye,isDetailsExpanded:U,isPinned:O,duplicatingId:A,onToggleExpand:ne,onToggleDetails:v,onTogglePin:L,onEdit:S,onDuplicate:ae,onDelete:te,onClose:G,onRepost:se,onPause:X,onShare:H,showReviewCTA:j=!1,onHighlightShortlisted:Ce,t:$,children:oe}){const N=st(),m=$.jobCard,pe=s.job_type==="sub_package",fe=s.bid_deadline,we=s.status,C=Cs(Js(we,{deletedAt:s.deleted_at,startDate:s.start_date}),qs(m))??we,ee=!!s.needs_closeout&&!Ct(s.status);s.slots-s.filled_slots;const de=s.slots>0?s.filled_slots/s.slots*100:0,ve=s.skills??[];I.filter(f=>f.filled).length,I.length;const qe=Ns(s.recurrence_pattern??null,$.scheduleLabels),Je=ks(s.shift_start_time??null,s.shift_end_time??null,$.scheduleLabels),Ee=Ss(s.start_date||null,s.end_date??null),[ce,_e]=p.useState(!1),Se=p.useRef(null),x=p.useRef(null),[Y,z]=p.useState("bottom"),[F,xe]=p.useState({top:0,right:0});p.useEffect(()=>{if(!ce)return;const f=le=>{var T,w;const q=le.target;(T=Se.current)!=null&&T.contains(q)||(w=x.current)!=null&&w.contains(q)||_e(!1)};return document.addEventListener("mousedown",f),()=>document.removeEventListener("mousedown",f)},[ce]),p.useEffect(()=>{if(!ce)return;const f=x.current;if(!f)return;(()=>{const T=f.getBoundingClientRect(),w=window.innerHeight-T.bottom,Te=T.top,Fe=w<280&&Te>w?"top":"bottom";z(Fe),xe({top:Fe==="bottom"?T.bottom+8:T.top-8,right:window.innerWidth-T.right})})();const q=()=>_e(!1);return window.addEventListener("scroll",q,!0),window.addEventListener("resize",q),()=>{window.removeEventListener("scroll",q,!0),window.removeEventListener("resize",q)}},[ce]);const me=s.status==="paused",V=ws(s.status),Z=Ct(s.status),je=vs(s.slots,s.filled_slots),Ne=!je&&(s.urgency==="asap"||s.urgency==="urgent")&&(V||s.status==="filled"),ge=s.duration,g=M.slice(0,4),Ke=Math.max(0,E-g.length),De=r>0;return e.jsxs(Pe.div,{"data-job-status":s.status,"data-has-pending-applicants":E>0?"true":"false","data-needs-wrap-up":je&&!Z&&s.status!=="draft"?"true":"false",onPointerEnter:qt,onTouchStart:qt,initial:{opacity:0,y:14,scale:.98},animate:{opacity:1,y:0,scale:1},transition:{delay:k*.06,duration:.45,ease:[.16,1,.3,1]},className:`rounded-card overflow-hidden transition-all relative group/card ${V?"bg-card/80 backdrop-blur-md border border-primary/30 shadow-[0_4px_20px_-6px_hsl(var(--primary)/0.15)] hover:shadow-[0_8px_30px_-6px_hsl(var(--primary)/0.25)] hover:border-primary/50":s.status==="filled"?"bg-card/80 backdrop-blur-md border border-warning/30 shadow-[0_4px_20px_-6px_hsl(var(--warning)/0.1)] hover:border-warning/50":s.status==="closed"&&B?"bg-card/80 backdrop-blur-md border border-warning/40 shadow-sm":Z?"bg-muted/30 backdrop-blur-sm border border-border/60 opacity-70":"bg-muted/20 backdrop-blur-sm border border-dashed border-border/60 opacity-60"}`,children:[V&&e.jsx("div",{className:"absolute -top-8 -right-8 w-28 h-28 rounded-full bg-primary/8 blur-2xl pointer-events-none"}),e.jsxs("div",{className:"p-3 sm:p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0 flex-1 flex-wrap",children:[e.jsx("h4",{className:`font-display text-base font-bold leading-tight truncate ${Z||s.status==="draft"?"text-muted-foreground":"text-foreground"}`,children:s.title}),e.jsx(be,{className:`text-micro py-0 px-1.5 shrink-0 uppercase tracking-wider ${V?"bg-success/15 text-success border-success/30":s.status==="filled"?"bg-warning/15 text-warning border-warning/30":Z?"bg-muted text-muted-foreground border-border":"bg-secondary text-muted-foreground border-border"}`,children:C}),ee&&e.jsxs(be,{className:"bg-warning/20 text-warning border-warning/40 text-micro py-0 px-1.5 shrink-0 uppercase tracking-wider gap-0.5",children:[e.jsx($e,{className:"w-2.5 h-2.5"})," ",$.jobCloseout.needsWrapUpChip]}),me&&e.jsxs(be,{className:"bg-muted text-muted-foreground border-border text-micro py-0 px-1.5 shrink-0 uppercase tracking-wider gap-0.5",children:[e.jsx(At,{className:"w-2.5 h-2.5"})," ",m.paused]}),s.urgency==="asap"&&e.jsxs(be,{className:"bg-destructive/15 text-destructive border-destructive/30 text-micro py-0 px-1.5 gap-0.5 animate-pulse",children:[e.jsx(Ze,{className:"w-2.5 h-2.5"})," ASAP"]}),s.urgency==="urgent"&&e.jsxs(be,{className:"bg-warning/15 text-warning border-warning/30 text-micro py-0 px-1.5 gap-0.5",children:[e.jsx(Ze,{className:"w-2.5 h-2.5"})," URGENT"]}),O&&e.jsx(Rt,{className:"w-3 h-3 text-primary fill-primary shrink-0"})]}),e.jsxs("span",{className:`text-base font-bold shrink-0 leading-tight ${Z?"text-muted-foreground":"text-primary"}`,children:["$",s.pay,s.pay_range_max?`â$${s.pay_range_max}`:"",e.jsx("span",{className:"text-micro font-medium opacity-80",children:pe?` ${m.cardBudgetFixed}`:`/${s.pay_type==="hourly"?m.payPerHr:s.pay_type==="daily"?m.payPerDay:m.payPerJob}`})]})]}),(s.location||s.start_date||ge)&&e.jsxs("div",{className:"flex items-center gap-3 text-caption text-muted-foreground flex-wrap",children:[s.location&&e.jsxs("span",{className:"inline-flex items-center gap-1 min-w-0",children:[e.jsx(Es,{className:"w-3 h-3 shrink-0"}),e.jsx("span",{className:"truncate max-w-[160px]",children:s.location})]}),(Ee||s.start_date)&&e.jsxs("span",{className:"inline-flex items-center gap-1 shrink-0",children:[e.jsx(Ds,{className:"w-3 h-3"}),Ee||(s.start_date?Nt(Pt(s.start_date),"MMM d"):"")]}),ge&&e.jsxs("span",{className:"inline-flex items-center gap-1 shrink-0",children:[e.jsx(Ie,{className:"w-3 h-3"}),ge]}),Je&&!ge&&e.jsxs("span",{className:"inline-flex items-center gap-1 shrink-0",children:[e.jsx(Ie,{className:"w-3 h-3"}),Je]})]}),pe&&e.jsxs("div",{className:"flex items-center gap-3 text-caption text-muted-foreground flex-wrap",children:[e.jsxs("span",{className:"inline-flex items-center gap-1 font-semibold text-foreground",children:[e.jsx(Wt,{className:"w-3 h-3"})," ",m.cardBidsCount(E)]}),fe&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Ie,{className:"w-3 h-3"}),m.cardBidDeadline(Nt(Pt(fe),"MMM d"))]})]}),!pe&&s.slots>0&&e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[je?e.jsxs("span",{className:"inline-flex items-center gap-1 text-caption font-semibold text-success",children:[e.jsx($e,{className:"w-3 h-3"})," ",m.fullyStaffed]}):Ne?e.jsxs("span",{className:"inline-flex items-center gap-1 text-caption font-semibold text-primary",children:[e.jsx(Ze,{className:"w-3 h-3"})," ",m.needsWorkers]}):e.jsxs("span",{className:"text-caption font-medium text-muted-foreground",children:[e.jsxs("span",{className:"text-foreground font-semibold",children:[s.filled_slots,"/",s.slots]})," ",m.filled]}),!je&&!Ne&&e.jsxs("span",{className:"text-micro text-muted-foreground",children:[Math.round(de),"%"]})]}),e.jsx("div",{className:"h-1.5 rounded-full bg-secondary/60 overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full transition-all ${je?"bg-success":Ne?"bg-primary":"bg-primary/70"}`,style:{width:`${Math.max(4,de)}%`}})})]}),E>0&&e.jsxs("button",{type:"button",onClick:f=>{f.stopPropagation(),N(`/contractor/applicants?job=${s.id}`)},className:"flex items-center gap-2 w-full text-left",children:[e.jsxs("div",{className:"flex -sp
11ace-x-2",children:[g.map(f=>e.jsx("div",{className:"w-7 h-7 rounded-full border-2 border-card overflow-hidden bg-secondary flex items-center justify-center text-micro font-semibold text-foreground",title:f.name,children:f.avatarUrl?e.jsx("img",{src:Bt(f.avatarUrl,96),alt:f.name,className:"w-full h-full object-cover",loading:"lazy",decoding:"async"}):(f.name||"?").split(" ").map(le=>le[0]).join("").slice(0,2).toUpperCase()},f.workerId)),Ke>0&&e.jsxs("div",{className:"w-7 h-7 rounded-full border-2 border-card bg-muted text-muted-foreground text-micro font-semibold flex items-center justify-center",children:["+",Ke]})]}),e.jsxs("span",{className:`text-caption font-semibold ${De?"text-primary":"text-muted-foreground"}`,children:[m.applicants(E),De&&e.jsx("span",{className:"ml-1 text-micro font-medium",children:m.newApplicants(r)})]}),e.jsx("div",{className:"flex-1"}),e.jsx(Le,{className:"w-3.5 h-3.5 text-muted-foreground"})]}),E===0&&(V||s.status==="filled")&&e.jsxs("button",{type:"button",onClick:f=>{f.stopPropagation(),H==null||H(s)},className:"flex items-center gap-2 w-full text-left text-caption text-muted-foreground hover:text-foreground transition-colors",children:[e.jsx("div",{className:"w-7 h-7 rounded-full border border-dashed border-border/60 bg-muted/30 flex items-center justify-center",children:e.jsx(We,{className:"w-3 h-3 opacity-60"})}),e.jsx("span",{children:m.noApplicantsYet}),e.jsx("div",{className:"flex-1"}),H&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-primary font-semibold",children:[e.jsx(Et,{className:"w-3 h-3"})," ",m.share]})]}),ve.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[ve.slice(0,6).map(f=>e.jsx("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full text-micro font-medium bg-secondary/80 text-foreground border border-border/60",children:f},f)),ve.length>6&&e.jsxs("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full text-micro font-medium bg-secondary/40 text-muted-foreground border border-border/60",children:["+",ve.length-6]})]}),(h>0||n>0||B&&W)&&e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[h>0&&e.jsxs(be,{className:"bg-primary text-primary-foreground text-micro py-0 px-1.5",children:[e.jsx(Be,{className:"w-2.5 h-2.5 mr-0.5"})," ",h]}),n>0&&e.jsxs("button",{onClick:Ce,className:"flex items-center gap-1 text-micro font-medium bg-destructive/10 text-destructive border border-destructive/25 rounded-md px-2 py-1 hover:bg-destructive/20 transition-colors",children:[e.jsx($s,{className:"w-2.5 h-2.5 fill-destructive"})," ",n]}),B&&W&&e.jsxs("span",{className:"flex items-center gap-1 text-micro font-bold bg-warning/15 text-warning border border-warning/40 rounded-md px-2 py-1 uppercase tracking-wide",children:[e.jsx(Me,{className:"w-2.5 h-2.5 fill-warning"})," ",m.reviewPending(W.pending)]})]}),e.jsx(Jt,{children:U&&s.status!=="closed"&&e.jsx(Pe.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},className:"overflow-hidden space-y-2",children:e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[qe&&e.jsxs("span",{className:"flex items-center gap-1 text-micro text-muted-foreground bg-muted/40 rounded-md px-2 py-0.5",children:[e.jsx(Ts,{className:"w-2.5 h-2.5"})," ",qe]}),Je&&ge&&e.jsxs("span",{className:"flex items-center gap-1 text-micro text-muted-foreground bg-muted/40 rounded-md px-2 py-0.5",children:[e.jsx(Ie,{className:"w-2.5 h-2.5"})," ",Je]})]})})}),e.jsxs("div",{className:"flex items-center gap-2 pt-2 border-t border-border/60",children:[ee&&G?e.jsxs("button",{onClick:f=>{f.stopPropagation(),G()},className:"flex-1 inline-flex items-center justify-center gap-1.5 px-3 py-2 rounded-lg text-xs font-bold bg-warning text-warning-foreground hover:bg-warning/90 transition-all shadow-md shadow-warning/30",children:[e.jsx($e,{className:"w-3.5 h-3.5"})," ",$.jobCloseout.wrapUpShort," ",e.jsx(Le,{className:"w-3.5 h-3.5"})]}):B&&s.status==="closed"?e.jsxs("button",{onClick:f=>{f.stopPropagation(),N("/contractor/pending-reviews")},className:"flex-1 inline-flex items-center justify-center gap-1.5 px-3 py-2 rounded-lg text-xs font-bold bg-primary text-primary-foreground hover:bg-primary/90 transition-all shadow-md shadow-primary/40 ring-2 ring-primary/30 animate-[pulse_2.4s_ease-in-out_infinite]",children:[e.jsx(Me,{className:"w-3.5 h-3.5 fill-primary-foreground"})," ",m.leaveReview," ",e.jsx(Le,{className:"w-3.5 h-3.5"})]}):r>0?e.jsxs("button",{onClick:f=>{f.stopPropagation(),N(`/contractor/applicants?job=${s.id}`)},className:"flex-1 inline-flex items-center justify-center gap-1.5 px-3 py-2 rounded-lg text-xs font-bold bg-primary text-primary-foreground hover:bg-primary/90 transition-all shadow-md shadow-primary/40 ring-2 ring-primary/30 animate-[pulse_2.4s_ease-in-out_infinite]",children:[m.reviewApplicantsCta(r)," ",e.jsx(Le,{className:"w-3.5 h-3.5"})]}):e.jsxs("button",{onClick:()=>N(`/contractor/jobs/${s.id}`),className:"flex-1 inline-flex items-center justify-center gap-1.5 px-3 py-2 rounded-lg text-xs font-semibold bg-primary text-primary-foreground hover:bg-primary/90 transition-all",children:[e.jsx(As,{className:"w-3.5 h-3.5"})," ",m.view]}),Z&&se&&e.jsxs("button",{onClick:f=>{f.stopPropagation(),se(s)},disabled:A===s.id,className:"inline-flex items-center justify-center gap-1.5 px-3 py-2 rounded-lg text-xs font-semibold bg-primary/10 text-primary border border-primary/30 hover:bg-primary/20 transition-all disabled:opacity-50",title:m.repostTitle,children:[A===s.id?e.jsx(ie,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(Dt,{className:"w-3.5 h-3.5"}),m.repost]}),s.status==="filled"&&G&&e.jsxs("button",{onClick:f=>{f.stopPropagation(),G==null||G()},className:"inline-flex items-center justify-center gap-1.5 px-3 py-2 rounded-lg text-xs font-semibold bg-success/10 text-success border border-success/40 hover:bg-success/20 transition-all",title:m.closeReviewTitle,children:[e.jsx($e,{className:"w-3.5 h-3.5"})," ",m.closeReview]}),e.jsxs("div",{className:"relative",children:[e.jsx("button",{ref:x,type:"button",onClick:f=>{f.stopPropagation(),_e(le=>!le)},className:"inline-flex items-center justify-center w-9 h-9 rounded-lg bg-card text-foreground border border-border/60 hover:border-primary/40 hover:text-primary transition-all","aria-label":m.moreActions,"aria-haspopup":"menu","aria-expanded":ce,children:e.jsx(Rs,{className:"w-4 h-4"})}),typeof document<"u"&&_s.createPortal(e.jsx(Jt,{children:ce&&e.jsx(Pe.div,{ref:Se,initial:{opacity:0,y:4,scale:.98}
11,animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:4,scale:.98},transition:{duration:.12},role:"menu",style:{position:"fixed",top:Y==="bottom"?F.top:void 0,bottom:Y==="top"?window.innerHeight-F.top:void 0,right:F.right,zIndex:1e3},className:"min-w-[200px] max-h-[60vh] overflow-y-auto rounded-lg border border-border/60 bg-popover shadow-lg",onClick:f=>f.stopPropagation(),children:(()=>{const f="w-full px-3 py-2 text-left text-xs font-medium flex items-center gap-2 hover:bg-accent/60",le="w-full px-3 py-2 text-left text-xs font-medium flex items-center gap-2 hover:bg-destructive/10 text-destructive border-t border-border/60",q=()=>_e(!1),T=[];return s.status==="filled"&&G&&T.push(e.jsxs("button",{role:"menuitem",onClick:w=>{w.stopPropagation(),q(),G()},className:`${f} text-success font-semibold`,children:[e.jsx($e,{className:"w-3.5 h-3.5 text-success"}),m.closeReview]},"close-review")),Z&&se&&T.push(e.jsxs("button",{role:"menuitem",onClick:w=>{w.stopPropagation(),q(),se(s)},disabled:A===s.id,className:`${f} disabled:opacity-50`,children:[A===s.id?e.jsx(ie,{className:"w-3.5 h-3.5 animate-spin text-muted-foreground"}):e.jsx(Dt,{className:"w-3.5 h-3.5 text-muted-foreground"}),m.repostJob]},"repost")),s.status==="draft"?(T.push(e.jsxs("button",{role:"menuitem",onClick:w=>{w.stopPropagation(),q(),S(s.id)},className:f,children:[e.jsx(et,{className:"w-3.5 h-3.5 text-muted-foreground"}),m.editPublish]},"edit-publish")),T.push(e.jsxs("button",{role:"menuitem",onClick:w=>{w.stopPropagation(),q(),ae(s)},disabled:A===s.id,className:`${f} disabled:opacity-50`,children:[A===s.id?e.jsx(ie,{className:"w-3.5 h-3.5 animate-spin text-muted-foreground"}):e.jsx(Xe,{className:"w-3.5 h-3.5 text-muted-foreground"}),m.duplicate]},"dup-draft")),T.push(e.jsxs("button",{role:"menuitem",onClick:w=>{w.stopPropagation(),q(),te(s.id)},className:le,children:[e.jsx(tt,{className:"w-3.5 h-3.5"}),m.deleteDraft]},"delete-draft")),T):(Z||(T.push(e.jsxs("button",{role:"menuitem",onClick:w=>{w.stopPropagation(),q(),L(s.id,O)},className:f,children:[e.jsx(Rt,{className:`w-3.5 h-3.5 ${O?"fill-primary text-primary":"text-muted-foreground"}`}),O?m.unpinJob:m.pinToTop]},"pin")),T.push(e.jsxs("button",{role:"menuitem",onClick:w=>{w.stopPropagation(),q(),S(s.id)},className:f,children:[e.jsx(et,{className:"w-3.5 h-3.5 text-muted-foreground"}),m.editJob]},"edit")),E>0&&T.push(e.jsxs("button",{role:"menuitem",onClick:w=>{w.stopPropagation(),q(),N(`/contractor/applicants?job=${s.id}`)},className:f,children:[e.jsx(We,{className:"w-3.5 h-3.5 text-muted-foreground"}),m.viewApplicants]},"view-applicants")),(V||me)&&X&&T.push(e.jsxs("button",{role:"menuitem",onClick:w=>{w.stopPropagation(),q(),X(s.id,me)},className:f,children:[me?e.jsx(Ms,{className:"w-3.5 h-3.5 text-muted-foreground"}):e.jsx(At,{className:"w-3.5 h-3.5 text-muted-foreground"}),me?m.resumeJob:m.pauseJob]},"pause")),T.push(e.jsxs("button",{role:"menuitem",onClick:w=>{w.stopPropagation(),q(),ae(s)},disabled:A===s.id,className:`${f} disabled:opacity-50`,children:[A===s.id?e.jsx(ie,{className:"w-3.5 h-3.5 animate-spin text-muted-foreground"}):e.jsx(Xe,{className:"w-3.5 h-3.5 text-muted-foreground"}),m.duplicateJob]},"dup")),V&&G&&T.push(e.jsxs("button",{role:"menuitem",onClick:w=>{w.stopPropagation(),q(),G()},className:f,children:[e.jsx(Ps,{className:"w-3.5 h-3.5 text-muted-foreground"}),m.closeJob]},"close"))),Z&&T.push(e.jsxs("button",{role:"menuitem",onClick:w=>{w.stopPropagation(),q(),ae(s)},disabled:A===s.id,className:`${f} disabled:opacity-50`,children:[A===s.id?e.jsx(ie,{className:"w-3.5 h-3.5 animate-spin text-muted-foreground"}):e.jsx(Xe,{className:"w-3.5 h-3.5 text-muted-foreground"}),m.duplicateAsDraft]},"dup-as-draft")),T.push(e.jsxs("button",{role:"menuitem",onClick:w=>{w.stopPropagation(),q(),H==null||H(s)},className:f,children:[e.jsx(Et,{className:"w-3.5 h-3.5 text-muted-foreground"}),m.shareJob]},"share")),T.push(e.jsxs("button",{role:"menuitem",onClick:w=>{w.stopPropagation(),q(),te(s.id)},className:le,children:[e.jsx(tt,{className:"w-3.5 h-3.5"}),Z?m.deleteJob:$.contractorJobs.deleteJob]},"delete")),T)})()})}),document.body)]})]}),V&&e.jsx("div",{className:"absolute bottom-0 left-3 right-3 h-px bg-gradient-to-r from-transparent via-primary/20 to-transparent"})]}),oe]})}const ir=p.memo(or);function nr(s){const{user:k}=Ue(),[E,r]=p.useState(!1),[h,n]=p.useState(!1);p.useEffect(()=>{let W=!1;if(!k){r(!1),n(!0);return}return n(!1),(async()=>{const{data:I}
11=await b.from("user_ui_hints").select("hint_key").eq("user_id",k.id).eq("hint_key",s).maybeSingle();W||(r(!I),n(!0))})(),()=>{W=!0}},[k,s]);const B=p.useCallback(async()=>{r(!1),k&&await b.from("user_ui_hints").upsert({user_id:k.id,hint_key:s},{onConflict:"user_id,hint_key"})},[k,s]);return{shouldShow:E&&h,markSeen:B}}function lr({open:s,onOpenChange:k,workerName:E,workerSkills:r,onSubmit:h,onUpdate:n,onDelete:B,isPending:W,isDeleting:I,suspendedUntil:y,readOnly:D,canEdit:M,existingRating:ye,existingComment:U,existingEndorsedSkills:O,existingCategoryRatings:A}){const[ne,v]=p.useState(U||""),[L,S]=p.useState(O||[]),[ae,te]=p.useState(!1),[G,se]=p.useState(!1),[X,H]=p.useState(A||{}),{t:j,lang:Ce}=Oe(),$=D&&!ae,oe=Vs(X),N=Gs($t,X);p.useEffect(()=>{s&&(v(U||""),S(O||[]),H(A||{}),te(!1),se(!1))},[s,U,O,A]);const m=y&&new Date(y)>new Date,pe=p.useCallback(C=>{$||S(ee=>ee.includes(C)?ee.filter(de=>de!==C):[...ee,C])},[$]),fe=()=>{v(U||""),S(O||[]),H(A||{}),te(!1)},we=p.useCallback((C,ee)=>{H(de=>({...de,[C]:ee}))},[]);return e.jsx(Ft,{open:s,onOpenChange:k,children:e.jsxs(Qt,{className:"sm:max-w-md max-h-[85vh] overflow-y-auto",children:[e.jsx(It,{children:e.jsx(Lt,{className:"font-display text-xl",children:ae?j.contractorJobs.editReviewHeader(E.toUpperCase()):$?j.contractorJobs.reviewHeader(E.toUpperCase()):`${j.contractorJobs.rate} ${E.toUpperCase()}`})}),e.jsxs("div",{className:"space-y-4 pt-2",children:[!$&&m&&e.jsxs("div",{className:"flex items-start gap-2.5 bg-warning/10 border border-warning/30 rounded-lg p-3",children:[e.jsx(Ot,{className:"w-4 h-4 text-warning mt-0.5 shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-warning",children:j.contractorJobs.reviewPrivilegesSuspended}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:j.contractorJobs.reviewSuspendedUntil(rs(y,Ce))})]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-3",children:$?j.contractorJobs.ratings:j.contractorJobs.howDidTheyPerform}),e.jsx(Ys,{categories:$t,values:X,onChange:we,readOnly:$}),!$&&oe>0&&e.jsxs("div",{className:"flex items-center gap-2 mt-3 pt-3 border-t border-border/60",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:j.contractorJobs.overall}),e.jsx("span",{className:"text-sm font-bold text-foreground",children:oe}),e.jsx("div",{className:"flex gap-0.5",children:[1,2,3,4,5].map(C=>e.jsx(Me,{className:`w-3.5 h-3.5 ${C<=Math.round(oe)?"text-warning fill-warning":"text-muted-foreground/20"}`},C))})]})]}),(ne||!$)&&e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:$?j.contractorJobs.comment:j.contractorJobs.leaveComment}),$?e.jsx("p",{className:"text-sm text-foreground bg-secondary/50 rounded-lg p-3 border border-border",children:ne||e.jsx("span",{className:"text-muted-foreground italic",children:j.contractorJobs.noCommentLeft})}):e.jsx(Ut,{value:ne,onChange:C=>v(C.target.value),placeholder:j.contractorJobs.commentPlaceholder,autoCapitalize:"sentences",enterKeyHint:"done",className:"bg-secondary border-border",rows:3,disabled:!!m})]}),r.length>0&&($?L.length>0:!0)&&e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:$?j.contractorJobs.endorsedSkills:j.contractorJobs.endorseSkillsOptional}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:($?r.filter(C=>L.includes(C)):r).map(C=>{const ee=L.includes(C);return e.jsxs("button",{type:"button",onClick:()=>pe(C),disabled:!!m||$,className:`px-2.5 py-1 rounded-full text-xs font-medium border transition-all ${ee?"bg-success/15 text-success border-success/40":"bg-card text-muted-foreground border-border hover:border-success/40 hover:text-success"} disabled:opacity-80 ${$?"cursor-default":"disabled:cursor-not-allowed"}`,children:[ee?"â ":"",C]},C)})}),!$&&e.jsx("p",{className:"text-micro text-muted-foreground mt-1.5",children:j.contractorJobs.endorsementsHelper})]}),$&&M&&e.jsxs("div",{className:"flex gap-2 pt-1",children:[e.jsxs("button",{onClick:()=>te(!0),className:"flex-1 py-2.5 rounded-md bg-secondary text-foreground text-sm font-medium hover:bg-secondary/80 transition-colors flex items-center justify-center gap-2 border border-border",children:[e.jsx(et,{className:"w-4 h-4"})," ",j.contractorJobs.editReview]}),e.jsx("button",{onClick:()=>
11se(!0),disabled:I,className:"py-2.5 px-4 rounded-md bg-destructive/10 text-destructive text-sm font-medium hover:bg-destructive/20 transition-colors flex items-center justify-center gap-2 border border-destructive/30 disabled:opacity-50",children:I?e.jsx(ie,{className:"w-4 h-4 animate-spin"}):e.jsx(tt,{className:"w-4 h-4"})})]}),G&&e.jsxs("div",{className:"bg-destructive/10 border border-destructive/30 rounded-lg p-3 space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-destructive",children:j.contractorJobs.deleteThisReview}),e.jsx("p",{className:"text-xs text-muted-foreground",children:j.contractorJobs.deleteReviewDesc}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>se(!1),className:"flex-1 py-2 rounded-md bg-secondary text-foreground text-xs font-medium hover:bg-secondary/80 transition-colors border border-border",children:j.contractorJobs.cancel}),e.jsxs("button",{onClick:()=>B==null?void 0:B(),disabled:I,className:"flex-1 py-2 rounded-md bg-destructive text-destructive-foreground text-xs font-medium hover:bg-destructive/90 transition-colors flex items-center justify-center gap-1 disabled:opacity-50",children:[I?e.jsx(ie,{className:"w-4 h-4 animate-spin"}):null,j.contractorJobs.deleteReview]})]})]}),ae&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:fe,className:"flex-1 py-2.5 rounded-md bg-secondary text-foreground text-sm font-medium hover:bg-secondary/80 transition-colors border border-border",children:j.contractorJobs.cancel}),e.jsxs("button",{disabled:!N||W,onClick:()=>n==null?void 0:n(oe,ne,L,X),className:"flex-1 py-2.5 rounded-md bg-primary text-primary-foreground text-sm font-medium hover:bg-primary/90 transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2",children:[W?e.jsx(ie,{className:"w-4 h-4 animate-spin"}):null,j.contractorJobs.saveChanges]})]}),!D&&!ae&&e.jsxs("button",{disabled:!N||W||!!m,onClick:()=>h(oe,ne,L,X),className:"w-full py-2.5 rounded-md bg-primary text-primary-foreground text-sm font-medium hover:bg-primary/90 transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2",children:[W?e.jsx(ie,{className:"w-4 h-4 animate-spin"}):null,m?j.contractorJobs.suspended:j.contractorJobs.submitReview]})]})]})})}function dr({applicant:s,jobId:k,jobType:E,jobStatus:r,jobClosedAt:h,onAccept:n,onReject:B,isShortlightHighlighted:W}){var Ee,ce,_e,Se;const I=st(),{user:y}=Ue(),{t:D,tr:M}=Oe(),U=Os()(s.status),O=Hs(s.status,s.created_at),A=Mt(),[ne,v]=p.useState(!1),L=((Ee=s.profile)==null?void 0:Ee.full_name)||D.contractorJobs.unknownWorker,S=L.split(" ").map(x=>x[0]).join(""),ae=((ce=s.worker_profile)==null?void 0:ce.total_jobs)??0,te=((_e=s.worker_profile)==null?void 0:_e.skills)??[],G=kt(s.created_at),se=r==="closed",X=h?new Date(h):null,H=X?new Date(X.getTime()+Xs):null,j=new Date,Ce=H?j<H:!1,$=H?Math.max(0,Math.ceil((H.getTime()-j.getTime())/(24*60*60*1e3))):0,oe=se&&Ce,{data:N}=re({queryKey:["review-exists",k,s.worker_id],queryFn:async()=>{const{data:x}=await b.from("reviews").select("id, rating, comment, rating_quality, rating_communication, rating_punctuality, rating_professionalism").eq("job_id",k).eq("worker_id",s.worker_id).maybeSingle();return x},enabled:s.status==="accepted"}),{data:m}=re({queryKey:["review-endorsements",k,s.worker_id],queryFn:async()=>{const{data:x}=await b.from("skill_endorsements").select("skill_name").eq("job_id",k).eq("worker_id",s.worker_id).eq("endorser_id",y.id);return(x==null?void 0:x.map(Y=>Y.skill_name))||[]},enabled:!!y&&!!N}),{data:pe}=re({queryKey:["review-suspension",y==null?void 0:y.id],queryFn:async()=>{const{data:x}=await b.from("contractor_profiles").select("review_suspended_until").eq("user_id",y.id).maybeSingle();return x},enabled:!!y&&s.status==="accepted"&&oe&&!N}),fe=(pe==null?void 0:pe.review_suspended_until)??null,we=fe?new Date(fe)>new Date:!1,{data:C}=re({queryKey:["last-message",y==null?void 0:y.id,s.worker_id],queryFn:async()=>{if(!y)return null;const{data:x}=await b.from("messages").select("content, created_at, sender_id, read").or(`and(sender_id.eq.${y.id},receiver_id.eq.${s.worker_id}),and(sender_id.eq.${s.worker_id},receiver_id.eq.${y.id})`).order("created_at",{ascending:!1}).limit(1).maybeSingle();return x},enabled:!!y}),ee=()=>
11{A.invalidateQueries({queryKey:["review-exists",k,s.worker_id]}),A.invalidateQueries({queryKey:["review-endorsements",k,s.worker_id]}),A.invalidateQueries({queryKey:["searchable-workers"]}),A.invalidateQueries({queryKey:["verified-skills",s.worker_id]}),A.invalidateQueries({queryKey:["contractor-pending-review-count"]})},de=Re({mutationFn:async({rating:x,comment:Y,endorsedSkills:z,categoryRatings:F})=>{const xe=await Zs({jobId:k,jobType:E??"day_labor",reviewerId:y.id,revieweeId:s.worker_id,reviewerIsJobPoster:!0,rating:x,comment:Y,categories:F});if(xe.ok===!1)throw new Error(xe.error);if(z.length>0){const{error:me}=await b.from("skill_endorsements").insert(z.map(g=>({endorser_id:y.id,worker_id:s.worker_id,job_id:k,skill_name:g}))),{data:V}=await b.from("profiles_public").select("full_name").eq("user_id",y.id).single(),Z=(V==null?void 0:V.full_name)||"A contractor",{count:je}=await b.from("skill_endorsements").select("id",{count:"exact",head:!0}).eq("endorser_id",y.id).eq("worker_id",s.worker_id),Ne=je??z.length,{data:ge}=await b.from("notifications").select("id").eq("user_id",s.worker_id).eq("title","Skill Endorsed").eq("read",!1).like("body",`${Z} endorsed%`).limit(1).maybeSingle();ge?await b.from("notifications").update({body:`${Z} endorsed ${Ne} of your skills`}).eq("id",ge.id):Ne===1?await b.from("notifications").insert({user_id:s.worker_id,type:"endorsement",role:"worker",title:"Skill Endorsed",body:`${Z} endorsed your "${z[0]}" skill`,link:"/profile"}):await b.from("notifications").insert({user_id:s.worker_id,type:"endorsement",role:"worker",title:"Skill Endorsed",body:`${Z} endorsed ${Ne} of your skills`,link:"/profile"})}},onSuccess:()=>{R.success(`Review submitted for ${L}`),v(!1),ee()},onError:x=>{R.error(x.message||"Failed to submit review")}}),ve=Re({mutationFn:async({rating:x,comment:Y,endorsedSkills:z,categoryRatings:F})=>{if(!N)throw new Error("No review to update");const{error:xe}=await b.from("reviews").update({rating:Math.round(x),comment:Y||null,rating_quality:F.rating_quality||null,rating_communication:F.rating_communication||null,rating_punctuality:F.rating_punctuality||null,rating_professionalism:F.rating_professionalism||null}).eq("id",N.id);if(xe)throw xe;if(await b.from("skill_endorsements").delete().eq("endorser_id",y.id).eq("worker_id",s.worker_id).eq("job_id",k),z.length>0){const{error:me}=await b.from("skill_endorsements").insert(z.map(V=>({endorser_id:y.id,worker_id:s.worker_id,job_id:k,skill_name:V})))}},onSuccess:()=>{R.success(`Review updated for ${L}`),v(!1),ee()},onError:x=>{R.error(x.message||"Failed to update review")}}),qe=Re({mutationFn:async()=>{if(!N)throw new Error("No review to delete");await b.from("skill_endorsements").delete().eq("endorser_id",y.id).eq("worker_id",s.worker_id).eq("job_id",k);const{error:x}=await b.from("reviews").delete().eq("id",N.id);if(x)throw x},onSuccess:()=>{R.success(`Review deleted for ${L}`),v(!1),ee()},onError:x=>{R.error(x.message||"Failed to delete review")}}),Je=W?"border-destructive/60 bg-destructive/5 ring-2 ring-destructive/30 ring-offset-1 ring-offset-background":s.status==="accepted"?"border-success/40 bg-success/5":s.status==="rejected"?"border-destructive/30 bg-destructive/5 opacity-60":"border-primary/20 bg-card";return e.jsxs(e.Fragment,{children:[e.jsxs(Pe.div,{initial:{opacity:0,y:5},animate:{opacity:1,y:0},className:`rounded-xl overflow-hidden border-2 transition-all ${Je}`,children:[e.jsxs("div",{className:"p-4 pb-3",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("button",{onClick:()=>I(`/profile/${s.worker_id}`),className:"shrink-0 group/avatar",children:(Se=s.profile)!=null&&Se.avatar_url?e.jsx("img",{src:Bt(s.profile.avatar_url,96),alt:L,className:"w-11 h-11 rounded-full object-cover ring-2 ring-border group-hover/avatar:ring-primary/50 transition-all",loading:"lazy",decoding:"async"}):e.jsx("div",{className:"w-11 h-11 rounded-full bg-muted flex items-center justify-center text-sm font-bold text-muted-foreground ring-2 ring-border group-hover/avatar:ring-primary/50 transition-all",children:S})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("button",{onClick:()=>I(`/profile/${s.worker_id}`),className:"text-left",children:e.jsx("h4",{className:"font-display text-sm text-foreground hover:text-primary transition-colors truncate",children:L})}),e.jsx("div",{className:"flex items-center gap-2.5 mt-0.5 flex-wrap",children:e.jsxs("span",{className:"text-xs text-muted-foreground",children:[ae," ",D.common.jobs]})})]}),U&&e.jsxs(be,{variant:"outline",className:`text-micro shrink-0 ${U.className}`,children:[U.label,O!=null?` · ${M("applicationStatus.waitingDays",{days:O})}`:""]}),e.jsx("span",{className:"text-micro text-muted-foreground shrink-0",children:G})]}),te.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1 mt-2.5",children:[te.slice(0,6).map(x=>e.jsx("span",{className:"text-micro px-1.5 py-0.5 bg-secondary rounded-md border border-border text-muted-foreground",children:x},x)),te.length>6&&e.jsxs("span",{className:"text-micro text-muted-foreground self-center",children:["+",te.length-6]})]}),s.message&&e.jsxs("div",{className:"mt-2.5 p-2.5 bg-muted/50 rounded-lg border border-border",children:[e.jsx("p",{className:"text-micro font-semibold text-muted-foreground uppercase tracking-wider mb-1",children:D.contractorJobs.applicationNote}),e.jsx("p",{className:"text-xs text-foreground leading-relaxed",children:s.message})]}),C&&(()=>{const x=C.sender_id!==(y==null?void 0:y.id)&&!C.read;return e.jsxs("button",{onClick:()=>I(`/contractor/messages?to=${s.worker_id}`),className:`mt-2.5 w-full p-2.5 rounded-lg border transition-colors text-left ${x?"bg-primary/5 border-primary/40":"bg-muted/30 border-border hover:border-primary/30"}`,children:[e.jsxs("div",{className:"flex items-center justify-between mb-0.5",children:[e.jsxs("p",{className:`text-micro font-medium flex items-center gap-1 ${x?"text-primary":"text-muted-foreground"}`,children:[x&&e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-primary inline-block"}),e.jsx(Be,{className:"w-2.5 h-2.5"}),C.sender_id===(y==null?void 0:y.id)?D.contractorJobs.you:L]}),e.jsx("span",{className:"text-micro text-muted-foreground",children:kt(C.created_at)})]}),e.jsx("p",{className:`text-xs truncate ${x?"text-foreground font-medium":"text-muted-foreground"}`,children:C.content.length>80?C.content.slice(0,80)+"â¦":C.content})]})})()]}),e.jsxs("div",{className:"border-t border-border px-4 py-3",children:[s.status==="pending"&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>I(`/contractor/messages?to=${s.worker_id}`),className:"flex items-center gap-1.5 px-3 py-2 rounded-lg text-xs font-medium bg-secondary text-secondary-foreground border border-border hover:bg-accent transition-colors",children:[e.jsx(Be,{className:"w-3.5 h-3.5"})," ",D.contractorJobs.message]}),e.jsx("div",{className:"flex-1"}),e.jsxs("button",{onClick:x=>{x.stopPropagation(),B()},className:"flex items-center gap-1.5 px-4 py-2 rounded-lg text-xs font-semibold bg-destructive/10 text-destructive border border-destructive/25 hover:bg-destructive/20 transition-colors",children:[e.jsx(er,{className:"w-3.5 h-3.5"})," ",D.contractorJobs.dismiss]}),e.jsxs("button",{onClick:x=>{x.stopPropagation(),n()},className:"flex items-center gap-1.5 px-5 py-2 rounded-lg text-xs font-semibold bg-success text-white hover:bg-success/90 transition-colors shadow-sm",children:[e.jsx($e,{className:"w-3.5 h-3.5"})," ",D.contractorJobs.accept]})]}),s.status==="accepted"&&e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs("button",{onClick:()=>I(`/contractor/messages?to=${s.worker_id}`),className:"flex items-center gap-1.5 px-3 py-2 rounded-lg text-xs font-medium bg-secondary text-secondary-foreground border border-border hover:bg-accent transition-colors",children:[e.jsx(Be,{className:"w-3.5 h-3.5"})," ",D.contractorJobs.message]}),e.jsx("div",{className:"flex-1"}),N?e.jsxs("button",{onClick:()=>v(!0),className:"flex items-center gap-1.5 px-3 py-2 rounded-lg text-xs font-medium bg-warning/15 text-warning border border-warning/30 hover:bg-warning/25 transition-colors",children:[e.jsx(Me,{className:"w-3.5 h-3.5 fill-current"})," ",D.contractorJobs.rateReviewed(N.rating)]}):oe&&we?e.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-2 rounded-lg text-xs bg-warning/10 text-warning border border-warning/20",children:[e.jsx(Ot,{className:"w-3.5 h-3.5"})," ",D.contractorJobs.suspended]}):oe?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-micro text-muted-foreground",children:D.contractorJobs.daysLeft($)}),e.jsxs("button",{onClick:()=>v(!0),className:"flex items-center gap-1.5 px-4 py-2 rounded-lg text-xs font-semibold bg-primary text-primary-foreground hover:bg-primary/90 transition-colors shadow-sm",children:[e.jsx(Me,{className:"w-3.5 h-3.5"})," ",D.contractorJobs.rate]})]}):se&&!Ce?e.jsx(be,{className:"bg-muted text-muted-foreground border-border text-micro py-1",children:D.contractorJobs.reviewWindowClosed}):se?null:e.jsx(be,{className:"bg-muted text-muted-foreground border-border text-micro py-1",children:D.contractorJobs.jobMustBeClosed})]}),s.status==="rejected"&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("span",{className:"text-xs text-muted-foreground italic",children:D.contractorJobs.dismissed})})]})]}),e.jsx(lr,{open:ne,onOpenChange:v,workerName:L,workerSkills:te,onSubmit:(x,Y,z,F)=>de.mutate({rating:x,comment:Y,endorsedSkills:z,categoryRatings:F}
11),onUpdate:(x,Y,z,F)=>ve.mutate({rating:x,comment:Y,endorsedSkills:z,categoryRatings:F}),onDelete:()=>qe.mutate(),isPending:de.isPending||ve.isPending,isDeleting:qe.isPending,suspendedUntil:fe,readOnly:!!N,canEdit:!!N&&oe,existingRating:N==null?void 0:N.rating,existingComment:N==null?void 0:N.comment,existingEndorsedSkills:m||[],existingCategoryRatings:N?{rating_quality:N.rating_quality??0,rating_communication:N.rating_communication??0,rating_punctuality:N.rating_punctuality??0,rating_professionalism:N.rating_professionalism??0}:void 0})]})}function cr({open:s,onOpenChange:k,applicants:E,jobTitle:r}){const{user:h}=Ue(),{t:n}=Oe(),[B,W]=p.useState(""),[I,y]=p.useState(!1),[D,M]=p.useState("all"),ye=D==="all"?E:E.filter(v=>v.status===D),U=ye.length,O={all:E.length,pending:E.filter(v=>v.status==="pending").length,accepted:E.filter(v=>v.status==="accepted").length,rejected:E.filter(v=>v.status==="rejected").length},A=async()=>{if(!(!h||!B.trim()||U===0)){y(!0);try{const v=ye.map(S=>({sender_id:h.id,receiver_id:S.worker_id,content:B.trim()})),{error:L}=await b.from("messages").insert(v);if(L)throw L;R.success(n.contractorJobs.messageSent(U)),W(""),M("all"),k(!1)}catch(v){R.error(v.message||"Failed to send messages")}finally{y(!1)}}},ne=[{value:"all",label:n.contractorJobs.all},{value:"pending",label:n.common.pending},{value:"accepted",label:n.common.accepted},{value:"rejected",label:n.common.rejected}];return e.jsx(Ft,{open:s,onOpenChange:k,children:e.jsxs(Qt,{className:"sm:max-w-md",children:[e.jsx(It,{children:e.jsx(Lt,{className:"font-display text-xl",children:n.contractorJobs.messageApplicants})}),e.jsxs("div",{className:"space-y-4 pt-2",children:[e.jsx("div",{className:"flex flex-wrap gap-2",children:ne.map(v=>e.jsxs("button",{onClick:()=>M(v.value),className:`px-3 py-1.5 rounded-md text-xs font-medium border transition-colors ${D===v.value?"bg-primary text-primary-foreground border-primary":"bg-secondary text-muted-foreground border-border hover:border-primary/40"}`,children:[v.label," (",O[v.value],")"]},v.value))}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[n.contractorJobs.sendMessageTo," ",e.jsx("span",{className:"text-foreground font-medium",children:U})," ",D!=="all"?D+" ":"",n.common.applicants," ",n.contractorJobs.applicantsFor," ",e.jsx("span",{className:"text-foreground font-medium",children:r}),"."]}),e.jsx(Ut,{value:B,onChange:v=>W(v.target.value),placeholder:n.contractorJobs.messagePlaceholder,autoCapitalize:"sentences",enterKeyHint:"send",className:"bg-secondary border-border",rows:4}),e.jsxs("button",{disabled:!B.trim()||I||U===0,onClick:A,className:"w-full py-2.5 rounded-md bg-primary text-primary-foreground text-sm font-medium hover:bg-primary/90 transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2",children:[I?e.jsx(ie,{className:"w-4 h-4 animate-spin"}):e.jsx(Ht,{className:"w-4 h-4"}),n.contractorJobs.sendTo(U)]})]})]})})}function to(){var nt,lt,dt,ct,mt,ut,pt,ft,xt,gt,ht,bt,yt,wt,vt,_t,jt;const s=st(),[k,E]=js(),{user:r}=Ue(),{t:h}=Oe(),n=Mt(),{openUpgrade:B}=rr(),W=()=>{ss()},I=k.get("filter"),D=I&&{all:"all",action_needed:"all",needs_review:"all",applicants:"all",shortlisted:"all",wrap_up:"all",active:"active",filled:"filled",closed:"closed",draft:"drafts",drafts:"drafts"}[I]||"all",[M,ye]=p.useState(D),U="knuckl.contractor_jobs.sort",[O,A]=p.useState(()=>{try{const t=localStorage.getItem(U);if(t==="mostApplicants"||t==="closingSoon"||t==="recent")return t}catch{}return"recent"}),ne=t=>{A(t);try{localStorage.setItem(U,t)}catch{}},[v,L]=p.useState("");p.useRef(!1);const[S,ae]=p.useState(null),[te,G]=p.useState(null),[se,X]=p.useState(null),[H,j]=p.useState(null);nr("contractor_jobs_close_swipe");const[Ce,$]=p.useState(new Date),[oe,N]=p.useState(null),[m,pe]=p.useState(""),[fe,we]=p.useState(null),[C,ee]=p.useState("week"),[de,ve]=p.useState(new Set),qe=p.useRef({}),[Je,Ee]=p.useState({});Fs();const ce=t=>{ve(a=>{const i=new Set(a);return i.has(t)?i.delete(t):i.add(t),i})},{shortlistedWorkerIds:_e}=Ws();re({queryKey:["shortlisted-job-ids",r==null?void 0:r.id],enabled:!!r,queryFn:async()=>{const{data:t}=await b.from("shortlists").select("job_id").eq("contractor_id",r.id).not("job_id","is",null);return(t??[]).map(a=>
11a.job_id).filter(Boolean)}});const Se=async t=>{var a,i;if(r){j(t.id);try{const{data:d,error:o}=await b.from("jobs").insert({contractor_id:r.id,post_source:"repost",title:`${t.title} (Copy)`,description:t.description,location:t.location,lat:t.lat,lng:t.lng,pay:t.pay,pay_type:t.pay_type,pay_range_max:t.pay_range_max,slots:t.slots,start_date:t.start_date,duration:t.duration,status:"draft",urgency:t.urgency,skills:t.skills,trade_type:t.trade_type,job_category:t.job_category,schedule_type:t.schedule_type,recurrence_pattern:t.recurrence_pattern,recurrence_end_date:t.recurrence_end_date,shift_start_time:t.shift_start_time,shift_end_time:t.shift_end_time,photos:t.photos,attachments:t.attachments,tools_policy:t.tools_policy,payment_schedule:t.payment_schedule,worker_type:t.worker_type,special_instructions:t.special_instructions,insurance_required:t.insurance_required,required_certifications:t.required_certifications,years_experience_needed:t.years_experience_needed,preferred_contact_method:t.preferred_contact_method,visibility:t.visibility}).select("id").single();if(o)throw o;return R.success(h.contractorJobs.duplicateJob+"!"),n.invalidateQueries({queryKey:["contractor-jobs",r.id]}),n.invalidateQueries({queryKey:["job-status-map"]}),d==null?void 0:d.id}catch(d){const o=d.message,l=tr(o);l?(R.error(((i=(a=h.subscriptionGates)==null?void 0:a.serverErrors)==null?void 0:i[l])??o),B(sr(d==null?void 0:d.hint)??"private_job")):R.error(o)}finally{j(null)}}},x=async t=>{const a=await Se(t);a&&s(`/contractor/post/${a}`)},[Y,z]=p.useState(null),[F,xe]=p.useState(null),[me,V]=p.useState(!1),Z=async()=>{if(!Y||!r)return;const t=Y,a=g.find(d=>d.id===t),i=(a==null?void 0:a.title)||"Job";V(!0);try{if(a!=null&&a.start_date){const o=a.shift_start_time||"00:00",l=new Date(`${a.start_date}T${o}`);if(!isNaN(l.getTime())&&Date.now()>=l.getTime()){const{count:_,error:u}=await b.from("applications").select("id",{count:"exact",head:!0}).eq("job_id",t).eq("status","accepted");if(u)throw u;if((_??0)>0){R.error(h.contractorJobs.cantDeleteStarted,{description:h.contractorJobs.closeJobInstead}),V(!1),z(null);return}}}const{error:d}=await b.from("jobs").update({deleted_at:new Date().toISOString()}).eq("id",t);if(d)throw d;S===t&&ae(null),n.invalidateQueries({queryKey:["contractor-jobs",r.id]}),n.invalidateQueries({queryKey:["job-status-map"]}),R(h.contractorJobs.jobDeletedTitle(i),{action:{label:h.contractorJobs.undo,onClick:async()=>{const{error:o}=await b.from("jobs").update({deleted_at:null}).eq("id",t);o?R.error(h.contractorJobs.failedRestoreJob):(R.success(h.contractorJobs.jobRestored),n.invalidateQueries({queryKey:["contractor-jobs",r.id]}),n.invalidateQueries({queryKey:["job-status-map"]}))}},duration:6e3})}catch(d){R.error(d.message)}finally{V(!1),z(null)}},je=async(t,a)=>{try{const{error:i}=await b.from("jobs").update({pinned:!a}).eq("id",t);if(i)throw i;n.invalidateQueries({queryKey:["contractor-jobs",r.id]}),n.invalidateQueries({queryKey:["job-status-map"]}),R.success(a?h.contractorJobs.jobUnpinned:h.contractorJobs.jobPinned)}catch(i){R.error(i.message)}},Ne=async(t,a)=>{try{const i=a?"active":"paused",{error:d}=await b.from("jobs").update({status:i}).eq("id",t);if(d)throw d;n.invalidateQueries({queryKey:["contractor-jobs",r.id]}),n.invalidateQueries({queryKey:["job-status-map"]}),R.success(a?h.pass3.jobResumed:h.pass3.jobPaused)}catch(i){R.error(i.message)}},ge=async t=>{await hs({id:t.id,title:t.title,location:t.location??void 0,payRate:t.pay_rate??void 0,payType:t.pay_type??void 0,spotsOpen:(t.slots??0)-(t.filled_slots??0)},h)},{data:g=[],isLoading:Ke}=re({queryKey:["contractor-jobs",r==null?void 0:r.id],queryFn:async()=>{if(!r)return[];const{data:t,error:a}=await b.from("jobs").select("*").eq("contractor_id",r.id).is("deleted_at",null).order("created_at",{ascending:!1});if(a)throw a;return t},enabled:!!r}),De=p.useMemo(()=>Array.from(new Set(g.map(t=>t.project_id).filter(Boolean))),[g]),{data:f=[]}=re({queryKey:["contractor-jobs-projects",r==null?void 0:r.id,De.join(",")],enabled:!!r&&De.length>0,queryFn:async()=>{const{data:t,error:a}=await b.from("projects").select("id, name, status, start_date, end_date, address, updated_at").in("id",De).eq("contractor_id",r.id);if(a)throw a;return t??[]}});p.useEffect(()=>{if(!r)return;const t=g.map(i=>i.id);if(t.length===0)return;const a=b.channel(`contractor-jobs-realtime-${Math.random().toString(36).slice(2,10)}`).on("postgres_changes",{event:"*",schema:"public",table:"applications"},i=>{var o,l;const d=((o=i.new)==null?void 0:o.job_id)||((l=i.old)==null?void 0:l.job_id);d&&t.includes(d)&&(n.invalidateQueries({queryKey:["contractor-jobs",r.id]}),n.invalidateQueries({queryKey:["job-status-map"]}),n.invalidateQueries({queryKey:["application-counts",r.id]}),n.invalidateQueries({queryKey:["pending-counts-per-job",r.id]}),n.invalidateQueries({queryKey:["job-skill-coverage",r.id]}),n.invalidateQueries({queryKey:["job-applicants",S]}),n.invalidateQueries({queryKey:["job-match-applicants"]}),n.invalidateQueries({queryKey:["all-job-applicants-search"]}))}).on("postgres_changes",{event:"UPDATE",schema:"public",table:"jobs"},i=>{var o;const d=(o=i.new)==null?void 0:o.id;d&&t.includes(d)&&(n.invalidateQueries({queryKey:["contractor-jobs",r.id]}),n.invalidateQueries({queryKey:["job-status-map"]}),n.invalidateQueries({queryKey:["pending-review-counts",r.id]}),n.invalidateQueries({queryKey:["pending-counts-per-job",r.id]}))}).subscribe();return()=>{b.removeChannel(a)}},[r==null?void 0:r.id,g.length,S]);const{data:le=[]}=re({queryKey:["all-job-applicants-search",r==null?void 0:r.id,g.map(t=>
11t.id).join(",")],queryFn:async()=>{if(!r||g.length===0)return[];const t=g.map(l=>l.id),{data:a,error:i}=await b.from("applications").select("job_id, worker_id").in("job_id",t);if(i||!a)return[];const d=[...new Set(a.map(l=>l.worker_id))];if(d.length===0)return[];const o=await Ge(d);return a.map(l=>{var _;const c=o.get(l.worker_id);return{job_id:l.job_id,worker_id:l.worker_id,name:(c==null?void 0:c.displayName)||"",avatar_url:(c==null?void 0:c.avatarUrl)??null,skills:((_=c==null?void 0:c.laborer)==null?void 0:_.skills)||[]}})},enabled:!!r&&g.length>0});p.useMemo(()=>{const t=m.trim().toLowerCase();if(!t)return null;const a=new Set;return le.forEach(i=>{const d=i.name.toLowerCase().includes(t),o=i.skills.some(l=>l.toLowerCase().includes(t));(d||o)&&a.add(i.job_id)}),a},[m,le]);const{data:q=[],isLoading:T}=re({queryKey:["job-applicants",S],queryFn:async()=>{if(!S)return[];const{data:t,error:a}=await b.from("applications").select("*").eq("job_id",S).order("created_at",{ascending:!1});if(a)throw a;if(!t||t.length===0)return[];const i=t.map(o=>o.worker_id),d=await Ge(i);return t.map(o=>{const l=d.get(o.worker_id),c=l?{user_id:o.worker_id,full_name:l.displayName,avatar_url:l.avatarUrl,role:l.role}:null,_=l!=null&&l.laborer?{user_id:o.worker_id,total_jobs:l.laborer.totalJobs,reliability_score:l.laborer.reliabilityScore,skills:l.laborer.skills,languages:l.laborer.languages}:null;return{...o,profile:c,worker_profile:_}})},enabled:!!S}),w=Re({mutationFn:async({id:t,status:a,workerId:i})=>{await ys({applicationId:t,status:a,source:"ContractorJobs",jobId:S,workerId:i})},onMutate:async({id:t,status:a})=>{await Promise.all([n.cancelQueries({queryKey:["job-applicants",S]}),n.cancelQueries({queryKey:["contractor-jobs",r==null?void 0:r.id]})]);const i=n.getQueryData(["job-applicants",S]),d=n.getQueryData(["contractor-jobs",r==null?void 0:r.id]);if(n.setQueryData(["job-applicants",S],l=>l==null?void 0:l.map(c=>c.id===t?{...c,status:a}:c)),S){const l=i==null?void 0:i.find(_=>_.id===t),c=(l==null?void 0:l.status)==="pending";n.setQueryData(["contractor-jobs",r==null?void 0:r.id],_=>_==null?void 0:_.map(u=>{if(u.id!==S)return u;let J=u.filled_slots;a==="accepted"&&c?J=u.filled_slots+1:a==="rejected"&&(l==null?void 0:l.status)==="accepted"&&(J=Math.max(0,u.filled_slots-1));const Q=J>=u.slots&&u.status==="active"?"filled":J<u.slots&&u.status==="filled"?"active":u.status;return{...u,filled_slots:J,status:Q}}))}const o=bs(n,t,a);return{previousApplicants:i,previousJobs:d,rollbackGeneric:o}},onError:(t,a,i)=>{var d;i!=null&&i.previousApplicants&&n.setQueryData(["job-applicants",S],i.previousApplicants),i!=null&&i.previousJobs&&n.setQueryData(["contractor-jobs",r==null?void 0:r.id],i.previousJobs),(d=i==null?void 0:i.rollbackGeneric)==null||d.call(i),R.error(t.message||"Failed to update application")},onSettled:()=>{n.invalidateQueries({queryKey:["job-applicants",S]}),n.invalidateQueries({queryKey:["contractor-jobs",r==null?void 0:r.id]}),n.invalidateQueries({queryKey:["job-status-map"]}),n.invalidateQueries({queryKey:["application-counts",r==null?void 0:r.id]}),n.invalidateQueries({queryKey:["pending-counts-per-job",r==null?void 0:r.id]}),n.invalidateQueries({queryKey:["job-skill-coverage",r==null?void 0:r.id]}),n.invalidateQueries({queryKey:["pending-review-counts",r==null?void 0:r.id]}),n.invalidateQueries({queryKey:["job-match-applicants"]}),n.invalidateQueries({queryKey:["all-job-applicants-search"]}),n.invalidateQueries({queryKey:["contractor-needs-review"]}),n.invalidateQueries({queryKey:["contractor-pending-apps-count"]})}});Re({mutationFn:async t=>{if(!r||t.length===0)return;const{error:a}=await b.from("messages").update({read:!0}).eq("receiver_id",r.id).eq("read",!1).in("sender_id",t);if(a)throw a},onSuccess:()=>{n.invalidateQueries({queryKey:["unread-per-job"]}),n.invalidateQueries({queryKey:["last-message"]}),n.invalidateQueries({queryKey:["unread-messages"]}),R.success(h.contractorJobs.allMessagesMarkedRead)},onError:t=>{R.error(t.message||h.contractorJobs.failedMarkRead)}});const Te=re({queryKey:["application-counts",r==null?void 0:r.id],queryFn:async()=>
11{if(!r||g.length===0)return{};const t=g.map(o=>o.id),{data:a,error:i}=await b.from("applications").select("job_id").in("job_id",t);if(i)throw i;const d={};return(a??[]).forEach(o=>{d[o.job_id]=(d[o.job_id]||0)+1}),d},enabled:!!r&&g.length>0}),rt=re({queryKey:["pending-counts-per-job",r==null?void 0:r.id],queryFn:async()=>{if(!r||g.length===0)return{};const t=g.map(o=>o.id),{data:a,error:i}=await b.from("applications").select("job_id").in("job_id",t).eq("status","pending");if(i)throw i;const d={};return(a??[]).forEach(o=>{d[o.job_id]=(d[o.job_id]||0)+1}),d},enabled:!!r&&g.length>0}),Fe=re({queryKey:["unread-per-job",r==null?void 0:r.id,g.map(t=>t.id).join(",")],queryFn:async()=>{if(!r||g.length===0)return{};const t=g.map(u=>u.id),{data:a,error:i}=await b.from("applications").select("job_id, worker_id").in("job_id",t);if(i||!a)return{};const d=[...new Set(a.map(u=>u.worker_id))];if(d.length===0)return{};const{data:o,error:l}=await b.from("messages").select("sender_id").eq("receiver_id",r.id).eq("read",!1).in("sender_id",d);if(l||!o)return{};const c={};a.forEach(u=>{c[u.worker_id]||(c[u.worker_id]=[]),c[u.worker_id].push(u.job_id)});const _={};return o.forEach(u=>{(c[u.sender_id]??[]).forEach(Q=>{_[Q]=(_[Q]||0)+1})}),_},enabled:!!r&&g.length>0}),{data:zt={}}=re({queryKey:["pending-review-counts",r==null?void 0:r.id,g.map(t=>t.id).join(",")],queryFn:async()=>{if(!r)return{};const t=new Date,a=14*24*60*60*1e3,i=g.filter(u=>u.status!=="closed"||!u.closed_at?!1:t.getTime()-new Date(u.closed_at).getTime()<=a);if(i.length===0)return{};const d=i.map(u=>u.id),[o,l]=await Promise.all([b.from("applications").select("job_id, worker_id").in("job_id",d).eq("status","accepted"),b.from("reviews").select("job_id, worker_id").eq("reviewer_id",r.id).in("job_id",d)]),c=new Set((l.data??[]).map(u=>`${u.job_id}:${u.worker_id}`)),_={};for(const u of o.data??[]){if(!_[u.job_id]){const J=i.find(he=>he.id===u.job_id),Q=Math.max(0,Math.ceil((new Date(J.closed_at).getTime()+a-t.getTime())/(24*60*60*1e3)));_[u.job_id]={pending:0,total:0,daysLeft:Q}}_[u.job_id].total++,c.has(`${u.job_id}:${u.worker_id}`)||_[u.job_id].pending++}return _},enabled:!!r&&g.length>0}),{data:Vt={}}=re({queryKey:["job-skill-coverage",r==null?void 0:r.id,g.map(t=>t.id).join(",")],queryFn:async()=>{var u;if(!r||g.length===0)return{};const t=g.filter(J=>(J.skills??[]).length>0).map(J=>J.id);if(t.length===0)return{};const{data:a}=await b.from("applications").select("job_id, worker_id").in("job_id",t).eq("status","accepted");if(!a||a.length===0){const J={};return g.forEach(Q=>{(Q.skills??[]).length>0&&(J[Q.id]=(Q.skills??[]).map(he=>({skill:he,filled:!1})))}),J}const i=[...new Set(a.map(J=>J.worker_id))],d=await Ge(i),o={},l={},c={};for(const[J,Q]of d)o[J]=((u=Q.laborer)==null?void 0:u.skills)??[],l[J]=Q.displayName||h.contractorJobs.workerDefault,c[J]=Q.avatarUrl??null;const _={};return g.forEach(J=>{const Q=J.skills??[];if(Q.length===0)return;const he=a.filter(P=>P.job_id===J.id);_[J.id]=Q.map(P=>{const ue=he.find(es=>(o[es.worker_id]??[]).some(ts=>ts.toLowerCase()===P.toLowerCase()));return{skill:P,filled:!!ue,workerName:ue?l[ue.worker_id]:void 0,workerAvatarUrl:ue?c[ue.worker_id]:void 0}})}),_},enabled:!!r&&g.length>0}),{data:Gt={}}=re({queryKey:["job-accepted-workers",r==null?void 0:r.id,g.map(t=>t.id).join(",")],queryFn:async()=>{if(!r||g.length===0)return{};const t=g.map(c=>c.id),{data:a}=await b.from("applications").select("job_id, worker_id").in("job_id",t).eq("status","accepted");if(!a||a.length===0)return{};const i=[...new Set(a.map(c=>c.worker_id))],{data:d}=await b.from("profiles_public").select("user_id, full_name, avatar_url").in("user_id",i),o={};(d??[]).forEach(c=>{o[c.user_id]={name:c.full_name||h.contractorJobs.workerDefault,avatarUrl:c.avatar_url}});const l={};return a.forEach(c=>{l[c.job_id]||(l[c.job_id]=[]);const _=o[c.worker_id];_&&!l[c.job_id].some(u=>u.workerId===c.worker_id)&&l[c.job_id].push({workerId:c.worker_id,..._})}),l},enabled:!!r&&g.length>0}),{items:at}=Ls(r==null?void 0:r.id),ot=p.useMemo(()=>at.map(t=>t.kind==="pending_review_closing"?{...t,onExtend:()=>X(t.jobId)}:t),[at]);p.useEffect(()=>{const t=k.get("edit");if(t&&g.some(a=>a.id===t)){X(t);const a=new URLSearchParams(k);a.delete("edit"),E(a,{replace:!0})}},[k,g,E]);const Ae=p.useMemo(()=>{let t=g;M==="active"?t=t.filter(o=>o.status==="active"||o.status==="paused"):M==="filled"?t=t.filter(o=>o.status==="filled"):M==="closed"?t=t.filter(o=>o.status==="closed"):M==="drafts"&&(t=t.filter(o=>o.status==="draft"));const a=v.trim().toLowerCase();a&&(t=t.filter(o=>(o.title??"").toLowerCase().includes(a)));const i=Te.data??{};return[...t].sort((o,l)=>{const c=o.pinned?1:0,_=l.pinned?1:0;if(c!==_)return _-c;if(O==="mostApplicants")return(i[l.id]??0)-(i[o.id]??0);if(O==="closingSoon"){const Q=o.start_date?St(o.start_date).getTime():1/0,he=l.start_date?St(l.start_date).getTime():1/0;return Q-he}const u=o.created_at?new Date(o.created_at).getTime():0;return(l.created_at?new Date(l.created_at).getTime():0)-u})},[g,M,v,O,Te.data]),ke=p.useMemo(()=>{const t=Ae.filter(o=>!!o.project_id&&o.status!=="draft"),a=Ae.filter(o=>!o.project_id&&o.job_type==="sub_package"&&o.status!=="draft"),i=Ae.filter(o=>!o.project_id&&o.job_type!=="sub_package"&&o.status!=="draft"),d=Ae.filter(o=>o.status==="draft");return{phase:t,subPackages:a,quick:i,drafts:d}},[Ae]),it=g.length>0,Yt=ke.phase.length+ke.subPackages.length+ke.quick.length+ke.drafts.length,K=((nt=h.contractorJobs)==null?void 0:nt.v2)??{},Zt=((lt=h.contractorJobs)==null?void 0:lt.attention)??{},Xt=(t,a)=>{var J,Q,he;const i=((J=Te.data)==null?void 0:J[t.id])??0,d=((Q=Fe.data)==null?void 0:Q[t.id])??0,o=zt[t.id],l=o&&o.pending>0,c=0,_=((he=rt.data)==null?void 0:he[t.id])??0,u=Vt[t.id]??(t.skills??[]).map(P=>({skill:P,filled:!1}));return e.jsx("div",{children:e.jsx(ir,{job:t,index:a,applicantCount:i,pendingAppCount:_,jobUnread:d,shortlistedCount:c,needsReview:!!l,reviewInfo:o,skillCoverage:u,acceptedWorkers:Gt[t.id]??[],acceptedWorkerCount:t.filled_slots,applicantPreview:[],isExpanded:S===t.id,isDetail
11sExpanded:de.has(t.id),isPinned:!!t.pinned,duplicatingId:H,onToggleExpand:()=>ae(S===t.id?null:t.id),onToggleDetails:()=>ce(t.id),onTogglePin:je,onEdit:P=>t.job_type==="sub_package"?X(P):s(`/contractor/post/${P}`),onDuplicate:Se,onDelete:P=>z(P),onRepost:x,showReviewCTA:_>0,onClose:()=>xe({id:t.id,title:t.title,pay:Number(t.pay)||0,payType:t.pay_type,jobType:t.job_type}),onPause:Ne,onShare:ge,onHighlightShortlisted:()=>{ae(t.id),we(t.id),setTimeout(()=>we(null),4e3)},t:h,children:S===t.id&&e.jsxs(Pe.div,{ref:P=>{qe.current[t.id]=P},initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},className:"border-t border-primary/15 bg-muted/10 backdrop-blur-sm",children:[e.jsx("div",{className:"px-4 pt-4 pb-2",children:e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(We,{className:"w-4 h-4 text-primary"}),e.jsx("h5",{className:"font-display text-sm text-foreground",children:h.common.applicants}),e.jsxs(be,{variant:"outline",className:"text-micro border-border",children:[i," total"]})]}),q.length>0&&e.jsxs("button",{onClick:()=>G(t.id),className:"flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg bg-secondary text-secondary-foreground text-micro font-medium hover:bg-accent transition-colors border border-border",children:[e.jsx(Ht,{className:"w-3 h-3"})," Message All"]})]})}),e.jsx("div",{className:"px-4 pb-4 space-y-3",children:T?e.jsx("div",{className:"flex justify-center py-6",children:e.jsx(ie,{className:"w-5 h-5 animate-spin text-primary"})}):q.length>0?e.jsxs(e.Fragment,{children:[q.filter(P=>P.status==="pending").slice(0,3).map(P=>e.jsx(dr,{applicant:P,jobId:t.id,jobType:t.job_type,jobStatus:t.status,jobClosedAt:t.closed_at,isShortlightHighlighted:fe===t.id&&_e.has(P.worker_id),onAccept:()=>{w.mutate({id:P.id,status:"accepted",workerId:P.worker_id},{onSuccess:()=>{var ue;return R.success(`${((ue=P.profile)==null?void 0:ue.full_name)||h.common.worker} ${h.common.accepted.toLowerCase()}!`)}})},onReject:()=>{w.mutate({id:P.id,status:"rejected",workerId:P.worker_id},{onSuccess:()=>{var ue;return R.success(`${((ue=P.profile)==null?void 0:ue.full_name)||h.common.worker} ${h.common.rejected.toLowerCase()}`)}})}},P.id)),q.filter(P=>P.status==="pending").length>3&&e.jsxs("button",{onClick:()=>s(`/contractor/applicants?job=${t.id}`),className:"w-full text-center py-2.5 text-xs font-medium text-primary hover:text-primary/80 transition-colors",children:["View all"," ",q.filter(P=>P.status==="pending").length," ","pending â"]})]}):e.jsxs("div",{className:"text-center py-6 space-y-2",children:[e.jsx(We,{className:"w-6 h-6 text-muted-foreground mx-auto"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"No applicants yet"})]})})]})})},t.id)},Qe=(t,a,i)=>{var d,o,l;if(a.length===0){if(M==="all")return null;
11const c=((d=K.filter)==null?void 0:d[M])??M;return e.jsxs("section",{className:"space-y-2",children:[e.jsx("div",{className:"flex items-center gap-2 px-1",children:e.jsx("h2",{className:"text-caption font-semibold uppercase tracking-widest text-muted-foreground",children:t})}),e.jsxs("div",{className:"rounded-xl border border-dashed border-border/60 bg-card/60 px-4 py-3 text-xs text-muted-foreground flex items-center justify-between",children:[e.jsx("span",{children:(o=K.empty)!=null&&o.noJobsInFilter?K.empty.noJobsInFilter(c):`No ${c} jobs`}),e.jsx("button",{onClick:()=>{ye("all"),E({})},className:"text-primary hover:underline",children:((l=K.empty)==null?void 0:l.showAll)??"Show all"})]})]},i)}return e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 px-1",children:[e.jsx("h2",{className:"text-caption font-semibold uppercase tracking-widest text-muted-foreground",children:t}),e.jsxs("span",{className:"text-caption text-muted-foreground/70",children:["(",a.length,")"]})]}),e.jsx("div",{className:"space-y-3",children:a.map(Xt)})]},i)},He=se?g.find(t=>t.id===se)??null:null,ze=Y?g.find(t=>t.id===Y)??null:null,Ve=te?g.find(t=>t.id===te)??null:null;return e.jsxs("div",{className:"px-4 py-5 space-y-4",children:[e.jsx(Us,{current:"work"}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h1",{className:"font-display text-2xl text-foreground",children:K.pageTitle??"Jobs"}),e.jsxs("button",{onClick:W,"aria-label":K.newJob??"New Job",className:"inline-flex items-center gap-1.5 px-3 py-2 rounded-full bg-primary text-primary-foreground text-sm font-semibold shadow-sm hover:bg-primary/90 active:scale-95 transition-all",children:[e.jsx(Tt,{className:"w-4 h-4"})," ",K.newJob??"New Job"]})]}),e.jsx(Qs,{}),e.jsx(Is,{}),r&&ot.length>0&&e.jsx(Bs,{userId:r.id,items:ot,a:Zt}),it&&e.jsxs("div",{className:"space-y-2 sticky top-0 z-20 -mx-4 px-4 pt-2 pb-2 bg-background/95 backdrop-blur-md border-b border-border/60",children:[e.jsx("div",{className:"flex items-center gap-2 overflow-x-auto no-scrollbar -mx-1 px-1 pb-0.5",children:["all","active","filled","closed","drafts"].map(t=>{var d;const a=((d=K.filter)==null?void 0:d[t])??t,i=M===t;return e.jsx("button",{onClick:()=>{ye(t),E(t==="all"?{}:{filter:t})},className:`flex-shrink-0 px-3 py-1.5 rounded-full text-xs font-medium border transition-all ${i?"bg-primary text-primary-foreground border-primary shadow-sm":"bg-card text-muted-foreground border-border/60 hover:border-primary/40"}`,children:a},t)})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(ar,{className:"w-4 h-4 absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground pointer-events-none"}),e.jsx(as,{value:v,onChange:t=>L(t.target.value),placeholder:K.searchPlaceholder??"Search jobs by title",className:"pl-9 h-9 text-sm bg-card"})]}),e.jsxs(ps,{value:O,onValueChange:t=>ne(t),children:[e.jsx(fs,{className:"flex-shrink-0 w-auto min-w-[130px] h-9 text-xs bg-card",children:e.jsx(xs,{placeholder:((dt=K.sort)==null?void 0:dt.label)??"Sort"})}),e.jsxs(gs,{children:[e.jsx(Ye,{value:"recent",children:((ct=K.sort)==null?void 0:ct.recent)??"Recent"}),e.jsx(Ye,{value:"mostApplicants",children:((mt=K.sort)==null?void 0:mt.mostApplicants)??"Most applicants"}),e.jsx(Ye,{value:"closingSoon",children:((ut=K.sort)==null?void 0:ut.closingSoon)??"Closing soon"})]})]})]})]}),Ke?e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx(ie,{className:"w-6 h-6 animate-spin text-primary"})}):it?M!=="all"&&Yt===0?e.jsxs(Pe.div,{initial:{opacity:0,scale:.97},animate:{opacity:1,scale:1},className:"text-center py-10 px-6 rounded-card bg-card/60 border border-border/60",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:(xt=K.empty)!=null&&xt.noJobsInFilter?K.empty.noJobsInFilter(((gt=K.filter)==null?void 0:gt[M])??M):`No ${M} jobs`}),e.jsx("button",{onClick:()=>{ye("all"),E({})},className:"text-xs text-primary mt-2 hover:underline",children:((ht=K.empty)==null?void 0:ht.showAll)??"Show all"})]}):e.jsxs("div",{className:"space-y-6",children:[Qe(((bt=K.section)==null?void 0:bt.phaseJobs)??"Project phases",ke.phase,"phase"),ke.subPackages.length>0&&e.jsx("div",{className:"flex justify-end -mb-4",children:e.jsxs("button",{type:"button",onClick:()=>s("/contractor/proposals"),className:"text-label font-semibold text-primary hover:underline",children:[((wt=(yt=h.inviteToBid)==null?void 0:yt.proposals)==null?void 0:wt.link)??"Proposals"," â"]})}),Qe(((vt=K.section)==null?void 0:vt.subPackages)??"Sub packages",ke.subPackages,"sub"),Qe(((_t=K.section)==null?void 0:_t.quickJobs)??"Quick jobs",ke.quick,"quick"),(M==="all"||M==="drafts")&&Qe(((jt=K.section)==null?void 0:jt.drafts)??"Drafts",ke.drafts,"drafts")]}):e.jsxs(Pe.div,{initial:{opacity:0,scale:.97}
11,animate:{opacity:1,scale:1},className:"text-center py-14 px-6 rounded-card bg-card/80 backdrop-blur-md border border-border/60 relative overflow-hidden",children:[e.jsx("div",{className:"absolute -top-10 -right-10 w-28 h-28 rounded-full bg-primary/5 blur-2xl pointer-events-none"}),e.jsxs("div",{className:"relative flex flex-col items-center gap-2",children:[e.jsx("div",{className:"w-12 h-12 rounded-full bg-primary/10 flex items-center justify-center mb-1",children:e.jsx(Wt,{className:"w-6 h-6 text-primary"})}),e.jsx("p",{className:"font-display text-base text-foreground",children:((pt=K.empty)==null?void 0:pt.noJobs)??"Post your first job to start hiring."}),e.jsxs("button",{onClick:W,className:"mt-3 inline-flex items-center gap-1.5 px-4 py-2 rounded-full text-xs font-semibold bg-primary text-primary-foreground hover:bg-primary/90 transition-all shadow-sm",children:[e.jsx(Tt,{className:"w-3.5 h-3.5"})," ",((ft=K.empty)==null?void 0:ft.postFirstJob)??"+ Post a job"]})]})]}),He&&e.jsx(zs,{open:!!He,onOpenChange:t=>!t&&X(null),job:He,onSaved:()=>n.invalidateQueries({queryKey:["contractor-jobs",r==null?void 0:r.id]})}),ze&&e.jsx(os,{open:!!ze,onOpenChange:t=>!t&&z(null),children:e.jsxs(is,{children:[e.jsxs(ns,{children:[e.jsxs(ls,{children:[h.contractorJobs.deleteConfirm,' "',ze.title,'"?']}),e.jsx(ds,{children:h.contractorJobs.deleteDesc})]}),e.jsxs(cs,{children:[e.jsx(ms,{disabled:me,children:h.common.cancel}),e.jsxs(us,{onClick:Z,disabled:me,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:[me?e.jsx(ie,{className:"w-4 h-4 animate-spin mr-2"}):null,h.common.delete]})]})]})}),Ve&&e.jsx(cr,{open:!!Ve,onOpenChange:t=>!t&&G(null),applicants:q,jobTitle:Ve.title}),F&&e.jsx(Ks,{open:!!F,onOpenChange:t=>{t||xe(null)},jobId:F.id,jobTitle:F.title,jobPay:F.pay,jobPayType:F.payType,jobType:F.jobType})]})}export{to 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.