import { jsxs, jsx } from "react/jsx-runtime";
import { Link } from "@tanstack/react-router";
import { useState, useEffect } from "react";
import { s as supabase } from "./client-P40JY-SL.js";
import "@supabase/supabase-js";
function AdminHome() {
  const [stats, setStats] = useState({
    projects: 0,
    blogs: 0,
    leads: 0
  });
  const [isAdmin, setIsAdmin] = useState(null);
  useEffect(() => {
    (async () => {
      const {
        data: user
      } = await supabase.auth.getUser();
      if (user.user) {
        const {
          data: roles
        } = await supabase.from("user_roles").select("role").eq("user_id", user.user.id);
        setIsAdmin(!!roles?.some((r) => r.role === "admin"));
      }
      const [p, b, l] = await Promise.all([supabase.from("projects").select("*", {
        count: "exact",
        head: true
      }), supabase.from("blog_posts").select("*", {
        count: "exact",
        head: true
      }), supabase.from("leads").select("*", {
        count: "exact",
        head: true
      })]);
      setStats({
        projects: p.count ?? 0,
        blogs: b.count ?? 0,
        leads: l.count ?? 0
      });
    })();
  }, []);
  return /* @__PURE__ */ jsxs("div", { children: [
    /* @__PURE__ */ jsx("h1", { className: "font-display text-3xl font-bold", children: "Dashboard" }),
    isAdmin === false && /* @__PURE__ */ jsx("div", { className: "mt-4 border border-amber-500/40 bg-amber-50 p-4 text-sm", children: "Your account is not yet an admin. Lead inserts, project edits, and blog edits will be denied until an admin role is granted to you in the database." }),
    /* @__PURE__ */ jsxs("div", { className: "mt-8 grid gap-6 sm:grid-cols-3", children: [
      /* @__PURE__ */ jsx(StatCard, { label: "Projects", value: stats.projects, to: "/admin/projects" }),
      /* @__PURE__ */ jsx(StatCard, { label: "Blog Posts", value: stats.blogs, to: "/admin/blogs" }),
      /* @__PURE__ */ jsx(StatCard, { label: "Leads", value: stats.leads, to: "/admin/leads" })
    ] })
  ] });
}
function StatCard({
  label,
  value,
  to
}) {
  return /* @__PURE__ */ jsxs(Link, { to, className: "block bg-white p-6 ring-1 ring-navy/10 hover:ring-gold", children: [
    /* @__PURE__ */ jsx("div", { className: "text-[10px] uppercase tracking-widest text-navy/40", children: label }),
    /* @__PURE__ */ jsx("div", { className: "mt-2 font-display text-4xl font-extrabold text-navy", children: value })
  ] });
}
export {
  AdminHome as component
};
