import{i as e,n as t}from"./jsx-runtime-bzQ4Vb5N.js";import{x as n}from"./index-t_-MMk0R.js";var r=e(t(),1);function i(){let[e,t]=(0,r.useState)(null),[i,a]=(0,r.useState)(null),[o,s]=(0,r.useState)([]),[c,l]=(0,r.useState)(!0);return(0,r.useEffect)(()=>{let e=null,{data:r}=n.auth.onAuthStateChange((e,r)=>{t(r),a(r?.user??null),r?.user?setTimeout(async()=>{let{data:e}=await n.from(`user_roles`).select(`role`).eq(`user_id`,r.user.id);s((e??[]).map(e=>e.role))},0):s([])});return e=r,n.auth.getSession().then(({data:{session:e}})=>{t(e),a(e?.user??null),l(!1)}),()=>{e?.subscription.unsubscribe()}},[]),{session:e,user:i,roles:o,isAdmin:o.includes(`hq_admin`),loading:c}}export{i as t};