1import{u as d,b as a}from"./tanstack-query-C4Rmc9IY.js";import{s}from"./conversation-persistence-CGWp55YO.js";import{aq as m,aB as f,a9 as c,q as l}from"./main-COtOSdW3.js";import{f as w}from"./functionsError-DtuP0aRo.js";function v(){const{user:e}=m(),{data:r,isLoading:t}=f(),{data:i,isLoading:o,error:_}=a({queryKey:["stripe-subscription",r],queryFn:async()=>{const{data:p,error:u}=await s.from("stripe_subscriptions").select("stripe_subscription_id, stripe_customer_id, company_id, user_id, status, granted_seats, granted_module_keys, granted_video_minutes, price_ids, currency, collection_method, current_period_end, cancel_at_period_end").order("created_at",{ascending:!1}).limit(1);if(u)throw u;return p?.[0]??null},enabled:!!e?.id,staleTime:60*1e3,retry:1}),n=i??null;return{subscription:n,hasActiveSubscription:!!n&&c(n.status),isActive:!!n&&c(n.status),currentPeriodEnd:n?.current_period_end?new Date(n.current_period_end):null,isPastDue:n?.status==="past_due",isLoading:!!e?.id&&(o||t),error:_}}function k(e=24){return a({queryKey:["stripe-invoices",e],queryFn:async()=>{const{data:r,error:t}=await s.from("stripe_invoices").select("stripe_invoice_id, number, status, amount_due, amount_paid, currency, due_date, hosted_invoice_url, invoice_pdf, paid_out_of_band").order("created_at",{ascending:!1}).limit(e);if(t)throw t;return r??[]},staleTime:300*1e3})}function q(e){return a({queryKey:["company-seat-status",e],queryFn:async()=>{if(!e)return null;const{data:r,error:t}=await s.rpc("get_company_seat_status",{_company_id:e});if(t)throw t;return r??null},enabled:!!e,staleTime:60*1e3})}function S(){return d({mutationFn:async e=>{const r=window.location.origin,t=`${r}${window.location.pathname}`,{data:i,error:o}=await s.functions.invoke("stripe-checkout",{body:{successUrl:`${r}/billing`,cancelUrl:t,...e}});if(o)throw new Error(await w(o,"Kunne ikke starte kjøpet. Prøv igjen."));if(!i?.url)throw new Error(i?.message||"Checkout session returned no URL");return l(i.url)},onSuccess:e=>{window.location.href=e}})}function U(){return d({mutationFn:async()=>{const{data:e,error:r}=await s.functions.invoke("stripe-portal",{body:{returnUrl:`${window.location.origin}/billing`}});if(r)throw r;if(!e?.url)throw new Error("Portal session returned no URL");return l(e.url)},onSuccess:e=>{window.location.href=e}})}export{k as a,U as b,S as c,v as d,q 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.