import { r as reactExports, U as jsxRuntimeExports, _ as Outlet } from "./worker-entry-Xz__m-MI.js";
import { u as useNavigate, a as useAuth, b as useBusinessSettings, L as Link, s as supabase, t as toast } from "./router-CHpUX3w1.js";
import { B as Button } from "./button-DpKP5ewx.js";
import { c as createLucideIcon } from "./createLucideIcon-4cZKQB6y.js";
import { S as ShoppingBag } from "./shopping-bag-CbDsBdXX.js";
import { P as Package } from "./package-49HcQA4V.js";
import { T as Tags } from "./tags-CGCicbmq.js";
import "node:events";
import "node:async_hooks";
import "node:stream/web";
import "node:stream";
import "./utils-Bz4m9VPB.js";
const __iconNode$3 = [
  ["rect", { width: "7", height: "9", x: "3", y: "3", rx: "1", key: "10lvy0" }],
  ["rect", { width: "7", height: "5", x: "14", y: "3", rx: "1", key: "16une8" }],
  ["rect", { width: "7", height: "9", x: "14", y: "12", rx: "1", key: "1hutg5" }],
  ["rect", { width: "7", height: "5", x: "3", y: "16", rx: "1", key: "ldoo1y" }]
];
const LayoutDashboard = createLucideIcon("layout-dashboard", __iconNode$3);
const __iconNode$2 = [
  ["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" }]
];
const LogOut = createLucideIcon("log-out", __iconNode$2);
const __iconNode$1 = [
  [
    "path",
    {
      d: "M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915",
      key: "1i5ecw"
    }
  ],
  ["circle", { cx: "12", cy: "12", r: "3", key: "1v7zrd" }]
];
const Settings = createLucideIcon("settings", __iconNode$1);
const __iconNode = [
  [
    "path",
    {
      d: "M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",
      key: "oel41y"
    }
  ],
  ["path", { d: "M12 8v4", key: "1got3b" }],
  ["path", { d: "M12 16h.01", key: "1drbdi" }]
];
const ShieldAlert = createLucideIcon("shield-alert", __iconNode);
function AdminLayout() {
  const navigate = useNavigate();
  const {
    user,
    loading,
    isStaff,
    roleLoading
  } = useAuth();
  const business = useBusinessSettings();
  reactExports.useEffect(() => {
    if (!loading && !user) {
      navigate({
        to: "/auth/login"
      });
    }
  }, [loading, user, navigate]);
  const handleLogout = async () => {
    await supabase.auth.signOut();
    toast.success("লগআউট সফল");
    navigate({
      to: "/auth/login"
    });
  };
  if (loading || roleLoading) {
    return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "min-h-screen flex items-center justify-center text-muted-foreground", children: "লোড হচ্ছে..." });
  }
  if (!user) return null;
  if (!isStaff) {
    return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "min-h-screen flex items-center justify-center bg-background px-4", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "max-w-md text-center space-y-4", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(ShieldAlert, { className: "h-12 w-12 mx-auto text-destructive" }),
      /* @__PURE__ */ jsxRuntimeExports.jsx("h1", { className: "text-2xl font-semibold", children: "অ্যাডমিন অ্যাক্সেস নেই" }),
      /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-muted-foreground", children: "আপনার অ্যাকাউন্টে এখনো অ্যাডমিন বা স্টাফ রোল দেওয়া হয়নি। প্রথম অ্যাডমিনকে SQL এর মাধ্যমে রোল দিতে হবে।" }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "rounded-md bg-muted p-3 text-left font-mono text-xs", children: [
        "INSERT INTO public.user_roles (user_id, role)",
        /* @__PURE__ */ jsxRuntimeExports.jsx("br", {}),
        "VALUES ('",
        user.id,
        "', 'admin');"
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-muted-foreground", children: "আপনার ইউজার ID উপরে দেখানো হয়েছে।" }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { variant: "outline", onClick: handleLogout, children: "লগআউট" })
    ] }) });
  }
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "min-h-screen bg-muted/30", children: [
    /* @__PURE__ */ jsxRuntimeExports.jsxs("header", { className: "bg-background border-b sticky top-0 z-30", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "max-w-7xl mx-auto px-4 h-14 flex items-center justify-between", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsxs(Link, { to: "/admin", className: "flex items-center gap-2", children: [
          business.logo_url ? /* @__PURE__ */ jsxRuntimeExports.jsx("img", { src: business.logo_url, alt: business.site_name, className: "h-7 w-auto" }) : /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "font-script text-xl text-primary", children: business.site_name }),
          /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-xs text-muted-foreground hidden sm:inline", children: "Admin" })
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs(Button, { variant: "ghost", size: "sm", onClick: handleLogout, children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(LogOut, { className: "h-4 w-4 mr-1" }),
          " লগআউট"
        ] })
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs("nav", { className: "max-w-7xl mx-auto px-4 flex gap-1 overflow-x-auto border-t", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(NavItem, { to: "/admin", icon: /* @__PURE__ */ jsxRuntimeExports.jsx(LayoutDashboard, { className: "h-4 w-4" }), label: "ড্যাশবোর্ড", exact: true }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(NavItem, { to: "/admin/orders", icon: /* @__PURE__ */ jsxRuntimeExports.jsx(ShoppingBag, { className: "h-4 w-4" }), label: "অর্ডার" }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(NavItem, { to: "/admin/products", icon: /* @__PURE__ */ jsxRuntimeExports.jsx(Package, { className: "h-4 w-4" }), label: "প্রোডাক্ট" }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(NavItem, { to: "/admin/categories", icon: /* @__PURE__ */ jsxRuntimeExports.jsx(Tags, { className: "h-4 w-4" }), label: "ক্যাটাগরি" }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(NavItem, { to: "/admin/blacklist", icon: /* @__PURE__ */ jsxRuntimeExports.jsx(ShieldAlert, { className: "h-4 w-4" }), label: "ব্ল্যাকলিস্ট" }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(NavItem, { to: "/admin/settings", icon: /* @__PURE__ */ jsxRuntimeExports.jsx(Settings, { className: "h-4 w-4" }), label: "সেটিংস" })
      ] })
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsx("main", { className: "max-w-7xl mx-auto px-4 py-6", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Outlet, {}) })
  ] });
}
function NavItem({
  to,
  icon,
  label,
  exact
}) {
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(Link, { to, activeOptions: {
    exact
  }, className: "flex items-center gap-2 px-3 py-2.5 text-sm font-medium text-muted-foreground hover:text-foreground border-b-2 border-transparent transition-colors whitespace-nowrap", activeProps: {
    className: "text-primary border-primary"
  }, children: [
    icon,
    " ",
    label
  ] });
}
export {
  AdminLayout as component
};
