import { ReactNode } from "react";

import { requireAuthorizedPageUser } from "@/lib/authorization";
import { getPageCopy } from "@/lib/i18n-server";
import { MobileNav } from "@/components/layout/mobile-nav";
import { Sidebar } from "@/components/layout/sidebar";
import { Topbar } from "@/components/layout/topbar";

type AppShellProps = {
  children: ReactNode;
  title: string;
  description: string;
  pathname: string;
};

export async function AppShell({
  children,
  title,
  description,
  pathname
}: AppShellProps) {
  const user = await requireAuthorizedPageUser(pathname);
  const copy = await getPageCopy(pathname, title, description);

  return (
    <div className="min-h-screen bg-canvas">
      <div className="flex min-h-screen">
        <Sidebar pathname={pathname} user={user} />
        <main className="min-w-0 flex-1 xl:ml-64">
          <div className="flex min-h-screen flex-col">
            <MobileNav pathname={pathname} userRole={user.role} />
            <Topbar title={copy.title} description={copy.description} user={user} />
            <div className="flex-1 p-6">{children}</div>
            <footer className="border-t border-line/70 px-6 py-4 text-center text-sm text-slate-500">
              © 2026 AbelBirdnest
            </footer>
          </div>
        </main>
      </div>
    </div>
  );
}
