1import{a as y,b as v,s,u as l,d as c}from"./index-DH6psoju.js";import{b as g,f as S,s as _}from"./shootBookings-D8UnERv-.js";import{n as w}from"./bookingMessages-cZ8LmiNX.js";function b(){const{user:o}=y();return v({queryKey:["shoot-requests",o==null?void 0:o.id],queryFn:async()=>{if(!o)return[];const{data:t,error:i}=await s.from("shoot_plan_talent").select("*, package:service_packages(id, title, rate_cents, rate_type), shoot_plan:shoot_plans!shoot_plan_talent_shoot_plan_id_fkey(id, title, shoot_date, shoot_time, location, user_id, created_at, is_paid, commercial, notes, shoot_types, creator:profiles!shoot_plans_user_id_fkey(display_name, avatar_url))").eq("user_id",o.id).eq("status","pending");if(i)throw i;return t||[]},enabled:!!o})}function D(){const{user:o}=y(),t=l();return c({mutationFn:async({talentEntryId:i,rateCents:a})=>{if(!o)throw new Error("Not authenticated");const{data:e,error:r}=await s.from("shoot_plan_talent").select("id, shoot_plan_id, user_id, package_id").eq("id",i).single();if(r||!e)throw new Error("Talent entry not found");const{data:u,error:m}=await s.from("shoot_plans").select("id, user_id, title, shoot_date, shoot_time, location, notes, commercial, is_paid").eq("id",e.shoot_plan_id).single();if(m||!u)throw new Error("Shoot plan not found");let d;if(a&&a>0){const{data:n,error:q}=await s.functions.invoke("accept-shoot-invoice",{body:{talent_entry_id:i,rate_cents:a}});if(q)throw q;if(n!=null&&n.error)throw new Error(n.error);d=n}else{const{error:n}=await s.from("shoot_plan_talent").update({status:"accepted"}).eq("id",i);if(n)throw n;d=void 0}const h=(d==null?void 0:d.invoice_status)==="awaiting_payment"?"awaiting_payment":"accepted",p=g(u,i,e.package_id??null),f=await S(i);return f?await s.from("booking_requests").update({status:h,rate_cents:a||0,platform_fee_cents:a?Math.round(a*.2):0,details:p}).eq("id",f.id):await s.from("booking_requests").insert({requester_id:u.user_id,target_id:o.id,status:h,rate_cents:a||0,platform_fee_cents:a?Math.round(a*.2):0,details:p}),await w(o.id,u.user_id,h==="awaiting_payment"?"awaiting_payment":"accepted",u.title||"Shoot",{rateCents:a,link:`View this shoot at /shoot/${u.id}`}),d},onMutate:async({talentEntryId:i})=>{await t.cancelQueries({queryKey:["shoot-requests"]});const a=t.getQueryData(["shoot-requests"]);return t.setQueriesData({queryKey:["shoot-requests"]},e=>(e||[]).filter(r=>r.id!==i)),{prev:a}},onError:(i,a,e)=>{e!=null&&e.prev&&t.setQueriesData({queryKey:["shoot-requests"]},e.prev)},onSettled:()=>{t.invalidateQueries({queryKey:["shoot-requests"]}),t.invalidateQueries({queryKey:["my-shoots"]}),t.invalidateQueries({queryKey:["shoot-detail"]}),t.invalidateQueries({queryKey:["shoot-talent-detail"]}),t.invalidateQueries({queryKey:["booking-requests"]})}})}function F(){const{user:o}=y(),t=l();return c({mutationFn:async i=>{const{error:a}=await s.from("shoot_plan_talent").update({status:"denied"}).eq("id",i);if(a)throw a;await _(i,"declined");const{data:e}=await s.from("shoot_plan_talent").select("shoot_plan_id").eq("id",i).maybeSingle();if(e&&o){const{data:r}=await s.from("shoot_plans").select("id, user_id, title").eq("id",e.shoot_plan_id).maybeSingle();r&&await w(o.id,r.user_id,"declined",r.title||"Shoot",{link:`View this shoot at /shoot/${r.id}`})}},onMutate:async i=>{await t.cancelQueries({queryKey:["shoot-requests"]});const a=t.getQueryData(["shoot-requests"]);return t.setQueriesData({queryKey:["shoot-requests"]},e=>(e||[]).filter(r=>r.id!==i)),{prev:a}},onError:(i,a,e)=>{e!=null&&e.prev&&t.setQueriesData({queryKey:["shoot-requests"]},e.prev)},onSettled:()=>{t.invalidateQueries({queryKey:["shoot-requests"]}),t.invalidateQueries({queryKey:["my-shoots"]}),t.invalidateQueries({queryKey:["shoot-detail"]}),t.invalidateQueries({queryKey:["shoot-talent-detail"]})}})}function M(){const o=l();return c({mutationFn:async({shootPlanId:t,role:i,talentEntryId:a})=>{if(i==="creator"){const{error:e}=await s.from("shoot_plans").update({checked_in_at:new Date().toISOString(),status:"in_progress"}).eq("id",t);if(e)throw e}else if(a){const{error:e}=await s.from("shoot_plan_talent").update({checked_in_at:new Date().toISOString()}).eq("id",a);if(e)throw e;await _(a,"checked_in",{checked_in_at:new Date().toISOString()})}},onSettled:()=>{o.invalidateQueries({queryKey:["my-shoots"]}),o.invalidateQueries({queryKey:["shoot-talent-profiles"]}),o.invalidateQueries({queryKey:["booking-requests"]})}})}function O(){const o=l();return c({mutationFn:async t=>{const{error:i}=await s.from("shoot_plan_talent").update({checked_in_at:new Date().toISOString()}).eq("id",t);if(i)throw i;await _(t,"checked_in",{checked_in_at:new Date().toISOString()})},onSettled:()=>{o.invalidateQueries({queryKey:["my-shoots"]}),o.invalidateQueries({queryKey:["shoot-talent-profiles"]}),o.invalidateQueries({queryKey:["booking-requests"]})}})}function B(){const o=l();return c({mutationFn:async t=>{const{error:i}=await s.from("shoot_plans").update({status:"completed"}).eq("id",t);if(i)throw i;const{data:a}=await s.from("shoot_plan_talent").select("id, status").eq("shoot_plan_id",t);for(const e of a||[])e.status!=="denied"&&await _(e.id,"completed")},onSettled:()=>{o.invalidateQueries({queryKey:["my-shoots"]}),o.invalidateQueries({queryKey:["review-pending-shoots"]}),o.invalidateQueries({queryKey:["booking-requests"]})}})}function A(){const o=l();return c({mutationFn:async({shootPlanId:t,role:i,talentEntryId:a})=>{if(i==="creator"){const{error:e}=await s.from("shoot_plans").update({creator_has_reviewed:!0}).eq("id",t);if(e)throw e}else if(a){const{error:e}=await s.from("shoot_plan_talent").update({has_reviewed:!0}).eq("id",a);if(e)throw e}},onSettled:()=>{o.invalidateQueries({queryKey:["review-pending-shoots"]}),o.invalidateQueries({queryKey:["my-shoots"]})}})}
1export{D as a,F as b,M as c,B as d,O as e,A as f,b as u};
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.