/**
 * Layout Content Wrapper
 * Conditionally renders Nav, Footer, and CookieConsent based on current route
 *
 * IMPORTANT: Dashboard routes should NEVER have Nav/Footer
 * This provides a clean app-like experience for authenticated users
 */

"use client";

import { usePathname } from "next/navigation";
import Nav from "@/components/Nav";
import Footer from "@/components/Footer";
import CookieConsent from "@/components/CookieConsent";
import type { Lang } from "@/lib/config";

interface LayoutContentProps {
  lang: Lang;
  children: React.ReactNode;
}

/**
 * Routes that should NEVER show navigation bar or footer
 * These are app-like experiences that need clean, distraction-free UI
 */
const ROUTES_WITHOUT_NAV_FOOTER = [
  "/dashboard", // Main user dashboard (e.g., /en/dashboard, /ar/dashboard)
  "/staff/dashboard", // Staff admin dashboard
  "/user/dashboard", // User-specific dashboard
  "/clerk-login", // Clerk auth pages — distraction-free, no nav/footer
  "/clerk-signup",
] as const;

/**
 * Routes that look like dashboards but are actually marketing pages
 * These SHOULD show navigation bar and footer
 */
const MARKETING_DASHBOARD_ROUTES = [
  "/features/dashboard", // Marketing page showcasing dashboard features
] as const;

/**
 * Check if the current path is a dashboard route that should hide nav/footer
 */
function isDashboardRoute(pathname: string | null): boolean {
  if (!pathname) return false;

  // First check if it's a marketing page (these always show nav/footer)
  const isMarketingPage = MARKETING_DASHBOARD_ROUTES.some((route) =>
    pathname.includes(route),
  );
  if (isMarketingPage) return false;

  // Check if it matches any dashboard route pattern
  return ROUTES_WITHOUT_NAV_FOOTER.some((route) => pathname.includes(route));
}

export default function LayoutContent({ lang, children }: LayoutContentProps) {
  const pathname = usePathname();
  const hideNavFooter = isDashboardRoute(pathname);

  return (
    <>
      {!hideNavFooter && <Nav lang={lang} />}
      <main className="min-h-screen">{children}</main>
      {!hideNavFooter && <Footer lang={lang} />}
      {!hideNavFooter && <CookieConsent lang={lang} />}
    </>
  );
}
