"use client";
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
import { useAuth } from "../../../hooks/useAuth.js";
import { useRouter } from "next/navigation";
import { useEffect, Suspense } from "react";
import { Loader2 } from "lucide-react";
import { DashboardTranslationPreloader } from "../../../lib/i18n/DashboardTranslationPreloader.js";
import { TranslationDebugger } from "../../../utils/dev/TranslationDebugger.js";
import { useEnsureUserMetadata } from "../../../hooks/useEnsureUserMetadata.js";
import { useAuthMethodDetector } from "../../../hooks/useAuthMethodDetector.js";
function AuthMethodDetectorWrapper() {
  useAuthMethodDetector();
  return null;
}
function DashboardLayoutContent({ children }) {
  const { user, isLoading } = useAuth();
  const router = useRouter();
  useEnsureUserMetadata();
  useEffect(() => {
    if (!isLoading && !user) {
      router.push("/login");
    }
  }, [user, isLoading, router]);
  if (isLoading) {
    return /* @__PURE__ */ jsx("div", { className: "min-h-screen flex items-center justify-center", children: /* @__PURE__ */ jsx(Loader2, { className: "h-8 w-8 animate-spin text-muted-foreground" }) });
  }
  if (!user) {
    return null;
  }
  return /* @__PURE__ */ jsxs(Fragment, { children: [
    /* @__PURE__ */ jsx(DashboardTranslationPreloader, {}, "dashboard-translation-preloader"),
    /* @__PURE__ */ jsx(TranslationDebugger, {}, "translation-debugger"),
    /* @__PURE__ */ jsx(Suspense, { fallback: null, children: /* @__PURE__ */ jsx(AuthMethodDetectorWrapper, {}) }, "auth-method-detector"),
    /* @__PURE__ */ jsx("div", { "data-cy": "dashboard-container", children }, "dashboard-children")
  ] });
}
function DashboardAuthLayout({
  children
}) {
  return /* @__PURE__ */ jsx(DashboardLayoutContent, { children });
}
export {
  DashboardAuthLayout
};
