"use client";
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
import { useSession } from "../../../lib/auth-client.js";
import { useRouter } from "next/navigation";
import { useEffect } from "react";
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "../../ui/card.js";
import { AlertTriangle, ArrowLeft } from "lucide-react";
import { Button } from "../../ui/button.js";
import { useTranslations } from "next-intl";
function DeveloperGuard({ children, fallback }) {
  var _a;
  const { data: session, isPending } = useSession();
  const router = useRouter();
  const t = useTranslations();
  useEffect(() => {
    var _a2;
    if (!isPending && session && ((_a2 = session.user) == null ? void 0 : _a2.role) !== "developer") {
      router.push("/dashboard?error=access_denied");
    }
  }, [session, isPending, router]);
  if (isPending) {
    return /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center min-h-screen", children: /* @__PURE__ */ jsxs("div", { className: "animate-pulse", children: [
      /* @__PURE__ */ jsx("div", { className: "h-8 bg-muted rounded w-48 mb-4" }),
      /* @__PURE__ */ jsx("div", { className: "h-4 bg-muted rounded w-32" })
    ] }) });
  }
  if (!session) {
    return /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center min-h-screen", children: /* @__PURE__ */ jsxs(Card, { className: "w-full max-w-md border-purple-500/20", children: [
      /* @__PURE__ */ jsxs(CardHeader, { children: [
        /* @__PURE__ */ jsxs(CardTitle, { className: "flex items-center gap-2", children: [
          /* @__PURE__ */ jsx(AlertTriangle, { className: "h-5 w-5 text-purple-500" }),
          t("common.status.error")
        ] }),
        /* @__PURE__ */ jsx(CardDescription, { children: "Session not found. Please sign in again." })
      ] }),
      /* @__PURE__ */ jsx(CardContent, { children: /* @__PURE__ */ jsx(Button, { onClick: () => router.push("/login"), className: "w-full bg-purple-600 hover:bg-purple-700", children: "Sign In" }) })
    ] }) });
  }
  if (((_a = session.user) == null ? void 0 : _a.role) !== "developer") {
    if (fallback) {
      return /* @__PURE__ */ jsx(Fragment, { children: fallback });
    }
    return /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center min-h-screen bg-gradient-to-br from-purple-50 to-violet-50 dark:from-purple-950/20 dark:to-violet-950/20", children: /* @__PURE__ */ jsxs(Card, { className: "w-full max-w-md border-purple-500/20", children: [
      /* @__PURE__ */ jsxs(CardHeader, { children: [
        /* @__PURE__ */ jsxs(CardTitle, { className: "flex items-center gap-2 text-purple-700 dark:text-purple-400", children: [
          /* @__PURE__ */ jsx(AlertTriangle, { className: "h-5 w-5" }),
          "Developer Access Only"
        ] }),
        /* @__PURE__ */ jsx(CardDescription, { children: "You need developer privileges to access this area." })
      ] }),
      /* @__PURE__ */ jsxs(CardContent, { className: "space-y-4", children: [
        /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: "This section is restricted to platform developers only. If you believe this is an error, please contact the development team." }),
        /* @__PURE__ */ jsxs("div", { className: "flex gap-2", children: [
          /* @__PURE__ */ jsxs(
            Button,
            {
              variant: "outline",
              onClick: () => router.back(),
              className: "flex items-center gap-2 border-purple-200 hover:bg-purple-50 dark:border-purple-800 dark:hover:bg-purple-950/50",
              children: [
                /* @__PURE__ */ jsx(ArrowLeft, { className: "h-4 w-4" }),
                "Go Back"
              ]
            }
          ),
          /* @__PURE__ */ jsx(
            Button,
            {
              onClick: () => router.push("/dashboard"),
              className: "bg-purple-600 hover:bg-purple-700",
              children: "Dashboard"
            }
          )
        ] })
      ] })
    ] }) });
  }
  return /* @__PURE__ */ jsx(Fragment, { children });
}
function useIsDeveloper() {
  var _a;
  const { data: session } = useSession();
  return ((_a = session == null ? void 0 : session.user) == null ? void 0 : _a.role) === "developer";
}
export {
  DeveloperGuard,
  useIsDeveloper
};
