import{aR as c,s as p}from"./index-v-J1XWPJ.js";import{s as d}from"./supabase-edge-DhGEu5kl.js";async function l(){var a;const t=c(),{data:r}=await p.auth.getSession(),n=((a=r.session)==null?void 0:a.access_token)??t;return{"Content-Type":"application/json",apikey:t,Authorization:`Bearer ${n}`}}async function f(t,r){const n=d(t),a=await l();let e;try{e=await fetch(n,{method:"POST",headers:a,body:JSON.stringify(r)})}catch(s){const i=s instanceof Error?s.message:"Failed to fetch";return console.error(`[invokeEdgeFunctionPost] fetch threw for "${t}":`,i),{data:null,errorMessage:i==="Failed to fetch"?`Could not reach "${t}". In development, set VITE_SUPABASE_URL and restart the dev server so requests use the /sb-functions proxy. In production, deploy: supabase functions deploy ${t}`:i,httpStatus:0}}const u=await e.text();let o;try{o=JSON.parse(u)}catch{o={}}if(!e.ok){let s=typeof o.error=="string"?o.error:`Edge function "${t}" returned HTTP ${e.status}`;return e.status===404&&(s+=`. That usually means the function is not deployed to this Supabase project (running migrations does not deploy functions). From the project root: npx supabase functions deploy ${t}`),console.error(`[invokeEdgeFunctionPost] ${t} failed`,{status:e.status,err:s,body:u.slice(0,500)}),{data:null,errorMessage:s,httpStatus:e.status}}return{data:o,errorMessage:null,httpStatus:e.status}}export{l as g,f as i};