import type { ReactNode } from "react";
import { redirect } from "next/navigation";

import { Footer } from "@/components/footer";
import { Navbar } from "@/components/navbar";
import { getMaintenanceMode } from "@/lib/app-config";
import { resolveLocale } from "@/lib/site-data";

type SiteLayoutProps = {
  children: ReactNode;
  params: {
    locale: string;
  };
};

export default async function SiteLayout({ children, params: { locale } }: SiteLayoutProps) {
  const localeKey = resolveLocale(locale);
  const maintenanceEnabled = await getMaintenanceMode();

  if (maintenanceEnabled) {
    redirect(`/${localeKey}/coming-soon`);
  }

  return (
    <div className="flex min-h-screen flex-col">
      <Navbar />
      <main className="flex-1">{children}</main>
      <Footer />
    </div>
  );
}
