1import{j as e,u as We,a as p,e as Z,k as De}from"./vendor-query-CRhh6spR.js";import{J as ss,S as as,A as is,W as os,I as ns,a as ls}from"./JobDetail-BeNRaQRR.js";import{I as cs,a as fr,i as Ie}from"./ProjectBanner-DkiB2638.js";import{B as ie}from"./badge-DfIFDYyU.js";import{W as ds}from"./WhatsAppBadge-DmgCB4SX.js";import{c as ms,b as oe,S as ve,q as we,bF as ps,v as Ne,w as Ee,X as Se,g as dt,r as Je,L as ue,h as M,s as _,j as us,t as it,a6 as xs,a7 as hs,a8 as bs,a9 as fs,I as Be,l as gs,T as Ce,B as T,A as pt,bc as rt,u as js,a as ys,bG as vs,P as gr,z as jr,o as Ue,ab as vt}from"./index-BkVb42KZ.js";import{r as ws}from"./repost-job-DMhN92aJ.js";import{D as Fr,a as Ir,b as Er,c as ye,d as wt}from"./dropdown-menu-CR6TaDw3.js";import{A as Ns,a as _s,b as yr,c as vr,d as wr,e as Nr,f as _r,g as kr}from"./alert-dialog-whTlFcP7.js";import{P as Dr,a as Cr,b as Sr}from"./popover-D6r7zknv.js";import{u as ks}from"./use-primary-query-LdYs10m3.js";import{u as Ds,j as Cs}from"./jobs-DatLXsfQ.js";import{u as Ss}from"./use-contextual-prompt-C-UOBaQg.js";import{S as te}from"./skeleton-CRf0VGJi.js";import{H as Nt}from"./Head-B4hXUiBE.js";import{E as Ct}from"./eye-D9PTLHAC.js";import{C as Js}from"./CloseJobDialog-C9XMNcT0.js";import{T as Jt}from"./textarea-BQTQ5UjX.js";import{M as As}from"./megaphone-CYm1f7Md.js";import{C as Me}from"./clock-B5A68DmX.js";import{M as $e}from"./map-pin-BnyER353.js";import{C as Br}from"./circle-x-D3XjrB4n.js";import{R as Rr}from"./rotate-ccw-H-Njgz4G.js";import{u as Ps,p as qs,E as Ls}from"./application-status-badge-BKnZ1jNL.js";import{u as Ts}from"./use-feature-gate-CQ1xTF7b.js";import{m as Ms}from"./tier-error-C6TW3of0.js";import{S as $s}from"./switch-rgNxObl6.js";import{J as Ws}from"./JobSkillPicker-P68J6Ibd.js";import{d as Fs,b as Is}from"./bid-deadline-BsuXNHJh.js";import{u as ut,g as Es,d as Bs}from"./vendor-react-BAmwgVqg.js";import{a as Rs}from"./use-profile-summary-CvkL6Ay4.js";import{t as Re,f as Os}from"./image-url-_sEuZELz.js";import{L as Or}from"./lock-BhoZ9g-C.js";import{S as Ks}from"./search-BNuSVdRk.js";import{U as Ve}from"./users-CLblnKO6.js";import{U as ot}from"./user-plus-C-YQzt8j.js";import{C as ee}from"./check-BtcgJ1Z4.js";import{u as zs}from"./use-worker-recommendations-BIjZsPXJ.js";import{c as St,a as Kr}from"./applicant-match-C-uzOpYD.js";import{C as Jr}from"./chevron-right-DSioQ7mT.js";import{R as Qs}from"./radio-saDtXqoJ.js";import{C as Us}from"./circle-alert-0D7rBznR.js";import{f as Hs,b as Vs,a as Ys}from"./schedule-utils-1F0KefuA.js";import{a as Gs,b as Xs}from"./PostJobTypes-BHSlqdI4.js";import{a as Zs}from"./use-job-translation-DgJuK921.js";import{a as ea,o as ta,u as ra}from"./application-status-E6n3bMhj.js";import{u as sa}from"./use-contractor-bench-B02yJ0Kt.js";import{B as aa}from"./briefcase-D-vMkZXu.js";import{A as nt}from"./arrow-right-B52b088t.js";import{L as Ar}from"./label-Xk_s6Ck5.js";import{u as ia}from"./WithdrawJobSheet-fadPIlys.js";import{E as zr}from"./ellipsis-vertical-4BGDn3no.js";import{M as lt}from"./message-square-BwPXUwfW.js";import{C as ct}from"./circle-check-BibDl6sq.js";import{U as oa}from"./user-x-DR9ABI6G.js";import{D as mt}from"./dollar-sign-CoQE7qNd.js";import{S as na}from"./star-BpldOkBP.js";import{T as la}from"./trash-2-eLOCP2Wl.js";import{m as K}from"./vendor-motion-BcLIBd36.js";import{W as ca}from"./profile-strength-i18n-DH37Xk18.js";import{u as da}from"./use-call-worker-3r5ezR1Y.js";import{L as ma}from"./LoadErrorCard-B2FnJgy6.js";import{W as pa}from"./WorkerHistoryStat-BL9Z5Bie.js";import{u as ua}from"./use-worker-completion-stats-Dkil4v5p.js";import{A as _t}from"./arrow-left-B9mh4lKG.js";import{S as Pr}from"./share-2-qYpHQYhX.js";import{R as qr}from"./repeat-msnld17P.js";import{Z as st}from"./zap-lWgtODcO.js";import{P as Lr}from"./pencil-Bd8KNKwZ.js";import{G as xa}from"./globe-BUYI8zey.js";import{C as at}from"./calendar-BOzI1TJy.js";import{C as ha}from"./chevron-down-CXoJibNt.js";import{L as ba}from"./lightbulb-DpFV_zaq.js";import{H as fa}from"./hard-hat-DFuF37sz.js";import{C as ga}from"./clipboard-list-DxTA222t.js";import{W as ja}from"./wrench-CQB9vgwx.js";import{A as ya}from"./award-ollJZsJj.js";import{E as va}
1from"./eye-off-CCw-EuVt.js";import{p as He}from"./parseISO-3q6JebNo.js";import{P as wa}from"./paperclip-DL8oCpsi.js";import{F as Na}from"./file-text-DfpMrF0r.js";import{D as _a}from"./download-C8JTs7FR.js";import{C as ka}from"./car-Bi5bG36r.js";import{N as Da}from"./navigation-Z4x6zh4R.js";import{E as Tr}from"./external-link-ibDNud24.js";import"./SampleBadge-DfdiBrQW.js";import"./flask-conical-RfZJi1zC.js";import"./MilestoneBuilder-mWfovT8f.js";import"./plus-CoZSqMco.js";import"./share-job-mklACVdJ.js";import"./copy-BEFhSt3P.js";import"./use-directory-BxzlBvBe.js";import"./use-saved-jobs-MCfxJCDI.js";import"./haptics-C4kiRWSa.js";import"./bookmark-CmJJf9yt.js";import"./calendar-plus-CPs8_l8O.js";import"./use-job-recommendations-Bt8tPFEU.js";import"./ProBadge-CeeKgQ59.js";import"./sparkles-BuBBRAeM.js";import"./MiniMapPreview-5ibW19p3.js";import"./ChatView-ukaCOHC8.js";import"./use-messaging-permission-Dax1aQua.js";import"./ban-DV16IFya.js";import"./flag-CJw6Dv0L.js";import"./building-2-C8te0Xoz.js";import"./message-circle-BTvelDNo.js";import"./send-5x2Iukow.js";import"./maximize-2-CpEFOstG.js";import"./use-worker-crew-DVwnth8Z.js";import"./TransportOptions-loD-saWv.js";import"./circle-check-big-Cjr7FrMh.js";import"./skill-tiers-B5nM_Fe9.js";import"./profile-completion-CCj5IUp0.js";import"./attachment-url-BGa7v_B7.js";import"./InsurancePartnerCard-DRRhT2mH.js";import"./use-apply-with-mismatch-check-BqUVS2Pa.js";import"./shield-alert-DxK97mGJ.js";import"./marketing-events-Ch2Ss8qi.js";import"./job-standards-BYp9G5Eu.js";import"./minus-CXZ9_FJ0.js";import"./house-0Xv-8BDy.js";import"./vendor-charts-BVeOEGzI.js";import"./vendor-stripe-2y4Jo9_W.js";import"./vendor-supabase-Csx7YFID.js";import"./flash-prefill-CtQFfO_E.js";import"./post-job-sheet-BxL-Oe-u.js";import"./index-Bmtd1gWP.js";import"./index-fVqgy0Om.js";import"./index-D5IzgxZK.js";import"./circle-Sm8JI_tc.js";import"./QuickJobDialog-ZZpSNq89.js";import"./use-pending-review-count-CQb0BGms.js";import"./review-window-bRPqN3sJ.js";import"./LocationAutocomplete-DhEGcuTZ.js";import"./geocode-CX448-fu.js";import"./locate-fixed-BvHUYlGL.js";import"./MarketRateWarning-CGmSGXXM.js";import"./use-geolocation-CHbY3Amh.js";import"./trending-up-WeSkWL9_.js";import"./feedback-B_lOwORB.js";import"./submit-review-BGi0EQeK.js";import"./appReview-Bk4fLWAZ.js";import"./undo-2-BMAwPfs4.js";import"./select-B5KGv1Do.js";import"./index-D17hSi50.js";import"./chevron-up-DcqJwcAx.js";import"./JobMediaUpload-Ci6igMQG.js";import"./image-resize-D0CnxHUe.js";import"./camera-il4dw7D6.js";import"./use-subscription-Q7kB2EwX.js";import"./shield-4ZV1RAa7.js";import"./info-CsexF6vj.js";import"./skill-catalog-CiwHrT6-.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 Ca=ms("CloudRain",[["path",{d:"M4 14.899A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.242",key:"1pljnt"}],["path",{d:"M16 14v6",key:"1j4efv"}],["path",{d:"M8 14v6",key:"17c4r9"}],["path",{d:"M12 16v6",key:"c8a4gj"}]]);function Sa(){return e.jsxs("div",{className:"px-4 py-6 space-y-6 max-w-3xl mx-auto",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(te,{className:"h-7 w-2/3"}),e.jsx(te,{className:"h-4 w-1/3"})]}),e.jsxs("div",{className:"rounded-card bg-card/80 backdrop-blur-md border border-border/60 p-5 space-y-4",children:[e.jsx(te,{className:"h-4 w-1/2"}),e.jsx("div",{className:"flex gap-2",children:[1,2,3].map(a=>e.jsx(te,{className:"h-6 w-20 rounded-full"},a))}),e.jsx(te,{className:"h-3 w-full"}),e.jsx(te,{className:"h-3 w-5/6"})]}),e.jsx("div",{className:"grid grid-cols-3 gap-3",children:[1,2,3].map(a=>e.jsx(te,{className:"h-20 rounded-xl"},a))}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(te,{className:"h-5 w-40"}),[1,2,3].map(a=>e.jsxs("div",{className:"rounded-card bg-card/80 backdrop-blur-md border border-border/60 p-4 flex gap-3",children:[e.jsx(te,{className:"w-12 h-12 rounded-full"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx(te,{className:"h-4 w-1/2"}),e.jsx(te,{className:"h-3 w-2/3"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(te,{className:"h-3 w-16"}),e.jsx(te,{className:"h-3 w-16"})]})]})]},a))]})]})}function Ja({jobId:a,open:u,onOpenChange:o}){const{t:n}=oe();return e.jsx(ve,{open:u,onOpenChange:o,children:e.jsxs(we,{side:"bottom",hideClose:!0,className:"h-[100dvh] max-h-[100dvh] pb-0 p-0 gap-0 flex flex-col overflow-hidden rounded-none border-t-0 shadow-none sm:max-w-none",children:[e.jsxs(ps,{children:[e.jsx(Ne,{children:n.pass2.previewBannerTitle}),e.jsx(Ee,{children:n.pass2.previewBannerBody})]}),e.jsx("div",{className:"shrink-0 bg-primary text-primary-foreground pt-[env(safe-area-inset-top)]",children:e.jsxs("div",{className:"flex items-start gap-3 px-4 py-3",children:[e.jsx(Ct,{className:"w-5 h-5 shrink-0 mt-0.5"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-base font-semibold leading-snug",children:n.pass2.previewBannerTitle}),e.jsx("p",{className:"text-xs leading-snug mt-0.5",children:n.pass2.previewBannerBody})]}),e.jsxs("button",{type:"button",onClick:()=>o(!1),className:"shrink-0 inline-flex min-h-[48px] items-center gap-1.5 rounded-full bg-primary-foreground
6/15 px-4 text-sm font-semibold",children:[e.jsx(Se,{className:"w-4 h-4"}),n.pass2.exitPreview]})]})}),e.jsx("div",{className:"flex-1 overflow-y-auto overscroll-contain bg-background pb-[calc(env(safe-area-inset-bottom)+24px)]",children:e.jsx("div",{className:"select-none",inert:"",children:e.jsx(ss,{previewJobId:a,previewMode:!0})})})]})})}function Aa(){const a=new Date;return new Date(a.getFullYear(),a.getMonth(),a.getDate()).toISOString()}function Pa({jobId:a,crew:u}){const{t:o}=oe(),n=o.jobsite,b=We(),[m,l]=p.useState(!1),[w,d]=p.useState("weather"),[J,D]=p.useState(""),{data:f=[]}=Z({queryKey:["job-crew-checkins",a],enabled:!!a,queryFn:async()=>{const{data:k}=await _.from("job_checkins").select("worker_id, kind, distance_m, created_at").eq("job_id",a).gte("created_at",Aa()).order("created_at",{ascending:!1});return k??[]}}),E=p.useMemo(()=>{const k=new Map;for(const C of f)k.has(C.worker_id)||k.set(C.worker_id,C);return k},[f]),A=De({mutationFn:async()=>{const{data:k,error:C}=await _.functions.invoke("job-delay-alert",{body:{job_id:a,reason:w,message:J.trim()||void 0}});if(C)throw C;return k},onSuccess:()=>{M.success(n.alertSent),l(!1),D(""),b.invalidateQueries({queryKey:["job-crew-checkins",a]})},onError:()=>M.error(n.alertFailed)}),O=k=>{const C=E.get(k);if(!C)return null;const B=typeof C.distance_m=="number"?C.distance_m/1609.34:null,R=C.kind==="ready"?n.ready:C.kind==="not_coming"?n.notComing:C.kind==="on_my_way"?n.onMyWay:n.arrived,g=B==null?null:B<.15?n.onSiteConfirmed:n.distanceAway.replace("{miles}",B.toFixed(1));return{label:R,detail:g,bad:C.kind==="not_coming"}},z=[{key:"weather",icon:e.jsx(Ca,{className:"w-4 h-4"})},{key:"delay",icon:e.jsx(Me,{className:"w-4 h-4"})},{key:"moved",icon:e.jsx($e,{className:"w-4 h-4"})},{key:"cancelled",icon:e.jsx(Br,{className:"w-4 h-4"})},{key:"back_on",icon:e.jsx(Rr,{className:"w-4 h-4"})}];return e.jsxs("div",{className:"rounded-xl border border-border/60 bg-card/60 p-3 space-y-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-semibold text-foreground",children:n.crewStatusTitle}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n.alertHint})]}),e.jsxs("button",{type:"button",onClick:()=>l(!0),className:"inline-flex min-h-10 shrink-0 items-center gap-1.5 rounded-lg bg-primary px-3 text-sm font-semibold text-primary-foreground",children:[e.jsx(As,{className:"w-4 h-4"}),n.alertButton]})]}),u.length===0||E.size===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:n.noCheckins}):e.jsx("ul",{className:"space-y-1.5",children:u.map(k=>{const C=O(k.worker_id);return C?e.jsxs("li",{className:"flex items-center justify-between gap-2 text-sm",children:[e.jsx("span",{className:"min-w-0 truncate text-foreground",children:k.name}),e.jsxs("span",{className:"flex shrink-0 items-center gap-2",children:[e.jsx("span",{className:dt("rounded-md px-2 py-0.5 text-xs font-semibold",C.bad?"bg-destructive/15 text-destructive":"bg-primary/15 text-primary"),children:C.label}),C.detail&&e.jsx("span",{className:"text-xs text-muted-foreground",children:C.detail})]})]},k.worker_id):null})}),e.jsx(ve,{open:m,onOpenChange:l,children:e.jsxs(we,{side:"bottom",className:"rounded-t-2xl",children:[e.jsxs(Je,{className:"text-left",children:[e.jsx(Ne,{children:n.alertTitle}),e.jsx(Ee,{children:n.alertHint})]}),e.jsxs("div",{className:"mt-4 space-y-4",children:[e.jsx("div",{className:"flex flex-wrap gap-2",children:z.map(k=>e.jsxs("button",{type:"button","aria-pressed":w===k.key,onClick:()=>d(k.key),className:dt("inline-flex min-h-10 items-center gap-1.5 rounded-full border px-3 text-sm font-semibold",w===k.key?"border-primary bg-primary text-primary-foreground":"border-border bg-background text-foreground"),children:[k.icon,n.reason[k.key]]},k.key))}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-semibold text-muted-foreground",children:n.alertNoteLabel}),e.jsx(Jt,{value:J,maxLength:240,onChange:k=>D(k.target.value),placeholder:n.alertNotePlaceholder,rows:3})]}),e.jsxs("button",{type:"button",disabled:A.isPending,onClick:()=>A.mutate(),className:"inline-flex min-h-12 w-full items-center justify-center gap-2 rounded-xl bg-primary text-sm font-bold text-primary-foreground disabled:opacity-60",children:[A.isPending&&e.jsx(ue,{className:"w-4 h-4 animate-spin"}),A.isPending?n.alertSending:n.alertSend]})]})]})})]})}function qa({open:a,onOpenChange:u,job:o}){const{t:n}=oe(),b=ut(),m=We(),l=n.convertToSubPackage,{flags:w,openUpgrade:d}=Ts(),{ensurePhoneVerified:J}=us(),D=(o.skills??[]).length===1?o.skills[0]:"",[f,E]=p.useState(o.title??""),[A,O]=p.useState(o.description??""),[z,k]=p.useState(D),[C,B]=p.useState(/^\d{4}-\d{2}-\d{2}$/.test(o.start_date??"")?o.start_date:""),[R,g]=p.useState(Fs()),[N,h]=p.useState(""),[y,Q]=p.useState("single"),[j,U]=p.useState(""),[xe,ce]=p.useState(""),[_e,Ae]=p.useState(""),[Y,ne]=p.useState(o.visibility==="private"),[he,re]=p.useState(!1),[Pe,G]=p.useState(null),[be,s]=p.useState(null);p.useEffect(()=>{a&&(it("post.subpackage.opened",{converted:!0}),E(o.title??""),O(o.description??""),k((o.skills??[]).length===1?o.skills[0]:""),B(/^\d{4}-\d{2}-\d{2}$/.test(o.start_date??"")?o.start_date:""),G(null),s(null))},[a,o.id]);const x=p.useMemo(()=>
6{if(y==="single"){const q=parseFloat(j);return{low:Number.isFinite(q)&&q>0?q:null,high:null}}const S=parseFloat(xe),F=parseFloat(_e);return{low:Number.isFinite(S)&&S>0?S:null,high:Number.isFinite(F)&&F>0?F:null}},[y,j,xe,_e]),L=()=>{if(!f.trim())return l.errTitle;if(A.trim().length<40)return l.errDescription;if(!z)return l.errTrade;if(!C)return l.errStart;if(x.low==null)return l.errBudget;if(y==="range"&&(x.high==null||x.high<x.low))return l.errBudgetRange;const S=parseInt(N);if(!S||S<1)return l.errDuration;if(R){const F=new Date(`${R}T23:59:59`);if(F.getTime()<Date.now())return l.errDeadlineFuture;if(F.getTime()>new Date(`${C}T23:59:59`).getTime())return l.errDeadlineBeforeStart}return null},$=async()=>{G(null),s(null);const S=L();if(S){G(S);return}if(J()){re(!0);try{const{data:F,error:q}=await _.rpc("convert_job_to_sub_package",{_job_id:o.id,_title:f.trim(),_description:A.trim(),_trade:z,_budget_low:x.low,_budget_high:x.high,_bid_deadline:Is(R),_duration_days:parseInt(N),_start_date:C,_visibility:w.private_job&&Y?"private":"public"});if(q)throw q;it("post.subpackage.submitted",{ok:!0,converted:!0}
6),M.success(l.toastSuccess),m.invalidateQueries({queryKey:["contractor-job-detail",o.id]}),m.invalidateQueries({queryKey:["job-detail-applicants",o.id]}),m.invalidateQueries({queryKey:["job-applicant-stats",o.id]}),m.invalidateQueries({queryKey:["contractor-jobs"]}),m.invalidateQueries({queryKey:["job-status-map"]}),m.invalidateQueries({queryKey:["contractor-home"]}),m.invalidateQueries({queryKey:["sub-package-feed"]}),m.invalidateQueries({queryKey:["active-job-count"]}),u(!1),b("/contractor/jobs")}catch(F){const q=(F==null?void 0:F.message)??"";it("post.subpackage.submitted",{ok:!1,converted:!0,error_code:(F==null?void 0:F.code)??gs((F==null?void 0:F.name)??"Error")}),Ms(q)||q.includes("paid_tier_required")?(d("sub_package"),s(l.errQuota)):q.includes("phone_verification_required")?(J(),s(l.errPhone)):q.includes("job_has_accepted_workers")?s(l.errAcceptedWorkers):q.includes("job_has_shift_assignments")?s(l.errShiftAssignments):q.includes("job_not_day_labor")?s(l.errNotDayLabor):q.includes("job_already_closed")||q.includes("job_status_not_convertible")?s(l.errNotConvertible):q.includes("job_not_found")||q.includes("not_authenticated")?s(l.errNotFound):q.includes("invalid_description")?G(l.errDescription):q.includes("invalid_bid_deadline")?G(l.errDeadlineBeforeStart):q.includes("invalid_budget")?G(l.errBudget):q.includes("invalid_duration")?G(l.errDuration):q.includes("invalid_start_date")?G(l.errStart):q.includes("invalid_trade")?G(l.errTrade):q.includes("invalid_title")?G(l.errTitle):q.includes("invalid_visibility")?G(l.errVisibility):(M.error(l.errUnknown),s(l.errUnknown))}finally{re(!1)}}};return e.jsx(xs,{open:a,onOpenChange:S=>he?null:u(S),children:e.jsxs(hs,{className:"max-w-lg max-h-[90vh] overflow-y-auto",children:[e.jsx(bs,{children:e.jsx(fs,{className:"font-display text-xl",children:l.title})}),e.jsx("p",{className:"text-sm text-muted-foreground leading-snug",children:l.explainer}),e.jsxs("div",{className:"space-y-4 pt-1",children:[e.jsx(je,{label:l.titleLabel,children:e.jsx(Be,{value:f,onChange:S=>E(S.target.value)})}),e.jsxs(je,{label:l.scopeLabel,children:[e.jsx(Jt,{value:A,onChange:S=>O(S.target.value),rows:5,maxLength:2e3}),e.jsx("span",{className:dt("block text-xs mt-1",A.trim().length<40?"text-destructive":"text-muted-foreground"),children:A.trim().length<40?l.scopeHintShort.replace("{n}",String(A.trim().length)):`${A.trim().length}/2000`})]}),e.jsxs(je,{label:l.tradeLabel,children:[e.jsx(Ws,{singleSelect:!0,selectedNames:z?[z]:[],onAdd:S=>k(S),onRemove:()=>k(""),allowCustom:!1,compact:!0}),(o.skills??[]).length>1&&e.jsx("span",{className:"block text-xs text-muted-foreground mt-1",children:l.tradeMultiHint})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx(je,{label:l.startDateLabel,children:e.jsx(Be,{type:"date",value:C,onChange:S=>B(S.target.value)})}),e.jsx(je,{label:l.durationLabel,children:e.jsx(Be,{type:"number",inputMode:"numeric",min:1,value:N,onChange:S=>h(S.target.value),placeholder:"7"})})]}),e.jsx(je,{label:l.bidDeadlineLabel,hint:l.bidDeadlineHint,children:e.jsx(Be,{type:"date",value:R,onChange:S=>g(S.target.value),max:C||void 0})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"flex gap-2",children:["single","range"].map(S=>e.jsx("button",{type:"button",onClick:()=>Q(S),className:dt("flex-1 min-h-[48px] rounded-lg text-xs font-semibold border transition",y===S?"bg-primary text-primary-foreground border-primary":"bg-card border-border text-foreground"),children:S==="single"?l.budgetToggleSingle:l.budgetToggleRange},S))}),y==="single"?e.jsx(je,{label:l.budgetSingleLabel,children:e.jsx(kt,{value:j,onChange:U})}):e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx(je,{label:l.budgetLowLabel,children:e.jsx(kt,{value:xe,onChange:ce})}),e.jsx(je,{label:l.budgetHighLabel,children:e.jsx(kt,{value:_e,onChange:Ae})})]})]}),e.jsxs("div",{className:"flex items-center justify-between rounded-xl border border-border bg-card p-3 gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-semibold text-foreground",children:Y?l.visibilityPrivate:l.visibilityPublic}),e.jsx("div",{className:"text-xs text-muted-foreground mt-0.5",children:Y?l.visibilityPrivateHint:l.visibilityPublicHint})]}),e.jsx($s,{checked:Y,onCheckedChange:S=>{ne(S)}})]}),Pe&&e.jsx("p",{className:"text-sm text-destructive",children:Pe}),be&&e.jsx("div",{className:"rounded-xl border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive",children:be}),e.jsxs("div",{className:"flex gap-2 pt-1",children:[e.jsx("button",{type:"button",onClick:()=>u(!1),disabled:he,className:"flex-1 min-h-[48px] rounded-xl border border-border bg-card text-sm font-semibold text-foreground disabled:opacity-50",children:l.cancel}),e.jsx("button",{type:"button",onClick:$,disabled:he,className:"flex-[1.4] min-h-[48px] rounded-xl bg-primary text-primary-foreground text-sm font-semibold disabled:opacity-50 inline-flex items-center justify-center gap-2",children:he?e.jsx(ue,{className:"w-4 h-4 animate-spin"}):l.submit})]})]})]})})}function je({label:a,hint:u,children:o}){return e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground mb-1 block",children:a}),o,u&&e.jsx("span",{className:"block text-xs text-muted-foreground mt-1",children:u})]})}function kt({value:a,onChange:u}){return e.jsxs("div",{className:"relative",children:[e.jsx("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-sm text-muted-foreground",children:"$"}),e.jsx(Be,{type:"number",inputMode:"decimal",min:0,value:a,onChange:o=>u(o.target.value),className:"pl-7"})]})}function La({open:a,onClose:u,jobId:o,jobTitle:n,contractorId:b}){const{t:m,lang:l}=oe(),w=We(),[d,J]=p.useState(""),[D,f]=p.useState(null),[E,A]=p.useState(new Set),{data:O=[],isLoading:z}=Z({queryKey:["invite-known-workers",b],enabled:!!b&&a,queryFn:async()=>{const{data:g}=await _.from("saved_workers").select("worker_id").eq("contractor_id",b),N=[...new Set((g??[]).map(y=>y.worker_id))];if(N.length===0)return[];const h=await Rs(N);return N.map(y=>{var j,U;const Q=h.get(y);return Q?{user_id:y,name:Q.displayName??"Worker",avatar_url:Q.avatarUrl??null,primary_skill:((U=(j=Q.laborer)==null?void 0:j.skills)==null?void 0:U[0])??null,source:"saved"}:null}).filter(y=>y!==null)}}),{data:k=[],isFetching:C}=Z({queryKey:["invite-search-workers",d],enabled:a&&d.trim().length>=2,queryFn:async()=>{const g=`%${d.trim()}%`,{data:N}=await _.from("profiles_public").select("user_id, full_name, avatar_url").ilike("full_name",g).limit(20),h=(N??[]).map(j=>
6j.user_id);if(h.length===0)return[];const{data:y}=await _.from("worker_profiles_public").select("user_id, skills").in("user_id",h),Q=new Map((y??[]).map(j=>{var U;return[j.user_id,((U=j.skills)==null?void 0:U[0])??null]}));return(N??[]).map(j=>({user_id:j.user_id,name:j.full_name??"Worker",avatar_url:j.avatar_url??null,primary_skill:Q.get(j.user_id)??null,source:"search"}))}}),B=p.useMemo(()=>d.trim().length>=2?k:O,[d,k,O]),R=async g=>{if(!D){f(g.user_id);try{const{data:N}=await _.from("profiles").select("full_name").eq("user_id",b).maybeSingle(),h=(N==null?void 0:N.full_name)??m.pass2.aContractor,{data:y,error:Q}=await _.rpc("invite_workers_to_job",{_job_id:o,_worker_ids:[g.user_id],_notification_title:m.pass2.invitedToPrivateJobTitle,_notification_body:m.pass2.invitedYouToBody(h,n),_invite_method:"browse"});if(Q)throw Q;if(((y==null?void 0:y.invited)??0)===0){M.error(m.privateJobs.alreadyInvited),A(j=>new Set(j).add(g.user_id));return}A(j=>new Set(j).add(g.user_id)),M.success(m.pass2.invitedWorker(g.name)),w.invalidateQueries({queryKey:["job-invitations",o]}),w.invalidateQueries({queryKey:["job-invitation-count",o]})}catch(N){M.error((N==null?void 0:N.message)??m.pass2.couldNotInvite)}finally{f(null)}}};return e.jsx(ve,{open:a,onOpenChange:g=>!g&&u(),children:e.jsxs(we,{side:"bottom",className:"rounded-t-2xl max-h-[85dvh]",children:[e.jsxs(Je,{className:"pb-3",children:[e.jsxs(Ne,{className:"font-display text-xl flex items-center gap-2",children:[e.jsx(Or,{className:"w-4 h-4 text-primary"}),m.privateJobs.inviteWorkers]}),e.jsx("p",{className:"text-label text-muted-foreground text-left truncate",children:n})]}),e.jsxs("div",{className:"relative mb-3",children:[e.jsx(Ks,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(Be,{value:d,onChange:g=>J(g.target.value),placeholder:m.pass2.searchWorkers,type:"search",autoComplete:"off",autoCapitalize:"none",autoCorrect:"off",spellCheck:!1,className:"pl-9 h-9 text-sm"})]}),d.trim().length<2&&O.length>0&&e.jsxs("p",{className:"text-micro uppercase tracking-wider font-medium text-muted-foreground mb-2 px-1 flex items-center gap-1",children:[e.jsx(Ve,{className:"w-3 h-3"}),m.pass2.yourNetwork]}),e.jsx("div",{className:"overflow-y-auto max-h-[55vh] space-y-1",children:z||C?e.jsx("div",{className:"flex justify-center py-10",children:e.jsx(ue,{className:"w-5 h-5 animate-spin text-primary"})}):B.length===0?e.jsxs("div",{className:"text-center py-8",children:[e.jsx(ot,{className:"w-8 h-8 text-muted-foreground/30 mx-auto mb-2"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:d.trim().length>=2?m.pass2.noMatches:m.pass2.noSavedWorkers}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:m.pass2.searchByNameAbove})]}):B.map(g=>{const N=E.has(g.user_id),h=D===g.user_id;return e.jsxs("button",{disabled:N||h,onClick:()=>R(g),className:"w-full flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-secondary/50 transition-colors disabled:opacity-60 text-left",children:[e.jsx("div",{className:"w-9 h-9 rounded-full bg-secondary flex items-center justify-center overflow-hidden shrink-0",children:g.avatar_url?e.jsx("img",{loading:"lazy",decoding:"async",src:Re(g.avatar_url,96),alt:"",className:"w-full h-full object-cover"}):e.jsx("span",{className:"text-sm font-medium text-secondary-foreground",children:g.name.charAt(0)})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-foreground truncate",children:g.name}),e.jsxs("p",{className:"text-caption text-muted-foreground truncate",children:[g.primary_skill??"â",g.source==="saved"&&" · "+m.pass2.savedSource]})]}),e.jsx("div",{className:"shrink-0",children:h?e.jsx(ue,{className:"w-4 h-4 animate-spin text-primary"}):N?e.jsxs("div",{className:"flex items-center gap-1 text-success",children:[e.jsx(ee,{className:"w-4 h-4"}),e.jsx("span",{className:"text-micro font-medium",children:m.pass2.sent})]}):e.jsx("span",{className:"px-2.5 py-1 rounded-lg bg-primary/10 border border-primary/20 text-caption font-medium text-primary",children:m.workerRelationships.invite})})]},g.user_id)})})]})})}const Dt=(a,u="en")=>{if(!a)return"";const o=new Date(`${a}T12:00:00`);return Number.isNaN(o.getTime())?"":o.toLocaleDateString(u,{weekday:"short",month:"short",day:"numeric"})};function Ta({open:a,onClose:u,shiftId:o,jobId:n,contractorId:b}){const{t:m,lang:l}=oe(),w=We(),[d,J]=p.useState(new Set),[D,f]=p.useState(new Set),[E,A]=p.useState(!1),[O,z]=p.useState(!1),[k,C]=p.useState(null),[B,R]=p.useState("menu"),{data:g,isLoading:N}=Z({queryKey:["refill-context",o],enabled:a&&!!o,queryFn:async()=>{var F;const{data:x}=await _.from("shifts").select("id, job_id, shift_date, start_time, slots, filled_slots").eq("id",o).maybeSingle(),{data:L}=await _.from("jobs").select("id, title, skills, lat, lng, slots, filled_slots").eq("id",n).maybeSingle(),{data:$}=await _.from("shift_assignments").select("worker_id").eq("shift_id",o).eq("status","declined").limit(1);let S=null;if((F=$==null?void 0:$[0])!=null&&F.worker_id){const{data:q}=await _.from("profiles_public").select("full_name").eq("user_id",$[0].worker_id).maybeSingle();S=(q==null?void 0:q.full_name)??null}return{shift:x,job:L,declinedName:S}}}),h=g==null?void 0:g.shift,y=g==null?void 0:g.job,Q=Math.max(0,((h==null?void 0:h.slots)??0)-((h==null?void 0:h.filled_slots)??0)),j=Q>0,U=p.useMemo(()=>
6{if(!(h!=null&&h.shift_date))return null;const x=new Date(`${h.shift_date}T${h.start_time??"07:00:00"}`);return Number.isNaN(x.getTime())?null:(x.getTime()-Date.now())/36e5},[h==null?void 0:h.shift_date,h==null?void 0:h.start_time]),xe=U!=null&&U>=0&&U<12,{data:ce=[],isLoading:_e}=Z({queryKey:["refill-prior-applicants",n,o],enabled:a&&!!n&&!!y,queryFn:async()=>{const{data:x}=await _.from("applications").select("worker_id, status").eq("job_id",n).in("status",["pending","not_selected"]),L=x??[];if(L.length===0)return[];const $=L.map(V=>V.worker_id),{data:S}=await _.from("shift_assignments").select("worker_id").eq("shift_id",o).in("status",["proposed","confirmed"]),F=new Set((S??[]).map(V=>V.worker_id)),[q,Ye]=await Promise.all([_.from("profiles_public").select("user_id, full_name, avatar_url").in("user_id",$),_.from("worker_profiles_public").select("user_id, skills, total_jobs, approx_lat, approx_lng").in("user_id",$)]),Oe=new Map((q.data??[]).map(V=>[V.user_id,V])),Ke=new Map((Ye.data??[]).map(V=>[V.user_id,V]));return L.filter(V=>!F.has(V.worker_id)).map(V=>{var Ge;const de=Oe.get(V.worker_id),t=Ke.get(V.worker_id);return{workerId:V.worker_id,name:(de==null?void 0:de.full_name)??"Worker",avatarUrl:(de==null?void 0:de.avatar_url)??null,skill:((Ge=t==null?void 0:t.skills)==null?void 0:Ge[0])??null,status:V.status,match:St({jobSkills:(y==null?void 0:y.skills)??[],workerSkills:(t==null?void 0:t.skills)??[],totalJobs:(t==null?void 0:t.total_jobs)??null,jobLat:y==null?void 0:y.lat,jobLng:y==null?void 0:y.lng,workerLat:t==null?void 0:t.approx_lat,workerLng:t==null?void 0:t.approx_lng})}}).sort((V,de)=>de.match.score-V.match.score)}}),{data:Ae=[],isLoading:Y}=zs(),ne=p.useMemo(()=>new Set(ce.map(x=>x.workerId)),[ce]),he=p.useMemo(()=>{const x=Ae.find(L=>L.jobId===n);return((x==null?void 0:x.workers)??[]).filter(L=>!ne.has(L.userId)).map(L=>{var $;return{workerId:L.userId,name:L.name,avatarUrl:null,skill:(($=L.skills)==null?void 0:$[0])??null,status:"not_selected",match:St({jobSkills:(y==null?void 0:y.skills)??[],workerSkills:L.skills??[],totalJobs:L.totalJobs??null})}})},[Ae,n,ne,y==null?void 0:y.skills]),re=B==="prior"?ce:B==="suggested"?he:[],Pe=x=>J(L=>{const $=new Set(L);return $.has(x)?$.delete(x):$.add(x),$}),G=async()=>{if(d.size===0||E)return;A(!0);let x=0;try{for(const L of d){const{error:$}=await _.from("job_invitations").upsert({job_id:n,worker_id:L,contractor_id:b,status:"pending",invite_method:"refill",shift_id:o},{onConflict:"job_id,worker_id"});$||(await _.from("notifications").insert({user_id:L,type:"job_invitation",role:"worker",title:m.pass2.invitedToPrivateJobTitle,body:m.pass2.invitedYouToBody(m.pass2.aContractor,`${(y==null?void 0:y.title)??""} · ${Dt(h==null?void 0:h.shift_date,l)}`),data:{job_id:n,shift_id:o,invitation_type:"refill"},job_id:n,link:`/jobs/${n}`,read:!1}),x+=1)}x===0?M.error(m.refill.inviteFailed):(f(L=>new Set([...L,...d])),J(new Set),M.success(m.refill.inviteSent(x)),w.invalidateQueries({queryKey:["refill-prior-applicants",n,o]}))}catch{M.error(m.refill.inviteFailed)}finally{A(!1)}},be=async()=>{if(!O){z(!0);try{const{data:x,error:L}=await _.rpc("broadcast_shift_refill",{_shift_id:o});if(L)throw L;const $=Number(x??0);C($),M.success($>0?m.refill.broadcastDone($):m.refill.broadcastNone)}catch(x){M.error(x instanceof Error?x.message:m.refill.inviteFailed)}finally{z(!1)}}},s=g!=null&&g.declinedName?m.refill.cantMake(g.declinedName,Dt(h==null?void 0:h.shift_date,l)):Dt(h==null?void 0:h.shift_date,l);return e.jsx(ve,{open:a,onOpenChange:x=>!x&&u(),children:e.jsxs(we,{side:"bottom",className:"rounded-t-2xl max-h-[88dvh] overflow-y-auto",children:[e.jsxs(Je,{className:"pb-2",children:[e.jsx(Ne,{className:"font-display text-xl",children:m.refill.title}),e.jsx("p",{className:"text-label text-muted-foreground text-left",children:s})]}),N?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(ue,{className:"w-5 h-5 animate-spin text-primary"})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx("span",{className:"px-2 py-0.5 rounded-full bg-primary/10 border border-primary/20 text-caption font-medium text-primary",children:Q>0?m.refill.slotsOpen(Q):m.refill.shiftCovered}),xe&&e.jsxs("span",{className:"text-caption text-muted-foreground flex items-center gap-1",children:[e.jsx(Ce,{className:"w-3 h-3 text-primary"}),m.refill.urgentHint]})]}),B==="menu"?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("button",{onClick:()=>R("prior"),className:"w-full flex items-center gap-3 px-3 py-3 rounded-xl bg-secondary/40 hover:bg-secondary/60 transition-colors text-left",children:[e.jsx(Ve,{className:"w-4 h-4 text-primary shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:m.refill.priorTitle}),e.jsx("p",{className:"text-caption text-muted-foreground",children:_e?"â¦":m.refill.priorDesc(ce.length)})]}),e.jsx(Jr,{className:"w-4 h-4 text-muted-foreground shrink-0"})]}),e.jsxs("button",{onClick:()=>R("suggested"),className:"w-full flex items-center gap-3 px-3 py-3 rounded-xl bg-secondary/40 hover:bg-secondary/60 transition-colors text-left",children:[e.jsx($e,{className:"w-4 h-4 text-primary shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:m.refill.suggestedTitle}),e.jsx("p",{className:"text-caption text-muted-foreground",children:Y?"â¦":m.refill.suggestedDesc(he.length)})]}),e.jsx(Jr,{className:"w-4 h-4 text-muted-foreground shrink-0"})]}),e.jsxs("div",{className:"px-3 py-3 rounded-xl bg-secondary/40",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Qs,{className:"w-4 h-4 text-primary shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:m.refill.broadcastTitle}),e.jsx("p",{className:"text-caption text-muted-foreground",children:k!=null?m.refill.broadcastDone(k):j?m.refill.broadcastDesc:m.refill.broadcastBlocked})]})]}),e.jsx(T,{size:"sm",variant:"outline",className:"w-full mt-2",disabled:O||k!=null||!j,onClick:be,children:O?e.jsx(ue,{className:"w-4 h-4 animate-spin"}):m.refill.broadcastCta})]})]}):e.jsxs("div",{className:"space-y-1",children:[e.jsxs("button",{onClick:()=>R("menu"),className:"text-caption text-primary font-medium mb-1",children:["â ",m.refill.title]}),(B==="prior"?_e:Y)?e.jsx("div",{className:"flex justify-center py-10",children:e.jsx(ue,{className:"w-5 h-5 animate-spin text-primary"})}):re.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-8",children:B==="prior"?m.refill.priorEmpty:m.refill.suggestedEmpty}):re.map(x=>{const L=d.has(x.workerId),$=D.has(x.workerId);return e.jsxs("button",{disabled:$,onClick:()=>Pe(x.workerId),className:`w-full flex items-center gap-2.5 px-2.5 py-2 rounded-lg text-left transition-colors disabled:opacity-60 ${L?"bg-primary/10 border border-primary/30":"border border-transparent hover:bg-secondary/50"}`,children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-secondary flex items-center justify-center overflow-hidden shrink-0",children:x.avatarUrl?e.jsx("img",{loading:"lazy",decoding:"async",src:Re(x.avatarUrl,96),alt:"",className:"w-full h-full object-cover"}):e.jsx("span",{className:"text-xs font-medium text-secondary-foreground",children:x.name.charAt(0)})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-foreground truncate",children:x.name}),e.jsxs("p",{className:"text-caption text-muted-foreground truncate",children:[x.skill??"â",x.match.distanceMi!=null&&` · ${Math.round(x.match.distanceMi)} mi`,B==="prior"&&` · ${x.status==="pending"?m.refill.stillPending:m.refill.notPicked}`]})]}),e.jsx("span",{className:`shrink-0 px-2 py-0.5 rounded-full border text-micro font-medium ${Kr(x.match.band)}`,children:x.match.label}),e.jsx("span",{className:"shrink-0 w-5 flex justify-center",children:$?e.jsx(ee,{className:"w-4 h-4 text-success"}):L?e.jsx(ee,{className:"w-4 h-4 text-primary"}):null})]},x.workerId)}),d.size>0&&e.jsx(T,{className:"w-full mt-3",disabled:E,onClick:G,children:E?e.
6jsx(ue,{className:"w-4 h-4 animate-spin"}):m.refill.inviteSelected(d.size)})]})]})]})})}const Ma=()=>{const{tr:a}=oe();return u=>{const o=cs[u??"browse"];return o?a(o):u??""}},Mr={pending:"border-warning/40 text-warning bg-warning/10",accepted:"border-success/40 text-success bg-success/10",declined:"border-border/60 text-muted-foreground bg-muted/30",expired:"border-border/60 text-muted-foreground bg-muted/30"},$a=({status:a})=>{const{tr:u}=oe(),o=u(fr[a]??fr.pending),n=Mr[a]??Mr.pending,b=a==="accepted"?ee:a==="declined"?Se:a==="expired"?Us:Me;return e.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-full border text-caption font-semibold ${n}`,children:[e.jsx(b,{size:10})," ",o]})};function Wa({jobId:a}){const{t:u,lang:o}=oe(),n=Ma(),{data:b,isLoading:m}=Z({queryKey:["job-invitations",a],queryFn:async()=>{const{data:w,error:d}=await _.from("job_invitations").select("id, worker_id, status, invited_at, responded_at, invite_method").eq("job_id",a).order("invited_at",{ascending:!1});if(d)throw d;const J=w??[];if(J.length===0)return[];const D=[...new Set(J.map(A=>A.worker_id))],{data:f}=await _.from("profiles_public").select("user_id, full_name").in("user_id",D),E=new Map((f??[]).map(A=>[A.user_id,A.full_name]));return J.map(A=>({...A,full_name:E.get(A.worker_id)??u.pass2.worker}))},enabled:!!a});if(m)return e.jsxs("div",{className:"flex items-center justify-center py-6 text-muted-foreground text-sm",children:[e.jsx(ue,{className:"w-4 h-4 animate-spin mr-2"}),u.pass2.loadingEllipsis]});if(!b||b.length===0)return e.jsx("div",{className:"rounded-xl border border-dashed border-border/60 p-4 text-sm text-muted-foreground text-center",children:u.pass2.noInvitationsYet});const l={invited:b.length,applied:b.filter(w=>w.status==="accepted").length,declined:b.filter(w=>w.status==="declined").length};return e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-label text-muted-foreground",children:u.privateJobs.countsLine(l.invited,l.applied,l.declined)}),b.map(w=>e.jsxs("div",{className:"flex items-center justify-between gap-3 p-3 rounded-xl border border-border/60 bg-card/60",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-foreground truncate",children:w.full_name}),e.jsxs("p",{className:"text-caption text-muted-foreground mt-0.5",children:[n(w.invite_method),w.invited_at?` · ${pt(w.invited_at)}`:""]})]}),e.jsx($a,{status:w.status})]},w.id))]})}function Fa({open:a,onOpenChange:u,applicant:o,jobTitle:n,jobSkills:b,queueRemaining:m,onAccept:l,onDecline:w,isMutating:d}){var z,k,C,B;const{tr:J}=oe(),D=ut(),f=p.useMemo(()=>{var g;if(!o)return[];const R=b.map(N=>N.toLowerCase());return(((g=o.worker)==null?void 0:g.skills)??[]).filter(N=>R.includes(N.toLowerCase()))},[o,b]);if(!o)return null;const E=((z=o.profile)==null?void 0:z.full_name)??"Worker",A=E.split(" ").map(R=>R[0]).join("").slice(0,2).toUpperCase(),O=((k=o.worker)==null?void 0:k.total_jobs)??0;return e.jsx(ve,{open:a,onOpenChange:u,children:e.jsx(we,{side:"bottom",className:"rounded-t-3xl border-t border-border/60 bg-card/95 backdrop-blur-xl p-0 max-h-[92dvh] overflow-y-auto",children:e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"pointer-events-none absolute -top-16 right-0 w-48 h-48 bg-primary/10 rounded-full blur-3xl"}),e.jsx("div",{className:"pointer-events-none absolute -bottom-12 -left-12 w-40 h-40 bg-primary/5 rounded-full blur-3xl"}),e.jsxs("div",{className:"relative px-5 pt-6 pb-5",children:[e.jsxs(Je,{className:"text-left mb-4",children:[e.jsxs("p",{className:"text-xs uppercase tracking-wide text-muted-foreground font-medium",children:["New applicant · ",pt(o.created_at)]}),e.jsx(Ne,{className:"font-display text-xl text-foreground",children:E}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["applied to ",e.jsx("span",{className:"text-foreground font-medium",children:n})]})]}),e.jsxs("div",{className:"flex items-start gap-4 mb-5",children:[e.jsx("div",{className:"shrink-0 w-16 h-16 rounded-full overflow-hidden border-2 border-border bg-primary/10 flex items-center justify-center text-primary font-semibold text-lg",children:(C=o.profile)!=null&&C.avatar_url?e.jsx("img",{src:Re(o.profile.avatar_url,96),alt:(B=o.profile)!=null&&B.full_name?`${o.profile.full_name}'s profile photo`:"Applicant profile photo",className:"w-full h-full object-cover"}):A}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsx(ie,{className:`${Kr(o.matchBand)} border text-caption uppercase tracking-wide`,children:o.matchLabel})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 mb-5",children:[e.jsx($r,{icon:e.jsx($e,{className:"w-4 h-4"}),label:J("applicantSheet.distance"),value:o.distanceMi!=null?`${Math.round(o.distanceMi)} mi`:J("applicantSheet.unknown"),muted:o.distanceMi==null}),e.jsx($r,{icon:e.jsx(aa,{className:"w-4 h-4"}),label:J("applicantSheet.jobsDone"),value:O>0?`${O}`:J("applicantSheet.first"),muted:O===0})]}),e.jsxs("div",{className:"mb-5",children:[e.jsxs("p",{className:"text-xs uppercase tracking-wide text-muted-foreground mb-2 font-medium",children:[J("applicantSheet.skillsMatched")," (",f.length,"/",b.length,")"]}),f.length>0?e.jsx("div",{className:"flex flex-wrap gap-1.5",children:f.map(R=>e.jsxs(ie,{variant:"outline",className:"bg-success/10 text-success border-success/30 text-caption",children:[e.jsx(ee,{className:"w-3 h-3 mr-1"}),R]},R))}):e.jsx("p",{className:"text-sm text-muted-foreground",children:J("applicantSheet.noOverlap")})]}),o.message&&e.jsxs("div",{className:"mb-5 p-3 rounded-card bg-secondary/40 border border-border/60",children:[e.jsx("p",{className:"text-xs uppercase tracking-wide text-muted-foreground mb-1 font-medium",children:J("applicantSheet.theirNote")}),e.jsxs("p",{className:"text-sm text-foreground italic",children:['"',o.message,'"']})]}),e.jsxs(T,{variant:"ghost",className:"w-full mb-3 justify-between text-sm",onClick:()=>D(`/profile/${o.worker_id}`),children:[J("applicantSheet.viewFullProfile"),e.jsx(nt,{className:"w-4 h-4"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 pb-[env(safe-area-inset-bottom)]",children:[e.jsxs(T,{variant:"outline",className:"h-12 rounded-card",disabled:d||o.status!=="pending",onClick:()=>w(o),children:[e.jsx(Se,{className:"w-4 h-4 mr-1.5"})," ",J("applicantSheet.decline")]}),e.jsxs(T,{className:"h-12 rounded-card bg-primary hover:bg-primary/90 text-primary-foreground",disabled:d||o.status!=="pending",onClick:()=>l(o),children:[e.jsx(ee,{className:"w-4 h-4 mr-1.5"})," ",J("applicantSheet.accept")]})]}),m>0&&e.jsx("p",{className:"text-center text-xs text-muted-foreground mt-3",children:J("applicantSheet.morePending",{count:String(m)})})]})]})})})}function $r({icon:a,label:u,value:o,muted:n}){return e.jsxs("div",{className:"rounded-card border border-border/60 bg-secondary/30 px-3 py-2.5 text-center",children:[e.jsx("div",{className:`flex items-center justify-center gap-1 mb-1 ${n?"text-muted-foreground":"text-primary"}`,children:a}),e.jsx("p",{className:`text-sm font-semibold ${n?"text-muted-foreground":"text-foreground"}`,children:o}),e.jsx("p",{className:"text-micro uppercase tracking-wide text-muted-foreground mt-0.5",children:u})]})}const Ia=["changedPlans","foundSomeoneElse","workerRequested","other"];
6function Ea({applicationId:a,workerId:u,workerName:o,jobId:n,jobTitle:b,status:m}){const l=ut(),w=We(),{tr:d}=oe(),{data:J}=ia(n),[D,f]=p.useState(null),[E,A]=p.useState(""),[O,z]=p.useState(""),k=!!(J!=null&&J.within24h),C=!!(J!=null&&J.jobDayOrPast),B=!C,R=C,g=["accepted","completed","paid"].includes(m),N=()=>{f(null),A(""),z("")},h=De({mutationFn:async j=>{await ea({applicationId:a,status:j.next,reason:j.reasonText,source:"AcceptedWorkerActions",jobId:n,workerId:u})},onSuccess:(j,U)=>{const xe={removed:d("acceptedWorkerActions.toastRemoved",{name:o}),no_show:d("acceptedWorkerActions.toastNoShow",{name:o}),completed:d("acceptedWorkerActions.toastCompleted",{name:o}),paid:d("acceptedWorkerActions.toastPaid",{name:o})};M.success(xe[U.next]||d("acceptedWorkerActions.toastUpdated")),w.invalidateQueries({queryKey:["job-detail-applicants",n]}),w.invalidateQueries({queryKey:["job-applicant-stats",n]}),w.invalidateQueries({queryKey:["contractor-job-detail",n]}),w.invalidateQueries({queryKey:["contractor-jobs"]}),w.invalidateQueries({queryKey:["job-status-map"]}),N(),U.next==="completed"&&setTimeout(()=>{M(d("acceptedWorkerActions.reviewPromptTitle",{name:o}),{description:d("acceptedWorkerActions.reviewPromptDesc"),action:{label:d("acceptedWorkerActions.reviewPromptAction"),onClick:()=>l(`/profile/${u}#review`)}})},300)},onError:j=>{M.error((j==null?void 0:j.message)||d("acceptedWorkerActions.toastUpdateError"))}}),y=D==="remove"&&k,Q=h.isPending||D==="remove"&&y&&!E;return e.jsxs(e.Fragment,{children:[e.jsxs(Fr,{children:[e.jsx(Ir,{asChild:!0,children:e.jsx(T,{size:"sm",variant:"ghost",className:"h-8 w-8 p-0 rounded-lg","aria-label":d("acceptedWorkerActions.manageWorker",{name:o}),children:e.jsx(zr,{className:"w-4 h-4"})})}),e.jsxs(Er,{align:"end",className:"w-56",children:[e.jsxs(ye,{onClick:()=>l(`/contractor/messages?to=${u}&job=${n}`),children:[e.jsx(lt,{className:"w-4 h-4 mr-2"})," ",d("acceptedWorkerActions.messageWorker")]}),R&&e.jsxs(e.Fragment,{children:[e.jsx(wt,{}),e.jsxs(ye,{onClick:()=>f("completed"),children:[e.jsx(ct,{className:"w-4 h-4 mr-2 text-primary"})," ",d("acceptedWorkerActions.markCompleted")]}),e.jsxs(ye,{onClick:()=>f("no_show"),children:[e.jsx(oa,{className:"w-4 h-4 mr-2 text-destructive"})," ",d("acceptedWorkerActions.markNoShow")]})]}),g&&e.jsxs(e.Fragment,{children:[e.jsx(wt,{}),e.jsxs(ye,{onClick:()=>f("paid"),children:[e.jsx(mt,{className:"w-4 h-4 mr-2 text-success"})," ",d("acceptedWorkerActions.markPaid")]})]}),R&&e.jsxs(ye,{onClick:()=>l(`/profile/${u}#review`),children:[e.jsx(na,{className:"w-4 h-4 mr-2 text-primary"})," ",d("acceptedWorkerActions.leaveReview")]}),B&&e.jsxs(e.Fragment,{children:[e.jsx(wt,{}),e.jsxs(ye,{onClick:()=>f("remove"),className:"text-destructive focus:text-destructive",children:[k?e.jsx(Ce,{className:"w-4 h-4 mr-2"}):e.jsx(la,{className:"w-4 h-4 mr-2"}),d("acceptedWorkerActions.removeFromJob")]})]})]})]}),e.jsx(ve,{open:D==="remove",onOpenChange:j=>!j&&N(),children:e.jsxs(we,{side:"bottom",className:"rounded-t-2xl",children:[e.jsxs(Je,{className:"text-left",children:[e.jsx(Ne,{children:d("acceptedWorkerActions.removeTitle",{name:o})}),e.jsx(Ee,{children:d(y?"acceptedWorkerActions.removeDescLate":"acceptedWorkerActions.removeDescNormal")})]}),y&&e.jsxs("div",{className:"mt-4 flex items-start gap-2 p-3 rounded-lg bg-warning/10 border border-warning/30 text-warning-foreground",children:[e.jsx(Ce,{className:"w-4 h-4 mt-0.5 shrink-0 text-warning"}),e.jsx("p",{className:"text-sm",children:d("acceptedWorkerActions.within24hWarning")})]}),e.jsxs("div",{className:"mt-4 space-y-2",children:[e.jsxs(Ar,{className:"text-sm",children:[d("acceptedWorkerActions.reasonLabel")," ",y?e.jsx("span",{className:"text-destructive",children:"*"}):e.jsx("span",{className:"text-muted-foreground",children:d("acceptedWorkerActions.reasonOptional")})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:Ia.map(j=>{const U=d(`acceptedWorkerActions.reasons.${j}`);return e.jsx("button",{type:"button",onClick:()=>A(U),className:`px-3 py-1.5 rounded-full text-xs font-medium border transition-colors ${E===U?"bg-primary text-primary-foreground border-primary":"bg-background border-border hover:bg-muted"}`,children:U},j)})})]}),e.jsxs(rt,{className:"mt-6 flex-row gap-2 sm:flex-row",children:[e.jsx(T,{variant:"outline",className:"flex-1",onClick:N,children:d("acceptedWorkerActions.cancel")}),e.jsx(T,{variant:"destructive",className:"flex-1",disabled:Q,onClick:()=>h.mutate({next:"removed",reasonText:E||null}),children:d("acceptedWorkerActions.removeWorker")})]})]})}),e.jsx(ve,{open:D==="no_show",onOpenChange:j=>!j&&N(),children:e.jsxs(we,{side:"bottom",className:"rounded-t-2xl",children:[e.jsxs(Je,{className:"text-left",children:[e.jsx(Ne,{children:d("acceptedWorkerActions.noShowTitle",{name:o})}),e.jsx(Ee,{children:d("acceptedWorkerActions.noShowDesc",{job:b})})]}),e.jsxs(rt,{className:"mt-6 flex-row gap-2 sm:flex-row",children:[e.jsx(T,{variant:"outline",className:"flex-1",onClick:N,children:d("acceptedWorkerActions.cancel")}),e.jsx(T,{variant:"destructive",className:"flex-1",disabled:h.isPending,onClick:()=>h.mutate({next:"no_show",reasonText:null}),children:d("acceptedWorkerActions.markNoShowConfirm")})]})]})}),e.jsx(ve,{open:D==="completed",onOpenChange:j=>!j&&N(),children:e.jsxs(we,{side:"bottom",className:"rounded-t-2xl",children:[e.jsxs(Je,{className:"text-left",children:[e.jsx(Ne,{children:d("acceptedWorkerActions.completedTitle",{name:o})}),e.jsx(Ee,{children:d("acceptedWorkerActions.completedDesc",{job:b})})]}),e.jsxs("div",{className:"mt-4 space-y-2",children:[e.jsx(Ar,{htmlFor:"completed-note",className:"text-sm text-muted-foreground",children:d("acceptedWorkerActions.noteOptional")}),e.jsx(Jt,{id:"completed-note",value:O,onChange:j=>
6z(j.target.value),placeholder:d("acceptedWorkerActions.notePlaceholder"),className:"resize-none",rows:3})]}),e.jsxs(rt,{className:"mt-6 flex-row gap-2 sm:flex-row",children:[e.jsx(T,{variant:"outline",className:"flex-1",onClick:N,children:d("acceptedWorkerActions.cancel")}),e.jsx(T,{className:"flex-1",disabled:h.isPending,onClick:()=>h.mutate({next:"completed",reasonText:O||null}),children:d("acceptedWorkerActions.markCompletedConfirm")})]})]})}),e.jsx(ve,{open:D==="paid",onOpenChange:j=>!j&&N(),children:e.jsxs(we,{side:"bottom",className:"rounded-t-2xl",children:[e.jsxs(Je,{className:"text-left",children:[e.jsx(Ne,{children:d("acceptedWorkerActions.paidTitle",{name:o})}),e.jsx(Ee,{children:d("acceptedWorkerActions.paidDesc",{name:o,job:b})})]}),e.jsxs(rt,{className:"mt-6 flex-row gap-2 sm:flex-row",children:[e.jsx(T,{variant:"outline",className:"flex-1",onClick:N,children:d("acceptedWorkerActions.cancel")}),e.jsx(T,{className:"flex-1 bg-success hover:bg-success/90 text-success-foreground",disabled:h.isPending,onClick:()=>h.mutate({next:"paid",reasonText:null}),children:d("acceptedWorkerActions.confirmPaid")})]})]})})]})}function Ba({jobId:a,jobTitle:u,maxCents:o,acceptedWorkers:n}){const{tr:b}=oe(),m=We(),{data:l=[]}=Z({queryKey:["contractor-ride-claims",a],queryFn:async()=>{const{data:D}=await _.from("ride_reimbursements").select("id, worker_id, ride_provider, claimed_amount_cents, status").eq("job_id",a);return D??[]}}),w=De({mutationFn:async({claim:D,next:f})=>{const E={status:f};f==="confirmed"&&(E.contractor_confirmed_at=new Date().toISOString());const{error:A}=await _.from("ride_reimbursements").update(E).eq("id",D.id);if(A)throw A;const O={pending:"ð Reimbursement update",confirmed:"â
Reimbursement confirmed",paid:"ðµ Reimbursement paid",declined:"â Reimbursement declined"},z={pending:`Your ride reimbursement for "${u}" is pending`,confirmed:`Your ride reimbursement for "${u}" has been confirmed`,paid:`Your contractor confirmed payment for your ride to "${u}"`,declined:`Your ride reimbursement for "${u}" was declined`};await _.from("notifications").insert({user_id:D.worker_id,type:"ride_reimbursement_status",role:"worker",title:O[f],body:z[f],link:`/jobs/${a}`})},onSuccess:()=>{m.invalidateQueries({queryKey:["contractor-ride-claims",a]})},onError:D=>M.error((D==null?void 0:D.message)||b("ride.updateError"))}),d=new Map(l.map(D=>[D.worker_id,D])),J=Math.round(o/100);return e.jsxs(K.div,{initial:{opacity:0,y:6},animate:{opacity:1,y:0},className:"bg-card/60 backdrop-blur-sm border border-border/60 rounded-xl p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h3",{className:"font-display text-lg text-foreground flex items-center gap-2",children:[e.jsx(ca,{className:"w-5 h-5 text-primary"})," ",b("ride.contractorTitle")]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:b("ride.perWorker",{amount:`$${J}`})})]}),n.length===0?e.jsx("p",{className:"text-sm text-muted-foreground italic",children:b("ride.noAcceptedWorkers")}):e.jsx("div",{className:"space-y-2",children:n.map(D=>{const f=d.get(D.workerId);return e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-xl bg-background/40 border border-border/60",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-semibold text-foreground truncate",children:D.name}),f?e.jsxs("p",{className:"text-xs text-muted-foreground",children:[f.ride_provider==="uber"?"Uber":"Lyft",f.claimed_amount_cents?` · $${(f.claimed_amount_cents/100).toFixed(0)}`:""," ","· ",f.status]}):e.jsx("p",{className:"text-xs text-muted-foreground",children:b("ride.noClaimYet")})]}),f&&f.status==="pending"&&e.jsxs("div",{className:"flex gap-2 shrink-0",children:[e.jsxs(T,{size:"sm",onClick:()=>w.mutate({claim:f,next:"confirmed"}),disabled:w.isPending,className:"h-8 px-3 gap-1 rounded-lg bg-success hover:bg-success/90 text-success-foreground",children:[e.jsx(ee,{className:"w-3.5 h-3.5"})," ",b("ride.confirm")]}),e.jsxs(T,{size:"sm",variant:"outline",onClick:()=>w.mutate({claim:f,next:"declined"}),disabled:w.isPending,className:"h-8 px-3 gap-1 rounded-lg border-destructive/40 text-destructive hover:bg-destructive/10",children:[e.jsx(Se,{className:"w-3.5 h-3.5"})," ",b("ride.decline")]})]}),f&&f.status==="confirmed"&&e.jsx(T,{size:"sm",onClick:()=>w.mutate({claim:f,next:"paid"}),disabled:w.isPending,className:"h-8 px-3 gap-1 rounded-lg shrink-0",children:w.isPending?e.jsx(ue,{className:"w-3.5 h-3.5 animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsx(mt,{className:"w-3.5 h-3.5"})," ",b("ride.markPaid")]})}),f&&f.status==="paid"&&e.jsxs("span",{className:"text-xs text-success font-semibold shrink-0",children:["ðµ ",b("ride.paid")]}),f&&f.status==="declined"&&e.jsx("span",{className:"text-xs text-destructive font-semibold shrink-0",children:b("ride.declined")})]},D.workerId)})})]})}function Ra(a){if(!a)return"";try{return pt(a)}catch{return""}}const Wr=a=>{if(!a||a.length===0)return 3;const u=a[0];return u.has_credential?u.expired?2:u.verified?0:1:3};function Wn(){var Qt,Ut,Ht,Vt,Yt,Gt,Xt,Zt,er,tr;const{id:a}=Es(),u=ut(),{user:o}=js(),n=We(),[b,m]=Bs(),l=b.get("applicant"),w=b.get("review"),d=b.get("refill"),[J,D]=p.useState(!1),[f,E]=p.useState(!1),[A,O]=p.useState(!1),[z,k]=p.useState({}),[C,B]=p.useState(!1),[R,g]=p.useState(null),[N,h]=p.useState(null),[y,Q]=p.useState(!1),[j,U]=p.useState(!1),[xe,ce]=p.useState(!1),[_e,Ae]=p.useState(!1),[Y,ne]=p.useState(null),[he,re]=p.useState("confirm"),[Pe,G]=p.useState(""),be=p.useRef(null),{t:s,tr:x,lang:L}=oe(),$=Ps(),{initiateCall:S,isCalling:F}=da(),{data:q}=ys(o==null?void 0:o.id),Ye=!!((Qt=q==null?void 0:q.sub)!=null&&Qt.licenseNumber),Oe=Ss("contractor_add_license_after_first_hire",!!(o!=null&&o.id),{alreadyDone:Ye}),Ke=((Vt=(Ht=(Ut=s.prompts)==null?void 0:Ut.contextual)==null?void 0:Ht.contractor)==null?void 0:Vt.addLicense)??{},V=((Gt=(Yt=s.prompts)==null?void 0:Yt.contextual)==null?void 0:Gt.dismissCta)??"Not now",de=()=>{Oe.show&&M(Ke.title??"Add DBPR license for verified badge",{description:Ke.body??"First hire done â a verified badge means faster future hires.",duration:8e3,action:{label:Ke.cta??"Add license",onClick:()=>{Oe.markComplete(),u("/contractor/settings")}},cancel:{label:V,onClick:()=>Oe.dismiss()}})},{data:t,isLoading:Ge,isError:Qr,refetch:Ur}=ks({queryKey:["contractor-job-detail",a],queryFn:async()=>{const{data:r,error:i}=await _.from("jobs").select("id, title, contractor_id, description, location, lat, lng, pay, pay_type, pay_range_max, slots, filled_slots, status, urgency, start_date, shift_start_time, shift_end_time, skills, visibility, requires_license, required_license_skills, required_certifications, years_experience_needed, tools_policy, payment_schedule, payment_methods, worker_type, insurance_required, special_instructions, application_deadline, boosted_until, photos, attachments, ride_reimbursement_offered, ride_reimbursement_amount, deleted_at, closed_at, created_at, updated_at, duration, recurrence_pattern, recurrence_end_date, trade_type, job_category, schedule_type, preferred_contact_method, job_type, converted_to_job_id, notified_worker_count, needs_closeout, bid_deadline, project_id").eq("id",a).eq("contractor_id",o.id
6).single();if(i)throw i;return r},enabled:!!a&&!!o}),{translation:le}=Zs(t?{id:t.id,title:t.title,description:t.description??"",category:t.job_category??"",duration:t.duration??"",tradeType:t.trade_type??"",workerType:t.worker_type??"",paymentSchedule:t.payment_schedule??"",skills:t.skills??[],certifications:t.required_certifications??[]}:null),{data:se}=Z({queryKey:["job-applicant-stats",a],enabled:!!a,queryFn:async()=>{const{data:r}=await _.from("applications").select("status").eq("job_id",a),i=r||[];return{total:i.length,pending:i.filter(c=>c.status==="pending").length,accepted:i.filter(c=>c.status==="accepted").length,rejected:i.filter(c=>c.status==="rejected").length}}}),{data:fe=[]}=Z({queryKey:["job-detail-applicants",a],enabled:!!a,queryFn:async()=>{const{data:r,error:i}=await _.from("applications").select("id, job_id, worker_id, status, status_changed_at, created_at, credential_status, needs_pickup, pickup_confirmed, self_reported_skills").eq("job_id",a).order("created_at",{ascending:!1});if(i||!r||r.length===0)return[];const c=r.map(I=>I.worker_id),[v,W]=await Promise.all([_.from("profiles_public").select("user_id, full_name, avatar_url").in("user_id",c),_.from("worker_profiles_public").select("user_id, skills, reliability_score, total_jobs, approx_lat, approx_lng, hourly_rate, years_experience, has_own_tools, has_transportation, travel_radius_miles").in("user_id",c)]),P=Object.fromEntries((v.data??[]).map(I=>[I.user_id,I])),me=Object.fromEntries((W.data??[]).map(I=>[I.user_id,I]));return r.map(I=>({...I,profile:P[I.worker_id]??null,worker:me[I.worker_id]??null}))}}),{data:At=0}=Z({queryKey:["nearby-worker-count",a,(Xt=t==null?void 0:t.skills)==null?void 0:Xt.join(",")],enabled:!!t,queryFn:async()=>{const r=(t==null?void 0:t.skills)??[];let i=_.from("worker_profiles_public").select("user_id",{count:"exact",head:!0});r.length>0&&(i=i.overlaps("skills",r));const{count:c}=await i;return c??0}}),{data:Hr=0}=Z({queryKey:["job-view-count",a],enabled:!!a,queryFn:async()=>{const{count:r}=await _.from("job_views").select("id",{count:"exact",head:!0}).eq("job_id",a);return r??0}}),xt=Ds(a?[a]:[]).get(a),ke=xt.openShifts,ht=fe.filter(r=>["accepted","completed","paid"].includes(r.status)).map(r=>r.worker_id),{data:Pt={}}=Z({queryKey:["accepted-applicant-can-call",a,ht.sort().join(",")],enabled:ht.length>0,queryFn:async()=>{const r=await Promise.all(ht.map(async c=>{const{data:v}=await _.rpc("can_call_user",{target_user_id:c});return[c,v===!0]})),i={};for(const[c,v]of r)v&&(i[c]=!0);return i}}),{data:Vr=0}=Z({queryKey:["job-message-count",a],enabled:!!a,queryFn:async()=>{const{data:r}=await _.from("messages").select("sender_id, receiver_id").eq("job_id",a),i=r||[],c=new Set;return i.forEach(v=>{v.sender_id&&v.sender_id!==(o==null?void 0:o.id)&&c.add(v.sender_id),v.receiver_id&&v.receiver_id!==(o==null?void 0:o.id)&&c.add(v.receiver_id)}),c.size}}),{data:Yr}=Z({queryKey:["job-invitation-count",a],enabled:!!a&&Ie(t==null?void 0:t.visibility),queryFn:async()=>{const{count:r}=await _.from("job_invitations").select("id",{count:"exact",head:!0}).eq("job_id",a);return r??0}}),ae=De({mutationFn:async({appId:r,status:i,workerId:c})=>{await ra({applicationId:r,status:i,source:"ContractorJobDetail",jobId:a,workerId:c})},onMutate:async({appId:r,status:i})=>{await n.cancelQueries({queryKey:["job-detail-applicants",a]});const c=n.getQueryData(["job-detail-applicants",a]);c&&n.setQueryData(["job-detail-applicants",a],c.map(P=>P.id===r?{...P,status:i}:P));const v=n.getQueryData(["job-applicant-stats",a]);if(v){const P={...v};
6P.pending=Math.max(0,(P.pending??0)-1),i==="accepted"?P.accepted=(P.accepted??0)+1:P.rejected=(P.rejected??0)+1,n.setQueryData(["job-applicant-stats",a],P)}const W=ta(n,r,i);return{prevApplicants:c,prevStats:v,rollbackGeneric:W}},onSuccess:(r,i)=>{i.status==="accepted"?(re("success"),M.success(s.contractorJobDetail.toasts.accepted.replace("{name}",Pe||s.contractorJobDetail.worker),{description:s.contractorJobDetail.toasts.acceptedDesc}),de()):M.success(s.contractorJobDetail.toasts.declined),n.invalidateQueries({queryKey:["job-detail-applicants",a]}),n.invalidateQueries({queryKey:["job-applicant-stats",a]}),n.invalidateQueries({queryKey:["contractor-job-detail",a]}),n.invalidateQueries({queryKey:["contractor-needs-review"]}),n.invalidateQueries({queryKey:["contractor-pending-apps-count"]})},onError:(r,i,c)=>{var v;c!=null&&c.prevApplicants&&n.setQueryData(["job-detail-applicants",a],c.prevApplicants),c!=null&&c.prevStats&&n.setQueryData(["job-applicant-stats",a],c.prevStats),(v=c==null?void 0:c.rollbackGeneric)==null||v.call(c),M.error(s.contractorJobDetail.toasts.updateFailed)}});p.useEffect(()=>{if(!a)return;const r=_.channel(`job-applications-${a}-${Math.random().toString(36).slice(2,10)}`).on("postgres_changes",{event:"*",schema:"public",table:"applications",filter:`job_id=eq.${a}`},()=>{n.invalidateQueries({queryKey:["job-detail-applicants",a]}),n.invalidateQueries({queryKey:["job-applicant-stats",a]}),n.invalidateQueries({queryKey:["contractor-job-detail",a]})}).subscribe();return()=>{_.removeChannel(r)}},[a,n]);const qt=De({mutationFn:async r=>{const{error:i}=await _.from("jobs").update({urgency:r}).eq("id",a);if(i)throw i},onSuccess:()=>{M.success(s.contractorJobDetail.toasts.urgencyUpdated),n.invalidateQueries({queryKey:["contractor-job-detail",a]}),Ae(!1)},onError:()=>M.error(s.contractorJobDetail.toasts.urgencyFailed)}),Lt=De({mutationFn:async()=>{const{error:r}=await _.from("jobs").update({visibility:"public"}).eq("id",a).eq("contractor_id",o.id);if(r)throw r},onSuccess:()=>{M.success(s.privateJobs.jobNowPublic),n.invalidateQueries({queryKey:["contractor-job-detail",a]}),n.invalidateQueries({queryKey:["contractor-jobs"]}),n.invalidateQueries({queryKey:["job-status-map"]})},onError:()=>M.error(s.pass2.couldNotUpdateVisibility)}),Gr=()=>{window.confirm(s.privateJobs.makePublicConfirm)&&Lt.mutate()},Tt=De({mutationFn:async({appId:r,workerId:i})=>{const{error:c}=await _.from("applications").update({pickup_confirmed:!0}).eq("id",r);if(c)throw c;const v=(t==null?void 0:t.pickup_time)||"the scheduled time",W=(t==null?void 0:t.pickup_location)||"the pickup location";await _.from("notifications").insert({user_id:i,type:"pickup_confirmed",role:"worker",title:"â
Pickup confirmed",body:`Your pickup is confirmed â ${v} at ${W} for "${t==null?void 0:t.title}"`,link:`/jobs/${a}`})},onSuccess:()=>{M.success(s.contractorJobDetail.toasts.pickupConfirmed),n.invalidateQueries({queryKey:["job-detail-applicants",a]})},onError:()=>M.error(s.contractorJobDetail.toasts.pickupConfirmFailed)}),Mt=De({mutationFn:async({appId:r,workerId:i})=>{const{error:c}=await _.from("applications").update({needs_pickup:!1,pickup_confirmed:!1}).eq("id",r);if(c)throw c;await _.from("notifications").insert({user_id:i,type:"pickup_update",role:"worker",title:"ð Pickup update",body:`Pickup is no longer available for "${t==null?void 0:t.title}" â please arrange your own transportation`,link:`/jobs/${a}`})},onSuccess:()=>{M.success(s.contractorJobDetail.toasts.workerNotified),n.invalidateQueries({queryKey:["job-detail-applicants",a]})},onError:()=>M.error(s.contractorJobDetail.toasts.pickupUpdateFailed)}),{data:$t=[]}=sa(o==null?void 0:o.id,100),Wt=p.useMemo(()=>new Map($t.map(r=>[r.userId,r.jobsTogether])),[$t]),qe=p.useMemo(()=>fe.map(r=>{var c,v,W,P;const i=St({jobSkills:(t==null?void 0:t.skills)??[],workerSkills:((c=r.worker)==null?void 0:c.skills)??[],reliabilityScore:(v=r.worker)==null?void 0:v.reliability_score,jobLat:(t==null?void 0:t.lat)??null,jobLng:(t==null?void 0:t.lng)??null,workerLat:((W=r.worker)==null?void 0:W.approx_lat)??null,workerLng:((P=r.worker)==null?void 0:P.approx_lng)??null,jobsTogether:Wt.get(r.worker_id)??0});return{...r,match:i.score,matchBand:i.band,matchLabel:i.label,distanceMi:i.distanceMi}}).sort((r,i)=>i.match-r.match),[fe,t,Wt]),Le=qe.filter(r=>r.status==="pending"),bt=qe.filter(r=>["accepted","completed","paid"].includes(r.status)),Ft=[...Le,...bt],Xe=Ft.length>0?Ft:qe,It=10,ft=A?Xe:Xe.slice(0,It),gt=l?qe.find(r=>r.worker_id===l):null,Et=gt&&!ft.find(r=>r.id===gt.id)?[gt,...ft]:ft,{data:jt}=ua(fe.map(r=>r.worker_id)),Bt=t!=null&&t.requires_license?[...Et].sort((r,i)=>{const c=Wr((r==null?void 0:r.credential_status)??null),v=Wr((i==null?void 0:i.credential_status)??null);return c!==v?c-v:(i.match??0)-(r.match??0)}):Et,Fe=!!t&&!Cs({status:t.status,slots:t.slots,filled_slots:t.filled_slots,open_shift_count:xt.open_shift_count,upcoming_shift_
6count:xt.upcoming_shift_count});p.useEffect(()=>{if(!a)return;const r=_.channel(`contractor-job-detail-${a}-${Math.random().toString(36).slice(2,10)}`).on("postgres_changes",{event:"*",schema:"public",table:"applications",filter:`job_id=eq.${a}`},()=>{n.invalidateQueries({queryKey:["job-detail-applicants",a]}),n.invalidateQueries({queryKey:["job-applicant-stats",a]}),n.invalidateQueries({queryKey:["contractor-job-detail",a]})}).on("postgres_changes",{event:"UPDATE",schema:"public",table:"jobs",filter:`id=eq.${a}`},()=>{n.invalidateQueries({queryKey:["contractor-job-detail",a]})}).subscribe();return()=>{_.removeChannel(r)}},[a,n]),p.useEffect(()=>{l&&be.current&&be.current.scrollIntoView({behavior:"smooth",block:"start"})},[l,fe.length]);const Ze=t?Math.max(0,(t.slots??1)-(t.filled_slots??0)):0,Rt=Le.filter(r=>r.id!==(Y==null?void 0:Y.id)).length>0,[ze,Te]=p.useState(null),Ot=p.useMemo(()=>ze?qe.find(r=>r.id===ze)??null:null,[ze,qe]);p.useEffect(()=>{if(!(!o||!t)&&!ze){if(l){const r=qe.find(i=>i.id===l||i.worker_id===l);r&&Te(r.id);return}w==="pending"&&Le.length>0&&Te(Le[0].id)}},[o,t,l,w,fe.length]);const Xr=Le.filter(r=>r.id!==ze).length,yt=()=>{let r=!1;b.has("applicant")&&(b.delete("applicant"),r=!0),b.has("review")&&(b.delete("review"),r=!0),r&&m(b,{replace:!0})};if(Ge)return e.jsx(Sa,{});if(Qr)return e.jsxs("div",{className:"max-w-3xl mx-auto px-4 pt-6",children:[e.jsx(Nt,{title:s.contractorJobDetail.pageTitle,description:"View and manage your job listing."}),e.jsx(ma,{onRetry:()=>void Ur()})]});if(!t)return e.jsxs("div",{className:"px-4 py-12 text-center",children:[e.jsx(Nt,{title:s.contractorJobDetail.pageTitle,description:"View and manage your job listing."}),e.jsx("p",{className:"text-muted-foreground",children:s.contractorJobDetail.notFound}),e.jsx(T,{variant:"ghost",onClick:()=>u("/contractor/jobs"),className:"mt-4",children:s.contractorJobDetail.backToMyJobs})]});const Zr=pt(t.created_at),es={hidden:{},visible:{transition:{staggerChildren:.07}}},X={hidden:{opacity:0,y:18},visible:{opacity:1,y:0,transition:{duration:.45,ease:[.22,1,.36,1]}}},Kt={active:"bg-success/15 text-success border-success/30",open:"bg-success/15 text-success border-success/30",draft:"bg-muted text-muted-foreground border-border",filled:"bg-primary/15 text-primary border-primary/30",closed:"bg-destructive/15 text-destructive border-destructive/30",reviewed:"bg-muted text-muted-foreground border-border"},ts=((Zt=Gs.find(r=>r.value===t.tools_policy))==null?void 0:Zt.label)||t.tools_policy,zt=(t.job_type??"day_labor")==="day_labor"&&["open","active","draft","filled"].includes(t.status)&&!t.deleted_at&&!t.converted_to_job_id,rs=((er=Xs.find(r=>r.value===t.preferred_contact_method))==null?void 0:er.label)||t.preferred_contact_method;return e.jsxs(K.div,{initial:{opacity:0}
6,animate:{opacity:1},className:"pb-6",children:[e.jsx(Nt,{title:`${t.title} â ${s.contractorJobDetail.jobDetails}`,description:"View and manage your job listing details."}),t.job_type==="sub_package"&&e.jsx(as,{job:t,role:"poster"}),e.jsxs(K.div,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},transition:{duration:.5,ease:[.22,1,.36,1]},className:"relative overflow-hidden bg-card/80 backdrop-blur-md border-b border-border/60 px-4 py-5",children:[e.jsx("div",{className:"pointer-events-none absolute -top-20 -right-20 w-52 h-52 rounded-full bg-primary/8 blur-3xl"}),e.jsx("div",{className:"pointer-events-none absolute -bottom-16 -left-16 w-40 h-40 rounded-full bg-primary/5 blur-2xl"}),e.jsxs("div",{className:"relative z-10",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx("button",{onClick:()=>u("/contractor/jobs"),className:"p-2 rounded-xl bg-secondary/60 backdrop-blur-sm border border-border/60 hover:bg-secondary transition-colors",children:e.jsx(_t,{className:"w-5 h-5 text-foreground"})}),e.jsx("span",{className:"text-sm text-muted-foreground font-medium",children:s.contractorJobDetail.jobDetails}),e.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[e.jsx(is,{job:{id:t.id,title:t.title,location:t.location??null,description:t.description??null,start_date:t.start_date??null,recurrence_end_date:t.recurrence_end_date??null,shift_start_time:t.shift_start_time??null,shift_end_time:t.shift_end_time??null},variant:"icon"}),e.jsx("button",{className:"p-2 rounded-xl bg-secondary/60 backdrop-blur-sm border border-border/60 hover:bg-secondary transition-colors",onClick:()=>D(!0),children:e.jsx(Pr,{className:"w-4 h-4 text-muted-foreground"})}),e.jsxs(Fr,{children:[e.jsx(Ir,{asChild:!0,children:e.jsx("button",{className:"p-2 rounded-xl bg-secondary/60 backdrop-blur-sm border border-border/60 hover:bg-secondary transition-colors","aria-label":s.contractorJobDetail.moreOptions,children:e.jsx(zr,{className:"w-4 h-4 text-muted-foreground"})})}),e.jsxs(Er,{align:"end",children:[e.jsxs(ye,{onClick:()=>{it("post.repost.opened",{from:"job_detail"}),ws({id:t.id,title:t.title,description:t.description,skills:t.skills??null,slots:t.slots??1,pay:t.pay??null,pay_type:t.pay_type??null,location:t.location??null,lat:t.lat??null,lng:t.lng??null,shift_start_time:t.shift_start_time??null,payment_methods:t.payment_methods??null})},children:[e.jsx(Rr,{className:"w-4 h-4 mr-2"})," ",s.postShortcutsMenu.repost]}),zt&&e.jsxs(ye,{onClick:()=>U(!0),children:[e.jsx(qr,{className:"w-4 h-4 mr-2"})," ",s.convertToSubPackage.menuItem]}),!["closed","reviewed"].includes(t.status)&&e.jsxs(ye,{onClick:()=>Q(!0),children:[e.jsx(ct,{className:"w-4 h-4 mr-2"})," ",s.contractorJobDetail.closeJob]})]})]})]})]}),t.needs_closeout&&!["closed","reviewed"].includes(t.status)&&e.jsxs("div",{className:"mb-4 rounded-xl border border-warning/40 bg-warning/10 p-3 flex items-start gap-3",children:[e.jsx(ct,{className:"w-5 h-5 text-warning shrink-0 mt-0.5"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-sm font-semibold text-foreground leading-tight",children:x("jobCloseout.detailBannerTitle")}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5 leading-snug",children:x("jobCloseout.detailBannerDesc")})]}),e.jsx(T,{onClick:()=>Q(!0),size:"sm",className:"shrink-0 rounded-lg bg-warning text-warning-foreground hover:bg-warning/90 font-semibold",children:x("jobCloseout.wrapUpShort")})]}),e.jsx("div",{className:"flex items-start justify-between gap-3",children:e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1.5 flex-wrap",children:[e.jsx("h1",{className:"font-display text-2xl sm:text-3xl text-foreground leading-tight",children:t.title}),e.jsx(ie,{className:`${Kt[t.status]||Kt.draft} text-micro uppercase shrink-0 border`,children:s.common[t.status]??t.status}),t.urgency!=="normal"&&e.jsxs(ie,{className:"bg-destructive/15 text-destructive border-destructive/30 text-micro uppercase shrink-0",children:[e.jsx(st,{className:"w-3 h-3 mr-0.5"}),t.urgency]}),(()=>{const r=t.boosted_until;return!!r&&new Date(r).getTime()>Date.now()?e.jsxs(ie,{className:"bg-primary text-primary-foreground border-primary text-micro uppercase shrink-0 shadow-sm",children:[e.jsx(st,{className:"w-3 h-3 mr-0.5"})," ",s.contractorJobDetail.boosted]}):null})()]}),e.jsxs("div",{className:"flex items-center gap-3 mt-1.5 text-xs text-muted-foreground",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(Me,{className:"w-3.5 h-3.5"})," ",s.contractorJobDetail.postedAgo.replace("{ago}",Zr)]}),t.location&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx($e,{className:"w-3.5 h-3.5"})," ",t.location]})]})]})}),e.jsxs("div",{className:"mt-4 flex flex-col-reverse sm:flex-row sm:items-end sm:justify-between gap-3 min-w-0",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2 sm:flex sm:flex-wrap min-w-0
6w-full sm:w-auto",children:[e.jsxs(T,{onClick:()=>t.job_type==="sub_package"?ce(!0):u(`/contractor/post/${t.id}`),size:"default",className:"gap-2 rounded-xl min-h-[48px] w-full sm:w-auto font-display tracking-wider bg-primary hover:bg-primary/90 text-primary-foreground shadow-[0_4px_16px_-4px_hsl(var(--primary)/0.4)]",children:[e.jsx(Lr,{className:"w-4 h-4"})," ",s.contractorJobDetail.editJob]}),e.jsxs(T,{onClick:()=>D(!0),variant:"outline",size:"default",className:"gap-2 rounded-xl min-h-[48px] w-full sm:w-auto border-border/60 bg-transparent",children:[e.jsx(Pr,{className:"w-4 h-4"})," ",s.contractorJobDetail.share]}),e.jsxs(T,{onClick:()=>E(!0),variant:"secondary",size:"default",className:"gap-2 rounded-xl min-h-[48px] w-full sm:w-auto",children:[e.jsx(Ct,{className:"w-4 h-4"})," ",s.pass2.previewAsWorker]}),Ie(t==null?void 0:t.visibility)&&e.jsxs(T,{onClick:()=>B(!0),size:"default",className:"gap-2 rounded-xl min-h-[48px] w-full sm:w-auto bg-primary text-primary-foreground hover:bg-primary/90 shadow-[0_4px_16px_-4px_hsl(var(--primary)/0.4)]",children:[e.jsx(ot,{className:"w-4 h-4"}),s.privateJobs.inviteWorkers]}),Ie(t==null?void 0:t.visibility)&&e.jsxs(T,{onClick:Gr,disabled:Lt.isPending,variant:"outline",size:"default",className:"gap-2 rounded-xl min-h-[48px] w-full sm:w-auto border-border/60 bg-transparent",children:[e.jsx(xa,{className:"w-4 h-4"}),s.privateJobs.makePublic]})]}),e.jsxs("div",{className:"text-left sm:text-right shrink-0 max-w-full",children:[e.jsxs("div",{className:"inline-block max-w-full bg-gradient-to-br from-primary to-primary/80 rounded-xl px-4 py-2 shadow-[0_4px_20px_-4px_hsl(var(--primary)/0.35)]",children:[e.jsxs("p",{className:"font-display text-2xl sm:text-4xl text-primary-foreground leading-none break-words",children:["$",t.pay,t.pay_range_max?`â$${t.pay_range_max}`:""]}),e.jsxs("p",{className:"text-micro text-primary-foreground/70 uppercase mt-0.5",children:["/",t.pay_type]})]}),t.pay_type==="hourly"&&Number(t.pay)>0&&Number(t.pay)<15&&e.jsxs("div",{className:"mt-2 sm:max-w-[220px] sm:ml-auto flex items-start gap-1.5 px-2.5 py-1.5 rounded-lg bg-warning/10 border border-warning/30 text-warning text-caption leading-snug text-left",children:[e.jsx(Ce,{className:"w-3 h-3 shrink-0 mt-0.5"}),e.jsx("span",{children:s.contractorJobDetail.lowPayWarning})]})]})]}),e.jsx("div",{className:"mt-3",children:e.jsxs(Dr,{open:_e,onOpenChange:Ae,children:[e.jsx(Cr,{asChild:!0,children:e.jsxs("button",{className:`inline-flex items-center gap-1.5 px-3 py-1.5 rounded-full text-xs font-medium border transition-colors ${t.urgency==="asap"?"bg-destructive/15 text-destructive border-destructive/30 hover:bg-destructive/20":t.urgency==="urgent"?"bg-primary/15 text-primary border-primary/30 hover:bg-primary/20":"bg-secondary/60 text-foreground border-border/60 hover:bg-secondary"}`,children:[t.urgency!=="normal"&&e.jsx(st,{className:"w-3 h-3"}),e.jsx("span",{className:"capitalize",children:t.urgency==="asap"?s.contractorJobDetail.urgencyAsap:t.urgency==="urgent"?s.contractorJobDetail.urgencyUrgent:s.contractorJobDetail.urgencyNormal}),e.jsx("span",{className:"text-muted-foreground",children:"·"}),e.jsx("span",{className:"text-muted-foreground",children:s.contractorJobDetail.change})]})}),e.jsx(Sr,{align:"start",className:"w-44 p-1",children:["normal","urgent","asap"].map(r=>e.jsxs("button",{onClick:()=>qt.mutate(r),disabled:qt.isPending,className:`w-full flex items-center gap-2 px-2.5 py-2 rounded-md text-sm text-left hover:bg-secondary transition-colors ${t.urgency===r?"bg-secondary/70 font-medium":""}`,children:[r!=="normal"&&e.jsx(st,{className:`w-3.5 h-3.5 ${r==="asap"?"text-destructive":"text-primary"}`}),e.jsx("span",{className:"capitalize",children:r==="asap"?s.contractorJobDetail.urgencyAsap:r==="urgent"?s.contractorJobDetail.urgencyUrgent:s.contractorJobDetail.urgencyNormal}),t.urgency===r&&e.jsx(ee,{className:"w-3.5 h-3.5 ml-auto text-primary"})]},r))})]})})]})]}),e.jsxs(K.div,{variants:es,initial:"hidden",animate:"visible",className:"px-4 py-5 space-y-5",children:[Ie(t==null?void 0:t.visibility)&&Yr===0&&e.jsxs(K.div,{variants:X,className:"rounded-card border border-destructive/40 bg-destructive/10 p-4 flex items-start gap-3",children:[e.jsx(Ce,{className:"w-5 h-5 text-destructive shrink-0 mt-0.5"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-title font-semibold text-foreground",children:s.pass2.zeroInv
6iteTitle}),e.jsx("p",{className:"text-small text-muted-foreground mt-0.5 leading-relaxed",children:s.pass2.zeroInviteBody}),e.jsxs(T,{onClick:()=>B(!0),size:"sm",className:"mt-3 gap-2 rounded-xl bg-primary text-primary-foreground hover:bg-primary/90",children:[e.jsx(ot,{className:"w-4 h-4"}),s.pass2.zeroInviteCta]})]})]}),(()=>{const r=[{ok:Number(t.pay)>=15,label:s.contractorJobDetail.checkPay,fix:s.contractorJobDetail.fixPay},{ok:!!t.description&&t.description.length>=50,label:s.contractorJobDetail.checkDesc,fix:s.contractorJobDetail.fixDesc},{ok:!!t.start_date,label:s.contractorJobDetail.checkStart,fix:s.contractorJobDetail.fixStart},{ok:(t.skills??[]).length>0,label:s.contractorJobDetail.checkSkills,fix:s.contractorJobDetail.fixSkills},{ok:!!t.location,label:s.contractorJobDetail.checkLocation,fix:s.contractorJobDetail.fixLocation}],i=r.filter(P=>P.ok).length,c=r.length,v=i===c?"strong":i>=c-1?"good":"needs",W={strong:{label:s.contractorJobDetail.healthStrong,dot:"bg-success",text:"text-success",bg:"bg-success/10 border-success/30"},good:{label:s.contractorJobDetail.healthGood,dot:"bg-warning",text:"text-warning",bg:"bg-warning/10 border-warning/30"},needs:{label:s.contractorJobDetail.healthNeeds,dot:"bg-destructive",text:"text-destructive",bg:"bg-destructive/10 border-destructive/30"}}[v];return e.jsx(K.div,{variants:X,children:e.jsxs(Dr,{children:[e.jsx(Cr,{asChild:!0,children:e.jsxs("button",{className:`w-full flex items-center gap-3 px-3.5 py-2.5 rounded-xl border ${W.bg} transition-colors hover:opacity-90`,children:[e.jsxs("span",{className:"relative flex items-center justify-center",children:[e.jsx("span",{className:`w-2.5 h-2.5 rounded-full ${W.dot}`}),v!=="strong"&&e.jsx("span",{className:`absolute w-2.5 h-2.5 rounded-full ${W.dot} animate-ping opacity-60`})]}),e.jsxs("div",{className:"flex-1 text-left",children:[e.jsxs("p",{className:`text-sm font-semibold ${W.text}`,children:[s.contractorJobDetail.jobHealth,": ",W.label]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s.contractorJobDetail.healthChecksPassing.replace("{passed}",String(i)).replace("{total}",String(c))})]}),e.jsx(nt,{className:"w-4 h-4 text-muted-foreground"})]})}
6),e.jsxs(Sr,{align:"start",className:"w-[320px] p-3",children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground mb-2",children:s.contractorJobDetail.checklist}),e.jsx("ul",{className:"space-y-1.5",children:r.map((P,me)=>e.jsxs("li",{className:"flex items-start gap-2 text-sm",children:[P.ok?e.jsx(ee,{className:"w-4 h-4 text-success shrink-0 mt-0.5"}):e.jsx(Se,{className:"w-4 h-4 text-destructive shrink-0 mt-0.5"}),e.jsx("span",{className:P.ok?"text-foreground":"text-muted-foreground",children:P.ok?P.label:P.fix})]},me))}),i<c&&e.jsxs(T,{onClick:()=>t.job_type==="sub_package"?ce(!0):u(`/contractor/post/${t.id}`),size:"sm",className:"w-full mt-3 rounded-lg",children:[e.jsx(Lr,{className:"w-3.5 h-3.5 mr-1.5"})," ",s.contractorJobDetail.editJobBtn]})]})]})})})(),(()=>{const r=Hs(t.recurrence_pattern,s.scheduleLabels),i=Vs(t.shift_start_time,t.shift_end_time,s.scheduleLabels),c=Ys(t.start_date,t.recurrence_end_date),v=r||i;return e.jsx(K.div,{variants:X,className:`grid gap-2.5 ${v?"grid-cols-2 sm:grid-cols-4":"grid-cols-3"}`,children:(()=>{const W=c||t.start_date||s.contractorJobDetail.tbd,P=!c&&!t.start_date;return[{icon:e.jsx(at,{className:"w-4 h-4 text-primary"}),value:W,label:t.recurrence_end_date?s.scheduleLabels.dates:s.contractorJobDetail.start,tbd:P},...i?[{icon:e.jsx(Me,{className:"w-4 h-4 text-primary"}),value:i,label:s.scheduleLabels.shift}]:[],...r?[{icon:e.jsx(qr,{className:"w-4 h-4 text-primary"}),value:r,label:s.scheduleLabels.schedule}]:[],...v?[]:[{icon:e.jsx(Me,{className:`w-4 h-4 ${le.duration||t.duration,"text-primary"}`}),value:le.duration||t.duration||s.contractorJobDetail.notSpecified,label:s.contractorJobDetail.duration,tbd:!(le.duration||t.duration)}],{icon:e.jsx(Ve,{className:"w-4 h-4 text-primary"}),value:`${t.filled_slots}/${t.slots}`,label:s.contractorJobDetail.filled}].map((I,ge)=>{const pe=I.tbd,et=e.jsxs(e.Fragment,{children:[e.jsx("div",{className:`mx-auto mb-1.5 w-8 h-8 rounded-lg flex items-center justify-center ${pe?"bg-primary/15":"bg-primary/10"}`,children:I.icon}),e.jsx("p",{className:`text-sm font-medium ${pe?"text-primary":"text-foreground"}`,children:I.value}),e.jsx("p",{className:`text-micro uppercase mt-0.5 ${pe?"text-primary/80":"text-muted-foreground"}`,children:pe?I.label===s.contractorJobDetail.duration?s.contractorJobDetail.addArrow:s.contractorJobDetail.tapToSetStart:I.label})]});return pe?e.jsx("button",{onClick:()=>u(`/contractor/post/${t.id}`),title:s.contractorJobDetail.workersNeedToApply,className:"bg-primary/5 backdrop-blur-sm rounded-xl p-3 border border-primary/30 text-center shadow-sm hover:shadow-md hover:bg-primary/10 transition-all",children:et},ge):e.jsx("div",{className:"bg-card/60 backdrop-blur-sm rounded-xl p-3 border border-border/60 text-center shadow-sm hover:shadow-md transition-shadow",children:et},ge)})})()})})(),a&&bt.length>0&&e.jsx(K.div,{variants:X,children:e.jsx(Pa,{jobId:a,crew:bt.map(r=>{var i;return{worker_id:r.worker_id,name:((i=r.profile)==null?void 0:i.full_name)??s.common.worker}})})}),ke.length>0&&e.jsxs(K.button,{variants:X,onClick:()=>g(ke[0].id),className:"w-full flex items-center gap-3 bg-primary/10 border border-primary/25 rounded-card p-3 text-left",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:s.refill.bannerNeedsRefill(ke.length)}),e.jsx("p",{className:"text-caption text-muted-foreground truncate",children:new Date(`${ke[0].shift_date}T12:00:00`).toLocaleDateString(L,{weekday:"short",month:"short",day:"numeric"})})]}),e.jsx("span",{className:"shrink-0 px-3 py-1 rounded-lg bg-primary text-primary-foreground text-label font-medium",children:s.refill.bannerCta})]}),e.jsxs(K.div,{ref:be,variants:X,className:"bg-card/60 backdrop-blur-sm rounded-card border border-border/60 p-4 shadow-sm scroll-mt-20",children:[e.jsx("div",{className:"flex items-center justify-between mb-3",children:e.jsxs("h3",{className:"font-display text-lg text-foreground flex items-center gap-2 flex-wrap",children:[s.contractorJobDetail.applicants,se&&se.total>0&&e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[se.pending>0&&e.jsxs(ie,{className:"bg-primary/15 text-primary border-primary/30 font-semibold",children:[se.pending," ",s.contractorJobDetail.pending]}),se.accepted>0&&e.jsxs(ie,{className:"bg-success/15 text-success border-success/30 font-semibold",children:[se.accepted," ",s.contractorJobDetail.accepted]}),se.pending===0&&se.accepted===0&&e.jsx(ie,{variant:"outline",className:"font-semibold",children:se.total})]})]})}),fe.length===0?e.jsxs("div",{className:"text-center py-6 px-4",children:[e.jsx("div",{className:"mx-auto w-12 h-12 rounded-full bg-primary/10 flex items-center justify-center mb-3",children:e.jsx(Ve,{className:"w-6 h-6 text-primary"})}),e.jsx("p",{className:"text-sm font-medium text-foreground",children:s.contractorJobDetail.noApplicantsYet}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:(At===1?s.contractorJobDetail.jobLiveVisible:s.contractorJobDetail.jobLiveVisiblePlural).replace("{count}",vs(At,L))}),e.jsxs(T,{onClick:()=>{const r=t.skills??[],i=new URLSearchParams({job:t.id});r.length>0&&i.set("skills",r.join(","));const c=`?${i.toString()}`;u(`/contractor/workers${c}`)},size:"sm",className:"mt-4 gap-2 rounded-xl font-display tracking-wider",children:[e.jsx(ot,{className:"w-4 h-4"})," ",s.contractorJobDetail.inviteWorkers]})]}):e.jsxs("div",{className:"space-y-1",children:[(t==null?void 0:t.requires_license)&&Bt.length>0&&e.jsx("p",{className:"text-label text-[#888888] dark:text-[#B8B8B8] px-1",children:s.contractorJobDetail.sortedByLicense}),Bt.map(r=>{var rr,sr,ar,ir,or,nr,lr,cr,dr,mr,pr,ur,xr,hr;
6const i=((rr=r.profile)==null?void 0:rr.full_name)||s.contractorJobDetail.worker,c=i.split(" ").map(H=>H[0]).slice(0,2).join("").toUpperCase()||"W",v=((ar=(sr=r.worker)==null?void 0:sr.skills)==null?void 0:ar[0])??null,W=(jt==null?void 0:jt.get(r.worker_id))??null,P=r.match>=80?"bg-success/10 text-success border-success/30":r.match>=60?"bg-primary/10 text-primary border-primary/30":"bg-muted/50 text-muted-foreground border-border/60",me=r.status==="pending",I=z[r.id]??l===r.worker_id,ge=$(r.status),pe=qs(r.status,r.created_at),et=ge&&e.jsxs(ie,{variant:"outline",className:`text-micro uppercase ${ge.className}`,children:[ge.label,pe!=null?` · ${x("applicationStatus.waitingDays",{days:pe})}`:""]}),tt=(()=>{const H=!!(t!=null&&t.requires_license),br=Array.isArray(r==null?void 0:r.credential_status)?r.credential_status:[];if(!H||br.length===0)return null;const Qe=br[0];return Qe!=null&&Qe.has_credential?Qe.expired?{Icon:Ce,label:s.contractorJobDetail.licenseExpired,className:"text-[#8a6500] bg-[#FFF8E6] border-[#F5D78A]"}:Qe.verified?{Icon:ct,label:s.contractorJobDetail.licenseVerified,className:"text-[#1A7C3A] bg-[#E8F5EC] border-[#A8D5B5]"}:{Icon:Me,label:s.contractorJobDetail.licenseOnFileUnverified,className:"text-foreground bg-muted/50 border-border"}:{Icon:Ce,label:s.contractorJobDetail.noLicenseOnFile,className:"text-[#8a6500] bg-[#FFF8E6] border-[#F5D78A]"}})();return e.jsxs("div",{className:`rounded-lg bg-background/40 border transition-colors ${l===r.worker_id?"border-primary/60 ring-1 ring-primary/30 bg-primary/5":"border-border/60 hover:border-primary/30"}`,children:[e.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5",children:[e.jsx("button",{onClick:()=>u(`/profile/${r.worker_id}`),className:"shrink-0","aria-label":s.contractorJobDetail.viewWorkerProfile.replace("{name}",i),children:(ir=r.profile)!=null&&ir.avatar_url?e.jsx("img",{src:Re(r.profile.avatar_url,64),alt:i,className:"w-8 h-8 rounded-full object-cover border border-border/60",loading:"lazy",decoding:"async"}):e.jsx("div",{className:"w-8 h-8 rounded-full bg-primary/15 text-primary flex items-center justify-center font-semibold text-caption border border-border/60",children:c})}),e.jsxs("button",{onClick:()=>k(H=>({...H,[r.id]:!I})),"aria-expanded":I,className:"flex-1 min-w-0 text-left",children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("span",{className:"text-small font-semibold text-foreground truncate",children:i}),e.jsx("span",{className:`shrink-0 text-micro font-bold uppercase px-1.5 py-px rounded border ${P}`,children:r.matchLabel}),et]}),e.jsxs("div",{className:"flex items-center gap-1 text-caption text-muted-foreground truncate",children:[v&&e.jsx("span",{className:"text-primary font-medium truncate max-w-[90px]",children:v}),v&&e.jsx("span",{children:"·"}),e.jsx(pa,{stat:W,compact:!0}),r.distanceMi!=null&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"·"}),e.jsxs("span",{className:"inline-flex items-center gap-0.5 shrink-0",children:[e.jsx($e,{className:"w-2.5 h-2.5"}),Math.round(r.distanceMi),"mi"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-0.5 shrink-0",children:[Pt[r.worker_id]&&e.jsx("button",{onClick:()=>S({workerId:r.worker_id,jobId:t.id}),disabled:F(r.worker_id),title:s.calling.callWorker,"aria-label":s.calling.callWorker,className:"p-1.5 rounded-md hover:bg-primary/10 text-primary disabled:opacity-50",children:e.jsx(gr,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>u(`/contractor/messages?to=${r.worker_id}&job=${t.id}`),title:s.contractorJobDetail.message,"aria-label":s.contractorJobDetail.message,className:"p-1.5 rounded-md hover:bg-primary/10 text-muted-foreground hover:text-primary",children:e.jsx(lt,{className:"w-4 h-4"})}),me&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>{var H;if(Fe){M.error(s.contractorJobDetail.toasts.allSpotsFilledLong);return}ne(r),re("confirm"),G(((H=r.profile)==null?void 0:H.full_name)||s.contractorJobDetail.worker)},disabled:ae.isPending||Fe,title:s.contractorJobDetail.accept,"aria-label":s.contractorJobDetail.accept,className:"p-1.5 rounded-md text-success hover:bg-success/10 disabled:opacity-40",children:e.jsx(ee,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>ae.mutate({appId:r.id,status:"rejected",workerId:r.worker_id}),disabled:ae.isPending,title:s.contractorJobDetail.decline,"aria-label":s.contractorJobDetail.decline,className:"p-1.5 rounded-md text-destructive hover:bg-destructive/10 disabled:opacity-40",children:e.jsx(Se,{className:"w-4 h-4"})})]}),e.jsx("button",{onClick:()=>k(H=>({...H,[r.id]:!I})),"aria-label":i,"aria-expanded":I,className:"p-1.5 rounded-md hover:bg-secondary text-muted-foreground",children:e.jsx(ha,{className:`w-4 h-4 transition-transform ${I?"rotate-180":""}`})})]})]}),I&&e.jsxs("div",{className:"px-2.5 pb-2.5 pt-1 border-t border-border/60",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-caption text-muted-foreground flex-wrap mb-1",children:[e.jsx(ds,{userId:r.worker_id}),r.created_at&&e.jsxs("span",{className:"inline-flex items-center gap-0.5",children:[e.jsx(Me,{className:"w-3 h-3"})," ",Ra(r.created_at)]})]}),ke.length>0&&e.jsxs("div",{className:"flex items-center gap-1 flex-wrap mb-1",children:[e.jsx("span",{className:"text-micro uppercase tracking-wide text-muted-foreground",children:s.refill.openDaysLabel}),ke.slice(0,4).map(H=>e.jsxs("span",{className:"px-1.5 py-px rounded-full bg-warning/10 border border-warning/30 text-warning text-micro font-medium",children:[new Date(`${H.shift_date}T12:00:00`).toLocaleDateString(L,{month:"short",day:"numeric"})," · ",Math.max(0,(H.slots??0)-(H.filled_slots??0))]},`open-${r.id}-${H.id}`)),ke.length>4&&e.jsxs("span",{className:"text-micro text-muted-foreground",children:["+",ke.length-4]})]}),tt&&e.jsx("div",{className:"mt-1.5",children:e.jsxs("span",{className:`inline-flex items-center gap-1 text-caption font-medium px-2 py-0.5 rounded-full border ${tt.className}`,children:[e.jsx(tt.Icon,{className:"w-3 h-3"}),tt.label]})}),(((or=r.worker)==null?void 0:or.years_experience)||((nr=r.worker)==null?void 0:nr.has_own_tools)==="yes"||((lr=r.worker)==null?void 0:lr.has_transportation)===!0||((cr=r.worker)==null?void 0:cr.travel_radius_miles))&&e.jsxs("div",{className:"flex flex-wrap gap-1 mt-1 mb-1",children:[((dr=r.worker)==null?void 0:dr.years_experience)&&e.jsxs("span",{className:"px-2 py-0.5 rounded-full bg-muted border border-border text-caption text-muted-foreground",children:[r.worker.years_experience," ",s.pass2.yrsExp]}),((mr=r.worker)==null?void 0:mr.has_own_tools)==="yes"&&e.jsxs("span",{className:"px-2 py-0.5 rounded-full bg-muted border border-border text-caption text-muted-foreground",children:["ð§ ",s.workPreferences.ownToolsShort]}),((pr=r.worker)==null?void 0:pr.has_transportation)===!0&&e.jsxs("span",{className:"px-2 py-0.5 rounded-full bg-muted border border-border text-caption text-muted-foreground",children:["ð ",s.workPreferences.hasTransport]}),((ur=r.worker)==null?void 0:ur.travel_radius_miles)&&e.jsxs("span",{className:"px-2 py-0.5 rounded-full bg-muted border border-border text-caption text-muted-foreground",children:["ð ",s.workPreferences.upTo," ",r.worker.travel_radius_miles," ",s.workPreferences.milesAway]})]}),Array.isArray(r.self_reported_skills)&&r.self_reported_skills.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1 mt-1 mb-1",children:r.self_reported_skills.map(H=>e.jsxs("span",{className:"px-2 py-0.5 rounded-full text-caption font-medium border border-warning/40 text-warning bg-warning/10",title:s.contractorJobDetail.selfReportedTooltip,children:["â ",H," ",s.contractorJobDetail.selfReportedSuffix]},`sr-${r.id}-${H}`))}),me&&e.jsxs("div",{className:"flex gap-2 mt-2.5",children:[e.jsxs(T,{size:"sm",onClick:()=>{var H;if(Fe){M.error(s.contractorJobDetail.toasts.allSpotsFilledLong);return}ne(r),re("confirm"),G(((H=r.profile)==null?void 0:H.full_name)||s.c
6ontractorJobDetail.worker)},disabled:ae.isPending||Fe,title:Fe?s.contractorJobDetail.allSpotsFilled:void 0,className:"h-8 px-3 gap-1 rounded-lg bg-success hover:bg-success/90 text-success-foreground disabled:opacity-50",children:[e.jsx(ee,{className:"w-3.5 h-3.5"})," ",s.contractorJobDetail.accept]}),e.jsxs(T,{size:"sm",variant:"outline",onClick:()=>ae.mutate({appId:r.id,status:"rejected",workerId:r.worker_id}),disabled:ae.isPending,className:"h-8 px-3 gap-1 rounded-lg border-destructive/40 text-destructive hover:bg-destructive/10",children:[e.jsx(Se,{className:"w-3.5 h-3.5"})," ",s.contractorJobDetail.decline]})]}),["accepted","completed","paid"].includes(r.status)&&e.jsxs("div",{className:"flex flex-wrap gap-2 mt-2.5",children:[e.jsxs(T,{size:"sm",onClick:()=>u(`/contractor/messages?to=${r.worker_id}&job=${t.id}`),className:"h-8 px-3 gap-1.5 rounded-lg",children:[e.jsx(lt,{className:"w-3.5 h-3.5"})," ",s.contractorJobDetail.message]}),Pt[r.worker_id]&&e.jsxs(T,{size:"sm",variant:"outline",onClick:()=>S({workerId:r.worker_id,jobId:t.id}),disabled:F(r.worker_id),title:s.calling.privacyNote,className:"h-8 px-3 gap-1.5 rounded-lg disabled:opacity-50",children:[e.jsx(gr,{className:"w-3.5 h-3.5 text-primary"}),F(r.worker_id)?s.calling.calling:s.calling.callWorker]}),e.jsx(os,{targetUserId:r.worker_id,jobTitle:t.title,jobId:t.id,jobLocation:t.location??null,recipientName:((xr=r.profile)==null?void 0:xr.full_name)??null,viewerRole:"contractor",size:"sm"}),e.jsx("div",{className:"ml-auto",children:e.jsx(Ea,{applicationId:r.id,workerId:r.worker_id,workerName:((hr=r.profile)==null?void 0:hr.full_name)||s.contractorJobDetail.worker,jobId:t.id,jobTitle:t.title,status:r.status})})]})]})]},r.id)}),Xe.length>It&&e.jsxs("button",{onClick:()=>O(r=>!r),className:"w-full mt-2 flex items-center justify-center gap-1.5 py-2 text-sm font-medium text-primary hover:bg-primary/5 rounded-lg transition-colors",children:[A?s.applicationOutcome.showLess:s.applicationOutcome.showAllApplicants.replace("{count}",String(Xe.length)),e.jsx(nt,{className:"w-3.5 h-3.5"})]})]})]}),Ie(t==null?void 0:t.visibility)&&e.jsxs(K.div,{variants:X,className:"bg-card/60 backdrop-blur-sm rounded-card border border-border/60 p-4 shadow-sm",children:[e.jsxs("h3",{className:"text-[16px] font-semibold text-foreground mb-3 flex items-center gap-2",children:[e.jsx(Or,{className:"w-4 h-4 text-primary"}),s.privateJobs.invitations]}),e.jsx(Wa,{jobId:t.id})]}),(()=>{const r=Hr,i=(t==null?void 0:t.notified_worker_count)??null,c=(se==null?void 0:se.total)??0,v=Vr;let W="";return r>0&&r>=20&&c>0&&c/r<.05?W=s.contractorJobDetail.insightLowApply:c>=5?W=s.contractorJobDetail.insightStrong:r<10?W=s.contractorJobDetail.insightLowVisibility:c===0?W=s.contractorJobDetail.insightLowApply:W=s.contractorJobDetail.insightTraction,e.jsxs(K.div,{variants:X,className:"bg-card/60 backdrop-blur-sm rounded-xl p-4 border border-border/60",children:[e.jsx("h3",{className:"font-display text-lg text-foreground mb-3",children:s.contractorJobDetail.jobPerformance}),e.jsx("div",{className:i!==null?"grid grid-cols-4 gap-2":"grid grid-cols-3 gap-2",children:[...i!==null?[{emoji:"ð£",label:s.contractorJobDetail.sentToStat,value:i}]:[],{emoji:"ð",label:s.contractorJobDetail.views,value:r},{emoji:"ð",label:s.contractorJobDetail.applications,value:c},{emoji:"ð¬",label:s.contractorJobDetail.messagesLabel,value:v}].map(P=>e.jsxs("div",{className:"rounded-lg bg-background/40 border border-border/60 px-2 py-3 text-center",children:[e.jsx("div",{className:"text-lg leading-none",children:P.emoji}),e.jsx("div",{className:"mt-1.5 text-xl font-display font-semibold text-foreground tabular-nums",children:P.value}),e.jsx("div",{className:"text-caption text-muted-foreground uppercase tracking-wide mt-0.5",children:P.label})]},P.label))}),e.jsx("p",{className:"mt-3 text-xs text-muted-foreground leading-relaxed",children:W})]})})(),e.jsxs(K.div,{variants:X,className:"bg-card/60 backdrop-blur-sm rounded-xl p-4 border border-border/60",children:[e.jsx("h3",{className:"font-display text-lg text-foreground mb-2",children:s.contractorJobDetail.description}),t.description&&e.jsx("p",{className:"text-sm text-muted-foreground leading-relaxed whitespace-pre-wrap",children:t.description}),(!t.description||t.description.length<50)&&e.jsxs("div",{className:`flex items-start gap-2 ${t.description?"mt-3":""} px-3 py-2.5 rounded-lg bg-warning/10 border border-warning/30`,children:[e.jsx(ba,{className:"w-4 h-4 text-warning shrink-0 mt-0.5"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-xs text-warning leading-snug",children:s.contractorJobDetail.descTip}),e.jsxs("button",{onClick:()=>u(`/contractor/post/${t.id}`),className:"mt-1 text-xs font-semibold text-primary hover:underline inline-flex items-center gap-0.5",children:[s.contractorJobDetail.editDescription," ",e.jsx(nt,{className:"w-3 h-3"})]})]})]})]}),(()=>{const r=[];return t.trade_type&&r.push({icon:e.jsx(fa,{className:"w-4 h-4 text-primary"}),label:s.contractorJobDetail.trade,value:le.tradeType||t.trade_type}),t.job_category&&r.push({icon:e.jsx(ga,{className:"w-4 h-4 text-primary"}),label:s.contractorJobDetail.category,value:le.category||t.job_category}),t.schedule_type&&r.push({icon:e.jsx(at,{className:"w-4 h-4 text-primary"}),label:s.contractorJobDetail.scheduleType,value:t.schedule_type}),t.worker_type&&r.push({icon:e.jsx(Ve,{className:"w-4 h-4 text-primary"}),label:s.contractorJobDetail.workerType,value:(le.workerType||t.worker_type).replace(/_/g," ")}),t.payment_schedule&&r.push({icon:e.jsx(mt,{className:"w-4 h-4 text-primary"}),label:s.contractorJobDetail.payment,value:(le.paymentSchedule||t.payment_schedule).replace(/_/g," ")}),t.tools_policy&&t.tools_policy!=="not_specified"&&r.push({icon:e.jsx(ja,{className:"w-4 h-4 text-primary"}),label:s.contractorJobDetail.tools,value:ts||t.tools_policy}),t.years_experience_needed&&t.years_experience_needed>0&&r.push({icon:e.jsx(ya,{className:"w-4 h-4 text-primary"}),label:s.contractorJobDetail.experience,value:s.contractorJobDetail.yearsExperience.replace("{years}",String(t.years_experience_needed))}),t.insurance_required&&r.push({icon:e.jsx(jr,{className:"w-4 h-4 text-primary"}),label:s.contractorJobDetail.insurance,value:s.contractorJobDetail.required}),t.visibility&&r.push({icon:t.visibility==="public"?e.jsx(Ct,{className:"w-4 h-4 text-primary"}):e.jsx(va,{className:"w-4 h-4 text-primary"}),label:s.contractorJobDetail.visibility,value:t.visibility==="public"?s.contractorJobDetail.visibilityPublic:s.contractorJobDetail.visibilityPrivate}),t.preferred_contact_method&&r.push({icon:e.jsx(lt,{className:"w-4 h-4 text-primary"}),label:s.contractorJobDetail.contact,value:rs||t.preferred_contact_method}),t.application_deadline&&r.push({icon:e.jsx(at,{className:"w-4 h-4 text-primary"}),label:s.contractorJobDetail.deadline,value:Ue(He(t.application_deadline),"MMM d, yyyy")}),r.length>0?e.jsx(K.div,{variants:X,className:"grid grid-cols-2 gap-2",children:r.map((i,c)=>e.jsxs("div",{className:"flex items-center gap-2.5 p-3 rounded-xl bg-card/60 backdrop-blur-sm border border-border/60 hover:border-primary/20 transition-colors",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-primary/10 flex items-center justify-center shrink-0",children:i.icon}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-micro text-muted-foreground uppercase",children:i.label}),e.jsx("p",{className:"text-sm font-medium text-foreground capitalize truncate",children:i.value})]})]},c))}):null})(),(t.skills??[]).length>0&&e.jsxs(K.div,{variants:X,children:[e.jsx("h3",{className:"font-display text-lg text-foreground mb-2",children:s.contractorJobDetail.requiredSkills}),e.jsx("div",{className:"flex gap-2 flex-wrap",children:(t.skills??[]).map((r,i)=>e.jsx(ie,{variant:"secondary",className:"py-1.5 px-3 text-sm bg-secondary/70 backdrop-blur-sm rounded-full border border-border/60",children:le.
6skills&&le.skills[i]||r},r))})]}),(t.required_certifications??[]).length>0&&e.jsxs(K.div,{variants:X,children:[e.jsxs("h3",{className:"font-display text-lg text-foreground mb-2 flex items-center gap-2",children:[e.jsx(jr,{className:"w-5 h-5 text-primary"})," ",s.contractorJobDetail.requiredCertifications]}),e.jsx("div",{className:"flex gap-2 flex-wrap",children:(t.required_certifications??[]).map((r,i)=>e.jsx(ie,{variant:"outline",className:"py-1.5 px-3 text-sm border-primary/30 text-primary bg-primary/5 backdrop-blur-sm rounded-full",children:le.certifications&&le.certifications[i]||r},r))})]}),t.special_instructions&&e.jsxs(K.div,{variants:X,className:"bg-warning/5 backdrop-blur-sm border border-warning/20 rounded-xl p-4",children:[e.jsxs("h3",{className:"font-display text-lg text-foreground mb-2 flex items-center gap-2",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-warning/15 flex items-center justify-center",children:e.jsx(Ce,{className:"w-4 h-4 text-warning"})}),s.contractorJobDetail.specialInstructions]}),e.jsx("p",{className:"text-sm text-muted-foreground leading-relaxed",children:t.special_instructions})]}),(t.photos??[]).length>0&&e.jsxs(K.div,{variants:X,children:[e.jsxs("h3",{className:"font-display text-lg text-foreground mb-2 flex items-center gap-2",children:[e.jsx(ns,{className:"w-5 h-5 text-primary"})," ",s.contractorJobDetail.jobSitePhotos]}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-2",children:(t.photos??[]).map((r,i)=>e.jsxs("button",{onClick:()=>h(i),className:"group relative aspect-square rounded-xl overflow-hidden border border-border/60 bg-secondary cursor-zoom-in shadow-sm hover:shadow-md transition-all",children:[e.jsx("img",{src:Re(r,400),alt:`Job photo ${i+1}`,className:"w-full h-full object-cover transition-transform duration-300 group-hover:scale-105",loading:"lazy"}),e.jsx("div",{className:"absolute inset-0 bg-gradient-to-t from-black/30 to-transparent opacity-0 group-hover:opacity-100 transition-opacity"})]},i))})]}),(t.attachments??[]).length>0&&e.jsxs(K.div,{variants:X,children:[e.jsxs("h3",{className:"font-display text-lg text-foreground mb-2 flex items-center gap-2",children:[e.jsx(wa,{className:"w-5 h-5 text-primary"})," ",s.contractorJobDetail.attachments]}),e.jsx("div",{className:"space-y-2",children:(t.attachments??[]).map((r,i)=>{const c=decodeURIComponent(r.split("/").pop()||`Attachment ${i+1}`).replace(/^[^/]*\//,"");return e.jsxs("a",{href:r,target:"_blank",rel:"noopener noreferrer",onClick:v=>{v.preventDefault(),vt(r)},className:"flex items-center gap-3 p-3 rounded-xl border border-border/60 bg-card/60 backdrop-blur-sm hover:border-primary/30 hover:shadow-sm transition-all group",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg bg-primary/10 flex items-center justify-center shrink-0",children:e.jsx(Na,{className:"w-4 h-4 text-primary"})}),e.jsx("span",{className:"text-sm text-foreground truncate flex-1",children:c}),e.jsx(_a,{className:"w-4 h-4 text-muted-foreground group-hover:text-primary transition-colors shrink-0"})]},i)})})]}),t.pickup_offered&&(()=>{const r=fe.filter(i=>i.status==="accepted"&&i.needs_pickup);return e.jsxs(K.div,{variants:X,className:"bg-card/60 backdrop-blur-sm border border-border/60 rounded-xl p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h3",{className:"font-display text-lg text-foreground flex items-center gap-2",children:[e.jsx(ka,{className:"w-5 h-5 text-primary"})," ",s.contractorJobDetail.pickupCoordination]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:(r.length===1?s.contractorJobDetail.workersNeedPickup:s.contractorJobDetail.workersNeedPickupPlural).replace("{count}",String(r.length))})]}),t.pickup_location&&e.jsxs("div",{className:"text-xs text-muted-foreground flex items-start gap-1.5",children:[e.jsx($e,{className:"w-3.5 h-3.5 mt-0.5 text-primary/70 shrink-0"}),e.jsxs("span",{children:[t.pickup_location,t.pickup_time?` · ${t.pickup_time}`:""]})]}),r.length===0?e.jsx("p",{className:"text-sm text-muted-foreground italic",children:s.contractorJobDetail.noPickupRequests}):e.jsx("div",{className:"space-y-2",children:r.map(i=>{var P,me,I,ge;
6const c=((P=i.profile)==null?void 0:P.full_name)||s.contractorJobDetail.worker,v=c.split(" ").map(pe=>pe[0]).slice(0,2).join("").toUpperCase()||"W",W=((I=(me=i.worker)==null?void 0:me.skills)==null?void 0:I[0])??null;return e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-xl bg-background/40 border border-border/60",children:[(ge=i.profile)!=null&&ge.avatar_url?e.jsx("img",{src:Re(i.profile.avatar_url,96),alt:c,className:"w-10 h-10 rounded-full object-cover border border-border/60",loading:"lazy"}):e.jsx("div",{className:"w-10 h-10 rounded-full bg-primary/15 text-primary flex items-center justify-center font-semibold text-sm border border-border/60",children:v}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-semibold text-foreground truncate",children:c}),W&&e.jsx("p",{className:"text-xs text-primary truncate",children:W})]}),i.pickup_confirmed?e.jsxs(ie,{variant:"outline",className:"border-success/40 text-success bg-success/10 text-micro uppercase shrink-0",children:[e.jsx(ee,{className:"w-3 h-3 mr-0.5"})," ",s.contractorJobDetail.confirmedBadge]}):e.jsxs("div",{className:"flex gap-2 shrink-0",children:[e.jsxs(T,{size:"sm",onClick:()=>Tt.mutate({appId:i.id,workerId:i.worker_id}),disabled:Tt.isPending,className:"h-8 px-3 gap-1 rounded-lg bg-success hover:bg-success/90 text-success-foreground",children:[e.jsx(ee,{className:"w-3.5 h-3.5"})," ",s.contractorJobDetail.confirmBtn]}),e.jsxs(T,{size:"sm",variant:"outline",onClick:()=>Mt.mutate({appId:i.id,workerId:i.worker_id}),disabled:Mt.isPending,className:"h-8 px-3 gap-1 rounded-lg border-destructive/40 text-destructive hover:bg-destructive/10",children:[e.jsx(Se,{className:"w-3.5 h-3.5"})," ",s.contractorJobDetail.cantBtn]})]})]},i.id)})})]})})(),t.ride_reimbursement_offered&&e.jsx(Ba,{jobId:a,jobTitle:t.title,maxCents:Number(t.ride_reimbursement_amount??0),acceptedWorkers:fe.filter(r=>["accepted","completed","paid"].includes(r.status)).map(r=>{var i;return{workerId:r.worker_id,name:((i=r.profile)==null?void 0:i.full_name)||s.contractorJobDetail.worker}})}),t.location&&e.jsxs(K.div,{variants:X,className:"bg-card/60 backdrop-blur-sm border border-border/60 rounded-xl p-4 space-y-3",children:[e.jsxs("h3",{className:"font-display text-lg text-foreground flex items-center gap-2",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-primary/10 flex items-center justify-center",children:e.jsx(Da,{className:"w-4 h-4 text-primary"})}),s.contractorJobDetail.jobLocation]}),e.jsx("div",{className:"flex items-center text-sm text-muted-foreground",children:e.jsxs("p",{className:"flex items-center gap-1.5",children:[e.jsx($e,{className:"w-4 h-4 text-primary/70"}),t.location]})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>void vt(`https://www.google.com/maps/dir/?api=1&destination=${encodeURIComponent(t.location)}`),className:"flex-1 flex items-center justify-center gap-2 py-2.5 rounded-xl bg-primary/10 border border-primary/20 text-primary text-sm font-medium hover:bg-primary/20 transition-colors",children:[e.jsxs("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"none",children:[e.jsx("path",{d:"M12 2C8.13 2 5 5.13 5 9c0 5.25 7 13 7 13s7-7.75 7-13c0-3.87-3.13-7-7-7z",fill:"#EA4335"}),e.jsx("path",{d:"M12 2C8.13 2 5 5.13 5 9c0 2.61 1.43 4.88 3.5 6.73L12 12l3.5 3.73C17.57 13.88 19 11.61 19 9c0-3.87-3.13-7-7-7z",fill:"#4285F4"}),e.jsx("path",{d:"M8.5 15.73C9.91 17.24 11.41 19.04 12 22c.59-2.96 2.09-4.76 3.5-6.27L12 12 8.5 15.73z",fill:"#FBBC04"}),e.jsx("path",{d:"M5 9c0 2.61 1.43 4.88 3.5 6.73L12 12V2C8.13 2 5 5.13 5 9z",fill:"#34A853"}),e.jsx("circle",{cx:"12",cy:"9",r:"2.5",fill:"white"})]}),s.contractorJobDetail.googleMaps," ",e.jsx(Tr,{className:"w-3 h-3 opacity-60"})]}),e.jsxs("button",{type:"button",onClick:()=>void vt(`https://maps.apple.com/?daddr=${encodeURIComponent(t.location)}`),className:"flex-1 flex items-center justify-center gap-2 py-2.5 rounded-xl bg-secondary/80 border border-border/60 text-secondary-foreground text-sm font-medium hover:border-primary/30 transition-colors",children:[e.jsx("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",fill:"
6currentColor",children:e.jsx("path",{d:"M18.71 19.5c-.83 1.24-1.71 2.45-3.05 2.47-1.34.03-1.77-.79-3.29-.79-1.53 0-2 .77-3.27.82-1.31.05-2.3-1.32-3.14-2.53C4.25 17 2.94 12.45 4.7 9.39c.87-1.52 2.43-2.48 4.12-2.51 1.28-.02 2.5.87 3.29.87.78 0 2.26-1.07 3.8-.91.65.03 2.47.26 3.64 1.98-.09.06-2.17 1.28-2.15 3.81.03 3.02 2.65 4.03 2.68 4.04-.03.07-.42 1.44-1.38 2.83M13 3.5c.73-.83 1.94-1.46 2.94-1.5.13 1.17-.34 2.35-1.04 3.19-.69.85-1.83 1.51-2.95 1.42-.15-1.15.41-2.35 1.05-3.11z"})}),s.contractorJobDetail.appleMaps," ",e.jsx(Tr,{className:"w-3 h-3 opacity-60"})]})]})]})]}),e.jsxs("div",{className:"px-4 pb-6 pt-4 text-micro text-muted-foreground/70 space-y-0.5 leading-snug",children:[e.jsx("p",{children:s.contractorJobDetail.createdAt.replace("{date}",Ue(He(t.created_at),"MMM d, yyyy, h:mm a"))}),e.jsx("p",{children:s.contractorJobDetail.lastUpdatedAt.replace("{date}",Ue(He(t.updated_at),"MMM d, yyyy, h:mm a"))}),t.closed_at&&e.jsx("p",{children:s.contractorJobDetail.closedAt.replace("{date}",Ue(He(t.closed_at),"MMM d, yyyy, h:mm a"))})]}),e.jsx(ls,{open:J,onOpenChange:D,jobId:a,jobTitle:t.title,visibility:t.visibility??"public",contractorId:o==null?void 0:o.id}),a&&e.jsx(Ja,{jobId:a,open:f,onOpenChange:E}),Ie(t==null?void 0:t.visibility)&&o&&e.jsx(La,{open:C,onClose:()=>B(!1),jobId:a,jobTitle:t.title,contractorId:o.id}),o&&(d||R)&&e.jsx(Ta,{open:!0,onClose:()=>{g(null),d&&(b.delete("refill"),m(b,{replace:!0}))},shiftId:R??d,jobId:a,contractorId:o.id}),e.jsx(Ls,{open:xe,onOpenChange:ce,job:t,onSaved:()=>{n.invalidateQueries({queryKey:["contractor-job-detail",a]})}}),e.jsx(Js,{open:y,onOpenChange:Q,jobId:a,jobTitle:t.title,jobPay:Number(t.pay)||0,jobPayType:t.pay_type,jobType:t.job_type}),zt&&e.jsx(qa,{open:j,onOpenChange:U,job:{id:t.id,title:t.title,description:t.description??null,skills:t.skills??null,start_date:t.start_date??null,visibility:t.visibility??null}}),e.jsx(Fa,{open:!!Ot,onOpenChange:r=>{r||(Te(null),yt())},applicant:Ot,jobTitle:t.title,jobSkills:t.skills??[],queueRemaining:Xr,isMutating:ae.isPending,onAccept:r=>{var i;if(Fe){M.error(s.contractorJobDetail.toasts.allSpotsAlreadyFilled);return}G(((i=r.profile)==null?void 0:i.full_name)??s.contractorJobDetail.worker),ae.mutate({appId:r.id,status:"accepted",workerId:r.worker_id},{onSuccess:()=>{const c=Le.find(v=>v.id!==r.id);w==="pending"&&c?Te(c.id):(Te(null),yt())}})},onDecline:r=>{ae.mutate({appId:r.id,status:"rejected",workerId:r.worker_id},{onSuccess:()=>{const i=Le.find(c=>c.id!==r.id);w==="pending"&&i?Te(i.id):(Te(null),yt())}})}}),e.jsx(Ns,{open:!!Y,onOpenChange:r=>{r||(ne(null),re("confirm"))},children:e.jsx(_s,{children:he==="confirm"?e.jsxs(e.Fragment,{children:[e.jsxs(yr,{children:[e.jsx(vr,{children:s.contractorJobDetail.acceptForJob.replace("{name}",((tr=Y==null?void 0:Y.profile)==null?void 0:tr.full_name)||s.contractorJobDetail.thisWorker).replace("{job}",t.title)}),e.jsx(wr,{asChild:!0,children:e.jsxs("div",{className:"space-y-2 pt-1",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(at,{className:"w-4 h-4 text-primary"}),e.jsx("span",{className:"text-foreground",children:s.contractorJobDetail.startLabel.replace("{date}",t.start_date?Ue(He(t.start_date),"MMM d, yyyy"):s.contractorJobDetail.tbd)})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(mt,{className:"w-4 h-4 text-primary"}),e.jsx("span",{className:"text-foreground",children:s.contractorJobDetail.payLabel.replace("{pay}",String(t.pay)).replace("{type}",t.pay_type)})]}),e.jsx("p",{className:"text-xs text-muted-foreground pt-1",children:s.contractorJobDetail.acceptNotice})]})})]}),e.jsxs(Nr,{children:[e.jsx(_r,{onClick:()=>ne(null),children:s.contractorJobDetail.cancel}),e.jsx(kr,{onClick:r=>{r.preventDefault(),Y&&ae.mutate({appId:Y.id,status:"accepted",workerId:Y.worker_id})},disabled:ae.isPending,className:"bg-primary hover:bg-primary/90 text-primary-foreground",children:ae.isPending?s.contractorJobDetail.accepting:s.contractorJobDetail.confirmCta})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs(yr,{children:[e.jsxs(vr,{className:"flex items-center gap-2 text-success",children:[e.jsx(ee,{className:"w-5 h-5"})," ",s.contractorJobDetail.workerAcceptedTitle.replace("{name}",Pe)]}),e.jsx(wr,{asChild:!0,children:e.jsxs("div",{className:"space-y-2 pt-1",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:s.contractorJobDetail.workerNotifiedMsg}),Ze>1&&Rt&&e.jsx("p",{className:"text-xs text-foreground",children:(Ze-1===1?s.contractorJobDetail.positionsRemaining:s.contractorJobDetail.positionsRemainingPlural).replace("{count}",String(Ze-1))})]})})]}),e.jsxs(Nr,{className:"flex-col-reverse sm:flex-row gap-2",children:[e.jsx(_r,{onClick:()=>{ne(null),re("confirm")},children:s.contractorJobDetail.done}),Ze>1&&Rt&&e.jsx(kr,{onClick:r=>{var i;r.preventDefault(),ne(null),re("confirm"),l&&(b.delete("applicant"),m(b,{replace:!0})),(i=be.current)==null||i.scrollIntoView({behavior:"smooth",block:"start"})},className:"bg-primary hover:bg-primary/90 text-primary-foreground",children:s.contractorJobDetail.acceptAnother})]})]})})}),N!==null&&(t.photos??[]).length>0&&(()=>{const r=t.photos;return e.jsxs(K.div,{initial:{opacity:0}
6,animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-50 bg-black/90 backdrop-blur-sm flex items-center justify-center",onClick:()=>h(null),children:[e.jsx("button",{onClick:()=>h(null),className:"absolute top-4 right-4 z-50 p-2 rounded-full bg-white/10 hover:bg-white/20 transition-colors",children:e.jsx(Br,{className:"w-6 h-6 text-white"})}),r.length>1&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:i=>{i.stopPropagation(),h((N-1+r.length)%r.length)},className:"absolute left-3 z-50 p-2 rounded-full bg-white/10 hover:bg-white/20 transition-colors",children:e.jsx(_t,{className:"w-6 h-6 text-white"})}),e.jsx("button",{onClick:i=>{i.stopPropagation(),h((N+1)%r.length)},className:"absolute right-3 z-50 p-2 rounded-full bg-white/10 hover:bg-white/20 transition-colors rotate-180",children:e.jsx(_t,{className:"w-6 h-6 text-white"})})]}),e.jsx("img",{src:Os(r[N],1200),alt:`Job photo ${N+1}`,className:"max-h-[85vh] max-w-[90vw] object-contain rounded-lg",onClick:i=>i.stopPropagation(),loading:"lazy",decoding:"async"}),e.jsxs("div",{className:"absolute bottom-4 text-white/70 text-sm",children:[N+1," / ",r.length]})]})})()]})}export{Wn 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.