1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/emit.functions-Cw7QF_he.js","assets/index-BOoZFuWa.js"])))=>i.map(i=>d[i]); 2import{c as $,u as Q,e as H,z as V,r as N,s as d,a3 as W,a4 as K,j as t,L as v,I as z,g as P,a7 as U,M as Y,Q as b,a as G,h as x,_ as w,ay as J}from"./index-BOoZFuWa.js";import{a as X,C as Z}from"./app-shell-BjcDR96W.js";import{A as ee}from"./arrow-right-BB--XxhS.js";import{C as te}from"./calendar-dc_3PVmm.js";import{C as se}from"./clock-5RgofYM8.js";import{C as ae}from"./circle-x-COnvw6c-.js";import{C as E}from"./circle-check-Dlqecx-C.js";import{S as ie}from"./shield-check-D7xSLGV9.js";import{S as re}from"./siren-iH38AfWq.js";import"./bell-heW9z5p5.js";import"./at-sign-O0OVfKsi.js";import"./tier-badge-BS_ot_P_.js";import"./feedback.functions-52mFnH9m.js";import"./star-7QRc-wM9.js";import"./gift-B_HBNbrl.js";import"./users-CZw1mlml.js";import"./user-plus-B99o8SMc.js";import"./trophy-1OJ8FeBL.js";import"./crown-Daal2D_2.js";import"./info-Cf7MgNsT.js";import"./search-DLg3s1M3.js";import"./house-C5aSFVfe.js";import"./list-checks-Cv4-dcGV.js";import"./shopping-bag-CcD19NSf.js";import"./megaphone-UorZ1h2H.js";import"./chevron-down-DNuUnLmP.js";const ne=[["path",{d:"M12.659 22H18a2 2 0 0 0 2-2V8a2.4 2.4 0 0 0-.706-1.706l-3.588-3.588A2.4 2.4 0 0 0 14 2H6a2 2 0 0 0-2 2v9.34",key:"o6klzx"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M10.378 12.622a1 1 0 0 1 3 3.003L8.36 20.637a2 2 0 0 1-.854.506l-2.867.837a.5.5 0 0 1-.62-.62l.836-2.869a2 2 0 0 1 .506-.853z",key:"zhnas1"}]],oe=$("file-pen",ne),ce={requested:"bg-warning/15 text-warning",accepted:"bg-primary/15 text-primary",in_progress:"bg-primary/15 text-primary",completed:"bg-success/15 text-success",cancelled:"bg-muted text-muted-foreground",rejected:"bg-destructive/15 text-destructive",rescheduled:"bg-muted text-muted-foreground"};function De(){const{user:i}=Q(),L=H(),T=V(),[f,A]=N.useState("incoming"),[C,D]=N.useState([]);N.useEffect(()=>{i&&d.from("tasks").select("id,title,price_cents").eq("owner_id",i.id).eq("status","draft").order("updated_at",{ascending:!1}).limit(5).then(({data:e})=>D(e??[]))},[i]);const _=30,M=async(e,a)=>{if(!i)return[];const r=e==="incoming"?"provider_id":"requester_id";let n=d.from("bookings").select("*").eq(r,i.id).order("start_at",{ascending:!1}).limit(_);a&&(n=n.lt("start_at",a));const{data:o}=await n;let c=o||[];const u=e==="incoming"?"owner_id":"helper_id";let p=d.from("tasks").select("id,title,city,price_cents,duration_min,scheduled_at,status,owner_id,helper_id,created_at").eq(u,i.id).not("helper_id","is",null).in("status",["accepted","in_progress","completed","cancelled"]).order("created_at",{ascending:!1}).limit(_);a&&(p=p.lt("created_at",a));const{data:y}=await p,g=(y||[]).map(s=>({id:`task-${s.id}`,service_id:null,requester_id:s.helper_id,provider_id:s.owner_id,start_at:s.scheduled_at??s.created_at,end_at:s.scheduled_at??s.created_at,price_cents:s.price_cents??0,status:s.status==="in_progress"?"accepted":s.status,notes:s.title,service:s.city?{title:s.title,city:s.city,cover_url:null}:{title:s.title,city:"",cover_url:null}}));c=[...c,...g],c.sort((s,R)=>new Date(R.start_at).getTime()-new Date(s.start_at).getTime());const l=Array.from(new Set(c.map(s=>e==="incoming"?s.requester_id:s.provider_id))),[{data:k}]=await Promise.all([l.length?d.from("profiles").select("id,display_name,avatar_url,handle").in("id",l):Promise.resolve({data:[]})]),j=new Map((k||[]).map(s=>[s.id,s]));return c.map(s=>({...s,service:s.service??null,other:j.get(e==="incoming"?s.requester_id:s.provider_id)}))},m=W({queryKey:["bookings",i?.id,f,"infinite-v2"],enabled:!!i,staleTime:6e4,initialPageParam:null,queryFn:({pageParam:e})=>M(f,e),getNextPageParam:e=>{if(!(!e||!e.length||e.length<_))return e[e.length-1].start_at}}),S=(m.data?.pages??[]).flat(),q=m.isLoading&&!m.data,B=K({hasNextPage:m.hasNextPage,isFetchingNextPage:m.isFetchingNextPage,fetchNextPage:m.fetchNextPage}),O=()=>{T.invalidateQueries({queryKey:["bookings",i?.id]})},h=async(e,a)=>{if(e.startsWith("task-")){const r=e.slice(5),n=a==="rejected"?"cancelled":a,{error:o}=await d.from("tasks").update({status:n}).eq("id",r);
2if(o)return x.error(o.message)}else{const{error:r}=await d.from("bookings").update({status:a}).eq("id",e);if(r)return x.error(r.message)}x.success(`Booking ${a}`),O()},F=async e=>{if(!i||!await b({title:"Send SOS alert?",message:"This will notify our safety team and your buddy with your current location.",confirmLabel:"Send SOS",danger:!0}))return;const r=await J({title:"Contact number",message:"Best number for our safety team to call you on now.",placeholder:"+91 98xxxxxxx",confirmLabel:"Send"});if(!r)return;let n=null,o=null;try{const{requestBrowserCoords:g}=await w(async()=>{const{requestBrowserCoords:k}=await import("./index-BOoZFuWa.js").then(j=>j.bP);return{requestBrowserCoords:k}},[]),l=await g();l&&(n=l.lat,o=l.lng)}catch{}const c=e.startsWith("task-"),u={user_id:i.id,lat:n,lng:o,message:`SOS · call ${r}`};c?u.task_id=e.slice(5):u.booking_id=e;const{data:p,error:y}=await d.from("sos_events").insert(u).select("id").single();if(y)return x.error(y.message);try{const{safeEmit:g}=await w(async()=>{const{safeEmit:l}=await import("./emit.functions-Cw7QF_he.js");return{safeEmit:l}},__vite__mapDeps([0,1]));g({type:"sos.raised",payload:{sosId:p.id}})}catch{}x.success("SOS sent. Help is on the way.")},I=async e=>{if(!i)return;const a=e.startsWith("task-");if(!await b({title:"Safety check-in",message:"Confirm you're safe. This is logged for our safety team and clears any open SOS alert you raised for this job.",confirmLabel:"I'm safe"}))return;const{data:n,error:o}=await d.rpc("safety_checkin_create",{_task_id:a?e.slice(5):null,_booking_id:a?null:e,_status:"ok",_note:"All good"});if(o)return x.error(o.message);const c=n||{};try{const{safeEmit:u}=await w(async()=>{const{safeEmit:p}=await import("./emit.functions-Cw7QF_he.js");return{safeEmit:p}},__vite__mapDeps([0,1]));u({type:"safety.checkin_created",payload:{checkinId:c.checkin_id??""}})}catch{}x.success(c.sos_resolved?"Check-in recorded · your open SOS was closed":"Check-in recorded · safety team notified")};return t.jsxs("div",{className:"mx-auto max-w-md",children:[t.jsx(X,{back:!0,backTo:"/app",title:"Bookings",subtitle:"Your service requests and jobs"}),t.jsx("div",{className:"px-5",children:t.jsx("div",{className:"grid grid-cols-2 bg-card rounded-2xl p-1 shadow-soft",children:["incoming","outgoing"].map(e=>t.jsx("button",{onClick:()=>A(e),className:`py-2.5 rounded-xl text-sm font-semibold capitalize transition ${f===e?"bg-foreground text-background":"text-muted-foreground"}`,children:e==="incoming"?"Jobs for me":"My bookings"},e))})}),t.jsxs("div",{className:"px-5 mt-4 pb-6 space-y-3",children:[C.length>0&&t.jsxs("div",{className:"rounded-2xl bg-warning/10 border border-warning/30 p-4",children:[t.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold",children:[t.jsx(oe,{className:"size-4 text-warning"})," Drafts"]}),t.jsx("ul",{className:"mt-2 space-y-1.5",children:C.map(e=>t.jsx("li",{children:t.jsxs(v,{to:"/app/create",search:{draft:e.id},className:"flex items-center justify-between gap-2 rounded-xl bg-card px-3 py-2 text-sm",children:[t.jsx("span",{className:"truncate",children:e.title||"Untitled draft"}),t.jsxs("span",{className:"text-xs text-muted-foreground inline-flex items-center gap-1 shrink-0",children:[z(e.price_cents)," ",t.jsx(ee,{className:"size-3"})]})]})},e.id))})]}),q&&t.jsx("div",{className:"flex justify-center py-10",children:t.jsx(P,{className:"size-5 animate-spin text-primary"})}),!q&&S.length===0&&t.jsx(U,{icon:Z,title:"No bookings yet",description:f==="incoming"?"Task requests will appear here.":"Book a buddy for a task to get started.",actionLabel:"Browse tasks",onAction:()=>L({to:"/app/browse"})}),S.map(e=>{const a=f==="incoming";return t.jsxs("div",{className:"bg-card rounded-2xl p-4 shadow-soft",children:[t.jsxs("div",{className:"flex items-start gap-3",children:[e.service?.cover_url?t.jsx("img",{src:e.service.cover_url,alt:"",className:"size-14 rounded-xl object-cover shrink-0"}):t.jsx("div",{className:"size-14 rounded-xl bg-secondary flex items-center justify-center shrink-0",children:t.jsx(te,{className:"size-5 text-muted-foreground"})}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsx("h3",{className:"font-display font-semibold truncate",children:e.service?.title??"Service"}),t.jsx("span",{className:`text-[10px] font-bold uppercase px-2 py-0.5 rounded-full ${ce[e.status]||"bg-muted"}`,children:e.status})]}),t.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5 inline-flex items-center gap-1",children:[t.jsx(se,{className:"size-3"}
2),new Date(e.start_at).toLocaleString()]}),e.service?.city&&t.jsxs("p",{className:"text-xs text-muted-foreground inline-flex items-center gap-1",children:[t.jsx(Y,{className:"size-3"}),e.service.city]}),e.other&&t.jsxs("p",{className:"text-xs mt-1",children:[a?"From":"With"," ",t.jsxs(v,{to:"/app/profile/$id",params:{id:e.other.id},className:"font-semibold text-primary",children:["@",e.other.handle??e.other.display_name]})]}),e.notes&&t.jsxs("p",{className:"text-xs text-muted-foreground mt-1 line-clamp-2",children:['"',e.notes,'"']})]})]}),t.jsxs("div",{className:"mt-3 flex items-center justify-between",children:[t.jsx("p",{className:"font-bold text-primary",children:z(e.price_cents)}),t.jsxs("div",{className:"flex gap-2",children:[a&&e.status==="requested"&&t.jsxs(t.Fragment,{children:[t.jsxs("button",{onClick:()=>h(e.id,"rejected"),className:"rounded-full bg-muted px-3 py-1.5 text-xs font-semibold inline-flex items-center gap-1",children:[t.jsx(ae,{className:"size-3.5"}),"Decline"]}),t.jsxs("button",{onClick:()=>h(e.id,"accepted"),className:"rounded-full bg-gradient-warm text-primary-foreground px-3 py-1.5 text-xs font-semibold inline-flex items-center gap-1",children:[t.jsx(E,{className:"size-3.5"}),"Accept"]})]}),e.status==="accepted"&&t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:async()=>{await b({title:"Cancel booking?",message:"Funds will be refunded to the buyer.",confirmLabel:"Cancel booking",danger:!0})&&h(e.id,"cancelled")},className:"rounded-full bg-muted px-3 py-1.5 text-xs font-semibold",children:"Cancel"}),t.jsxs("button",{onClick:()=>h(e.id,"completed"),className:"rounded-full bg-gradient-warm text-primary-foreground px-3 py-1.5 text-xs font-semibold inline-flex items-center gap-1",children:[t.jsx(E,{className:"size-3.5"}),"Mark complete"]})]}),(e.status==="requested"||e.status==="accepted")&&!a&&t.jsxs(v,{to:"/app/chats",className:"rounded-full bg-card border border-border px-3 py-1.5 text-xs font-semibold inline-flex items-center gap-1",children:[t.jsx(G,{className:"size-3.5"}),"Chat"]})]})]}),e.status==="accepted"&&t.jsxs("div",{className:"mt-2 pt-2 border-t border-border flex items-center gap-2",children:[t.jsxs("button",{onClick:()=>I(e.id),className:"flex-1 rounded-full bg-success/10 text-success text-xs font-semibold py-2 inline-flex items-center justify-center gap-1",children:[t.jsx(ie,{className:"size-3.5"}),"Safety check-in"]}),t.jsxs("button",{onClick:()=>F(e.id),className:"flex-1 rounded-full bg-destructive/10 text-destructive text-xs font-semibold py-2 inline-flex items-center justify-center gap-1",children:[t.jsx(re,{className:"size-3.5"}),"SOS"]})]})]},e.id)}),t.jsx("div",{ref:B,className:"h-6 flex items-center justify-center",children:m.isFetchingNextPage&&t.jsx(P,{className:"size-4 animate-spin text-muted-foreground"})})]})]})}export{De as component};
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.