1import{j as e,r as c}from"./react-vendor-DKK5h-4S.js";import{N as k,L as n}from"./router-CKFl4ZoT.js";import{aQ as q,aR as D,aS as E,s as i}from"./index-rOX5Rmnz.js";import{B as r}from"./button-OGp97DSX.js";import{C as d,d as o,a as p,b as f}from"./card-C_8Augd4.js";import{B as g}from"./badge-Bx20qK3l.js";import{A as B}from"./AdminLayout-xtLJHO7X.js";import{a1 as $,D as I,y as P,as as j,aa as z,aq as u,a2 as Q}from"./icons-CoEihuPy.js";import"./query-BddnajNh.js";import"./supabase-CJoCJpoI.js";import"./ui-extras-CIMz-jDr.js";import"./radix-DQ8yzr2B.js";import"./forms-DGqSpeMD.js";import"./dropdown-menu-COjvxBet.js";function T(){const{user:v,loading:N}=q(),{hasRole:l,loading:b}=D("admin"),{activeSite:s,loading:m}=E(),[a,w]=c.useState(null),[_,h]=c.useState(!0);if(c.useEffect(()=>{if(!l||m||!s)return;let t=!1;return(async()=>{h(!0);const[y,A,L,R,S]=await Promise.all([i.from("landing_pages").select("id",{count:"exact",head:!0}).eq("site_id",s.id),i.from("landing_pages").select("id",{count:"exact",head:!0}).eq("site_id",s.id).like("slug","services/%"),i.from("therapist_routing").select("id",{count:"exact",head:!0}).eq("active",!0),i.from("sites").select("id",{count:"exact",head:!0}),i.from("landing_pages").select("id",{count:"exact",head:!0}).eq("site_id",s.id).eq("status","published")]);t||(w({pages:y.count??0,published:S.count??0,services:A.count??0,therapists:L.count??0,sites:R.count??0}),h(!1))})(),()=>{t=!0}},[l,m,s?.id]),N||b)return e.jsx("div",{className:"p-8",children:"Loadingâ¦"});if(!v)return e.jsx(k,{to:"/_studio/auth",replace:!0});if(!l)return e.jsx("div",{className:"min-h-screen flex items-center justify-center p-8 text-center",children:e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-serif mb-2",children:"Access pending"}),e.jsx("p",{className:"text-muted-foreground mb-4",children:"Your account does not have admin access yet."}),e.jsx(r,{onClick:async()=>{await i.auth.signOut()},variant:"outline",children:"Sign out"})]})});const C=[{label:"Landing pages",value:a?.pages??"â",icon:$,href:"/_studio/pages",sub:a?`${a.published} live`:""},{label:"Service pages",value:a?.services??"â",icon:I,href:"/_studio/services",sub:"In services/*"},{label:"Active therapists",value:a?.therapists??"â",icon:P,href:"/_studio/therapists",sub:"Across all sites"},{label:"Sites",value:a?.sites??"â",icon:j,href:"/_studio/sites",sub:"Domains managed"}];return e.jsxs(B,{title:"Dashboard",subtitle:s?`Editing ${s.name} · ${s.primary_domain}`:"Choose a site to begin",children:[e.jsx("div",{className:"grid gap-4 sm:grid-cols-2 lg:grid-cols-4",children:C.map(t=>{const x=t.icon;return e.jsx(n,{to:t.href,children:e.jsx(d,{className:"hover:shadow-elevated transition-shadow cursor-pointer h-full",children:e.jsxs(o,{className:"pt-5",children:[e.jsxs("div",{className:"flex items-start justify-between mb-3",children:[e.jsx("div",{className:"h-10 w-10 rounded-xl bg-primary/10 text-primary flex items-center justify-center",children:e.jsx(x,{className:"h-5 w-5"})}),e.jsx(z,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx("div",{className:"text-2xl font-semibold",children:_?"â¦":t.value}),e.jsx("div",{className:"text-sm text-muted-foreground",children:t.label}),t.sub&&e.jsx("div",{className:"text-xs text-muted-foreground/80 mt-1",children:t.sub})]})})},t.label)})}),e.jsxs("div",{className:"mt-8 grid gap-4 lg:grid-cols-2",children:[e.jsxs(d,{children:[e.jsx(p,{children:e.jsx(f,{className:"text-base",children:"Quick actions"})}),e.jsxs(o,{className:"flex flex-wrap gap-2",children:[e.jsx(r,{asChild:!0,children:e.jsxs(n,{to:"/_studio/pages/new",children:[e.jsx(u,{className:"h-4 w-4 mr-1"}),"New landing page"]})}),e.jsx(r,{asChild:!0,variant:"outline",children:e.jsxs(n,{to:"/_studio/services",children:[e.jsx(u,{className:"h-4 w-4 mr-1"}),"Import service page"]})}),e.jsx(r,{asChild:!0,variant:"outline",children:e.jsxs(n,{to:"/_studio/sites/new",children:[e.jsx(u,{className:"h-4 w-4 mr-1"}),"New site"]})})]})]}),e.jsxs(d,{children:[e.jsx(p,{children:e.jsx(f,{className:"text-base",children:"Active site"})}),e.jsx(o,{children:s?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium",children:s.name}),s.is_default&&e.jsx(g,{children:"Default"})]}),e.jsxs("div",{className:"text-sm text-muted-foreground flex items-center gap-1",children:[e.jsx(j,{className:"h-3 w-3"})," ",s.primary_domain]}),e.jsx("div",{className:"flex flex-wrap gap-1 mt-2",children:s.domains.map(t=>e.jsx(g,{variant:"secondary",className:"text-[10px]",children:t},t))}),e.jsxs("div",{className:"pt-3 flex gap-2",children:[e.jsx(r,{asChild:!0,size:"sm",variant:"outline",children:e.jsx(n,{to:`/_
1studio/sites/${s.id}/edit`,children:"Edit site"})}),e.jsx(r,{asChild:!0,size:"sm",variant:"outline",children:e.jsxs("a",{href:`https://${s.primary_domain}`,target:"_blank",rel:"noreferrer",children:[e.jsx(Q,{className:"h-3 w-3 mr-1"}),"Visit"]})})]})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"No active site. Pick one from the switcher above."})})]})]})]})}function se(){return e.jsx(T,{})}export{se as default};
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.