1import{c as C,a as g,j as a}from"./vendor-query-BxlSJxfF.js";import{p as v,s as j,u as M,a as _,e as h}from"./index-DO0aGFYL.js";import{H as T}from"./Head-CFjoxvyt.js";import{u as D,a as W,M as L,C as k,E as $}from"./EditCommitmentSheet-3oIxmuf2.js";import{T as S}from"./TrackerViewSwitch-EaPPnucF.js";import{O as E}from"./OfferSheet-ChGpegXJ.js";import{u as F,c as A}from"./use-work-offers-i0L7CNkS.js";import{A as q}from"./AvailabilityCalendarCard-DYENFqXo.js";import{u as R}from"./vendor-react-DdNhUK9-.js";import{C as B}from"./calendar-bL1Vkweo.js";import"./vendor-supabase-Csx7YFID.js";import"./dollar-sign-4OmuIJls.js";import"./badge-4jZnSn2H.js";import"./alert-dialog-WBQzXKSB.js";import"./textarea-CY9O0h4D.js";import"./pencil-B-NCVQLG.js";import"./message-square-CLxZQpIa.js";import"./sheet-KxRpZ2qz.js";import"./label-Lh_RHPfV.js";import"./use-market-rate-BNhsAniP.js";import"./haptics-C4kiRWSa.js";import"./chevron-left-Bpy2VrDY.js";import"./chevron-right-n5eCbV2c.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 I=v("Compass",[["path",{d:"m16.24 7.76-1.804 5.411a2 2 0 0 1-1.265 1.265L7.76 16.24l1.804-5.411a2 2 0 0 1 1.265-1.265z",key:"9ktpf1"}],["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]]),N={earned:0,upcoming:0,potential:0,completedCount:0,upcomingCount:0,openOfferCount:0,isLoading:!1};function K(s){const t=(s==null?void 0:s.pay)!=null?Number(s.pay):0;if(!Number.isFinite(t)||t<=0)return 0;const i=Number(s==null?void 0:s.duration)>0?Number(s.duration):1,r=(s==null?void 0:s.pay_type)??"hourly";return r==="fixed"?t:r==="daily"?t*i:t*8*i}function P(s){const t=Number(s.rate);if(!Number.isFinite(t)||t<=0)return 0;let i=1;if(s.start_date&&s.end_date){const r=new Date(s.start_date).getTime(),n=new Date(s.end_date).getTime();Number.isFinite(r)&&Number.isFinite(n)&&n>=r&&(i=Math.round((n-r)/864e5)+1)}return s.pay_type==="fixed"?t:s.pay_type==="daily"?t*i:t*8*i}function V(s){const t=C({queryKey:["worker-financials",s],enabled:!!s,staleTime:6e4,queryFn:async()=>{const[i,r]=await Promise.all([j.from("applications").select("id, status, jobs!inner(id, title, pay, pay_type, duration, start_date, location, status)").eq("worker_id",s).in("status",["accepted","completed","paid"]),j.from("work_offers").select("id, rate, pay_type, start_date, end_date, status").eq("worker_id",s).in("status",["open","held","hired"])]),n=i.data??[],w=r.data??[];let u=0,f=0,y=0,m=0;for(const o of n){const l=K(o.jobs);o.status==="completed"||o.status==="paid"?(u+=l,y+=1):(f+=l,m+=1)}let x=0,d=0;for(const o of w){const l=P(o);o.status==="hired"?f+=l:(x+=l,d+=1)}return{earned:u,upcoming:f,potential:x,completedCount:y,upcomingCount:m,openOfferCount:d,isLoading:!1}}});return s?t.data??{...N,isLoading:t.isLoading}:N}function me(){const{user:s}=M(),{tr:t}=_(),i=R(),r=V(s==null?void 0:s.id),{data:n=[],isLoading:w}=D(),{data:u=[]}=F(),f=W(),y=A(),[m,x]=g.useState(null),[d,o]=g.useState(null),l=g.useMemo(()=>n.filter(e=>e.status==="accepted").sort((e,c)=>(e.startDate??"").localeCompare(c.startDate??"")),[n]),O=g.useMemo(()=>n.filter(e=>e.jobType!=="sub_package"),[n]),b=async(e,c)=>{try{await f.mutateAsync({id:e,reason:c}),h.success(t("crewOffers.withdrawn"))}catch(p){h.error((p==null?void 0:p.message)||t("crewOffers.withdrawFailed"))}};return a.jsxs("div",{className:"px-3 py-4 space-y-5 sm:px-5 sm:py-5 max-w-3xl mx-auto",children:[a.jsx(T,{title:"My work · Knuckl",description:"Your pay so far, upcoming work, availability and offers in one place."}),a.jsx(S,{current:"tracker",findWorkPath:"/jobs",findWorkLabelKey:"tabFindWork"}),a.jsxs("div",{className:"flex items-center justify-between gap-2",children:[a.jsx("h1",{className:"font-display text-xl text-foreground",children:t("crewOffers.workerBoardTitle")}),a.jsxs("button",{type:"button",onClick:()=>i("/future-work"),className:"inline-flex items-center gap-1 rounded-full bg-primary px-3 py-1.5 text-xs font-semibold text-primary-foreground",children:[a.jsx(I,{className:"w-3 h-3"})," ",t("crewOffers.futureWork")]})]}),a.jsx(L,{isLoading:r.isLoading,items:[{label:t("crewOffers.earned"),value:r.earned,hint:t("crewOffers.jobsDone").replace("{count}",String(r.completedCount))},{label:t("crewOffers.lockedIn"),value:r.upcoming,hint:t("crewOffers.upcomingCount").replace("{count}",String(r.upcomingCount))},{label:t("crewOffers.potential"),value:r.potential,hint:t("crewOffers.openOffers").replace("{count}",String(r.openOfferCount))}]}),a.jsxs("section",{className:"space-y-2",children:[a.jsx("h2",{className:"px-1 text-caption font-semibold uppercase tracking-widest text-muted-foreground",children:t("crewOffers.upcomingWork")}),w?a.jsx("div",{className:"h-20 rounded-card bg-card/60 border border-border/60 animate-pulse"}):l.length===0?a.jsx("p",{className:"px-1 text-xs text-muted-foreground",children:t("crewOffers.noUpcoming")}):a.jsx("div",{className:"space-y-2",children:l.map(e=>a.jsx(k,{kind:"application",status:e.status,title:e.jobTitle,subtitle:[e.startDate,e.location].filter(
6Boolean).join(" · "),meta:e.pay!=null?`$${Math.round(e.pay)}${e.payType==="hourly"?"/hr":""}`:void 0,affectsScore:!0,askReason:!0,onOpen:()=>i(`/jobs/${e.jobId}`),onWithdraw:c=>b(e.id,c),onMessage:()=>i("/messages")},e.id))})]}),a.jsxs("section",{className:"space-y-2",children:[a.jsxs("h2",{className:"px-1 flex items-center gap-1.5 text-caption font-semibold uppercase tracking-widest text-muted-foreground",children:[a.jsx(B,{className:"w-3.5 h-3.5"})," ",t("crewOffers.yourCalendar")]}),s&&a.jsx(q,{userId:s.id,editable:!0})]}),a.jsxs("section",{className:"space-y-2",children:[a.jsx("h2",{className:"px-1 text-caption font-semibold uppercase tracking-widest text-muted-foreground",children:t("crewOffers.myApplications")}),O.length===0?a.jsx("p",{className:"px-1 text-xs text-muted-foreground",children:t("crewOffers.noApplications")}):a.jsx("div",{className:"space-y-2",children:O.map(e=>a.jsx(k,{kind:"application",status:e.status,title:e.jobTitle,subtitle:[e.startDate,e.location].filter(Boolean).join(" · "),affectsScore:e.status==="accepted",onOpen:()=>i(`/jobs/${e.jobId}`),onEdit:()=>x(e),onWithdraw:c=>b(e.id,c),onMessage:()=>i("/messages")},e.id))})]}),a.jsxs("section",{className:"space-y-2",children:[a.jsx("h2",{className:"px-1 text-caption font-semibold uppercase tracking-widest text-muted-foreground",children:t("crewOffers.myOffers")}),u.length===0?a.jsx("p",{className:"px-1 text-xs text-muted-foreground",children:t("crewOffers.noOffers")}):a.jsx("div",{className:"space-y-2",children:u.map(e=>a.jsx(k,{kind:"offer",status:e.status,title:e.skill,subtitle:`$${Math.round(e.rate)}/hr${e.startDate?` · ${e.startDate}`:""}${e.endDate&&e.endDate!==e.startDate?`â${e.endDate}`:""}`,onEdit:()=>o(e),onWithdraw:async c=>{try{await y.withdraw.mutateAsync({id:e.id,reason:c}),h.success(t("crewOffers.withdrawn"))}catch(p){h.error((p==null?void 0:p.message)||t("crewOffers.withdrawFailed"))}},onMessage:()=>i("/messages")},e.id))})]}),a.jsx($,{open:!!m,onOpenChange:e=>!e&&x(null),item:m}),d&&a.jsx(E,{open:!!d,onOpenChange:e=>!e&&o(null),targetType:d.targetType,targetId:d.targetId,existing:d})]})}export{me 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.