import{r as l,u as j,j as e,L as x,O as b}from"./index-DEjMkqlI.js";import{s as c}from"./client-DXODAVLv.js";import{B as d}from"./button-CPTgagfA.js";import{c as h}from"./createLucideIcon-DqYrWYDW.js";const N=[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"M10 14 21 3",key:"gplh6r"}],["path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6",key:"a6xqqp"}]],y=h("external-link",N);const k=[["path",{d:"m16 17 5-5-5-5",key:"1bji2h"}],["path",{d:"M21 12H9",key:"dn1m92"}],["path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4",key:"1uf3rs"}]],v=h("log-out",k);function S(){const[s,i]=l.useState(null),[r,t]=l.useState(null),[n,g]=l.useState(!0);return l.useEffect(()=>{const{data:f}=c.auth.onAuthStateChange((a,o)=>{i(o),o?.user?setTimeout(()=>u(o.user.id),0):t(null)});c.auth.getSession().then(({data:a})=>{i(a.session),a.session?.user&&u(a.session.user.id),g(!1)});async function u(a){const{data:o}=await c.from("user_roles").select("role").eq("user_id",a),m=(o??[]).map(p=>p.role);m.includes("admin")?t("admin"):m.includes("editor")?t("editor"):t(null)}return()=>f.subscription.unsubscribe()},[]),{session:s,user:s?.user??null,role:r,loading:n}}function _(){const{session:s,role:i,loading:r,user:t}=S(),n=j();return l.useEffect(()=>{!r&&!s&&n({to:"/auth"})},[r,s,n]),r||!s?e.jsx("div",{className:"min-h-screen flex items-center justify-center text-muted-foreground",children:"Loading..."}):i?e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx("header",{className:"border-b border-border bg-onyx sticky top-0 z-40 backdrop-blur",children:e.jsxs("div",{className:"container mx-auto px-5 md:px-8 h-16 flex items-center justify-between",children:[e.jsxs(x,{to:"/admin",className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-display text-xl",children:"Luxxen"}),e.jsx("span",{className:"font-display text-xl text-gradient-gold",children:"Admin"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"hidden md:inline text-xs uppercase tracking-widest text-gold",children:i}),e.jsx(d,{asChild:!0,variant:"ghost",size:"sm",children:e.jsxs(x,{to:"/",children:["View Site ",e.jsx(y,{className:"ml-1",size:14})]})}),e.jsxs(d,{variant:"outline",size:"sm",onClick:async()=>{await c.auth.signOut(),n({to:"/auth"})},children:[e.jsx(v,{size:14})," Sign Out"]})]})]})}),e.jsx(b,{})]}):e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background bg-spotlight px-5",children:e.jsxs("div",{className:"max-w-md text-center bg-onyx border border-border p-10",children:[e.jsx("h1",{className:"font-display text-3xl",children:"Awaiting Access"}),e.jsxs("p",{className:"text-muted-foreground mt-4",children:["Your account is signed in but does not have a staff role assigned yet. An existing admin must grant you the ",e.jsx("span",{className:"text-gold",children:"admin"})," or"," ",e.jsx("span",{className:"text-gold",children:"editor"})," role from the backend."]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-4",children:["Signed in as ",e.jsx("span",{className:"text-foreground",children:t?.email})]}),e.jsx(d,{variant:"goldOutline",className:"mt-6",onClick:async()=>{await c.auth.signOut(),n({to:"/auth"})},children:"Sign Out"})]})})}export{_ as component};
