PageSourceSearch

https://knuckl.com/assets/Home-DSVua98R.js

js knuckl.com collected 2026-09-24 14:46:23 UTC 132,727 bytes, 26 lines download raw bytes

1import{a as x,c as V,j as e,u as Fe,i as yt}from"./vendor-query-BxlSJxfF.js";import{p as Ie,u as te,a as K,o as ge,g as Js,c as _e,B as G,t as J,L as ke,e as B,s as R,T as Gt,q as Vs,I as ut,b as Qs,S as Gs,P as Yt,X as be,d as Ve,r as Me}from"./index-DO0aGFYL.js";import{u as jt}from"./use-subscription-OP_b8dLc.js";import{H as Ys}from"./Head-CFjoxvyt.js";import{u as Zt}from"./use-user-hint-BN7WH046.js";import{m as Xt,p as es}from"./tier-error-C6TW3of0.js";import{F as ts,e as Zs,c as Xs,a as er}from"./flash-chips-C-5-oM_a.js";import{N as tr,a as sr,b as rr,c as nr}from"./NeedSteps-ps0nsiX_.js";import{m as ye,A as Qe,u as ar}from"./vendor-motion-CdL2ySym.js";import{H as Ge}from"./hammer-EIffoAvM.js";import{u as se,L as or}from"./vendor-react-DdNhUK9-.js";import{C as Ue}from"./check-BTT3mgzE.js";import{P as Se}from"./plus-Cn9YMeBw.js";import{C as ss}from"./chevron-left-Bpy2VrDY.js";import{C as Ye}from"./chevron-right-n5eCbV2c.js";import{W as ir}from"./WorkersMap-BwwtYqfj.js";import{n as de,u as lr,S as cr,M as dr,T as ur,W as mr,I as pr}from"./use-contractor-project-pins-Y1XNn7ry.js";import{S as $e,a as Re,b as Oe,c as qe,d as fr}from"./sheet-KxRpZ2qz.js";import{g as xr,F as br}from"./phase-status-C8GaQkLu.js";import{M as De}from"./map-pin-Clc12hBl.js";import{A as bt}from"./arrow-right-Cxpw4wQL.js";import{U as wt}from"./users-4wDC2oQA.js";import{f as hr}from"./use-profile-summary-pcsmjbRV.js";import{t as ht}from"./image-url-_sEuZELz.js";import{u as rs,C as gr}from"./ContactActions-5QM815IJ.js";import{u as ns}from"./use-call-worker-rKYeWsU9.js";import{F as yr}from"./vendor-supabase-Csx7YFID.js";import{T as Je}from"./textarea-CY9O0h4D.js";import{L as Ae}from"./label-Lh_RHPfV.js";import{o as he}from"./post-job-sheet-BxL-Oe-u.js";import{C as jr}from"./job-lifecycle-luKOFqVS.js";import{P as Ke}from"./package-BP6xMrsL.js";import{C as Ze}from"./clock-TDYRjmmL.js";import{G as vt}from"./gavel-C8K741vS.js";import{B as wr}from"./building-2-CTs9_w7h.js";import{E as as}from"./external-link-BMHb0t-K.js";import{A as vr}from"./award-BPuchHpr.js";import{M as os}from"./message-square-CLxZQpIa.js";import{s as Nr,u as kr,i as _r,d as Sr}from"./AttentionSection-BdU1R4Ht.js";import{u as Cr,a as Pr,J as Tr}from"./JobsMapSheet-CdJDTdb-.js";import{u as Ar}from"./use-upcoming-shifts-BnuZ9pEk.js";import{a as Lr}from"./use-pending-review-count-DlV_gBvd.js";import{u as Er}from"./use-sub-attention-items-BoA_Jnai.js";import{u as Xe}from"./use-home-mode-vjQLewqa.js";import{Z as Nt}from"./zap-3WSssjod.js";import{C as Mr}from"./calendar-bL1Vkweo.js";import{C as Fr}from"./circle-check-big-S3OQIQmC.js";import{M as Ir}from"./mail-jw7BVI6D.js";import{S as $r}from"./star-B2GJQJHh.js";import{u as Rr,c as Or}from"./profile-completeness-DMTzd9wk.js";import{F as is}from"./folder-kanban-BIitgRxF.js";import{B as qr}from"./briefcase-DprwYuVO.js";import{r as Dr,f as Kr}from"./repost-job-DVxzKbZ7.js";import{s as ls}from"./flash-prefill-CtQFfO_E.js";import{R as Br}from"./rotate-ccw-CaM1lpMX.js";import{u as Hr}from"./use-profile-edit-BGgdNu7H.js";import{u as cs}from"./use-sub-availability-C8UsG1aZ.js";import{C as Ur}from"./clipboard-list-BWoyDXDg.js";import{u as Wr}from"./use-feature-gate-D2hKRPw6.js";import{U as zr}from"./UpgradeCard-CvZNabGY.js";import{u as Jr}from"./use-contextual-prompt-D1DZFfx0.js";import{C as Vr}from"./ContextualPromptCard-6FgUlM7P.js";import{S as kt}from"./sparkles-B9Io74C_.js";import{H as ds}from"./house-D1lgTCJ7.js";import{r as us}from"./lead-interest-ClOYLsIo.js";import{H as Qr}from"./homeowner-trades-DdI3fK_X.js";import{t as Gr,a as Yr}from"./homeowner-i18n-BlSJu_P4.js";import{A as gt,P as Zr}from"./skill-catalog-CiwHrT6-.js";import{L as ms}from"./lock-CWPApfun.js";import{t as mt}from"./use-toast-DIh7BwqI.js";import{L as Xr}from"./LeadCrewSection-D4pI23rj.js";import{e as en,l as tn,f as Ht}from"./lead-kind-Cs-VxxJh.js";import{K as ps,p as We,i as fs,E as Ee,a as sn,r as rn,d as Ut,w as nn,c as an}from"./map-pins-B0KoeByN.js";import{E as on}from"./entity-icons-CSBLIDvu.js";import{u as ln,E as cn}from"./use-external-lead-notes-BMBVFioG.js";import{G as dn}from"./globe-BblBOU8M.js";import{C as un}from"./copy-0DH5VK1i.js";import{T as xs}
1from"./trash-2-EocM2Uxl.js";import{N as mn,A as pn,a as fn,b as xn}from"./AddLocationBanner-CCCqkWuX.js";import{h as bn}from"./haptics-C4kiRWSa.js";import{H as hn}from"./hard-hat-D6ZR2UoR.js";import{C as gn}from"./chevron-up-EG6HBK1O.js";import{C as yn}from"./chevron-down-Bc6tfcMh.js";import{C as jn}from"./circle-qEn4UVIP.js";import{i as _t}from"./ProjectBanner-BaboQU1f.js";import{Q as bs}from"./QuickJobDialog-DPtlmgFx.js";import{M as hs}from"./MessagingGate-Db7r_iQg.js";import{u as gs}from"./use-message-worker-action-CGVL2tf-.js";import{u as wn}from"./use-primary-query-B8u8fHwG.js";import{S as Wt}from"./seed-visibility-CpNgLkyT.js";import{haversineMiles as vn,geocodeCity as Nn}from"./geocode-CX448-fu.js";import{M as ys}from"./message-circle-BO3xv6Rs.js";import{U as kn}from"./user-plus-e-panZql.js";import{P as _n}from"./PersonPreviewSheet-mSiW1w0A.js";import{P as Sn}from"./ProBadge-XhoH1wyr.js";import{E as Cn}from"./EntityIcon-CBm0WMyj.js";import{L as Pn}from"./LoadErrorCard-DBbQlF04.js";import{u as Tn}from"./use-available-sub-packages-BCYvLeWL.js";import{u as An}from"./use-external-lead-pins-DVQQb9r4.js";import{u as Ln,P as En,g as Mn}from"./PushPrePrompt-CM-0ATu6.js";import{B as Fn}from"./bell-ring-DAwvedso.js";import{B as js}from"./bell-D4WR-0m3.js";import{u as In,a as $n,b as Rn}from"./use-saved-jobs-CAU8LXEx.js";import{B as On}from"./bell-off-C6e2vGli.js";import{S as qn}from"./search-BkqYkxAv.js";import{W as Dn}from"./wrench-BXv_aUNf.js";import"./payment-methods-B3AhwECb.js";import"./addDays-CBy3L5y7.js";import"./urgency-BdJ5O0G-.js";import"./skill-tiers-Dqp05d-G.js";import"./LocationAutocomplete-BSme0mji.js";import"./locate-fixed-DXW6AJ3Q.js";import"./MiniMapPreview-BDdJ0hjB.js";import"./MapUnavailable-B-QP0qIy.js";import"./circle-check-BzeG-ygw.js";import"./viewed-entities-B6ahwsNe.js";import"./notification-link-CENdaziQ.js";import"./use-crew-signals-mdI_4lDE.js";import"./list-BzmR_WE3.js";import"./repeat-B20BXHly.js";import"./info-CrnkT6_5.js";import"./flag-iQDr95MH.js";import"./parse-local-date-CGCN6Dtg.js";import"./parseISO-B5tfR1s8.js";import"./FirstTimeHint-DY83n2XR.js";import"./SampleBadge-BFUdi8Eh.js";import"./flask-conical-BAfNe3qI.js";import"./review-window-bRPqN3sJ.js";import"./completeness-core--su989Pr.js";import"./CrewAvailableList-C0Ra8Z0Z.js";import"./badge-4jZnSn2H.js";import"./use-work-offers-i0L7CNkS.js";import"./OfferSheet-ChGpegXJ.js";import"./use-market-rate-BNhsAniP.js";import"./switch-CdLpmXwy.js";import"./MarketRateWarning-ClC-iQuU.js";import"./use-geolocation-CF3oDqXg.js";import"./trending-up-DS_OYcrn.js";import"./dollar-sign-4OmuIJls.js";import"./file-text-CHUqxuo4.js";import"./car-DO0yWu1G.js";import"./send-C6vNENnO.js";import"./use-messaging-permission-ub7ydGOC.js";import"./AvailabilityCalendarCard-DYENFqXo.js";import"./ChatView-ByxmI7l5.js";import"./dropdown-menu-CWX03-u_.js";import"./index-Ce1IEqmK.js";import"./index-Bidgsva9.js";import"./index-B9yCq0Ag.js";import"./alert-dialog-WBQzXKSB.js";import"./ellipsis-vertical-hz3e7lEk.js";import"./ban-D47cmeaL.js";import"./application-status-OYVIyYV9.js";import"./arrow-left-DNK6fh5x.js";import"./circle-alert-CepIuroe.js";import"./truck-Lofw2l_u.js";import"./popover-wk50W3qJ.js";import"./bookmark-D2iy1XDt.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 Kn=Ie("CalendarClock",[["path",{d:"M21 7.5V6a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h3.5",key:"1osxxc"}],["path",{d:"M16 2v4",key:"4m81vk"}],["path",{d:"M8 2v4",key:"1cmpym"}],["path",{d:"M3 10h5",key:"r794hk"}],["path",{d:"M17.5 17.5 16 16.3V14",key:"akvzfd"}],["circle",{cx:"16",cy:"16",r:"6",key:"qoo3c4"}]]);/**
7 * @license lucide-react v0.462.0 - ISC
8 *
9 * This source code is licensed under the ISC license.
10 * See the LICENSE file in the root directory of this source tree.
11 */const Bn=Ie("CloudLightning",[["path",{d:"M6 16.326A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 .5 8.973",key:"1cez44"}],["path",{d:"m13 12-3 5h4l-3 5",key:"1t22er"}]]);/**
12 * @license lucide-react v0.462.0 - ISC
13 *
14 * This source code is licensed under the ISC license.
15 * See the LICENSE file in the root directory of this source tree.
16 */const Hn=Ie("PowerOff",[["path",{d:"M18.36 6.64A9 9 0 0 1 20.77 15",key:"dxknvb"}],["path",{d:"M6.16 6.16a9 9 0 1 0 12.68 12.68",key:"1x7qb5"}],["path",{d:"M12 2v4",key:"3427ic"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]]);/**
17 * @license lucide-react v0.462.0 - ISC
18 *
19 * This source code is licensed under the ISC license.
20 * See the LICENSE file in the root directory of this source tree.
21 */const Un=Ie("Power",[["path",{d:"M12 2v10",key:"mnfbl"}],["path",{d:"M18.4 6.6a9 9 0 1 1-12.77.04",key:"obofu9"}]]);/**
22 * @license lucide-react v0.462.0 - ISC
23 *
24 * This source code is licensed under the ISC license.
25 * See the LICENSE file in the root directory of this source tree.
26 */const Wn=Ie("Rocket",[["path",{d:"M4.5 16.5c-1.5 1.26-2 5-2 5s3.74-.5 5-2c.71-.84.7-2.13-.09-2.91a2.18 2.18 0 0 0-2.91-.09z",key:"m3
26kijz"}],["path",{d:"m12 15-3-3a22 22 0 0 1 2-3.95A12.88 12.88 0 0 1 22 2c0 2.72-.78 7.5-6 11a22.35 22.35 0 0 1-4 2z",key:"1fmvmk"}],["path",{d:"M9 12H4s.55-3.03 2-4c1.62-1.08 5 0 5 0",key:"1f8sc4"}],["path",{d:"M12 15v5s3.03-.55 4-2c1.08-1.62 0-5 0-5",key:"qeys4"}]]),Le=["intro","trade","crew","where","pay"];function zn(){const{user:t}=te(),{t:s}=K(),r=s.unifiedOnboarding.need,{data:a}=ge(t==null?void 0:t.id),{shown:i,isLoading:n,markShown:o}=Zt("need_first_prompt_seen"),{ensurePhoneVerified:d}=Js(),{open:u}=_e(),[l,y]=x.useState("intro"),[b,C]=x.useState(!1),[f,S]=x.useState(""),[h,w]=x.useState(1),[v,k]=x.useState(()=>{const W=new Date;return W.setDate(W.getDate()+1),W.setHours(0,0,0,0),W}),[j,g]=x.useState("07:00"),[T,p]=x.useState(""),[N,L]=x.useState(null),[E,$]=x.useState(""),[H,A]=x.useState("hourly"),[O,m]=x.useState(["cash"]),[M,I]=x.useState(""),P=!!(a!=null&&a.hiringVisible)||!!(a!=null&&a.subVisible),{data:U}=V({queryKey:["need-first-has-posted",t==null?void 0:t.id],enabled:!!(t!=null&&t.id)&&P&&!n&&!i,staleTime:5*6e4,queryFn:async()=>{const{count:W}=await R.from("jobs").select("id",{count:"exact",head:!0}).eq("contractor_id",t.id);return(W??0)>0}});if(!t||!P||n||i||U!==!1)return null;const q=(()=>{if(l==="trade")return!!f;if(l==="where")return!!N;if(l==="pay"){const W=parseFloat(E);return!!W&&W>0}return!0})(),Y=()=>y(Le[Math.min(Le.length-1,Le.indexOf(l)+1)]),Q=()=>y(Le[Math.max(0,Le.indexOf(l)-1)]);async function X(){var fe,xe;if(!t)return;const W=ts.find(Z=>Z.id===f);if(!W){B.error(r.errPickTrade);return}const oe=parseFloat(E);if(!oe||oe<=0){B.error(r.errInvalidPay);return}if(!d("flash")){J("reengage.job_post_failed",{reason:"phone_gate"});return}C(!0);try{const Z=Zs(T),D=Z?s.flashPost.titleNeededIn(W.label,Z):s.flashPost.titleNeeded(W.label);await Xs({contractorId:t.id,title:D,skills:W.skills,slots:h,pay:oe,payType:H,startDate:v,startTime:j,location:T,coords:N,paymentMethods:O,paymentMethodsOther:M,source:"onboarding_reengage"}),J("reengage.job_posted",{}),await o(),B.success(s.postJob.jobPosted)}catch(Z){const D=Z;if(D instanceof er){B.error(r.coordsRequired),y("where");return}const ue=Xt(D==null?void 0:D.message);if(ue){const Ce=(xe=(fe=s.subscriptionGates)==null?void 0:fe.serverErrors)==null?void 0:xe[ue];B.error(Ce||r.errPostFailed),u(ue==="paid_tier_required"?es(D==null?void 0:D.hint)??"generic":"generic")}else B.error(r.errPostFailed)}finally{C(!1)}}return e.jsx("div",{className:"fixed inset-0 z-[70] bg-background/95 backdrop-blur-sm flex items-center justify-center px-5 overflow-y-auto",children:e.jsx(ye.div,{initial:{opacity:0,y:16},animate:{opacity:1,y:0},transition:{duration:.25},className:"w-full max-w-sm rounded-3xl border border-border/60 bg-card p-6 shadow-2xl my-8",children:l==="intro"?e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"mx-auto mb-4 w-12 h-12 rounded-card bg-primary/15 text-primary flex items-center justify-center",children:e.jsx(Ge,{className:"w-6 h-6"})}),e.jsx("h2",{className:"font-display text-2xl text-foreground mb-2",children:r.reengageTitle}),e.jsx("p",{className:"text-sm text-muted-foreground mb-6",children:r.reengageBody}),e.jsx(G,{size:"lg",className:"w-full h-12 rounded-xl font-semibold",onClick:()=>{if(!d("flash")){J("reengage.job_post_failed",{reason:"phone_gate_pre"});return}J("reengage.started",{}),Y()},children:r.reengageCta}),e.jsx("button",{type:"button",onClick:()=>void o(),className:"mt-3 w-full text-sm text-muted-foreground underline underline-offset-4",children:r.reengageDismiss})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"text-left",children:[l==="trade"&&e.jsx(tr,{chipId:f,onChange:S}),l==="crew"&&e.jsx(sr,{workers:h,onWorkers:w,date:v,onDate:k,startTime:j,onStartTime:g}),l==="where"&&e.jsx(rr,{location:T,coords:N,onLocation:W=>{p(W),L(null)},onSelect:W=>{p(W.display),L({lat:W.lat,lng:W.lng})}}),l==="pay"&&e.jsx(nr,{pay:E,onPay:$,payType:H,onPayType:A,methods:O,onMethods:m,methodsOther:M,onMethodsOther:I})]}),e.jsxs("div",{className:"mt-6 flex items-center gap-3",children:[e.jsx(G,{variant:"outline",className:"h-12 rounded-xl px-4",onClick:Q,disabled:b,children:s.common.back}),e.jsx(G,{className:"flex-1 h-12 rounded-xl font-semibold",disabled:!q||b,onClick:()=>l==="pay"?void X():Y(),children:b?e.jsx(ke,{className:"w-4 h-4 animate-spin"}):l==="pay"?r.postCta:s.common.continue})]}),e.jsx("button",{type:"button",onClick:()=>void o(),className:"mt-3 w-full text-sm text-muted-foreground underline underline-offset-4",disabled:b,children:r.reengageDismiss})]})})})}const Jn="/assets/intro-welcome-0TZicj1K.jpg",Vn="/assets/intro-contractor-Dm2htjrC.jpg",Qn="/assets/intro-sub-B6p0PnGY.jpg",Gn="/assets/intro-wor
26ker-DdzH3OMM.jpg";function Yn(){const{user:t}=te(),{data:s}=ge(t==null?void 0:t.id),{t:r}=K(),a=se(),{shown:i,isLoading:n,markShown:o}=Zt("role_intro_seen"),[d,u]=x.useState(0),[l,y]=x.useState(null),[b,C]=x.useState(!1),f=r.intro,S={hiring:!!(s!=null&&s.hiringVisible),sub:!!(s!=null&&s.subVisible),laborer:!!(s!=null&&s.laborerVisible)},h=x.useMemo(()=>[{key:"welcome",img:Jn,title:f.welcome.title,body:f.welcome.body,bullets:[],role:null},{key:"hiring",img:Vn,title:f.contractor.title,body:"",bullets:[f.contractor.b1,f.contractor.b2,f.contractor.b3,f.contractor.b4,f.contractor.b5,f.contractor.b6,f.contractor.b7],role:"hiring"},{key:"sub",img:Qn,title:f.sub.title,body:"",bullets:[f.sub.b1,f.sub.b2,f.sub.b3,f.sub.b4,f.sub.b5,f.sub.b6,f.sub.b7],role:"sub"},{key:"laborer",img:Gn,title:f.worker.title,body:"",bullets:[f.worker.b1,f.worker.b2,f.worker.b3,f.worker.b4,f.worker.b5,f.worker.b6,f.worker.b7],role:"laborer"},{key:"setup",img:null,title:f.setup.title,body:f.setup.body,bullets:[],role:null}],[f]),w=h.length,v=d===w-1;if(x.useEffect(()=>{const g=T=>{T.key==="ArrowRight"&&u(p=>Math.min(p+1,w-1)),T.key==="ArrowLeft"&&u(p=>Math.max(p-1,0))};return window.addEventListener("keydown",g),()=>window.removeEventListener("keydown",g)},[w]),b||n||i||!s||!s.hiringVisible&&!s.subVisible&&!s.laborerVisible)return null;const k=async g=>{if(C(!0),await o(),g){const T=s.hiringVisible?"/contractor/settings":"/worker/settings";a(`${T}?role=${g}`)}},j=h[d];return e.jsxs("div",{className:"fixed inset-0 z-[1000] bg-background flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 pt-3",style:{paddingTop:"calc(env(safe-area-inset-top, 0px) + 12px)"},children:[e.jsx("div",{className:"flex items-center gap-1.5","aria-label":f.stepOf(d+1,w),children:h.map((g,T)=>e.jsx("span",{className:`h-1.5 rounded-full transition-all ${T===d?"w-6 bg-primary":"w-1.5 bg-muted"}`},g.key))}),e.jsx("button",{type:"button",onClick:()=>k(null),className:"h-11 px-3 text-sm font-medium text-muted-foreground",children:f.skip})]}),e.jsx("div",{className:"flex-1 overflow-y-auto px-5 pb-4",children:e.jsx("div",{className:"mx-auto w-full max-w-md",children:e.jsx(Qe,{mode:"wait",children:e.jsxs(ye.div,{initial:{opacity:0,x:24},animate:{opacity:1,x:0},exit:{opacity:0,x:-24},transition:{duration:.2},drag:"x",dragConstraints:{left:0,right:0},dragElastic:.2,onDragEnd:(g,T)=>{T.offset.x<-60&&u(p=>Math.min(p+1,w-1)),T.offset.x>60&&u(p=>Math.max(p-1,0))},children:[j.img&&e.jsx("img",{src:j.img,alt:"",loading:"lazy",width:1024,height:640,className:"w-full rounded-card border border-border/60 mt-4"}),e.jsxs("div",{className:"mt-6",children:[j.role&&S[j.role]&&e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-primary/15 text-primary text-caption font-semibold px-3 py-1 mb-2",children:[e.jsx(Ue,{className:"h-3.5 w-3.5"}),f.thisIsYou]}),e.jsx("h2",{className:"font-display text-2xl text-foreground leading-tight",children:j.title}),j.body&&e.jsx("p",{className:"text-sm text-muted-foreground mt-2",children:j.body}),j.bullets.length>0&&e.jsx("ul",{className:"mt-4 space-y-3",children:j.bullets.map((g,T)=>e.jsxs("li",{className:"flex gap-3 text-sm text-foreground",children:[e.jsx("span",{className:"text-primary mt-0.5",children:"•"}),e.jsx("span",{children:g})]},T))}),j.key==="setup"&&e.jsx("div",{className:"mt-5 flex flex-col gap-2",children:["hiring","sub","laborer"].map(g=>{const T=r.roles.summary[g];if(S[g])return e.jsxs("div",{className:"flex items-center justify-between min-h-[56px] px-4 rounded-card border border-primary/30 bg-primary/10",children:[e.jsx("span",{className:"text-sm font-medium text-foreground",children:T}),e.jsxs("span",{className:"inline-flex items-center gap-1 text-sm text-primary font-semibold",children:[e.jsx(Ue,{className:"h-4 w-4"}),f.setup.on]})]},g);const p=l===g;return e.jsxs("button",{type:"button",onClick:()=>y(p?null:g),"aria-pressed":p,className:`flex items-center justify-between min-h-[56px] px-4 rounded-card border transition-colors ${p?"border-primary bg-primary/10":"border-border bg-muted"}`,children:[e.jsx("span",{className:"text-sm font-medium text-foreground",children:T}),e.jsxs("span",{className:"inline-flex items-center gap-1 text-sm font-semibold text-muted-foreground",children:[p?e.jsx(Ue,{className:"h-4 w-4"}):e.jsx(Se,{className:"h-4 w-4"}),f.setup.add]})]},g)})})]})]},j.key)})})}),e.jsx("div",{className:"px-5 pb-5 border-t border-border/60 pt-3",style:{paddingBottom:"calc(env(safe-area-inset-bottom, 0px) + 20px)"},children:e.jsxs("div",{className:"mx-auto w-full max-w-md flex items-center gap-3",children:[d>0&&e.jsxs("button",{type:"button",onClick:()=>u(g=>
26g-1),className:"h-12 px-4 rounded-xl border border-border text-sm font-medium text-muted-foreground inline-flex items-center gap-1",children:[e.jsx(ss,{className:"h-4 w-4"}),f.back]}),e.jsxs("button",{type:"button",onClick:()=>v?k(l):u(g=>g+1),className:"flex-1 h-12 rounded-xl bg-primary text-primary-foreground text-sm font-semibold inline-flex items-center justify-center gap-1",children:[v?f.start:f.next,!v&&e.jsx(Ye,{className:"h-4 w-4"})]})]})})]})}const Zn={planning:"bg-blue-500/15 text-blue-500 border-blue-500/30",active:"bg-primary/15 text-primary border-primary/30",complete:"bg-emerald-500/15 text-emerald-500 border-emerald-500/30"},Xn=.65;function ea(t){return!isFinite(t)||t<=0?"$0":t>=1e3?`$${(t/1e3).toFixed(t>=1e4?0:1)}k`:`$${Math.round(t)}`}function ta({projectId:t,currentUserId:s,onClose:r,onViewDetails:a,onPostNextPhase:i,onReviewApplicants:n}){var T,p,N,L,E,$,H,A,O,m,M,I;const{t:o}=K(),d=(o==null?void 0:o.projectMapSheet)??{},u=!!t,{data:l,isLoading:y}=V({queryKey:["project-sheet",t,s??null],enabled:u,staleTime:6e4,queryFn:async()=>{const{data:P,error:U}=await R.from("projects").select("id, name, address, status, contractor_id").eq("id",t).maybeSingle();if(U)throw U;const q=P,Y=!!(q&&s&&q.contractor_id===s),{data:Q}=await R.from("jobs").select("id, title, status, slots, filled_slots, start_date, phase_budget, phase_labor_pct").eq("project_id",t).is("deleted_at",null),X=Q??[];if(!Y){const z=X.length,re=X.filter(ee=>ee.status==="active"||ee.status==="filled"||ee.status==="closed").length;return{project:q,isOwner:Y,total:z,posted:re,inProgress:0,phases:[],financials:null}}const W=X.map(z=>z.id);let oe=[];if(W.length>0){const{data:z}=await R.from("applications").select("id, job_id").eq("status","accepted").in("job_id",W);oe=z??[]}const fe=new Map;X.forEach(z=>fe.set(z.id,{budget:Number(z.phase_budget??0),laborPct:z.phase_labor_pct==null?Xn:Number(z.phase_labor_pct)}));const xe=X.reduce((z,re)=>z+Number(re.phase_budget??0),0),Z=oe.reduce((z,re)=>{const ee=fe.get(re.job_id);return!ee||!ee.budget?z:z+ee.budget*ee.laborPct},0),D=X.length,ue=X.filter(z=>z.status==="active"||z.status==="filled"||z.status==="closed").length,Ce=X.filter(z=>z.status==="active"&&Number(z.filled_slots??0)>0).length;return{project:q,isOwner:Y,total:D,posted:ue,inProgress:Ce,phases:X,financials:{activeBudget:xe,spent:Z,remaining:Math.max(0,xe-Z)}}}}),b=(l==null?void 0:l.project)??null,C=!!(l!=null&&l.isOwner),f=(l==null?void 0:l.total)??0,S=(l==null?void 0:l.posted)??0,h=(l==null?void 0:l.inProgress)??0,w=f>0?Math.round(S/f*100):0,v=(l==null?void 0:l.financials)??null,k=x.useMemo(()=>C?((l==null?void 0:l.phases)??[]).filter(P=>xr(P)==="at_risk").slice(0,2).map(P=>({id:P.id,title:P.title,slots:Number(P.slots??1),filled:Number(P.filled_slots??0)})):[],[C,l==null?void 0:l.phases]),j=((b==null?void 0:b.status)??"").toLowerCase(),g=((p=(T=o==null?void 0:o.home)==null?void 0:T.projectStatus)==null?void 0:p[j])??(j?j.charAt(0).toUpperCase()+j.slice(1):"");return e.jsx($e,{open:u,onOpenChange:P=>{P||r()},children:e.jsxs(Re,{side:"bottom",className:`rounded-t-2xl pb-[max(env(safe-area-inset-bottom),1rem)] z-[1250] overflow-y-auto ${C?"max-h-[70dvh]":"max-h-[55dvh]"}`,children:[e.jsx(Oe,{className:"text-left",children:e.jsx(qe,{className:"text-lg font-display",children:(b==null?void 0:b.name)??((L=(N=o==null?void 0:o.home)==null?void 0:N.projectSheet)==null?void 0:L.loading)??"Loading…"})}),e.jsxs("div",{className:"mt-3 space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[g&&e.jsx("span",{className:`inline-flex items-center h-6 px-2 rounded-full text-xs font-semibold border ${Zn[j]??"bg-muted text-muted-foreground border-border"}`,children:g}),(b==null?void 0:b.address)&&e.jsxs("span",{className:"inline-flex items-start gap-1 text-xs text-muted-foreground min-w-0",children:[e.jsx(De,{className:"w-3.5 h-3.5 mt-0.5 shrink-0"}),e.jsx("span",{className:"truncate",children:b.address})]})]}),C&&v&&v.activeBudget>0&&e.jsx("div",{className:"grid grid-cols-3 gap-2",children:[{k:"budget",label:((E=d==null?void 0:d.financial)==null?void 0:E.budget)??"Budget",val:v.activeBudget,tone:"text-foreground"},{k:"spent",label:(($=d==null?void 0:d.financial)==null?void 0:$.spent)??"Spent",val:v.spent,tone:"text-foreground"},{k:"remaining",label:((H=d==null?void 0:d.financial)==null?void 0:H.remaining)??"Remaining",val:v.remaining,tone:"text-primary"}].map(P=>e.jsxs("div",{className:"rounded-xl border border-border/60 bg-card px-3 py-2",children:[e.jsx("p",{className:"text-micro font-semibold uppercase tracking-wider text-muted-foreground",children:P.label}),e.jsx("p",{className:`text-base font-bold mt-0.5 ${P.tone}`,children:ea(P.val)})]},P.k))}),f>0&&e.jsxs("div",{children:[e.jsxs("p",{className:"text-xs text-muted-foreground mb-1.5",children:[(A=d==null?void 0:d.phases)!=null&&A.postedOf?d.phases.postedOf.replace("{n}",String(S)).replace("{total}",String(f)):`${S} of ${f} phases posted`,C&&h>0&&e.jsxs(e.Fragment,{children:[" · ",(O=d==null?void 0:d.phases)!=null&&O.inProgress?d.phases.inProgress.replace("{n}",String(h)):`${h} in progress`]}
26)]}),e.jsx("div",{className:"h-2 rounded-full bg-muted overflow-hidden",children:e.jsx("div",{className:"h-full bg-primary transition-all",style:{width:`${w}%`},"aria-label":`${w}%`})})]}),C&&k.length>0&&e.jsx("div",{className:"space-y-1.5",children:k.map(P=>e.jsxs("div",{className:"flex items-center gap-2 rounded-lg border border-red-500/40 bg-red-500/5 px-3 py-2",children:[e.jsx(Gt,{className:"w-3.5 h-3.5 text-red-500 shrink-0"}),e.jsx("span",{className:"text-xs font-semibold text-foreground truncate flex-1",children:P.title}),e.jsxs("span",{className:"text-caption text-muted-foreground shrink-0",children:[P.filled,"/",P.slots]})]},P.id))}),e.jsxs("button",{type:"button",disabled:!b||y,onClick:P=>{P.stopPropagation(),b!=null&&b.id&&a(b.id)},className:"w-full h-11 rounded-xl bg-primary text-primary-foreground text-sm font-semibold disabled:opacity-50 inline-flex items-center justify-center gap-1.5",children:[((m=d==null?void 0:d.cta)==null?void 0:m.openProject)??"Open project details",e.jsx(bt,{className:"w-4 h-4"})]}),C&&b&&e.jsxs("div",{className:"flex items-center justify-between gap-2 pt-1",children:[i&&e.jsxs("button",{type:"button",onClick:()=>i(b.id),className:"inline-flex items-center gap-1.5 text-sm font-semibold text-primary hover:underline",children:[e.jsx(Se,{className:"w-4 h-4"}),((M=d==null?void 0:d.cta)==null?void 0:M.postNextPhase)??"Post next phase"]}),n&&e.jsxs("button",{type:"button",onClick:()=>n(b.id),className:"inline-flex items-center gap-1.5 text-sm font-semibold text-primary hover:underline",children:[e.jsx(wt,{className:"w-4 h-4"}),((I=d==null?void 0:d.cta)==null?void 0:I.reviewApplicants)??"Review applicants"]})]})]})]})})}const sa=jr;function ws({open:t,onOpenChange:s,sub:r}){const{user:a}=te(),{t:i,lang:n}=K(),o=i.inviteToBid,{open:d}=_e(),u=Fe(),[l,y]=x.useState(!1),[b,C]=x.useState("invite"),[f,S]=x.useState(null),[h,w]=x.useState(""),[v,k]=x.useState(""),[j,g]=x.useState(""),[T,p]=x.useState(""),[N,L]=x.useState("");x.useEffect(()=>{t||(S(null),C("invite"),w(""),k(""),g(""),p(""),L(""))},[t]);const{data:E=[],isLoading:$}=V({queryKey:["invite-to-bid-packages",a==null?void 0:a.id],enabled:t&&!!(a!=null&&a.id),staleTime:3e4,queryFn:async()=>{const{data:m,error:M}=await R.from("jobs").select("id, title, bid_deadline").eq("contractor_id",a.id).eq("job_type","sub_package").is("deleted_at",null).not("status","in",`(${sa.join(",")})`).order("created_at",{ascending:!1}).limit(30);if(M)throw M;const I=m??[];if(I.length===0)return[];const{data:P}=await R.from("applications").select("job_id").in("job_id",I.map(q=>q.id)),U=new Map;return(P??[]).forEach(q=>{U.set(q.job_id,(U.get(q.job_id)??0)+1)}),I.map(q=>({id:q.id,title:q.title??"",bidDeadline:q.bid_deadline??null,bidCount:U.get(q.id)??0}))}}),H=()=>{u.invalidateQueries({queryKey:["invite-to-bid-packages",a==null?void 0:a.id]}),u.invalidateQueries({queryKey:["contractor-proposals",a==null?void 0:a.id]}),u.invalidateQueries({queryKey:["pending-applications-detail"]})},A=async m=>{var M;if(r){y(!0);try{const{data:I,error:P}=await R.functions.invoke("invite-sub-to-bid",{body:{job_id:m.id,sub_id:r.id,scope_note:h.trim()||null,budget:v.trim()?Number(v):null,respond_by:j||null}});if(P){let q=P.message??"",Y=null;if(P instanceof yr)try{const Q=await P.context.json();q=String((Q==null?void 0:Q.error)??q),Y=(Q==null?void 0:Q.hint)??null}catch{}if(Xt(q)==="paid_tier_required"){s(!1),d(es(Y)??"invite_to_bid");return}throw new Error(q||o.toastFailed)}const U=String((I==null?void 0:I.result)??"");if(J("contractor.invite_to_bid.sent",{sub_id:r.id,job_id:m.id,result:U,has_scope:!!h.trim(),has_budget:!!v.trim()}),U==="invited")B.success(o.toastInvited(r.name,m.title)),H(),s(!1);else if(U==="already_bid")B.info(o.toastAlreadyBid);else if(U==="already_invited"){const q=String((I==null?void 0:I.status)??"pending"),Y=((M=o.inviteStatus)==null?void 0:M[q])??q;B.info(o.toastAlreadyInvited(Y))}else B.error(o.toastFailed)}catch(I){B.error((I==null?void 0:I.message)??o.toastFailed)}finally{y(!1)}}},O=async m=>{if(!r)return;const M=Number(T);if(!T.trim()||!Number.isFinite(M)||M<=0){B.error(o.amountRequired);return}y(!0);try{const{data:I,error:P}=await R.rpc("record_sub_bid",{_job_id:m.id,_sub_id:r.id,_amount:M,_note:N.trim()||null});if(P)throw new Error(P.message);const U=String((I==null?void 0:I.result)??"");J("contractor.bid_recorded",{sub_id:r.id,job_id:m.id,result:U}),U==="recorded"?(B.success(o.toastRecorded(r.name,m.title)),H(),s(!1)):U==="already_bid"?B.info(o.toastAlreadyBid):B.error(o.toastFailed)}catch(I){B.error((I==null?void 0:I.message)??o.toastFailed)}finally{y(!1)}};return e.jsx($e,{open:t,onOpenChange:s,children:e.jsxs(Re,{side:"bottom",className:"rounded-t-2xl z-[1300]",children:[e.jsxs(Oe,{className:"text-left",children:[e.jsxs(qe,{className:"flex items-center gap-2",children:[f&&e.jsx("button",{type:"button","aria-label":o.back,onClick:()=>S(null),className:"-ml-1 p-1 rounded-md text-muted-foreground hover:bg-secondary",children:e.jsx(ss,{className:"w-4 h-4"})}),f?b==="invite"?o.detailsTitle:o.recordTitle:o.sheetTitle]}),r&&e.jsx(fr,{children:f?b==="invite"?o.detailsFor(f.title):o.recordFor(r.name):o.sheetSubtitle(r.name)})]}),e.jsxs("div",{className:"pt-4 pb-[calc(env(safe-area-inset-bottom)+16px)] space-y-3",children:[!f&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"grid grid-cols-2 gap-1 p-1 rounded-full bg-secondary/60",children:["invite","record"].map(m=>e.jsx("button",{type:"button",onClick:()=>C(m),className:`h-9 rounded-full text-small font-semibold transition-colors ${b===m?"bg-background text-foreground shadow-sm":"text-muted-foreground"}`,children:m==="invite"?o.modeInvite:o.modeRecord},m))}),$?e.jsx("div",{className:"h-16 rounded-xl bg-card/60 border border-border/60 animate-pulse"}):E.length===0?e.jsxs("div",{className:"text-center space-y-3 py-6",children:[e.jsx(Ke,{className:"w-8 h-8 text-muted-foreground mx-auto"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:o.emptyLine}),e.jsx(G,{onClick:()=>{s(!1),he("sub")},children:o.emptyCta})]}):E.map(m=>e.jsx("button",{type:"button",onClick:()=>S(m),className:"w-full min-h-[56px] flex items-center gap-3 rounded-xl border border-border bg-card px-3 py-3 text-left active:scale-[0.99] transition-transform",children:e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-sm font-semibold text-foreground truncate",children:m.title}),e.jsxs("div",{className:"flex items-center gap-3 text-caption text-muted-foreground mt-0.5",children:[m.bidDeadline&&e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Ze,{className:"w-3 h-3"}),o.deadline(Vs(m.bidDeadline,n,{month:"short",day:"numeric"}))]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(vt,{className:"w-3 h-3"}),o.bidCount(m.bidCount)]})]})]})},m.id))]}),f&&b==="invite"&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(Ae,{htmlFor:"bid-scope",children:o.scopeLabel}),e.jsx(Je,{id:"bid-scope",value:h,onChange:m=>w(m.target.value.slice(0,1e3)),placeholder:o.scopePlaceholder,rows:4})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(Ae,{htmlFor:"bid-budget",children:o.budgetLabel}),e.jsx(ut,{id:"bid-budget",type:"number",inputMode:"decimal",min:0,value:v,onCh
26ange:m=>k(m.target.value),placeholder:"$"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(Ae,{htmlFor:"bid-respond-by",children:o.respondByLabel}),e.jsx(ut,{id:"bid-respond-by",type:"date",value:j,onChange:m=>g(m.target.value)})]})]}),e.jsx(G,{className:"w-full h-12 rounded-full",disabled:l,onClick:()=>void A(f),children:l?e.jsx(ke,{className:"w-4 h-4 animate-spin"}):o.sendCta})]}),f&&b==="record"&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(Ae,{htmlFor:"bid-amount",children:o.amountLabel}),e.jsx(ut,{id:"bid-amount",type:"number",inputMode:"decimal",min:0,value:T,onChange:m=>p(m.target.value),placeholder:"$"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(Ae,{htmlFor:"bid-note",children:o.noteLabel}),e.jsx(Je,{id:"bid-note",value:N,onChange:m=>L(m.target.value.slice(0,1e3)),placeholder:o.notePlaceholder,rows:4})]}),e.jsx(G,{className:"w-full h-12 rounded-full",disabled:l,onClick:()=>void O(f),children:l?e.jsx(ke,{className:"w-4 h-4 animate-spin"}):o.recordCta})]})]})]})})}function ra({subId:t,onClose:s,onViewProfile:r,onMessage:a}){var O,m,M,I;const{t:i}=K(),n=i.subMapSheet,o=!!t,[d,u]=x.useState(!1),{data:l=!1}=rs(t,o),{initiateCall:y,isCalling:b}=ns(),C=i.inviteToBid,{roles:f}=Qs(),S=f.includes("contractor"),{effectiveTier:h}=jt(),{open:w}=_e(),[v,k]=x.useState(null),j=b(t??""),{data:g,isLoading:T}=V({queryKey:["sub-map-sheet",t],enabled:!!t,staleTime:6e4,queryFn:()=>hr(t)}),p=(g==null?void 0:g.sub)??null,N=((O=p==null?void 0:p.companyName)==null?void 0:O.trim())||(g==null?void 0:g.displayName)||"",L=N.trim().charAt(0).toUpperCase()||"?",E=((m=p==null?void 0:p.bio)==null?void 0:m.trim())??"",$=E.length>180,H=d||!$?E:E.slice(0,180).trimEnd()+"…",A=(()=>{const P=p==null?void 0:p.businessHours;if(!P||typeof P!="object")return null;const U=Object.entries(P).filter(([,q])=>typeof q=="string"&&q);return U.length===0?null:U.slice(0,2).map(([q,Y])=>`${q}: ${Y}`).join(" · ")})();return e.jsxs(e.Fragment,{children:[e.jsx($e,{open:o,onOpenChange:P=>{P||s()},children:e.jsxs(Re,{side:"bottom",className:"rounded-t-2xl pb-[max(env(safe-area-inset-bottom),1rem)] max-h-[85dvh] overflow-y-auto z-[1250]",children:[e.jsx(Oe,{className:"sr-only",children:e.jsx(qe,{children:N||"Sub-contractor"})}),T&&e.jsxs("div",{className:"animate-pulse space-y-3 mt-2",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-14 h-14 rounded-xl bg-muted"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx("div",{className:"h-4 bg-muted rounded w-1/2"}),e.jsx("div",{className:"h-3 bg-muted rounded w-1/3"})]})]}),e.jsx("div",{className:"h-16 bg-muted rounded"}),e.jsx("div",{className:"h-24 bg-muted rounded"})]}),!T&&g&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4 mt-2",children:[e.jsx("div",{className:"w-14 h-14 rounded-xl overflow-hidden bg-primary/15 border border-primary/30 flex items-center justify-center shrink-0",children:p!=null&&p.logoUrl?e.jsx("img",{loading:"lazy",decoding:"async",src:ht(p.logoUrl,128),alt:N,className:"w-full h-full object-cover"}):g.avatarUrl?e.jsx("img",{loading:"lazy",decoding:"async",src:ht(g.avatarUrl,96),alt:N,className:"w-full h-full object-cover"}):e.jsx("span",{className:"text-[20px] font-bold text-primary",children:L})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-lede font-bold text-foreground truncate",children:N}),e.jsxs("div",{className:"flex items-center gap-2 mt-0.5 flex-wrap",children:[(M=p==null?void 0:p.badges)==null?void 0:M.slice(0,2).map(P=>e.jsxs("span",{className:"inline-flex items-center gap-1 text-micro font-bold uppercase tracking-wider px-1.5 py-0.5 rounded-full bg-[hsl(var(--entity-sub))]/20 text-[hsl(var(--entity-sub-ink))] border border-[hsl(var(--entity-sub))]/40",children:[e.jsx(Gs,{size:9}),P]},P)),g.location&&e.jsx("span",{className:"text-label text-muted-foreground truncate",children:g.location})]})]})]}),((p==null?void 0:p.companySize)||(p==null?void 0:p.website))&&e.jsxs("div",{className:"grid grid-cols-2 gap-2 mb-4",children:[(p==null?void 0:p.companySize)&&e.jsxs("div",{className:"rounded-xl border border-border/60 p-2.5",children:[e.jsxs("p",{className:"text-micro font-bold uppercase tracking-widest text-muted-foreground mb-0.5 flex items-center gap-1",children:[e.jsx(wr,{size:10}),n.companySize]}),e.jsx("p",{className:"text-small font-semibold text-foreground",children:p.companySize})]}),(p==null?void 0:p.website)&&e.jsxs("a",{href:p.website.startsWith("http")?p.website:`https://${p.website}`,target:"_blank",rel:"noopener noreferrer",className:"rounded-xl border border-border/60 p-2.5 hover:bg-secondary/40 transition-colors",children:[e.jsxs("p",{className:"text-micro font-bold uppercase tracking-widest text-muted-foreground mb-0.5 flex items-center gap-1",children:[e.jsx(as,{size:10}),n.website]}),e.jsx("p",{className:"text-small font-semibold text-primary truncate",children:p.website.replace(/^https?:\/\//,"")})]})]}),(((I=p==null?void 0:p.specialties)==null?void 0:I.length)??0)>0&&e.jsxs("div",{className:"mb-4",children:[e.jsx("p",{className:"text-caption font-bold uppercase tracking-widest text-muted-foreground mb-2",children:n.specialties}),e.jsx("div",{className:"flex flex-wrap gap-2",children:p.specialties.slice(0,4).map(P=>e.jsx("span",{className:"px-3 py-1.5 rounded-full bg-primary/10 border border-primary/20 text-primary text-small font-semibold",children:P},P))})]}),(p==null?void 0:p.licenseNumber)&&e.jsxs("div",{className:"mb-4",children:[e.jsxs("p",{className:"text-caption font-bold uppercase tracking-widest text-muted-foreground mb-1.5 flex items-center gap-1",children:[e.jsx(vr,{size:11}),n.credentials]}),e.jsxs("p",{className:"text-small text-foreground",children:["Lic #",p.licenseNumber]})]}),E&&e.jsxs("div",{className:"mb-4",children:[e.jsx("p",{className:"text-small text-foreground leading-relaxed whitespace-pre-line",children:H}),$&&e.jsx("button",{type:"button",onClick:()=>u(P=>!P),className:"mt-1 text-label font-semibold text-primary",children:d?n.bio.readLess:n.bio.readMore})]}),A&&e.jsxs("div",{className:"mb-4",children:[e.jsx("p",{className:"text-caption font-bold uppercase tracking-widest text-muted-foreground mb-1",children:n.businessHours}),e.jsx("p",{className:"text-small text-muted-foreground",children:A})]}),e.jsxs("div",{className:"space-y-2",children:[S&&e.jsxs("button",{type:"button",onClick:()=>
26{if(J("contractor.subcard.invite_to_bid_tapped",{sub_id:g.userId}),h!=="paid"){w("invite_to_bid");return}k({id:g.userId,name:N})},className:"w-full h-12 rounded-full bg-primary text-primary-foreground text-title font-semibold active:scale-[0.97] transition-transform flex items-center justify-center gap-2",children:[e.jsx(vt,{size:15}),C.action]}),e.jsxs("div",{className:"flex gap-2",children:[a&&e.jsxs("button",{type:"button",onClick:()=>{a(g.userId),s()},className:"flex-1 h-12 rounded-full border border-border text-title font-medium text-foreground active:scale-[0.97] transition-transform flex items-center justify-center gap-2",children:[e.jsx(os,{size:15}),n.cta.text]}),l&&e.jsxs("button",{type:"button",disabled:j,onClick:()=>y({workerId:g.userId}),className:"flex-1 h-12 rounded-full border border-primary/30 bg-primary/10 text-primary text-title font-semibold active:scale-[0.97] transition-transform flex items-center justify-center gap-2 disabled:opacity-60",children:[j?e.jsx(ke,{size:15,className:"animate-spin"}):e.jsx(Yt,{size:15}),n.cta.call]})]}),e.jsx("button",{type:"button",onClick:()=>{r(g.userId),s()},className:"w-full h-10 text-body font-medium text-muted-foreground underline underline-offset-4 active:scale-[0.97] transition-transform",children:n.cta.viewProfile})]})]})]})}),e.jsx(ws,{open:!!v,onOpenChange:P=>{P||k(null)},sub:v})]})}function vs(t){return t.toISOString().slice(0,10)}function na(t){return t===vs(new Date)}function aa(t){const s=new Date;return s.setDate(s.getDate()+1),t===vs(s)}function oa(t,s){const r=new Date(t).getTime();return Number.isFinite(r)&&Date.now()-r<=s*864e5}function ia(t){const s=se(),r=Cr(t),a=Ar(t,{days:3}),i=Pr(t),n=Lr();return{items:x.useMemo(()=>{if(!t)return[];const d=[];return(a.data??[]).forEach(u=>{na(u.shift_date)?d.push({kind:"shift_today",id:`shift_today:${u.id}`,level:"red",shiftId:u.id,jobId:u.job_id,jobTitle:u.job_title,startTime:u.start_time,onOpen:()=>s(`/jobs/${u.job_id}`)}):aa(u.shift_date)&&d.push({kind:"shift_tomorrow",id:`shift_tomorrow:${u.id}`,level:"yellow",shiftId:u.id,jobId:u.job_id,jobTitle:u.job_title,startTime:u.start_time,onOpen:()=>s(`/jobs/${u.job_id}`)})}),(r.data??[]).filter(u=>u.status==="accepted"&&oa(u.updatedAt??u.appliedAt,3)).forEach(u=>{d.push({kind:"application_accepted",id:`application_accepted:${u.id}`,level:"yellow",applicationId:u.id,jobId:u.jobId,jobTitle:u.jobTitle,acceptedAt:u.updatedAt??u.appliedAt,onOpen:()=>s(`/jobs/${u.jobId}`)})}),(i.data??[]).forEach(u=>{d.push({kind:"unread_invitation",id:`unread_invitation:${u.id}`,level:"yellow",invitationId:u.id,jobId:u.jobId,jobTitle:u.jobTitle,contractorId:u.contractorId,onOpen:()=>s(`/jobs/${u.jobId}`)})}),n>0&&d.push({kind:"pending_review",id:"pending_review:worker",level:"yellow",count:n,onOpen:()=>s("/schedule")}),d.sort((u,l)=>{var C,f,S,h;if(u.level!==l.level)return u.level==="red"?-1:1;if(u.level==="red"){const w=u.startTime??"",v=l.startTime??"";return String(w).localeCompare(String(v))}const y=u.kind==="application_accepted"?u.acceptedAt:u.kind==="unread_invitation"?((f=(C=i.data)==null?void 0:C.find(w=>w.id===u.invitationId))==null?void 0:f.invitedAt)??"":"",b=l.kind==="application_accepted"?l.acceptedAt:l.kind==="unread_invitation"?((h=(S=i.data)==null?void 0:S.find(w=>w.id===l.invitationId))==null?void 0:h.invitedAt)??"":"";return String(b).localeCompare(String(y))})},[t,r.data,a.data,i.data,n,s]),isLoading:r.isLoading||a.isLoading||i.isLoading}}function zt(t){if(t.kind==="unread_sub_bids")return String(t.unreadCount);if(t.kind==="pending_review"||t.kind==="package_match")return String(t.count);if(t.kind==="bid_deadline")return String(t.hoursRemaining)}function la(t){return t==="understaffed"?Gt:t==="boost_expiring"?Nt:t==="shift_today"||t==="shift_tomorrow"?Mr:t==="application_accepted"||t==="bid_response"?Fr:t==="unread_invitation"||t==="new_invitation"?Ir:t==="pending_review"?$r:t==="bid_deadline"?Ze:t==="package_match"?Ke:t==="unposted_draft"?br:os}function ca(t,s){var i,n,o,d,u,l,y,b,C,f,S;const r=((n=(i=s==null?void 0:s.home)==null?void 0:i.laborer)==null?void 0:n.attention)??{},a=(d=(o=s==null?void 0:s.home)==null?void 0:o.sub)==null?void 0:d.attention;switch(t.kind){case"understaffed":return t.projectName??t.jobTitle;
26case"shift_today":return(u=r.shiftToday)!=null&&u.title?`${r.shiftToday.title} · ${t.jobTitle}`:t.jobTitle;case"shift_tomorrow":return(l=r.shiftTomorrow)!=null&&l.title?`${r.shiftTomorrow.title} · ${t.jobTitle}`:t.jobTitle;case"application_accepted":return(y=r.applicationAccepted)!=null&&y.title?`${r.applicationAccepted.title} · ${t.jobTitle}`:t.jobTitle;case"unread_invitation":return(b=r.unreadInvitation)!=null&&b.title?`${r.unreadInvitation.title} · ${t.jobTitle}`:t.jobTitle;case"pending_review":return typeof((C=r.pendingReview)==null?void 0:C.title)=="function"?r.pendingReview.title(t.count):((f=r.pendingReview)==null?void 0:f.title)??"Review your recent job";case"bid_response":{const h=t.status;return`${a?a.bidResponse.title(h):h==="accepted"?"Bid accepted":"Bid declined"} · ${t.jobTitle}`}case"bid_deadline":{const h=t.hoursRemaining;return`${a?a.bidDeadline.body(h):`Bid closes in ${h}h`} · ${t.jobTitle}`}case"new_invitation":return a?`${a.newInvitation.title} · ${t.jobTitle}`:t.jobTitle;case"package_match":{const h=t.count;return a?a.packageMatch.title(h):`${h} new sub package${h===1?"":"s"} match you`}case"unposted_draft":return`${(((S=s==null?void 0:s.contractorJobs)==null?void 0:S.attention)??{}).unpostedDraftTitle??"Job saved, never posted"} · ${t.jobTitle}`;default:return t.jobTitle??""}}function da({userId:t,hiringVisible:s,laborerVisible:r=!1,mode:a,onOpenAll:i}){var H,A,O,m,M,I;const{t:n}=K(),{isMulti:o}=Xe(),[d,u]=x.useState(0);x.useEffect(()=>Nr(()=>u(P=>P+1)),[]);const l=o?a??"hiring":s?"hiring":"laborer",y=l==="hiring"&&s,b=l==="laborer"&&r,C=l==="sub",{items:f}=kr(y?t:void 0),{items:S}=ia(b?t:void 0),{items:h}=Er(C?t:void 0),w=y?f:C?h:S,v=ar(0),k=x.useMemo(()=>t?w.filter(P=>!_r(t,P.id,{currentSig:zt(P)})):[],[w,d,t]);if(!s&&!r||!t||k.length===0)return null;const j=k[0],g=j.level==="red",T=la(j.kind),p=((A=(H=n==null?void 0:n.home)==null?void 0:H.attention)==null?void 0:A.overlayAria)??"Needs your attention",N=((m=(O=n==null?void 0:n.home)==null?void 0:O.attention)==null?void 0:m.openAll)??"See all",L=typeof((I=(M=n==null?void 0:n.home)==null?void 0:M.attention)==null?void 0:I.overlayMore)=="function"?n.home.attention.overlayMore(k.length-1):`+${k.length-1}`,E=ca(j,n),$=(P,U)=>{(U.offset.x>90||U.velocity.x>600)&&Sr(t,j.id,zt(j)),v.set(0)};return e.jsx("div",{className:"w-full flex justify-center","aria-live":"polite",children:e.jsxs(ye.button,{type:"button",onClick:()=>{"onOpen"in j&&typeof j.onOpen=="function"&&j.onOpen(),i()},"aria-label":p,drag:"x",dragConstraints:{left:0,right:0},dragElastic:{left:.1,right:.6},style:{x:v},onDragEnd:$,whileTap:{scale:.98},className:`pointer-events-auto max-w-md w-full h-11 flex items-center gap-2 px-3 rounded-full border shadow-[0_4px_14px_rgba(0,0,0,0.25)] backdrop-blur bg-card/95 ${g?"border-red-500/50":"border-amber-500/50"}`,children:[e.jsx("span",{className:`w-6 h-6 shrink-0 rounded-full flex items-center justify-center ${g?"bg-red-500/20 text-red-500":"bg-amber-500/20 text-amber-500"}`,children:e.jsx(T,{className:"w-3.5 h-3.5"})}),e.jsx("span",{className:"flex-1 min-w-0 text-left text-xs font-semibold text-foreground truncate",children:E}),k.length>1&&e.jsx("span",{className:"shrink-0 px-1.5 h-5 rounded-full bg-secondary text-micro font-bold text-foreground/80 flex items-center",children:L}),e.jsxs("span",{className:"shrink-0 flex items-center gap-0.5 text-micro font-semibold text-primary",children:[N,e.jsx(Ye,{className:"w-3 h-3"})]})]})})}const Ns="knuckl.completionNudge.dismissedAt",ua=7*24*60*60*1e3,ma=80;function pa(){try{const t=localStorage.getItem(Ns);if(!t)return!1;const s=parseInt(t,10);return Number.isFinite(s)?Date.now()-s<ua:!1}catch{return!1}}function fa({variant:t="card"}={}){var S,h,w,v,k,j;const{user:s}=te(),r=se(),{t:a}=K(),i=a.completion??{},{data:n}=ge(s==null?void 0:s.id),{data:o}=Rr(s==null?void 0:s.id),d=x.useMemo(()=>n?Or(n,o??{}):null,[n,o]),[u,l]=x.useState(()=>pa());if(!s||!n||!d||d.percent>=ma||u)return null;const y=d.missing.slice(0,3),b=d.missing.length,C=()=>{try{localStorage.setItem(Ns,String(Date.now()))}catch{}l(!0)},f=g=>{var T,p,N;return((N=(p=(T=i.boost)==null?void 0:T.item)==null?void 0:p[g])==null?void 0:N.label)??g};return t==="line"?e.jsxs("div",{className:"flex items-center gap-2 py-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>r("/profile/boost"),className:"flex min-w-0 flex-1 items-center gap-2 text-left",children:[e.jsx("span",{className:"relative h-1.5 w-16 shrink-0 overflow-hidden rounded-full bg-muted",children:e.jsx("span",{className:"absolute inset-y-0 left-0 bg-primary",style:{width:`${d.percent}%`}})}),e.jsx("span",{className:"truncate text-caption font-semibold text-foreground",children:((S=i.nudge)==null?void 0:S.title)??"Boost your profile"}),e.jsxs("span",{className:"shrink-0 text-caption font-bold tabular-nums text-primary",children:[d.percent,"%"]}),e.jsx(bt,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"})]}),e.jsx("button",{type:"button",onClick:C,"aria-label":((h=i.nudge)==null?void 0:h.dismiss)??"Not now",className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-full text-muted-foreground hover:bg-muted",children:e.jsx(be,{className:"h-3.5 w-3.5"})})]}):e.jsx("div",{className:"w-full",children:e.jsxs("div",{className:"rounded-xl border border-primary/30 bg-card/95 backdrop-blur-md shadow-lg p-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-semibold text-foreground truncate",children:((w=i.nudge)==null?void 0:w.title)??"Boost your profile"}),e.jsx("p",{className:"text-caption text-muted-foreground",children:(((v=i.nudge)==null?void 0:v.subt
26itle)??"{n} quick items left").replace("{n}",String(b))})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsxs("span",{className:"text-sm font-bold text-primary tabular-nums",children:[d.percent,"%"]}),e.jsx("button",{type:"button",onClick:C,"aria-label":((k=i.nudge)==null?void 0:k.dismiss)??"Not now",className:"h-7 w-7 rounded-full flex items-center justify-center text-muted-foreground hover:bg-muted",children:e.jsx(be,{className:"w-4 h-4"})})]})]}),e.jsx("div",{className:"mt-2 h-1.5 rounded-full bg-muted overflow-hidden",children:e.jsx("div",{className:"h-full bg-primary transition-all",style:{width:`${d.percent}%`}})}),e.jsxs("div",{className:"mt-2 flex flex-wrap gap-1.5",children:[y.map(g=>e.jsxs("button",{type:"button",onClick:()=>r(g.href),className:"inline-flex items-center gap-1 rounded-full border border-primary/30 bg-primary/10 hover:bg-primary/20 px-2.5 py-1 text-caption font-medium text-primary",children:[f(g.key),e.jsx(bt,{className:"w-3 h-3"})]},g.key)),e.jsx("button",{type:"button",onClick:()=>r("/profile/boost"),className:"inline-flex items-center gap-1 rounded-full px-2.5 py-1 text-caption font-semibold text-primary underline underline-offset-2",children:((j=i.nudge)==null?void 0:j.viewAll)??"See all"})]})]})})}function xa({onCreateProject:t,onPostQuickJob:s,onCreateSubPackage:r}){var f,S,h,w;const{t:a}=K(),[i,n]=x.useState(!1),o=x.useRef(null),d=((f=a==null?void 0:a.home)==null?void 0:f.createPill)??{},u=d.open??"Create",l=((S=d.menuItem)==null?void 0:S.createProject)??"Create project",y=((h=d.menuItem)==null?void 0:h.createQuickJob)??"Create quick job",b=((w=d.menuItem)==null?void 0:w.createSubPackage)??"Create sub package";x.useEffect(()=>{if(!i)return;const v=j=>{var g;(g=o.current)!=null&&g.contains(j.target)||n(!1)},k=j=>{j.key==="Escape"&&n(!1)};return window.addEventListener("pointerdown",v),window.addEventListener("keydown",k),()=>{window.removeEventListener("pointerdown",v),window.removeEventListener("keydown",k)}},[i]);const C=v=>{n(!1),v()};return e.jsxs("div",{ref:o,className:"flex flex-col items-end gap-2",children:[e.jsx("button",{type:"button","aria-label":u,"aria-expanded":i,onClick:()=>n(v=>!v),className:Ve("w-11 h-11 rounded-full bg-card border border-border/60 shadow-md","flex items-center justify-center text-primary","hover:bg-accent/40 active:scale-95 transition-transform"),children:i?e.jsx(be,{className:"w-5 h-5"}):e.jsx(Se,{className:"w-5 h-5",strokeWidth:2.5})}),e.jsx(Qe,{children:i&&e.jsxs(ye.div,{initial:{opacity:0,y:-6,scale:.96},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-6,scale:.96},transition:{duration:.15,ease:"easeOut"},role:"menu",className:"min-w-[200px] rounded-card bg-card border border-border/60 shadow-xl overflow-hidden",children:[e.jsx(pt,{icon:e.jsx(is,{className:"w-4 h-4"}),label:l,onClick:()=>C(t)}),e.jsx(pt,{icon:e.jsx(qr,{className:"w-4 h-4"}),label:y,onClick:()=>C(s)}),e.jsx(pt,{icon:e.jsx(Ke,{className:"w-4 h-4"}),label:b,onClick:()=>C(r)})]})})]})}function pt({icon:t,label:s,onClick:r}){return e.jsxs("button",{type:"button",role:"menuitem",onClick:r,className:"w-full flex items-center gap-3 px-3 py-2.5 text-left text-sm font-medium text-foreground hover:bg-accent/40 active:bg-accent/60 transition-colors",children:[e.jsx("span",{className:"shrink-0 w-7 h-7 rounded-full bg-primary/10 text-primary flex items-center justify-center",children:t}),e.jsx("span",{className:"min-w-0 truncate",children:s})]})}const ba=["general-laborer","cleanup-crew","demo-crew","painter"];function ha(){const{user:t}=te(),{t:s}=K(),r=s.b6.postShortcuts,{data:a}=V({queryKey:["post-shortcuts",t==null?void 0:t.id],enabled:!!(t!=null&&t.id),staleTime:2*6e4,queryFn:async()=>{const{count:n}=await R.from("jobs").select("id",{count:"exact",head:!0}).eq("contractor_id",t.id).in("status",["active","filled"]).is("deleted_at",null),o=await Kr(t.id);return{liveCount:n??0,last:o}}});if(!a||a.liveCount>0)return null;const i=ba.map(n=>ts.find(o=>o.id===n)).filter(n=>!!n);return e.jsxs("div",{className:"rounded-card border border-border/60 bg-card/95 backdrop-blur p-3 space-y-2.5",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:[e.jsx(Nt,{className:"w-3.5 h-3.5 text-primary"}),r.title]}),a.last&&e.jsxs("button",{type:"button",onClick:()=>
26{J("post.repost.opened",{from:"home"}),Dr(a.last)},className:"w-full flex items-center gap-2.5 rounded-xl bg-primary/10 hover:bg-primary/15 transition-colors px-3 py-2.5 text-left",children:[e.jsx(Br,{className:"w-4 h-4 text-primary shrink-0"}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block text-sm font-semibold text-foreground truncate",children:r.repostTitle}),e.jsx("span",{className:"block text-xs text-muted-foreground truncate",children:a.last.title??""})]})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:i.map(n=>e.jsx("button",{type:"button",onClick:()=>{J("post.preset.opened",{chip:n.id}),ls({source:"preset",chipId:n.id,skills:n.skills}),he("flash")},className:"px-3 py-1.5 rounded-full border border-border/60 bg-background/60 text-xs font-medium text-foreground hover:border-primary/60 transition-colors",children:s.b6.flashChips[n.labelKey]??n.label},n.id))})]})}function ga(){var r;const{t}=K(),s=((r=t.appLayout)==null?void 0:r.navProjects)??"Projects";return e.jsxs(or,{to:"/contractor/projects",className:"w-full flex items-center gap-3 rounded-card border border-border/60 bg-card/95 backdrop-blur px-3 py-3 hover:bg-muted/40 transition-colors",children:[e.jsx(is,{className:"w-4 h-4 text-primary shrink-0"}),e.jsx("span",{className:"flex-1 min-w-0 text-sm font-semibold text-foreground truncate",children:s}),e.jsx(Ye,{className:"w-4 h-4 text-muted-foreground shrink-0"})]})}function ya(){const{user:t}=te(),{t:s}=K(),r=s.b6.supplyCard,{data:a}=V({queryKey:["worker-supply",t==null?void 0:t.id],enabled:!!(t!=null&&t.id),staleTime:10*6e4,queryFn:async()=>{const{data:n}=await R.from("profiles").select("lat, lng").eq("user_id",t.id).maybeSingle();if(!(n!=null&&n.lat)||!(n!=null&&n.lng))return null;const{data:o,error:d}=await R.rpc("nearby_worker_supply",{_lat:n.lat,_lng:n.lng,_radius_miles:30});if(d)throw d;return o}});if(!a||a.total<3)return null;const i=(a.top_skills??[]).slice(0,3).map(n=>n.skill);return e.jsxs("button",{type:"button",onClick:()=>{J("supply_card.tapped"),he("flash")},className:"w-full text-left rounded-card border border-border/60 bg-card/95 backdrop-blur p-3 space-y-1.5 active:scale-[0.99] transition-transform",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:[e.jsx(wt,{className:"w-3.5 h-3.5 text-primary"}),r.title]}),e.jsx("p",{className:"text-sm font-semibold text-foreground",children:r.workersNearby(a.total)}),a.available_now>0&&e.jsx("p",{className:"text-xs text-muted-foreground",children:r.availableNow(a.available_now)}),i.length>0&&e.jsx("p",{className:"text-xs text-muted-foreground",children:r.mostCommon(i.join(", "))}),e.jsx("p",{className:"text-xs font-semibold text-primary pt-0.5",children:r.cta})]})}function ja(){var T,p,N,L,E,$,H;const{t}=K(),s=se(),{user:r}=te(),{data:a}=ge(r==null?void 0:r.id),{updateLaborer:i,isUpdating:n}=Hr((r==null?void 0:r.id)??""),[o,d]=x.useState(!1),u=x.useRef(null),l=x.useRef(!1),y=((T=t==null?void 0:t.home)==null?void 0:T.laborerPill)??{},b=y.open??"Quick actions",C=((p=y.menuItem)==null?void 0:p.toggleAvailability)??"I'm available today",f=((N=y.menuItem)==null?void 0:N.toggleAvailabilityOn)??"You're marked available",S=((L=y.menuItem)==null?void 0:L.toggleAvailabilityOff)??"Marked unavailable",h=((E=y.menuItem)==null?void 0:E.viewSchedule)??"View schedule",w=(($=y.menuItem)==null?void 0:$.browseCrews)??"Browse crews";x.useEffect(()=>{if(!o)return;const A=m=>{var M;(M=u.current)!=null&&M.contains(m.target)||d(!1)},O=m=>{m.key==="Escape"&&d(!1)};return window.addEventListener("pointerdown",A),window.addEventListener("keydown",O),()=>{window.removeEventListener("pointerdown",A),window.removeEventListener("keydown",O)}},[o]);const k=(((H=a==null?void 0:a.laborer)==null?void 0:H.availability)??"unavailable")==="available",j=async()=>{if(l.current||n||!r)return;l.current=!0;const A=k?"unavailable":"available";try{await i({availability:A}),B.success(A==="available"?f:S,{duration:2e3})}catch{B.error(y.updateFailed??"Couldn't update availability",{duration:2e3})}finally{l.current=!1,d(!1)}},g=A=>{d(!1),A()};return e.jsxs("div",{ref:u,className:"flex flex-col items-end gap-2",children:[e.jsx("button",{type:"button","aria-label":b,"aria-expanded":o,onClick:()=>d(A=>!A),className:Ve("w-11 h-11 rounded-full bg-card border border-border/60 shadow-md","flex items-center justify-center text-primary","hover:bg-accent/40 active:scale-95 transition-transform"),children:o?e.jsx(be,{className:"w-5 h-5"}):e.jsx(Se,{className:"w-5 h-5",strokeWidth:2.5})}),e.jsx(Qe,{children:o&&e.jsxs(ye.div,{initial:{opacity:0,y:-6,scale:.96}
26,animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-6,scale:.96},transition:{duration:.15,ease:"easeOut"},role:"menu",className:"min-w-[220px] rounded-card bg-card border border-border/60 shadow-xl overflow-hidden",children:[e.jsx(ft,{icon:e.jsx(Nt,{className:"w-4 h-4"}),label:C,hint:k?"On":"Off",onClick:j,disabled:n}),e.jsx(ft,{icon:e.jsx(Kn,{className:"w-4 h-4"}),label:h,onClick:()=>g(()=>s("/schedule"))}),e.jsx(ft,{icon:e.jsx(wt,{className:"w-4 h-4"}),label:w,onClick:()=>g(()=>s("/worker/crew-map"))})]})})]})}function ft({icon:t,label:s,hint:r,onClick:a,disabled:i}){return e.jsxs("button",{type:"button",role:"menuitem",onClick:a,disabled:i,className:"w-full flex items-center gap-3 px-3 py-2.5 text-left text-sm font-medium text-foreground hover:bg-accent/40 active:bg-accent/60 transition-colors disabled:opacity-50",children:[e.jsx("span",{className:"shrink-0 w-7 h-7 rounded-full bg-primary/10 text-primary flex items-center justify-center",children:t}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:s}),r&&e.jsx("span",{className:"shrink-0 text-micro font-semibold text-muted-foreground uppercase tracking-wide",children:r})]})}function wa(){var g,T,p,N,L,E;const{t}=K(),{user:s}=te(),r=se(),[a,i]=x.useState(!1),n=x.useRef(null),{available:o,setAvailable:d,isSaving:u}=cs(s==null?void 0:s.id),l=x.useRef(!1),y=((g=t==null?void 0:t.home)==null?void 0:g.subPill)??{},b=y.open??"Sub actions",C=((T=y.menuItem)==null?void 0:T.toggleAvailability)??"Available for sub work",f=((p=y.menuItem)==null?void 0:p.toggleAvailabilityOn)??"Marked available",S=((N=y.menuItem)==null?void 0:N.toggleAvailabilityOff)??"Marked unavailable",h=((L=y.menuItem)==null?void 0:L.viewBids)??"View my bids",w=((E=y.menuItem)==null?void 0:E.browsePackages)??"Browse packages",v=y.updateFailed??"Couldn't update availability";x.useEffect(()=>{if(!a)return;const $=A=>{var O;(O=n.current)!=null&&O.contains(A.target)||i(!1)},H=A=>{A.key==="Escape"&&i(!1)};return window.addEventListener("pointerdown",$),window.addEventListener("keydown",H),()=>{window.removeEventListener("pointerdown",$),window.removeEventListener("keydown",H)}},[a]);const k=$=>{i(!1),$()},j=async()=>{if(l.current||u)return;l.current=!0;const $=!o;try{await d($),B.success($?f:S,{duration:1600})}catch{B.error(v,{duration:2e3})}finally{l.current=!1,i(!1)}};return e.jsxs("div",{ref:n,className:"flex flex-col items-end gap-2",children:[e.jsx("button",{type:"button","aria-label":b,"aria-expanded":a,onClick:()=>i($=>!$),className:Ve("w-11 h-11 rounded-full bg-card border border-border/60 shadow-md","flex items-center justify-center text-primary","hover:bg-accent/40 active:scale-95 transition-transform"),children:a?e.jsx(be,{className:"w-5 h-5"}):e.jsx(Se,{className:"w-5 h-5",strokeWidth:2.5})}),e.jsx(Qe,{children:a&&e.jsxs(ye.div,{initial:{opacity:0,y:-6,scale:.96},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-6,scale:.96},transition:{duration:.15,ease:"easeOut"},role:"menu",className:"min-w-[220px] rounded-card bg-card border border-border/60 shadow-xl overflow-hidden",children:[e.jsx(xt,{icon:u?e.jsx(ke,{className:"w-4 h-4 animate-spin"}):o?e.jsx(Un,{className:"w-4 h-4"}):e.jsx(Hn,{className:"w-4 h-4"}),label:`${C}${o?" ✓":""}`,onClick:j,disabled:u}),e.jsx(xt,{icon:e.jsx(Ur,{className:"w-4 h-4"}),label:h,onClick:()=>k(()=>r("/profile/bids"))}),e.jsx(xt,{icon:e.jsx(Ke,{className:"w-4 h-4"}),label:w,onClick:()=>k(()=>r("/contractor/sub-jobs"))})]})})]})}function xt({icon:t,label:s,onClick:r,disabled:a}){return e.jsxs("button",{type:"button",role:"menuitem",onClick:r,disabled:a,className:"w-full flex items-center gap-3 px-3 py-2.5 text-left text-sm font-medium text-foreground hover:bg-accent/40 active:bg-accent/60 transition-colors disabled:opacity-50",children:[e.jsx("span",{className:"shrink-0 w-7 h-7 rounded-full bg-primary/10 text-primary flex items-center justify-center",children:t}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:s})]})}const Jt="knuckl.subUx.freeCard.dismissedAt",va=7*24*60*60*1e3;function Na(){const{t}=K(),{openUpgrade:s}=Wr(),[r,a]=x.useState(!1);if(x.useEffect(()=>{try{const o=localStorage.getItem(Jt);if(!o){a(!0);return}const d=Number(o);(!Number.isFinite(d)||Date.now()-d>va)&&a(!0)}catch{a(!0)}},[]),!r)return null;const i=()=>{try{localStorage.setItem(Jt,String(Date.now()))}catch{}a(!1)},n=t.subUx;return e.jsx("div",{className:"w-full",children:e.jsx(zr,{icon:Wn,title:n.freeCardTitle,body:n.freeCardBody,primaryCta:n.freeCardCta,onPrimary:()=>s("sub_bid"),secondaryCta:n.freeCardDismiss,onSecondary:i,dismissible:!0,onDismiss:i,className:"bg-card/95 backdrop-blur shadow-lg"})})}const ks=t=>`knuckl.roleSuggest.${t}`,ka=14*24*60*60*1e3,_a={sub:["laborer","hiring"],laborer:["sub","hiring"],hiring:["sub","laborer"]};function Sa(t){try{const s=window.localStorage.getItem(ks(t));if(!s)return!1;const r=Number(s);return Number.isFinite(r)?Date.now()-r<ka:!1}catch{return!1}}function Ca(t){try{window.localStorage.setItem(ks(t),String(Date.now()))}catch{}}function Pa(){const{user:t}=te(),{data:s}=ge(t==null?void 0:t.id),{t:r}=K(),a=se(),[i,n]=x.useState(0),[,o]=x.useState(0),d=x.useMemo(()=>
26{if(!s)return null;const w={hiring:!!s.hiringVisible,sub:!!s.subVisible,laborer:!!s.laborerVisible},v=Object.entries(w).filter(([,k])=>k).map(([k])=>k);return v.length===1?v[0]:null},[s]);if(!d)return null;const u=_a[d].filter(w=>!Sa(w));if(u.length===0)return null;const l=u[i%u.length],y=`${d}To${l==="hiring"?"Contractor":l==="sub"?"Sub":"Worker"}`,b=r.roles.suggest[y],C=s!=null&&s.hiringVisible?"/contractor/settings":"/worker/settings",f=()=>a(`${C}?role=${l}`),S=()=>{Ca(l),o(w=>w+1),n(0)},h=()=>n(w=>w+1);return e.jsx("div",{className:"rounded-card border border-primary/25 bg-card/95 backdrop-blur-md p-3 shadow-lg",role:"region","aria-label":b.title,children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-8 h-8 shrink-0 rounded-xl bg-primary/15 text-primary flex items-center justify-center",children:e.jsx(kt,{className:"w-4 h-4"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-sm font-semibold text-foreground",children:b.title}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:b.body}),e.jsxs("div",{className:"mt-2 flex items-center gap-2 flex-wrap",children:[e.jsx("button",{type:"button",onClick:f,className:"h-8 px-3 rounded-full bg-primary text-primary-foreground text-xs font-semibold",children:b.cta}),u.length>1&&e.jsx("button",{type:"button",onClick:h,className:"h-8 px-3 rounded-full border border-border text-xs text-muted-foreground",children:r.roles.suggest.seeOther}),e.jsx("button",{type:"button",onClick:S,className:"h-8 px-2 text-xs text-muted-foreground",children:r.roles.suggest.dismiss})]})]}),e.jsx("button",{type:"button",onClick:S,"aria-label":r.roles.suggest.dismiss,className:"w-7 h-7 shrink-0 rounded-full flex items-center justify-center text-muted-foreground hover:bg-muted",children:e.jsx(be,{className:"w-4 h-4"})})]})})}function Ta(){const{tr:t}=K(),s=se(),{data:r}=V({queryKey:["homeowner-leads-card"],staleTime:6e4,queryFn:async()=>{const{data:n,error:o}=await R.rpc("homeowner_leads_feed",{_limit:25,_offset:0});if(o)throw o;return n}}),i=((r==null?void 0:r.leads)??[]).filter(n=>!n.responded);return i.length===0?null:e.jsxs("button",{type:"button",onClick:()=>s("/homeowner-leads"),className:"w-full rounded-card border border-[hsl(var(--entity-homeowner))]/40 bg-card/95 backdrop-blur px-4 py-3 shadow-sm flex items-center gap-3 text-left",children:[e.jsx("span",{className:"w-9 h-9 rounded-xl bg-[hsl(var(--entity-homeowner))]/15 grid place-items-center shrink-0",children:e.jsx(ds,{className:"w-4 h-4 text-[hsl(var(--entity-homeowner))]"})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsxs("span",{className:"block text-sm font-semibold truncate",children:[i.length," homeowner project",i.length===1?"":"s"," near you"]}),e.jsx("span",{className:"block text-caption text-muted-foreground truncate",children:t("homeownerLeadsCard.subtitle")})]}),e.jsx(Ye,{className:"w-4 h-4 text-muted-foreground shrink-0"})]})}const Aa=[[/roof|shingle|gutter/i,["Asphalt Shingles"]],[/tile|shower|backsplash/i,["Tiling"]],[/bath|tub|toilet|sink|faucet|water heater|plumb|pipe|drain/i,["Rough Plumbing"]],[/electric|wiring|outlet|panel|light fixture|dryer conversion/i,["Residential Electrical"]],[/hvac|air condition|\bac\b|furnace|duct|vent/i,["HVAC Install"]],[/drywall|sheetrock/i,["Drywall Hanging"]],[/paint|stucco/i,["Interior Painting"]],[/concrete|driveway|asphalt|slab|paver/i,["Concrete Pouring"]],[/frame|framing|addition|garage|deck|carpent|cabinet|door|window|trim/i,["Framing"]],[/epoxy/i,["Epoxy Floors"]],[/floor/i,["Laminate / LVP"]],[/landscap|lawn|yard|mow|irrigation|sod|tree/i,["Lawn Mowing / Maintenance"]],[/demo|tear ?out|junk|haul|debris/i,["Demolition"]],[/clean|pressure wash/i,["General Labor"]],[/fence/i,["Fencing"]],[/pool/i,["General Labor"]]];function La(t){const s=(t??"").trim();if(!s)return["General Labor"];const r=gt.find(a=>a.toLowerCase()===s.toLowerCase());if(r)return[r];for(const[a,i]of Aa)if(a.test(s)){const n=i.filter(o=>gt.includes(o));if(n.length)return n}return["General Labor"]}
26function Ea(t,s){const r=[t,s].filter(Boolean);return r.length?r.join(", "):void 0}function _s(t){const s=La(t.trade),r=(t.trade??"").trim(),a=(t.body??"").trim().slice(0,400);ls({source:t.kind==="external"?"lead_conversion":"homeowner_conversion",skills:s,title:r?`${r} help needed`:t.title??void 0,description:a||void 0,location:Ea(t.city,t.state),sourceLeadId:t.leadId,sourceLeadKind:t.kind}),J("lead.convert.opened",{kind:t.kind,lead_id:t.leadId}),he("flash")}function Ma({leadId:t,meta:s,distanceMi:r,onClose:a}){const i=se(),{tr:n}=K(),{hiring:o}=Xe(),d=_e(),u=!!t&&!!s;return x.useEffect(()=>{u&&us(t)},[u,t]),e.jsx($e,{open:u,onOpenChange:l=>!l&&a(),children:e.jsx(Re,{side:"bottom",className:"rounded-t-2xl",children:s&&e.jsxs(e.Fragment,{children:[e.jsx(Oe,{className:"text-left",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"w-9 h-9 rounded-xl bg-[hsl(var(--entity-homeowner))]/15 grid place-items-center shrink-0",children:e.jsx(ds,{className:"w-4 h-4 text-[hsl(var(--entity-homeowner))]"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded-full bg-[hsl(var(--entity-homeowner))]/15 text-[hsl(var(--entity-homeowner))] text-micro font-bold uppercase tracking-wider",children:n("entityLabels.homeowner")}),e.jsx(qe,{className:"text-base truncate",children:Gr(n,s.trade,Qr)})]})]})}),e.jsxs("div",{className:"mt-3 space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-muted-foreground",children:[e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(De,{className:"w-3 h-3"}),[s.city,s.state].filter(Boolean).join(", ")||n("homeowner.feed.nearby"),r!=null&&` · ${r} mi`]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Ze,{className:"w-3 h-3"}),Me(s.created_at)]})]}),e.jsxs("p",{className:"text-sm text-foreground/90",children:[s.description,s.locked&&"…"]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-caption",children:[e.jsx("span",{className:"px-2 py-0.5 rounded-full bg-muted",children:Yr(n,s.timeline)}),s.budget_band&&e.jsx("span",{className:"px-2 py-0.5 rounded-full bg-muted",children:s.budget_band}),s.responded?e.jsx("span",{className:"px-2 py-0.5 rounded-full bg-primary/15 text-primary",children:n("homeowner.feed.youReplied")}):e.jsx("span",{className:"text-muted-foreground",children:s.response_count===0?n("homeowner.feed.noProsYet"):s.response_count===1?n("homeowner.feed.proReplied"):n("homeowner.feed.prosReplied",{count:s.response_count})})]}),!s.locked&&o&&e.jsxs("div",{className:"rounded-xl border border-primary/40 bg-primary/5 p-3",children:[e.jsxs(G,{className:"w-full rounded-xl h-11",onClick:()=>{a(),_s({leadId:t,kind:"homeowner",trade:s.trade,body:s.description,city:s.city,state:s.state})},children:[e.jsx(Ge,{className:"w-4 h-4 mr-1.5"}),n("homeowner.map.postAsJob")]}),e.jsx("p",{className:"text-caption text-muted-foreground mt-1.5 text-center",children:n("homeowner.map.postAsJobHint")})]}),s.locked?e.jsxs("div",{className:"rounded-xl border border-primary/40 bg-primary/10 p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx(kt,{className:"w-4 h-4 text-primary"}),n("homeowner.feed.paidFeature")]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:n("homeowner.map.approxLocation")}),e.jsxs(G,{className:"mt-3 w-full rounded-xl h-11",onClick:()=>{a(),d.open("generic",n("homeowner.feed.paidBody"))},children:[e.jsx(ms,{className:"w-4 h-4 mr-1.5"}),n("homeowner.feed.startTrial")]})]}):e.jsx(G,{className:"w-full rounded-xl h-11",onClick:()=>{a(),i(`/homeowner-leads/${t}`)},children:n("homeowner.map.viewRequest")})]})]})})})}function Fa({leadId:t,meta:s,distanceMi:r,onClose:a}){var H;const{tr:i}=K(),{hiring:n}=Xe(),o=_e(),d=!!t&&!!s,{notes:u,addNote:l,deleteNote:y,setStatus:b}=ln(d?t:null),[C,f]=x.useState(""),[S,h]=x.useState(null),[w,v]=x.useState(""),[k,j]=x.useState(!1),g=en(s??{}),T=tn(s),p=ps[g],N=((H=on[g])==null?void 0:H.Icon)??dn,L=A=>i(`external.notes.status${A.charAt(0).toUpperCase()}${A.slice(1)}`);x.useEffect(()=>{!d||!s||(us(t),f(""),h(null),j(!1),v(i("external.notes.draftTemplate").replace("{trade}",s.trade||"").replace("{city}",s.city||"").replace(/\s{2,}/g," ")))},[t,d]);const E=async()=>{try{await navigator.clipboard.writeText(w),j(!0),mt({description:i("external.notes.copied")}),window.setTimeout(()=>j(!1),2e3)}catch{}},$=()=>{const A=C.trim();A&&l.mutate(A,{onSuccess:()=>f(""),onError:()=>mt({description:i("external.notes.saveFailed"),variant:"destructive"})})};return e.jsx($e,{open:d,onOpenChange:A=>!A&&a(),children:e.jsx(Re,{side:"bottom",className:"rounded-t-2xl",children:s&&e.jsxs(e.Fragment,{children:[e.jsx(Oe,{className:"text-left",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"w-9 h-9 rounded-xl grid place-items-center shrink-0",style:{backgroundColor:`${p}26`},children:e.jsx(N,{className:"w-4 h-4",style:{color:p}})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded-full text-micro font-bold uppercase tracking-wider",style:{backgroundColor:`${p}26`,color:p},children:i(`external.pinKind.${g}`)}),s.source_label&&e.jsx("span",{className:"ml-1.5 text-micro text-muted-foreground uppercase tracking-wider",children:s.source_label}),s.matches_trades&&e.jsx("span",{className:"ml-1.5 inline-flex items-center px-1.5 py-0.5 rounded-full bg-primary/15 text-primary text-micro font-bold uppercase tracking-wider",children:i("external.feed.matchesTrades")}),e.jsx(qe,{className:"text-base truncate",children:T.headline||i("entityLabels.external")}),e.jsxs("div",{className:"flex items-center gap-2 text-caption text-muted-foreground",children:[T.hasAddress&&(s.title||s.trade)&&e.jsx("span",{className:"truncate",children:s.title||s.trade}),T.reference&&e.jsx("span",{className:"font-mono shrink-0",children:T.reference})]})]})]})}),e.jsxs("div",{className:"mt-3 space-y-3 overflow-y-auto max-h-[65vh] pb-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-muted-foreground",children:[e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(De,{className:"w-3 h-3"}
26),[s.city,s.state].filter(Boolean).join(", ")||i("external.feed.nearby"),r!=null&&` · ${r} mi`]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Ze,{className:"w-3 h-3"}),Me(s.posted_at)]})]}),s.permit_owner_type==="owner"&&e.jsx("p",{className:"text-xs text-primary font-medium",children:i("external.kind.ownerPulled")}),s.permit_owner_type==="contractor"&&e.jsx("p",{className:"text-xs text-muted-foreground",children:i("external.kind.contractorPulled")}),Ht(s.acts_by)&&e.jsx("p",{className:"text-xs text-muted-foreground",children:i("external.kind.actsBy").replace("{date}",Ht(s.acts_by))}),!s.locked&&e.jsx("div",{role:"group","aria-label":i("external.notes.statusLabel"),className:"flex gap-1.5 overflow-x-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",children:cn.map(A=>{const O=(S||s.my_status||"new")===A;return e.jsx("button",{type:"button","aria-pressed":O,disabled:b.isPending,onClick:()=>{const m=S;h(A),b.mutate(A,{onError:()=>{h(m),mt({description:i("external.notes.saveFailed"),variant:"destructive"})}})},className:`shrink-0 px-3 h-8 rounded-full border text-xs transition-colors ${O?"border-primary/60 bg-primary/15 text-primary font-semibold":"border-border/60 text-muted-foreground"}`,children:L(A)},A)})}),e.jsxs("p",{className:"text-sm text-foreground/90 whitespace-pre-line line-clamp-6",children:[s.body,s.locked&&"…"]}),s.location_precision!=="exact"&&e.jsx("p",{className:"text-caption text-muted-foreground",children:i("external.feed.approxLocation")}),e.jsx("p",{className:"text-caption text-muted-foreground",children:i("external.feed.disclaimer")}),!s.locked&&n&&e.jsxs("div",{className:"rounded-xl border border-primary/40 bg-primary/5 p-3",children:[e.jsxs(G,{className:"w-full rounded-xl h-11",onClick:()=>{a(),_s({leadId:t,kind:"external",trade:s.trade,title:s.title,body:s.body,city:s.city,state:s.state})},children:[e.jsx(Ge,{className:"w-4 h-4 mr-1.5"}),i("external.feed.postAsJob")]}),e.jsx("p",{className:"text-caption text-muted-foreground mt-1.5 text-center",children:i("external.feed.postAsJobHint")})]}),s.locked||!s.source_url?e.jsxs("div",{className:"rounded-xl border border-primary/40 bg-primary/10 p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx(kt,{className:"w-4 h-4 text-primary"}),i("external.feed.paidFeature")]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:i("external.feed.paidBody")}),e.jsxs(G,{className:"mt-3 w-full rounded-xl h-11",onClick:()=>{a(),o.open("generic",i("external.feed.paidBody"))},children:[e.jsx(ms,{className:"w-4 h-4 mr-1.5"}),i("external.feed.startTrial")]})]}):e.jsxs(G,{className:"w-full rounded-xl h-11",onClick:()=>{window.open(s.source_url,"_blank","noopener,noreferrer")},children:[e.jsx(as,{className:"w-4 h-4 mr-1.5"}),i("external.feed.openOriginal")]}),!s.locked&&e.jsxs(e.Fragment,{children:[t&&e.jsx(Xr,{targetType:"external_lead",targetId:t,title:s.title,trade:s.trade}),e.jsxs("div",{className:"rounded-xl border border-border/60 bg-card/60 p-3",children:[e.jsx("div",{className:"text-sm font-semibold mb-2",children:i("external.notes.draftTitle")}),e.jsx(Je,{value:w,onChange:A=>v(A.target.value),rows:4,className:"text-sm rounded-lg"}),e.jsxs(G,{variant:"outline",className:"mt-2 w-full rounded-xl h-10",onClick:E,children:[k?e.jsx(Ue,{className:"w-4 h-4 mr-1.5"}):e.jsx(un,{className:"w-4 h-4 mr-1.5"}),i("external.notes.copy")]})]}),e.jsxs("div",{className:"rounded-xl border border-border/60 bg-card/60 p-3",children:[e.jsx("div",{className:"text-sm font-semibold mb-2",children:i("external.notes.title")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Je,{value:C,onChange:A=>f(A.target.value),rows:2,placeholder:i("external.notes.placeholder"),className:"text-sm rounded-lg"}),e.jsx(G,{size:"icon","aria-label":i("external.notes.add"),className:"h-10 w-10 shrink-0 rounded-xl",disabled:!C.trim()||l.isPending,onClick:$,children:e.jsx(Se,{className:"w-4 h-4"})})]}),e.jsx("div",{className:"mt-3 space-y-2",children:(u.data??[]).length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:i("external.notes.empty")}):(u.data??[]).map(A=>e.jsxs("div",{className:"flex items-start gap-2 rounded-lg bg-secondary/40 p-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-sm whitespace-pre-line break-words",children:A.body}),e.jsx("p",{className:"text-caption text-muted-foreground mt-0.5",children:Me(A.created_at)})]}),e.jsx("button",{type:"button","aria-label":i("external.notes.delete"),onClick:()=>y.mutate(A.id),className:"p-1.5 text-muted-foreground hover:text-destructive",children:e.jsx(xs,{className:"w-3.5 h-3.5"})})]},A.id))})]})]})]})]})})})}function Ia(){const{user:t}=te(),{data:s=0}=V({queryKey:["contractor-open-jobs-count",t==null?void 0:t.id],enabled:!!(t!=null&&t.id),staleTime:6e4,queryFn:async()=>{const{count:r}=await R.from("jobs").select("id",{count:"exact",head:!0}).eq("contractor_id",t.id).in("status",["open","active"]);return r??0}});return e.jsx(mn,{variant:"contractor",show:s>0})}function $a({mode:t,onModeChange:s,hiring:r,sub:a,laborer:i}){var S;const{t:n}=K(),o=((S=n==null?void 0:n.home)==null?void 0:S.modeToggle)??{},d=o.hiring??"Hiring",u=o.sub??"Sub",l=o.laborer??"Looking for work",y=o.aria??"Switch Home mode",b=h=>{h!==t&&(bn(),s(h))},f=[{mode:"hiring",icon:Ge,label:d,show:r},{mode:"sub",icon:Ke,label:u,show:a},{mode:"laborer",icon:hn,label:l,show:i}].filter(h=>h.show);return f.length<2?null:e.jsx("div",{className:"pointer-events-auto",role:"tablist","aria-label":y,children:e.jsx("div",{className:"relative flex items-center h-11 rounded-full bg-card/95 border border-border/60 shadow-md backdrop-blur px-1 gap-1",children:f.map(h=>{const w=h.icon;return e.jsx(Ra,{active:t===h.mode,icon:e.jsx(w,{className:"w-3 h-3"}),label:h.label,onClick:()=>b(h.mode)},h.mode)})})})}function Ra({active:t,icon:s,label:r,onClick:a}){return e.jsxs("button",{type:"button",role:"tab","aria-selected":t,onClick:a,className:Ve("relative h-9 px-2 sm:px-3 rounded-full text-caption font-semibold flex items-center gap-1 transition-colors",t?"text-primary-foreground":"text-muted-foreground hover:text-foreground"),children:[t&&e.jsx(ye.span,{layoutId:"home-mode-toggle-active",className:"absolute inset-0 rounded-full bg-primary shadow-[0_2px_10px_rgba(228,109,44,0.35)]",transition:{type:"spring",stiffness:500,damping:40}}),e.jsxs("span",{className:"relative flex items-center gap-1",children:[s,e.jsx("span",{className:"hidden sm:inline whitespace-nowrap",children:r}),e.jsx("span",{className:"sr-only sm:hidden",children:r})]})]})}function Oa({modeToggle:t,attention:s,subNudge:r,nudge:a,quickAction:i,search:n,bottom:o}){var S,h;const{t:d}
26=K(),u=!!(t||s||r||a||i||n),l=x.useRef(null),[y,b]=x.useState(!0),C=((S=d==null?void 0:d.home)==null?void 0:S.cardsExpand)??"Show cards",f=((h=d==null?void 0:d.home)==null?void 0:h.cardsCollapse)??"Hide cards";return e.jsxs(e.Fragment,{children:[u&&e.jsxs("div",{className:"absolute top-3 left-3 right-3 z-[500] flex flex-col gap-2 pointer-events-none",children:[(t||i)&&e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsx("div",{className:"pointer-events-auto min-w-0",children:t}),e.jsx("div",{className:"pointer-events-auto shrink-0",children:i})]}),n&&e.jsx("div",{className:"w-full",children:n}),(s||r||a)&&e.jsxs("div",{className:"flex flex-col gap-2 max-w-md",children:[s&&e.jsx("div",{className:"pointer-events-auto w-full flex justify-start",children:s}),r&&e.jsx("div",{className:"pointer-events-auto w-full",children:r}),a&&e.jsx("div",{className:"pointer-events-auto w-full",children:a})]})]}),o&&e.jsxs("div",{className:"absolute left-3 right-3 z-20 pointer-events-none mx-auto max-w-md flex flex-col items-center gap-2",style:{bottom:"calc(var(--app-bottom-nav-h, 64px) + 16px)"},children:[e.jsxs("button",{type:"button",onClick:()=>b(w=>!w),"aria-expanded":!y,"aria-label":y?C:f,className:"pointer-events-auto inline-flex items-center gap-1 rounded-full border border-border/60 bg-card/95 backdrop-blur px-3 py-1 text-caption font-medium text-muted-foreground shadow-sm",children:[y?e.jsx(gn,{className:"h-3.5 w-3.5"}):e.jsx(yn,{className:"h-3.5 w-3.5"}),e.jsx("span",{children:y?C:f})]}),e.jsx("div",{ref:l,className:`w-full pointer-events-auto max-h-[42dvh] overflow-y-auto ${y?"hidden":""}`,children:o})]})]})}function qa({areaMode:t,onToggleArea:s,circle:r,onRadiusChange:a,onClearCircle:i,count:n}){const{tr:o}=K();return e.jsxs("div",{className:"pointer-events-none",children:[e.jsx("div",{className:"flex items-center justify-end gap-2",children:e.jsxs("button",{type:"button","aria-pressed":t||!!r,onClick:s,className:`pointer-events-auto shrink-0 h-10 px-3 inline-flex items-center gap-1.5 rounded-full border text-xs font-semibold shadow-sm backdrop-blur ${t||r?"border-primary/60 bg-primary/15 text-primary":"border-border/60 bg-card/95 text-muted-foreground"}`,children:[e.jsx(jn,{className:"w-4 h-4 shrink-0"}),e.jsx("span",{className:"hidden min-[360px]:inline",children:r?o("external.feed.areaRadius").replace("{miles}",String(r.radiusMi)):o("external.feed.areaDraw")})]})}),t&&!r?e.jsx("p",{className:"pointer-events-none mt-2 inline-block rounded-full bg-card/95 px-3 py-1 text-xs text-muted-foreground shadow-sm backdrop-blur",children:o("external.feed.areaHint")}):null,r?e.jsxs("div",{className:"pointer-events-auto ml-auto mt-2 flex max-w-sm items-center gap-2 rounded-full border border-border/60 bg-card/95 px-3 py-1.5 shadow-sm backdrop-blur",children:[e.jsx("input",{type:"range",min:2,max:100,step:1,value:r.radiusMi,"aria-label":o("external.feed.areaRadius").replace("{miles}",String(r.radiusMi)),onChange:d=>a(Number(d.target.value)),className:"flex-1 accent-[hsl(var(--primary))]"}),e.jsx("span",{className:"shrink-0 text-xs text-muted-foreground",children:o("external.feed.areaCount").replace("{count}",String(n))}),e.jsx("button",{type:"button",onClick:i,className:"shrink-0 text-xs font-semibold text-primary",children:o("external.feed.areaClear")}
26)]}):null]})}function Da({workerId:t,label:s}){const{data:r=!1}=rs(t,!0),{initiateCall:a,isCalling:i}=ns();if(!r)return null;const n=i(t);return e.jsx("button",{type:"button","aria-label":s,disabled:n,onClick:o=>{o.stopPropagation(),a({workerId:t})},className:"h-9 w-9 rounded-full border border-border flex items-center justify-center text-muted-foreground disabled:opacity-60",children:n?e.jsx(ke,{className:"w-4 h-4 animate-spin"}):e.jsx(Yt,{className:"w-4 h-4"})})}const Vt=20,Ss=x.createContext(null);function Cs(){const t=x.useContext(Ss);if(!t)throw new Error("PeopleFirst slots must render inside PeopleFirstProvider");return t}function Ka({children:t}){const{user:s}=te(),[r,a]=x.useState(null),[i,n]=x.useState(null),{data:o}=V({queryKey:["contractor-origin",s==null?void 0:s.id],enabled:!!s,queryFn:async()=>{const{data:h}=await R.from("contractor_profiles").select("lat, lng, city, location").eq("user_id",s.id).maybeSingle();let w=(h==null?void 0:h.lat)??null,v=(h==null?void 0:h.lng)??null;const k=(h==null?void 0:h.city)||(h==null?void 0:h.location);if((w==null||v==null)&&k&&k.trim())try{const j=await Nn(k);j&&(w=j.lat,v=j.lng,await R.from("contractor_profiles").update({lat:w,lng:v,city:j.city||((h==null?void 0:h.city)??null)}).eq("user_id",s.id))}catch{}return{lat:w,lng:v}}}),d=wn({queryKey:["people-first-workers",Wt],enabled:!!s,staleTime:5*60*1e3,queryFn:async()=>{const h=R.from("worker_profiles_public").select("user_id, skills, approx_lat, approx_lng, is_available_today, created_at");Wt||h.eq("is_seed",!1);const[w,v]=await Promise.all([R.from("profiles_public").select("user_id, full_name, avatar_url").eq("role","worker"),h]);if(v.error)throw v.error;const k=Object.fromEntries((v.data??[]).map(j=>[j.user_id,j]));return(w.data??[]).filter(j=>k[j.user_id]).filter(j=>{const g=k[j.user_id],T=!!(j.full_name&&j.full_name.trim()),p=Array.isArray(g==null?void 0:g.skills)&&g.skills.length>0;return T||p}).map(j=>{const g=k[j.user_id];return{user_id:j.user_id,full_name:j.full_name||"Unknown Worker",avatar_url:j.avatar_url??null,skills:(g==null?void 0:g.skills)??[],lat:(g==null?void 0:g.approx_lat)??null,lng:(g==null?void 0:g.approx_lng)??null,isAvailableToday:!!(g!=null&&g.is_available_today),created_at:(g==null?void 0:g.created_at)??null}}).filter(j=>j.user_id!==(s==null?void 0:s.id))}}),u=(o==null?void 0:o.lat)!=null&&(o==null?void 0:o.lng)!=null,l=h=>!u||h.lat==null||h.lng==null?null:vn(o.lat,o.lng,h.lat,h.lng),y=x.useMemo(()=>d.data??[],[d.data]),b=x.useMemo(()=>{const h=new Map;for(const w of y)for(const v of w.skills)v&&h.set(v,(h.get(v)??0)+1);return[...h.entries()].sort((w,v)=>v[1]-w[1]).slice(0,8).map(([w])=>w)},[y]),C=x.useMemo(()=>[...r?y.filter(w=>w.skills.some(v=>v.toLowerCase()===r.toLowerCase())):y].sort((w,v)=>{if(w.isAvailableToday!==v.isAvailableToday)return w.isAvailableToday?-1:1;if(u){const k=l(w),j=l(v);return k!=null&&j!=null?k-j:k!=null?-1:j!=null?1:0}return(v.created_at??"").localeCompare(w.created_at??"")}),[y,r,u,o]),f=d.data?`${y.length}:${y.filter(h=>h.isAvailableToday).length}`:null;f&&f!==i&&(n(f),J("contractor.peoplefirst.shown",{worker_count:y.length,available_count:y.filter(h=>h.isAvailableToday).length}));const S={all:y,sorted:C,topSkills:b,skill:r,setSkill:a,distanceOf:l,isLoading:d.isLoading,isError:d.isError};return e.jsx(Ss.Provider,{value:S,children:t})}function Ba(){const{t}=K(),s=t.peopleFirst,{topSkills:r,skill:a,setSkill:i}=Cs();return e.jsxs("div",{className:"space-y-2",children:[e.jsx("h2",{className:"text-sm font-semibold text-foreground px-0.5",children:s.header}),r.length>0&&e.jsx("div",{className:"flex gap-1.5 overflow-x-auto no-scrollbar pb-0.5",children:r.map(n=>{const o=(a==null?void 0:a.toLowerCase())===n.toLowerCase();return e.jsx("button",{type:"button",onClick:()=>{const d=o?null:n;i(d),d&&J("contractor.peoplefirst.skill_selected",{skill:d})},className:`flex-shrink-0 px-3 py-1 rounded-full border text-xs font-semibold transition-colors ${o?"bg-primary text-primary-foreground border-primary":"bg-card text-muted-foreground border-border"}`,children:n},n)})})]})}function Ha({q:t="",subsetIds:s=null,onCount:r}){var p;const{t:a}=K(),i=se(),n=a.peopleFirst,{sorted:o,skill:d,setSkill:u,distanceOf:l,isLoading:y,isError:b}
26=Cs(),[C,f]=x.useState(Vt),[S,h]=x.useState(null),{messageWorker:w,gateProps:v}=gs(),k=de(t),j=x.useMemo(()=>{const N=s&&s.length>0?new Set(s):null,L=N?o.filter(E=>N.has(E.user_id)):o;return k?L.filter(E=>de(E.full_name).includes(k)||E.skills.some($=>de($).includes(k))):L},[o,k,s]),g=j.slice(0,C);x.useEffect(()=>{r==null||r(j.length)},[j.length,r]);const T=N=>{J("contractor.peoplefirst.broadcast_tapped",{from:N,skill:d}),he("flash")};return y?e.jsx("div",{className:"space-y-2 px-1",children:[0,1,2].map(N=>e.jsx("div",{className:"h-16 rounded-xl bg-card/60 border border-border/60 animate-pulse"},N))}):b?e.jsx("p",{className:"text-center text-sm text-muted-foreground py-8",children:n.emptyNearby}):g.length===0&&s&&s.length>0?null:g.length===0?e.jsxs("div",{className:"rounded-xl border border-border bg-card p-4 space-y-3 mx-1",children:[e.jsx("p",{className:"text-sm text-foreground",children:d?n.emptyFiltered.replace("{skill}",d):n.emptyNearby}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{type:"button",onClick:()=>T(d?"filtered":"nearby"),className:"rounded-full bg-primary text-primary-foreground text-xs font-semibold px-4 h-9 active:scale-95 transition-transform",children:d?n.broadcastCta:n.postCta}),d&&e.jsx("button",{type:"button",onClick:()=>u(null),className:"text-xs font-semibold text-primary",children:n.clearFilter})]})]}):e.jsx(gr,{ids:g.map(N=>N.user_id),children:e.jsxs("div",{className:"space-y-2 px-1",children:[g.map(N=>{const L=l(N);return e.jsxs("div",{role:"button",tabIndex:0,onClick:()=>{J("contractor.peoplefirst.profile_opened",{worker_id:N.user_id}),i(`/profile/${N.user_id}`)},onKeyDown:E=>{E.key==="Enter"&&i(`/profile/${N.user_id}`)},className:"w-full flex items-center gap-3 rounded-xl border border-border bg-card px-3 py-2.5 text-left active:scale-[0.99] transition-transform cursor-pointer",children:[N.avatar_url?e.jsx("img",{src:N.avatar_url,alt:"",loading:"lazy",className:"w-10 h-10 rounded-full object-cover flex-shrink-0"}):e.jsx("div",{className:"w-10 h-10 rounded-full bg-muted flex items-center justify-center text-xs font-bold text-muted-foreground flex-shrink-0",children:N.full_name.trim().charAt(0).toUpperCase()||"?"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-sm font-semibold text-foreground truncate",children:N.full_name}),e.jsxs("p",{className:"text-caption text-muted-foreground truncate",children:[N.skills.slice(0,2).join(" · "),L!=null&&e.jsxs("span",{children:[" · ",n.distance.replace("{miles}",L.toFixed(0))]})]}),N.isAvailableToday&&e.jsxs("span",{className:"mt-0.5 inline-flex items-center gap-1 text-caption font-semibold text-emerald-600 dark:text-emerald-400",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-emerald-500"}),n.availableToday]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[e.jsx(Da,{workerId:N.user_id,label:a.workerMapSheet.call}),e.jsx("button",{type:"button","aria-label":n.message,onClick:E=>{E.stopPropagation(),J("contractor.peoplefirst.message_tapped",{worker_id:N.user_id}),w(N.user_id,N.full_name??void 0)},className:"h-9 w-9 rounded-full border border-border flex items-center justify-center text-muted-foreground",children:e.jsx(ys,{className:"w-4 h-4"})}),e.jsxs("button",{type:"button",onClick:E=>{E.stopPropagation(),J("contractor.peoplefirst.invite_tapped",{worker_id:N.user_id,skill:d??N.skills[0]??null}),h({workerId:N.user_id,workerName:N.full_name,skill:d??N.skills[0]??""})},className:"h-9 px-3 rounded-full bg-primary text-primary-foreground text-xs font-semibold inline-flex items-center gap-1 active:scale-95 transition-transform",children:[e.jsx(kn,{className:"w-3.5 h-3.5"}),n.invite]})]})]},N.user_id)}),j.length>g.length&&e.jsx("button",{type:"button",onClick:()=>f(N=>N+Vt),className:"w-full h-9 rounded-full border border-border text-xs font-semibold text-foreground",children:((p=a==null?void 0:a.common)==null?void 0:p.showMore)??"Show more"}),e.jsx(hs,{...v}),e.jsx(bs,{open:!!S,onClose:()=>h(null),skill:(S==null?void 0:S.skill)??"",workerId:(S==null?void 0:S.workerId)??"",workerName:(S==null?void 0:S.workerName)??"",source:"people_first_home"})]})})}function Ps(t={}){const s=t.enabled!==!1;return V({queryKey:["home-subs-for-map"],enabled:s,staleTime:5*6e4,queryFn:async()=>{const r=R,{data:a,error:i}=await r.from("contractor_profiles_public").select("user_id, company_name, logo_url, approx_lat, approx_lng, sub_visible, specialties, city, is_paid_tier").eq("sub_visible",!0).limit(500);if(i)throw i;return(a??[]).filter(n=>n.approx_lat!=null&&n.approx_lng!=null).map(n=>{const o=Array.isArray(n.specialties)?n.specialties.filter(d=>
26typeof d=="string"):[];return{id:n.user_id,entityKind:"sub",lat:n.approx_lat,lng:n.approx_lng,name:n.company_name??"Sub",logo:n.logo_url??null,avatar:n.logo_url??null,avatarUrl:n.logo_url??null,skills:o,meta:{city:n.city??null,specialties:o},isPaid:!!n.is_paid_tier}})}})}const Qt=20;function Ua({q:t="",subsetIds:s=null,onCount:r}){var T;const{t:a}=K();se();const i=a.peopleFirst,n=a.talentCluster,o=a.inviteToBid,{data:d,isLoading:u}=Ps(),{messageWorker:l,gateProps:y}=gs(),{effectiveTier:b}=jt(),{open:C}=_e(),[f,S]=x.useState(Qt),[h,w]=x.useState(null),[v,k]=x.useState(null),j=x.useMemo(()=>{const p=s&&s.length>0?new Set(s.map(We)):null,N=de(t);return(d??[]).map(L=>{var E;return{id:L.id,name:L.name??"Sub",avatarUrl:L.avatarUrl??null,specialties:Array.isArray(L.skills)?L.skills:[],city:((E=L.meta)==null?void 0:E.city)??null,isPaid:!!L.isPaid}}).filter(L=>p?p.has(L.id):!0).filter(L=>N?de(L.name).includes(N)||L.specialties.some(E=>de(E).includes(N))||(L.city?de(L.city).includes(N):!1):!0)},[d,s,t]);if(x.useEffect(()=>{r==null||r(j.length)},[j.length,r]),u||j.length===0)return u?e.jsx("div",{className:"space-y-2 px-1",children:e.jsx("div",{className:"h-16 rounded-xl bg-card/60 border border-border/60 animate-pulse"})}):null;const g=j.slice(0,f);return e.jsxs("div",{className:"space-y-2 px-1",children:[e.jsx("h2",{className:"text-sm font-semibold text-foreground px-0.5",children:i.subsHeader}),g.map(p=>e.jsxs("div",{role:"button",tabIndex:0,onClick:()=>{J("contractor.subcard.profile_tapped",{sub_id:p.id}),k(We(p.id))},onKeyDown:N=>{N.key==="Enter"&&k(We(p.id))},className:"w-full flex items-center gap-3 rounded-xl border border-border bg-card px-3 py-2.5 text-left active:scale-[0.99] transition-transform cursor-pointer",children:[p.avatarUrl?e.jsx("img",{src:ht(p.avatarUrl,96),alt:"",loading:"lazy",className:"w-10 h-10 rounded-full object-cover flex-shrink-0 border border-border/60"}):e.jsx("div",{className:"w-10 h-10 rounded-full bg-muted flex items-center justify-center text-xs font-bold text-muted-foreground flex-shrink-0",children:p.name.trim().charAt(0).toUpperCase()||"?"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("span",{className:"text-sm font-semibold text-foreground truncate",children:p.name}),e.jsxs("span",{className:"inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded-full bg-[hsl(var(--entity-sub))]/25 text-[hsl(var(--entity-sub-ink))] border border-[hsl(var(--entity-sub))]/40 text-micro font-bold uppercase tracking-wider shrink-0",children:[e.jsx(Cn,{type:"sub",size:9,className:"text-[hsl(var(--entity-sub-ink))]"}),n.subPill]}),p.isPaid&&e.jsx(Sn,{visible:!0,size:"xs"})]}),p.specialties.length>0&&e.jsx("p",{className:"text-caption text-muted-foreground truncate",children:p.specialties.slice(0,3).join(" · ")}),p.city&&e.jsxs("p",{className:"text-caption text-muted-foreground truncate flex items-center gap-0.5",children:[e.jsx(De,{className:"w-2.5 h-2.5"}),p.city]})]}),e.jsxs("button",{type:"button","aria-label":o.action,onClick:N=>{if(N.stopPropagation(),J("contractor.subcard.invite_to_bid_tapped",{sub_id:p.id}),b!=="paid"){C("invite_to_bid");return}w({id:p.id,name:p.name})},className:"h-12 min-w-[48px] px-1.5 rounded-xl border border-border flex flex-col items-center justify-center gap-0.5 text-muted-foreground flex-shrink-0",children:[e.jsx(vt,{className:"w-4 h-4"}),e.jsx("span",{className:"text-micro font-semibold leading-none",children:o.actionShort})]}),e.jsxs("button",{type:"button","aria-label":i.message,onClick:N=>{N.stopPropagation(),J("contractor.subcard.message_tapped",{sub_id:p.id}),l(p.id,p.name)},className:"h-12 min-w-[48px] px-1.5 rounded-xl border border-border flex flex-col items-center justify-center gap-0.5 text-muted-foreground flex-shrink-0",children:[e.jsx(ys,{className:"w-4 h-4"}),e.jsx("span",{className:"text-micro font-semibold leading-none",children:i.message})]})]},p.id)),j.length>g.length&&e.jsx("button",{type:"button",onClick:()=>S(p=>p+Qt),className:"w-full h-9 rounded-full border border-border text-xs font-semibold text-foreground",children:((T=a==null?void 0:a.common)==null?void 0:T.showMore)??"Show more"}),e.jsx(hs,{...y}),e.jsx(ws,{open:!!h,onOpenChange:p=>{p||w(null)},sub:h}),e.jsx(_n,{userId:v,onClose:()=>k(null),messageBasePath:"/contractor/messages"})]})}function Wa({alerts:t}){const{tr:s}=K();if(!t.length)return null;
26const r=t[0],a=[r.city,r.state].filter(Boolean).join(", ");return e.jsxs("div",{className:"rounded-card border border-amber-500/40 bg-amber-500/[0.07] p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 font-semibold text-sm",children:[e.jsx(Bn,{className:"w-4 h-4 text-amber-500"}),s("storm.card.title").replace("{n}",String(t.length))]}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:s("storm.card.body").replace("{event}",s(`storm.event.${r.event}`)).replace("{place}",a||s("external.feed.nearby")).replace("{when}",Me(r.occurred_at))}),e.jsx("p",{className:"text-caption text-muted-foreground mt-1.5",children:s("storm.card.source").replace("{source}",r.source_label||"NOAA")})]})}const za=["storm-alerts"];function Ja(t){return V({queryKey:za,enabled:t.enabled,staleTime:10*6e4,queryFn:async()=>{const{data:s,error:r}=await R.rpc("storm_alerts_feed",{_max_miles:75});if(r)throw r;return(s??{}).alerts??[]}})}function Va(t={}){const s=t.enabled!==!1;return V({queryKey:["home-workers-for-map"],enabled:s,staleTime:2*6e4,queryFn:async()=>{const r=R,{data:a,error:i}=await r.rpc("worker_map_pins",{_limit:600});if(i)throw i;return(a??[]).filter(o=>o.approx_lat!=null&&o.approx_lng!=null&&o.user_id).map(o=>{const d=Array.isArray(o.skills)?o.skills:[],u=d[0]??null,l=o.hourly_rate!=null?`$${Number(o.hourly_rate)}/hr`:null,y=typeof o.full_name=="string"?o.full_name.trim():"",b={full:y||null,first:y?y.split(/\s+/)[0]:null,avatar:o.avatar_url??null};return{id:o.user_id,entityKind:"worker",lat:o.approx_lat,lng:o.approx_lng,name:(b==null?void 0:b.full)??(b==null?void 0:b.first)??"Worker",avatar:(b==null?void 0:b.avatar)??null,avatarUrl:(b==null?void 0:b.avatar)??null,primarySkill:u,skills:d,rateLine:l,isAvailableToday:!!o.is_available_today}})}})}function Qa(t,s={}){const r=s.enabled!==!1&&!!t;return V({queryKey:["home-own-active-jobs",t],enabled:r,staleTime:6e4,queryFn:async()=>{const{data:a,error:i}=await R.from("jobs").select("id, title, lat, lng, pay, pay_type, status, project_id, job_type, slots, filled_slots, visibility").eq("contractor_id",t).in("status",["active","filled"]).is("deleted_at",null).neq("job_type","sub_package").limit(200);if(i)throw i;return(a??[]).filter(n=>n.lat!=null&&n.lng!=null).map(n=>({id:n.id,entityKind:"job",lat:n.lat,lng:n.lng,name:n.title,status:n.status,projectId:n.project_id??null,budget:n.pay!=null?Number(n.pay):null,rateLine:n.pay!=null?`$${Number(n.pay)}/${n.pay_type??"hr"}`:null,meta:{slots:n.slots??null,filledSlots:n.filled_slots??null,payType:n.pay_type??null,payAmount:n.pay!=null?Number(n.pay):null,visibility:n.visibility??"public",isPrivate:_t(n.visibility),isFull:n.status==="filled",isOwn:!0}}))}})}function Ga(t,s={}){const r=s.enabled!==!1;return V({queryKey:["home-available-jobs",t??"anon"],enabled:r,staleTime:6e4,queryFn:async()=>{let a=R.from("jobs").select("id, title, lat, lng, pay, pay_type, status, project_id, job_type, contractor_id, slots, filled_slots, visibility, skills, start_date, recurrence_end_date, duration, urgency, created_at").in("status",["active","filled"]).is("deleted_at",null).neq("job_type","sub_package").limit(150);t&&(a=a.neq("contractor_id",t));const{data:i,error:n}=await a;if(n)throw n;const o=(i??[]).filter(l=>l.lat!=null&&l.lng!=null),d=Array.from(new Set(o.map(l=>l.contractor_id).filter(Boolean))),u=new Set;if(d.length>0){const{data:l}=await R.from("contractor_profiles_public").select("user_id, is_paid_tier").in("user_id",d);(l??[]).forEach(y=>{y.is_paid_tier===!0&&u.add(y.user_id)})}return o.filter(l=>l.lat!=null&&l.lng!=null).sort((l,y)=>{const b=u.has(l.contractor_id)?1:0;return(u.has(y.contractor_id)?1:0)-b}).map(l=>({id:l.id,entityKind:"job",lat:l.lat,lng:l.lng,name:l.title,status:l.status,projectId:l.project_id??null,budget:l.pay!=null?Number(l.pay):null,rateLine:l.pay!=null?`$${Number(l.pay)}/${l.pay_type??"hr"}`:null,skills:Array.isArray(l.skills)?l.skills.filter(y=>
26typeof y=="string"):[],meta:{startDate:l.start_date??null,endDate:l.recurrence_end_date??null,duration:l.duration??null,urgency:l.urgency??null,createdAt:l.created_at??null,slots:l.slots??null,filledSlots:l.filled_slots??null,payType:l.pay_type??null,payAmount:l.pay!=null?Number(l.pay):null,isPaidContractor:u.has(l.contractor_id),visibility:l.visibility??"public",isPrivate:_t(l.visibility),isFull:l.status==="filled",contractorId:l.contractor_id??null}}))}})}function Ya(t){return V({queryKey:["homeowner-lead-pins"],enabled:t.enabled,staleTime:6e4,queryFn:async()=>{const{data:s,error:r}=await R.rpc("homeowner_leads_feed",{_limit:50,_offset:0});if(r)throw r;const a=s;return((a==null?void 0:a.leads)??[]).filter(n=>n.lat!=null&&n.lng!=null).map(n=>({entityKind:"homeowner",id:n.id,lat:n.lat,lng:n.lng,name:n.trade,primarySkill:n.trade,distanceMi:n.distance_miles,status:n.timeline,meta:{trade:n.trade,description:n.description,city:n.city,state:n.state,timeline:n.timeline,budget_band:n.budget_band,created_at:n.created_at,locked:n.locked,responded:n.responded,response_count:n.response_count,exact_location:n.exact_location}}))}})}function Za(){const[t,s]=x.useState(!1);return x.useEffect(()=>{const r=window;if(typeof r.requestIdleCallback=="function"){r.requestIdleCallback(()=>s(!0),{timeout:2e3});return}const a=window.setTimeout(()=>s(!0),600);return()=>window.clearTimeout(a)},[]),t}function Xa(t,s={}){var g;const r=!!(t!=null&&t.hiringVisible),a=!!(t!=null&&t.laborerVisible),i=!!(t!=null&&t.subVisible),{available:n}=cs(i?t==null?void 0:t.userId:void 0),o=Va({enabled:r}),d=Ps({enabled:r}),u=lr(r?t==null?void 0:t.userId:void 0),l=Qa(t==null?void 0:t.userId,{enabled:r}),y=Ga(t==null?void 0:t.userId,{enabled:a}),b=Tn(t==null?void 0:t.userId,{enabled:a||i&&n}),C=Za(),f=Ya({enabled:C&&(r||i)}),S=An({enabled:C&&(r||i),bounds:s.bounds??null,circle:s.circle??null,q:s.leadQuery??null,sort:s.leadSort??null}),h=x.useMemo(()=>{var L;const T=[...o.data??[],...d.data??[],...l.data??[],...y.data??[],...b.data??[],...f.data??[],...((L=S.data)==null?void 0:L.pins)??[]],p=new Set,N=[];for(const E of T){const $=`${E.entityKind}:${E.id}`;p.has($)||(p.add($),N.push(E))}return N},[o.data,d.data,l.data,y.data,b.data,f.data,S.data]),w=r&&(o.isLoading||d.isLoading||l.isLoading||u.isLoading)||a&&(y.isLoading||b.isLoading)||i&&b.isLoading,v=r&&(o.isError||d.isError||l.isError||u.isError)||a&&(y.isError||b.isError)||i&&b.isError,k=r&&(o.isFetching||d.isFetching||l.isFetching||u.isFetching)||a&&(y.isFetching||b.isFetching)||i&&b.isFetching,j=()=>{r&&(o.refetch(),d.refetch(),l.refetch(),u.refetch()),a&&y.refetch(),(a||i)&&b.refetch(),(r||i)&&(f.refetch(),S.refetch())};return{pins:h,projects:u.data??[],externalTotal:((g=S.data)==null?void 0:g.total)??0,isLoading:w,isError:v,isFetching:k,refetch:j}}const eo=10;function to({jobPinCount:t}){var p;const{user:s}=te(),{tr:r}=K(),a=se(),{data:i}=ge(s==null?void 0:s.id),{open:n,openPrompt:o,enable:d,dismiss:u,state:l}=Ln(),y=(i==null?void 0:i.lat)??null,b=(i==null?void 0:i.lng)??null,C=((p=i==null?void 0:i.laborer)==null?void 0:p.travelRadiusMiles)??40,{data:f}=V({queryKey:["worker-job-pulse",s==null?void 0:s.id,y,b,C],enabled:!!(s!=null&&s.id)&&y!=null&&b!=null,staleTime:5*6e4,queryFn:async()=>{const{data:N,error:L}=await R.rpc("worker_local_job_pulse",{_lat:y,_lng:b,_radius_miles:C});if(L)throw L;return N??null}});if(t>=eo)return null;const S=l==="enabled"||Mn()==="granted",h=(f==null?void 0:f.posted_7d)??0,w=y!=null&&b!=null,v=w?h===0?r("workerPulse.none"):h===1?r("workerPulse.one"):r("workerPulse.some",{n:h}):r("workerPulse.noLocationTitle"),k=r(w?h===0?"workerPulse.subtitleNone":"workerPulse.subtitleThin":"workerPulse.noLocationSubtitle"),j=(f==null?void 0:f.nearest_miles)!=null&&f.nearest_created_at?r("workerPulse.nearest",{miles:f.nearest_miles,time:Me(f.nearest_created_at)}):null,g=(f==null?void 0:f.crews_nearby)??0,T=w&&g>0?r("workerPulse.crewsNearby",{n:g}):null;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rounded-card border border-primary/30 bg-card/95 backdrop-blur px-4 py-3 shadow-sm",children:[e.jsx("p",{className:"text-sm font-semibold text-foreground",children:v}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:k}
26),j&&e.jsx("p",{className:"text-caption text-muted-foreground/80 mt-1",children:j}),T&&e.jsx("p",{className:"text-caption text-muted-foreground/80 mt-1",children:T}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[S?e.jsxs("span",{className:"inline-flex items-center gap-1.5 rounded-xl bg-primary/10 px-3 py-1.5 text-xs font-semibold text-primary",children:[e.jsx(Fn,{className:"h-3.5 w-3.5"}),r("workerPulse.alertsOn")]}):e.jsxs("button",{type:"button",onClick:o,className:"inline-flex items-center gap-1.5 rounded-xl bg-primary px-3 py-1.5 text-xs font-semibold text-primary-foreground",children:[e.jsx(js,{className:"h-3.5 w-3.5"}),r("workerPulse.alertsCta")]}),(!w||h===0)&&e.jsxs("button",{type:"button",onClick:()=>a("/profile"),className:w?"inline-flex items-center gap-1.5 rounded-xl px-3 py-1.5 text-xs font-semibold text-muted-foreground underline underline-offset-2":"inline-flex items-center gap-1.5 rounded-xl bg-primary px-3 py-1.5 text-xs font-semibold text-primary-foreground",children:[e.jsx(De,{className:"h-3.5 w-3.5"}),r(w?"workerPulse.widen":"workerPulse.setLocation")]})]})]}),e.jsx(En,{open:n,onEnable:d,onDismiss:u})]})}const ze={trades:[],minPay:null,payType:"any",length:"any",dates:"any",from:null,to:null,freshness:"any",sources:[]},Ts="knuckl.home.filters.v1";function As(t){let s=0;return t.trades.length&&(s+=1),t.minPay!=null&&(s+=1),t.payType!=="any"&&(s+=1),t.length!=="any"&&(s+=1),t.dates!=="any"&&(s+=1),t.freshness!=="any"&&(s+=1),t.sources.length&&(s+=1),s}function so(){if(typeof window>"u")return ze;try{const t=window.localStorage.getItem(Ts);if(!t)return ze;const s=JSON.parse(t);return Ls(s)}catch{return ze}}function ro(t){if(!(typeof window>"u"))try{window.localStorage.setItem(Ts,JSON.stringify(t))}catch{}}function Ls(t){const s=t??{},r=a=>typeof a=="string"?a:null;return{trades:Array.isArray(s.trades)?s.trades.filter(a=>typeof a=="string"):[],minPay:typeof s.minPay=="number"&&Number.isFinite(s.minPay)?s.minPay:null,payType:["any","hourly","daily","fixed"].includes(s.payType)?s.payType:"any",length:["any","one_day","few_days","week_plus"].includes(s.length)?s.length:"any",dates:["any","today","week","month","range"].includes(s.dates)?s.dates:"any",from:r(s.from),to:r(s.to),freshness:["any","3d","7d","30d"].includes(s.freshness)?s.freshness:"any",sources:Array.isArray(s.sources)?s.sources.filter(a=>typeof a=="string"):[]}}function no(){const t=new Date;return t.setHours(0,0,0,0),t}function pe(t){if(typeof t!="string"||!t)return null;const s=new Date(t);return Number.isNaN(s.getTime())?null:s}function ao(t){if(t.dates==="any")return null;const s=no(),r=new Date(s);if(t.dates==="today")return r.setHours(23,59,59,999),{start:s,end:r};if(t.dates==="week")return r.setDate(r.getDate()+7),{start:s,end:r};if(t.dates==="month")return r.setMonth(r.getMonth()+1),{start:s,end:r};const a=pe(t.from),i=pe(t.to);if(!a&&!i)return null;const n=a??s,o=i??new Date(n.getTime()+365*24*36e5);return o.setHours(23,59,59,999),{start:n,end:o}}function oo(t){if(t.freshness==="any")return null;const s=t.freshness==="3d"?3:t.freshness==="7d"?7:30;return new Date(Date.now()-s*24*36e5)}function io(t){const s=[];Array.isArray(t.skills)&&s.push(...t.skills),t.primarySkill&&s.push(t.primarySkill);const r=t.meta??{};return Array.isArray(r.specialties)&&s.push(...r.specialties.filter(a=>typeof a=="string")),typeof r.trade=="string"&&s.push(r.trade),typeof r.title=="string"&&s.push(r.title),t.name&&s.push(t.name),s}function lo(t,s){if(!s.length)return!0;const r=io(t).map(a=>de(a)).join(" | ");return r?s.some(a=>{const i=de(a);return!!i&&r.includes(i)}):!1}function co(t){const s=t.meta??{},r=pe(s.startDate),a=pe(s.endDate);if(r&&a)return Math.max(1,Math.round((a.getTime()-r.getTime())/864e5)+1);const i=s.duration;if(typeof i=="number"&&Number.isFinite(i))return i;if(typeof i=="string"){const n=i.match(/(\d+)/);if(n){const o=Number(n[1]);return/week/i.test(i)?o*7:/month/i.test(i)?o*30:o}if(/week/i.test(i))return 7;if(/month/i.test(i))return 30;if(/day/i.test(i))return 1}return t.entityKind==="job"?1:null}function Es(t,s){const r=t.entityKind,a=t.meta??{};if(!lo(t,s.trades))return!1;if(r==="job"||r==="sub_package"){if(s.payType!=="any"&&(typeof a.payType=="string"?a.payType:null)!==s.payType)return!1;if(s.minPay!=null){const o=typeof a.payAmount=="number"?a.payAmount:typeof t.budget=="number"?t.budget:null;if(o==null||o<s.minPay)return!1}if(s.length!=="any"){const o=co(t);if(o==null||s.length==="one_day"&&o>1||s.length==="few_days"&&(o<2||o>6)||s.length==="week_plus"&&o<7)return!1}const n=ao(s);if(n){const o=pe(a.startDate)??pe(a.createdAt);if(!o||(pe(a.endDate)??o)<n.start||o>n.end)return!1}}if(fs(r)){if(s.sources.length&&!s.sources.includes(r))return!1;const n=oo(s);if(n){const o=pe(a.posted_at);if(!o||o<n)return!1}}return!0}function uo({filters:t,onChange:s,onOpenPanel:r}){const{t:a}=K(),i=(a==null?void 0:a.mapFilters)??{},n=As(t),o=u=>`inline-flex shrink-0 snap-start items-center gap-1 h-8 px-3 rounded-full text-caption font-semibold border transition-colors whitespace-nowrap ${u?"bg-primary text-primary-foreground border-primary":"bg-card text-foreground border-border/60 hover:bg-secondary/40"}`,d=t.dates==="today"||t.dates==="week";return e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",onClick:r,className:o(n>0),children:[e.jsx(cr,{className:"w-3.5 h-3.5"}),e.jsx("span",{children:n>0?(i.filtersCount??"Filters ({count})").replace("{count}",String(n)):i.title??"Filters"})]}),e.jsx("button",{type:"button",onClick:()=>s({...t,dates:d?"any":"week"}),"aria-pressed":d,className:o(d),children:i.startsSoon??"Starts soon"}),e.jsx("button",{type:"button",onClick:()=>s({...t,minPay:t.minPay?null:20}),"aria-pressed":t.minPay!=null,className:o(t.minPay!=null),children:t.minPay!=null?(i.payAtLeast??"${amount}+").replace("{amount}",String(t.minPay)):i.pay??"Pay"}),t.trades.length>0&&e.jsx("button",{type:"button",onClick:r,className:o(!0),children:t.trades.length===1?t.trades[0]:(i.tradesCount??"{count} trades").replace("{count}",String(t.trades.length))})]})}const et=t=>["saved-searches",t??"anon"];function mo(t){return V({queryKey:et(t),enabled:!!t,staleTime:6e4,queryFn:async()=>{const{data:s,error:r}=await R.from("saved_searches").select("id, name, filters, notify, created_at").order("created_at",{ascending:!1});if(r)throw r;return(s??[]).map(a=>({id:a.id,name:a.name,filters:Ls(a.filters),notify:!!a.notify,createdAt:a.created_at}))}})}function po(t){const s=Fe();return yt({mutationFn:async r=>{if(!t)throw new Error("not signed in");const{error:a}=await R.from("saved_searches").insert({user_id:t,name:r.name,filters:r.filters,notify:r.notify});if(a)throw a},onSuccess:()=>{s.invalidateQueries({queryKey:et(t)}),B.success("Search saved")},onError:r=>{B.error(r instanceof Error?r.message:"Couldn't save that search")}})}function fo(t){const s=Fe();return yt({mutationFn:async r=>{const{error:a}=await R.from("saved_searches").delete().eq("id",r);
26if(a)throw a},onSuccess:()=>void s.invalidateQueries({queryKey:et(t)}),onError:r=>{B.error(r instanceof Error?r.message:"Couldn't delete that search")}})}function xo(t){const s=Fe();return yt({mutationFn:async({id:r,notify:a})=>{const{error:i}=await R.from("saved_searches").update({notify:a}).eq("id",r);if(i)throw i},onSuccess:()=>void s.invalidateQueries({queryKey:et(t)}),onError:r=>{B.error(r instanceof Error?r.message:"Couldn't change alerts")}})}function me({label:t,children:s}){return e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-caption font-semibold text-foreground",children:t}),s]})}function Ne({active:t,onClick:s,children:r,dot:a}){return e.jsxs("button",{type:"button",onClick:s,"aria-pressed":t,className:`inline-flex items-center gap-1.5 h-9 px-3 rounded-full border text-caption font-semibold transition-colors ${t?"bg-primary text-primary-foreground border-primary":"bg-card text-foreground border-border/60 hover:bg-secondary/40"}`,children:[a&&e.jsx("span",{"aria-hidden":!0,className:"w-2 h-2 rounded-full shrink-0",style:{backgroundColor:a}}),r]})}function bo({open:t,onClose:s,filters:r,onApply:a,pins:i,availableKinds:n,userId:o}){var O;const{t:d}=K(),u=(d==null?void 0:d.mapFilters)??{},[l,y]=x.useState(r),[b,C]=x.useState(""),[f,S]=x.useState(""),[h,w]=x.useState(!1);x.useEffect(()=>{t&&y(r)},[t,r]);const v=mo(o),k=po(o),j=fo(o),g=xo(o),T=x.useMemo(()=>{const m=b.trim().toLowerCase();return m?gt.filter(M=>M.toLowerCase().includes(m)).slice(0,24):Zr},[b]),p=Ee.filter(m=>n.includes(m));if(!t)return null;const N=m=>y(M=>({...M,...m})),L=m=>y(M=>({...M,trades:M.trades.includes(m)?M.trades.filter(I=>I!==m):[...M.trades,m]})),E=m=>y(M=>({...M,sources:M.sources.includes(m)?M.sources.filter(I=>I!==m):[...M.sources,m]})),$=As(l),H=i.filter(m=>Es(m,l)).length,A=i.length;return e.jsxs("div",{className:"fixed inset-0 z-[1300] flex items-end",role:"dialog","aria-modal":"true",children:[e.jsx("button",{type:"button","aria-label":u.close??"Close",onClick:s,className:"absolute inset-0 bg-black/50"}),e.jsxs("div",{className:"relative w-full max-h-[88dvh] rounded-t-2xl border border-b-0 border-border/60 bg-background shadow-[0_-8px_24px_rgba(0,0,0,0.35)] flex flex-col",children:[e.jsxs("div",{className:"shrink-0 flex items-center justify-between px-4 pt-4 pb-2 border-b border-border/60",children:[e.jsx("h2",{className:"font-display text-lg text-foreground",children:u.title??"Filters"}),e.jsx("button",{type:"button",onClick:s,"aria-label":u.close??"Close",className:"p-2 -mr-2",children:e.jsx(be,{className:"w-5 h-5 text-muted-foreground"})})]}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto px-4 py-4 space-y-5",children:[o&&(((O=v.data)==null?void 0:O.length)??0)>0&&e.jsx(me,{label:u.savedTitle??"Saved searches",children:e.jsx("div",{className:"flex flex-wrap gap-2",children:(v.data??[]).map(m=>e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full border border-border/60 bg-card pl-3 pr-1 h-9 text-caption font-semibold",children:[e.jsx("button",{type:"button",onClick:()=>y(m.filters),className:"max-w-[10rem] truncate",children:m.name}),e.jsx("button",{type:"button","aria-label":m.notify?u.alertsOff??"Turn alerts off":u.alertsOn??"Turn alerts on",onClick:()=>g.mutate({id:m.id,notify:!m.notify}),className:"p-1.5 text-muted-foreground",children:m.notify?e.jsx(js,{className:"w-3.5 h-3.5 text-primary"}):e.jsx(On,{className:"w-3.5 h-3.5"})}),e.jsx("button",{type:"button","aria-label":u.deleteSaved??"Delete saved search",onClick:()=>j.mutate(m.id),className:"p-1.5 text-muted-foreground",children:e.jsx(xs,{className:"w-3.5 h-3.5"})})]},m.id))})}),e.jsxs(me,{label:u.trades??"Trade",children:[e.jsxs("div",{className:"relative",children:[e.jsx(qn,{
26className:"w-3.5 h-3.5 absolute left-2.5 top-1/2 -translate-y-1/2 text-muted-foreground"}),e.jsx("input",{type:"search",value:b,onChange:m=>C(m.target.value),placeholder:u.tradesSearch??"Search trades",className:"w-full h-9 pl-8 pr-3 rounded-lg bg-secondary/40 border border-border/60 text-sm focus:outline-none focus:ring-2 focus:ring-primary/40"})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:Array.from(new Set([...l.trades,...T])).map(m=>e.jsx(Ne,{active:l.trades.includes(m),onClick:()=>L(m),children:m},m))})]}),e.jsxs(me,{label:u.pay??"Pay",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-caption text-muted-foreground",children:u.minPay??"At least"}),e.jsxs("div",{className:"relative",children:[e.jsx("span",{className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-sm text-muted-foreground",children:"$"}),e.jsx("input",{type:"number",inputMode:"numeric",min:0,value:l.minPay??"",onChange:m=>N({minPay:m.target.value===""?null:Math.max(0,Number(m.target.value))}),className:"w-28 h-9 pl-6 pr-2 rounded-lg bg-secondary/40 border border-border/60 text-sm focus:outline-none focus:ring-2 focus:ring-primary/40"})]})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:["any","hourly","daily","fixed"].map(m=>e.jsx(Ne,{active:l.payType===m,onClick:()=>N({payType:m}),children:u[`payType_${m}`]??(m==="any"?"Any":m==="hourly"?"Hourly":m==="daily"?"Daily":"Fixed price")},m))})]}),e.jsx(me,{label:u.length??"Job length",children:e.jsx("div",{className:"flex flex-wrap gap-2",children:["any","one_day","few_days","week_plus"].map(m=>e.jsx(Ne,{active:l.length===m,onClick:()=>N({length:m}),children:u[`length_${m}`]??(m==="any"?"Any":m==="one_day"?"One day":m==="few_days"?"A few days":"A week or more")},m))})}),e.jsxs(me,{label:u.dates??"Starts",children:[e.jsx("div",{className:"flex flex-wrap gap-2",children:["any","today","week","month","range"].map(m=>e.jsx(Ne,{active:l.dates===m,onClick:()=>N({dates:m}),children:u[`dates_${m}`]??(m==="any"?"Any time":m==="today"?"Today":m==="week"?"This week":m==="month"?"This month":"Pick dates")},m))}),l.dates==="range"&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"date",value:l.from??"",onChange:m=>N({from:m.target.value||null}),"aria-label":u.fromLabel??"From",className:"h-9 px-2 rounded-lg bg-secondary/40 border border-border/60 text-sm"}),e.jsx("span",{className:"text-muted-foreground text-caption",children:"–"}),e.jsx("input",{type:"date",value:l.to??"",onChange:m=>N({to:m.target.value||null}),"aria-label":u.toLabel??"To",className:"h-9 px-2 rounded-lg bg-secondary/40 border border-border/60 text-sm"})]})]}),p.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(me,{label:u.freshness??"Lead freshness",children:e.jsx("div",{className:"flex flex-wrap gap-2",children:["any","3d","7d","30d"].map(m=>e.jsx(Ne,{active:l.freshness===m,onClick:()=>N({freshness:m}),children:u[`freshness_${m}`]??(m==="any"?"Any time":m==="3d"?"Last 3 days":m==="7d"?"Last week":"Last month")},m))})}),e.jsx(me,{label:u.sources??"Lead source",children:e.jsx("div",{className:"flex flex-wrap gap-2",children:p.map(m=>{var M;return e.jsx(Ne,{active:l.sources.includes(m),onClick:()=>E(m),dot:ps[m],children:((M=d==null?void 0:d.entityLabels)==null?void 0:M[m])??m},m)})})})]}),o&&e.jsxs(me,{label:u.saveTitle??"Save this search",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"text",value:f,onChange:m=>S(m.target.value),placeholder:u.savePlaceholder??"Name it, e.g. Roofing near me",className:"flex-1 h-9 px-3 rounded-lg bg-secondary/40 border border-border/60 text-sm focus:outline-none focus:ring-2 focus:ring-primary/40"}),e.jsx(G,{type:"button",size:"sm",variant:"secondary",disabled:!f.trim()||h,onClick:async()=>{w(!0);try{await k.mutateAsync({name:f.trim(),filters:l,notify:!0}),S("")}finally{w(!1)}},children:u.save??"Save"})]}),e.jsx("p",{className:"text-micro text-muted-foreground",children:u.saveHint??"Saved searches alert you when new matching work shows up."})]})]}),e.jsxs("div",{className:"shrink-0 border-t border-border/60 px-4 py-3 space-y-2",style:{paddingBottom:"calc(0.75rem + env(safe-area-inset-bottom))"},children:[e.jsx("p",{className:"text-micro text-muted-foreground text-center",children:(u.showing??"Showing {showing} of {total}").replace("{showing}",String(H)).replace("{total}",String(A))}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(G,{type:"button",variant:"outline",className:"flex-1",onClick:()=>y(ze),children:u.clearAll??"Clear all"}),e.jsx(G,{type:"button",className:"flex-1",onClick:()=>{a(l),s()},children:$>0?(u.applyCount??"Apply ({count})").replace("{count}",String($)):u.apply??"Apply"})]})]})]})]})}function fc(){var Rt,Ot,qt,Dt;const{user:t}=te(),{data:s}=ge(t==null?void 0:t.id),{t:r,lang:a}=K(),i=se(),{data:n}=In(t==null?void 0:t.id),o=$n(t==null?void 0:t.id),d=Rn(t==null?void 0:t.id),{canPostPrivateJob:u,effectiveTier:l}=jt(),y=Fe(),{mode:b,setMode:C,isMulti:f,hiring:S,sub:h,laborer:w}=Xe(),v=b==="laborer"&&w,k=b==="hiring"&&S,j=b==="sub"&&h,g=v&&!k,{data:T}=Ja({enabled:k||j}
26),p=T??[],[N,L]=x.useState(null),[E,$]=x.useState(""),[H,A]=x.useState(""),[O,m]=x.useState(null),[M,I]=x.useState(!1),[P,U]=x.useState(()=>so()),[q,Y]=x.useState(!1);x.useEffect(()=>{ro(P)},[P]),x.useEffect(()=>{const c=window.setTimeout(()=>A(E.trim()),400);return()=>window.clearTimeout(c)},[E]);const{pins:Q,projects:X,isLoading:W,isError:oe,isFetching:fe,refetch:xe}=Xa(s??null,{bounds:N,circle:O,leadQuery:H||null,leadSort:O?"distance":null}),Z=x.useMemo(()=>{const c=new Set;return k&&(c.add("worker"),c.add("sub"),c.add("project"),c.add("job"),c.add("homeowner"),Ee.forEach(_=>c.add(_))),j&&(c.add("sub_package"),c.add("homeowner"),Ee.forEach(_=>c.add(_))),v&&(c.add("job"),c.add("sub_package")),sn.filter(_=>c.has(_))},[k,j,v]),[D,ue]=x.useState(()=>{const c=rn(Ut({hiringVisible:k,laborerVisible:v,subVisible:j}));return new Set(c)});x.useEffect(()=>{ue(c=>{const _=new Set;for(const F of c)Z.includes(F)&&_.add(F);return _.size===0&&Ut({hiringVisible:k,laborerVisible:v,subVisible:j}).filter(F=>Z.includes(F)).forEach(F=>_.add(F)),_})},[Z,k,v,j]),x.useEffect(()=>{nn(Array.from(D))},[D]);const Ce=c=>{ue(_=>{const F=new Set(_);return F.has(c)?F.size>1&&F.delete(c):F.add(c),F})},z=x.useMemo(()=>Q.filter(c=>c.entityKind==="job"||c.entityKind==="sub_package").length,[Q]),re=x.useMemo(()=>Q.filter(c=>Es(c,P)),[Q,P]),ee=x.useMemo(()=>re.filter(c=>D.has(c.entityKind)).map(c=>({id:an(c.entityKind,c.id),entityKind:c.entityKind,name:c.name??"",primarySkill:c.primarySkill??null,lat:c.lat,lng:c.lng,distanceMi:c.distanceMi??null,rateLine:c.rateLine??null,skills:c.skills,matchScore:c.matchScore,user_id:c.id,full_name:c.name,avatarUrl:c.avatar??c.logo??null,...c.bidCount!=null?{bidCount:c.bidCount}:{},...c.meta?{meta:c.meta}:{}})),[re,D]),St=D.has("project")?X:[],Ct=Z.length>0,Ms=x.useMemo(()=>{const c=[],_=r.mapLegend.entries;D.has("worker")&&c.push({kind:"entity",type:"worker",label:_.worker.label,description:_.worker.description}),D.has("sub")&&c.push({kind:"entity",type:"sub",label:_.sub.label,description:_.sub.description}),D.has("project")&&c.push({kind:"entity",type:"project",label:_.project.label,description:_.project.description}),D.has("job")&&c.push({kind:"entity",type:"job",label:_.job.label,description:_.job.description}),D.has("sub_package")&&c.push({kind:"entity",type:"sub_package",label:_.sub_package.label,description:_.sub_package.description}),D.has("homeowner")&&c.push({kind:"entity",type:"homeowner",label:_.homeowner.label,description:_.homeowner.description});for(const F of Ee){if(!D.has(F))continue;const ce=_[F];ce&&c.push({kind:"entity",type:F,label:ce.label,description:ce.description})}return D.has("job")&&c.push({kind:"state",visual:"locked",label:_.locked.label,description:_.locked.description},{kind:"state",visual:"full",label:_.full.label,description:_.full.description}),c.push({kind:"state",visual:"focused",label:_.focused.label,description:_.focused.description},{kind:"state",visual:"cluster",label:_.cluster.label,description:_.cluster.description},{kind:"state",visual:"viewed",label:_.viewed.label,description:_.viewed.description}),c},[D,r]),Pt=x.useMemo(()=>{const c={worker:0,sub:0,project:0,job:0,sub_package:0,homeowner:0,permit_owner:0,permit:0,violation:0,lead_post:0};for(const _ of re)c[_.entityKind]=(c[_.entityKind]??0)+1;return c.project=(c.project??0)+X.length,c},[re,X]),[Fs,Pe]=x.useState(null),[Is,je]=x.useState(null),[$s,tt]=x.useState(null),[we,st]=x.useState(null),[Rs,Tt]=x.useState(!1),[ne,At]=x.useState(null),[ie,Lt]=x.useState(null),[le,Et]=x.useState(null),[ae,Mt]=x.useState(null),rt=c=>{const _=c.entityKind;if(_==="project"){je(c.id);return}if(_==="sub"){const F=We(c.id);tt(F);return}if(_==="homeowner"){const F=c.meta;F&&Lt({id:c.id,meta:F,distanceMi:c.distanceMi});return}if(fs(_)){const F=c.meta;F&&Et({id:c.id,meta:F,distanceMi:c.distanceMi});return}if(_==="job"||_==="sub_package"){if(g){st(c.id);return}i(`/jobs/${c.id}`);return}Pe(c)},{data:ve}=V({queryKey:["home-quick-job",we],enabled:!!we,staleTime:6e4,queryFn:async()=>{const{data:c,error:_}=await R.from("jobs").select("id, title, pay, pay_type, location, urgency, visibility, skills, start_date, project_id, is_demo, contractor_id, status, slots, filled_slots").eq("id",we).maybeSingle();if(_)throw _;return c?{id:c.id,title:c.title,pay:c.pay,payType:c.pay_type,location:c.location,urgency:c.urgency,visibility:c.visibility,skills:c.skills??[],startDate:c.start_date,projectId:c.project_id,isDemo:!!c.is_demo,contractorId:c.contractor_id??null,status:c.status??null,isFull:c.status==="filled"}:null}}),{data:Os}=V({queryKey:["home-quick-job-invite",we,t==null?void 0:t.id],enabled:!!we&&!!(t!=null&&t.id),staleTime:6e4,queryFn:async()=>{const{data:c,error:_}=await R.from("job_invitations").select("status").eq("job_id",we).eq("worker_id",t.id).eq("status","accepted").maybeSingle();if(_)throw _;return!!c}}),qs=!!ve&&_t(ve.visibility)&&ve.contractorId!==(t==null?void 0:t.id)&&!Os,Ds=async c=>{var _,F,ce,Te;if(!t){i("/auth");return}Tt(!0);try{const{error:Kt}=await R.from("applications").insert({job_id:c,worker_id:t.id,apply_source:"map"});if(Kt){const He=Kt.code==="23505",Bt=((F=(_=r==null?void 0:r.home)==null?void 0:_.laborer)==null?void 0:F.quickApply)??{};B.error(He?Bt.alreadyApplied??"You've already applied to this job":Bt.applyFailed??"Couldn't apply — try again",{duration:2500})}else{const He=((Te=(ce=r==null?void 0:r.home)==null?void 0:ce.laborer)==null?void 0:Te.quickApply)??{};B.success(He.applied??"Application sent",{duration:2e3}),y.invalidateQueries({queryKey:["worker-applied-job-ids",t.id]}),y.invalidateQueries({queryKey:["worker-pending-applications",t.id]}),st(null)}}finally{Tt(!1)}},[nt,at]=x.useState(k?"half":"peek"),[Ft,ot]=x.useState("list"),It=k&&nt!=="peek"&&Ft==="list",Be=It&&D.has("worker"),it=It&&D.has("sub"),[lt,ct]=x.useState(null),[Ks,Bs]=x.useState(0),[Hs,Us]=x.useState(0);x.useEffect(()=>{ot("list"),ct(null)},[b]);const $t=x.useRef(null),dt=x.useRef(null);x.useEffect(()=>{var _;if(!v||dt.current==="laborer")return;const c=Q.filter(F=>F.entityKind==="job"||F.entityKind==="sub_package");c.length!==0&&(dt.current="laborer",(_=$t.current)==null||_.fitBounds(c.map(F=>({lat:F.lat,lng:F.lng})),{padding:[56,56],maxZoom:13}))},[v,Q]),x.useEffect(()=>{v||(dt.current=null)},[v]);const Ws=c=>{ct(c.map(_=>_.id)),at("half")},zs=()=>{ot("attention"),at("half")};return e.jsxs("div",{className:"h-full relative",children:[e.jsx(Ys,{title:"Home · Knuckl",description:"Your Knuckl home"}),e.jsx(zn,{}),e.jsx(Yn,{}),Ct?e.jsxs("div",{className:"fixed left-0 right-0 isolate min-h-[420px] z-0 mx-auto w-full max-w-6xl overflow-hidden",style:{to
26p:"var(--app-content-top, 64px)",bottom:"var(--app-bottom-nav-h, 64px)"},children:[e.jsx(ir,{ref:$t,workers:ee,projects:St,storms:p,focusCircle:O,onBoundsChange:L,onMapTap:c=>{M&&c&&(m({lat:c.lat,lng:c.lng,radiusMi:25}),I(!1))},onSelect:c=>{const _=ee.find(F=>F.id===c);_&&rt(_)},onWorkerSelect:rt,onProjectTap:c=>je(c),onClusterOpen:Ws,awayLabel:((Rt=r==null?void 0:r.home)==null?void 0:Rt.awayLabel)??"mi away",fillParent:!0}),e.jsx(dr,{position:"bottom-left",entries:Ms}),e.jsx(Oa,{modeToggle:f?e.jsx($a,{mode:b,onModeChange:C,hiring:S,sub:h,laborer:w}):null,attention:e.jsx(da,{userId:t==null?void 0:t.id,hiringVisible:S,laborerVisible:w,mode:b,onOpenAll:zs}),subNudge:b==="sub"&&h?l==="free"?e.jsx(Na,{}):e.jsx(ho,{active:!0,specialtiesCount:((qt=(Ot=s==null?void 0:s.sub)==null?void 0:Ot.specialties)==null?void 0:qt.length)??0}):null,quickAction:b==="hiring"&&S?e.jsx(xa,{onCreateProject:()=>i("/contractor/projects/new"),onPostQuickJob:()=>he("flash"),onCreateSubPackage:()=>he("sub")}):b==="sub"&&h?e.jsx(wa,{}):b==="laborer"&&w&&!k?e.jsx(ja,{}):null,search:e.jsx(qa,{areaMode:M,onToggleArea:()=>{if(O){m(null),I(!1);return}I(c=>!c)},circle:O,onRadiusChange:c=>m(_=>_&&{..._,radiusMi:c}),onClearCircle:()=>m(null),count:Ee.reduce((c,_)=>c+(Pt[_]??0),0)}),bottom:e.jsxs("div",{className:"space-y-2",children:[k&&e.jsx(ga,{}),k&&e.jsx(ha,{}),k&&e.jsx(ya,{}),(k||j)&&e.jsx(Ia,{}),(k||j)&&e.jsx(Ta,{}),(k||j)&&e.jsx(Wa,{alerts:p}),v&&s&&s.lat==null&&e.jsx(pn,{}),v&&e.jsx(to,{jobPinCount:z}),v&&e.jsx(fn,{}),v&&e.jsx(xn,{}),e.jsx(Pa,{})]})}),!W&&oe&&e.jsx("div",{className:"absolute inset-x-0 top-24 mx-auto max-w-xs pointer-events-auto px-2",children:e.jsx(Pn,{onRetry:xe,isRetrying:fe,title:r.home.loadErrorTitle})}),!W&&!oe&&ee.length===0&&St.length===0&&(()=>{var ce,Te;const c=((ce=r.home.emptyStates)==null?void 0:ce[b])??((Te=r.home.emptyStates)==null?void 0:Te.hiring),_=c.subtitle??c.widenRadius,F=b==="hiring"?"/contractor/quick-post":b==="sub"?"/contractor/sub-jobs":"/jobs";return e.jsxs("div",{className:"absolute inset-x-0 top-24 mx-auto max-w-xs text-center bg-card/95 backdrop-blur border border-border rounded-xl px-4 py-3 shadow-sm pointer-events-auto",children:[e.jsx("p",{className:"text-sm text-foreground font-medium",children:c.title}),e.jsxs("div",{className:"mt-2 flex flex-wrap gap-2 justify-center",children:[e.jsx("span",{className:"text-caption text-muted-foreground",children:_}),e.jsx("button",{type:"button",onClick:()=>i(F),className:"text-caption font-semibold text-primary underline underline-offset-2 min-h-11 px-2",children:c.secondaryCta})]})]})})()]}):e.jsxs("div",{className:"mx-auto max-w-md px-6 py-12 text-center",children:[e.jsx("h1",{className:"font-display text-2xl text-foreground mb-3",children:r.appLayout.navHome}),e.jsx("p",{className:"text-sm text-muted-foreground",children:((Dt=r==null?void 0:r.home)==null?void 0:Dt.enableVisibility)??"Turn on hiring or laborer visibility from your profile to see the map."})]}),Ct&&e.jsxs(Ka,{children:[e.jsx(ur,{workers:ee,snap:nt,onSnapChange:at,mode:Ft,onModeChange:ot,onSelect:rt,onQueryChange:$,quickFilters:e.jsx(uo,{filters:P,onChange:U,onOpenPanel:()=>Y(!0)}),entityFilter:"all",onEntityFilterChange:()=>{},clusterSubsetIds:lt,onClearSubset:()=>ct(null),nearProjectsEnabled:!1,onNearProjectsToggle:()=>{},nearProjectsRadius:15,onNearProjectsRadiusChange:()=>{},projectCount:0,availableKinds:Z,selectedKinds:D,onKindToggle:Ce,kindCounts:Pt,userId:t==null?void 0:t.id,leadContent:nt==="peek"?void 0:e.jsx(fa,{variant:"line"}),onProjectSelect:c=>i(`/contractor/projects/${c}`),onJobSelect:c=>i(`/jobs/${c}`),onSubPackageSelect:c=>i(`/jobs/${c}`),onSubSelect:c=>tt(c),listHeader:Be?e.jsx(Ba,{}):void 0,sections:Be||it?{workers:Be?({query:c})=>e.jsx(Ha,{q:c,subsetIds:lt,onCount:Bs}):void 0,subs:it?({query:c})=>e.jsx(Ua,{q:c,subsetIds:lt,onCount:Us}):void 0}:void 0,sectionRenderedCount:(Be?Ks:0)+(it?Hs:0)}),e.jsx(bo,{open:q,onClose:()=>Y(!1),filters:P,onApply:U,pins:Q.filter(c=>D.has(c.entityKind)),availableKinds:Z,userId:t==null?void 0:t.id})]}),e.jsx(mr,{worker:Fs,onClose:()=>Pe(null),onInviteToJob:(c,_,F)=>{Pe(null),At({skill:c,workerId:_,workerName:F})},onViewProfile:c=>{i(`/profile/${c}`)},onInvitePrivate:(c,_,F)=>{Pe(null),Mt({workerId:c,workerName:_,skills:F})},onMessage:c=>{Pe(null),i(`/contractor/messages?to=${c}`)},canPostPrivateJob:u,lang:a}),e.jsx(Ma,{leadId:(ie==null?void 0:ie.id)??null,meta:(ie==null?void 0:ie.meta)??null,distanceMi:ie==null?void 0:ie.distanceMi,onClose:()=>Lt(null)}),e.jsx(Fa,{leadId:(le==null?void 0:le.id)??null,meta:(le==null?void 0:le.meta)??null,distanceMi:le==null?void 0:le.distanceMi,onClose:()=>Et(null)}),e.jsx(ta,{projectId:Is,currentUserId:t==null?void 0:t.id,onClose:()=>je(null),onViewDetails:c=>{if(!c)return;const _=`/contractor/projects/${c}`;i(_),je(null)},onPostNextPhase:c=>{je(null),i(`/contractor/projects/${c}?post=1`)},onReviewApplicants:c=>{je(null),i(`/contractor/applicants?project=${c}`)}}),e.jsx(ra,{subId:$s,onClose:()=>tt(null),onViewProfile:c=>i(`/profile/${c}`),onMessage:c=>i(`/contractor/messages?to=${c}`)}),e.jsx(bs,{open:!!ne,onClose:()=>At(null),skill:(ne==null?void 0:ne.skill)??"",workerId:(ne==null?void 0:ne.workerId)??"",workerName:(ne==null?void 0:ne.workerName)??""}),e.jsx(pr,{open:!!ae,onClose:()=>
26Mt(null),workerId:(ae==null?void 0:ae.workerId)??"",workerName:(ae==null?void 0:ae.workerName)??"",workerSkills:(ae==null?void 0:ae.skills)??[]}),e.jsx(Tr,{job:ve??null,locked:qs,onClose:()=>st(null),applying:Rs,onApply:Ds,isSaved:ve?!!(n!=null&&n.has(ve.id)):!1,onToggleSave:c=>{var F;if(!t){i("/auth");return}const _=((F=r==null?void 0:r.jobsList)==null?void 0:F.toasts)??{};n!=null&&n.has(c)?d.mutate(c,{onSuccess:()=>B.success(_.unsaved??"Removed from saved",{duration:1500})}):o.mutate(c,{onSuccess:()=>B.success(_.saved??"Job saved",{duration:1500})})}})]})}function ho({active:t,specialtiesCount:s}){var l,y,b,C,f;const r=se(),{t:a}=K(),{show:i,dismiss:n,markComplete:o}=Jr("sub_add_specialties_after_signup",t,{alreadyDone:s>0});if(!i)return null;const d=((b=(y=(l=a.prompts)==null?void 0:l.contextual)==null?void 0:y.sub)==null?void 0:b.addSpecialties)??{},u=((f=(C=a.prompts)==null?void 0:C.contextual)==null?void 0:f.dismissCta)??"Not now";return e.jsx(Vr,{icon:Dn,title:d.title??"Add specialties to see matching packages",body:d.body,primaryCta:d.cta??"Add specialties",onPrimary:()=>{o(),r("/profile?edit=specialties")},dismissCta:u,onDismiss:n})}export{fc 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.