import{o as e,r as t}from"./jsx-runtime-Bypl69v7.js";import{t as n,w as r}from"./index-BMtPAEHs.js";import{a as i}from"./button-CYVyx32W.js";var a=i(`x`,[[`path`,{d:`M18 6 6 18`,key:`1bl5f8`}],[`path`,{d:`m6 6 12 12`,key:`d8bk6v`}]]),o=e(t(),1),s=[`dashboard`,`analytics`,`uploads`,`open-jobs`,`customers`,`emails`,`history`,`support`,`settings`];function c(e,t){if(e.isSuperAdmin)return!0;let n=e.perms[t];return!n||n.can_view}function l(){let[e,t]=(0,o.useState)({user:null,role:null,isSuperAdmin:!1,isAdmin:!1,perms:{},loading:!0,displayName:null});return(0,o.useEffect)(()=>{let e=!1;async function i(i){if(!i){e||t({user:null,role:null,isSuperAdmin:!1,isAdmin:!1,perms:{},loading:!1,displayName:null});return}n();let[a,o,s]=await Promise.all([r.from(`user_roles`).select(`role`).eq(`user_id`,i.id),r.from(`page_permissions`).select(`page,can_view,can_edit`).eq(`user_id`,i.id),r.from(`profiles`).select(`full_name`).eq(`id`,i.id).maybeSingle()]),c=(a.data??[]).map(e=>e.role),l=c.includes(`super_admin`),u=l||c.includes(`admin`),d=l?`super_admin`:u?`admin`:`user`,f={};for(let e of o.data??[])f[e.page]=e;let p=i.user_metadata?.nickname||i.user_metadata?.full_name,m=s.data?.full_name||p||null;e||t({user:i,role:d,isSuperAdmin:l,isAdmin:u,perms:f,loading:!1,displayName:m})}r.auth.getUser().then(({data:e})=>i(e.user));let{data:a}=r.auth.onAuthStateChange((e,t)=>i(t?.user??null));return()=>{e=!0,a.subscription.unsubscribe()}},[]),e}export{a as i,c as n,l as r,s as t};