'use client';

import { useSession } from 'next-auth/react';

import { KeyboardShortcutsProvider } from '@/components/KeyboardShortcutsProvider';
import { MobileNavigation } from '@/components/layout/MobileNavigation';
import { PortalBreadcrumbs } from '@/components/layout/PortalBreadcrumbs';
import { PortalHeader } from '@/components/layout/PortalHeader';
import { PortalSidebar } from '@/components/layout/PortalSidebar';

/**
 * Full console chrome only after sign-in. Unauthenticated routes render children alone
 * so the landing / sign-in view is not squeezed beside sidebar + mega-header.
 */
export function AppShell({ children }: { children: React.ReactNode }) {
  const { status } = useSession();

  if (status !== 'authenticated') {
    return <>{children}</>;
  }

  return (
    <KeyboardShortcutsProvider>
      <div className="flex min-h-screen flex-col bg-gray-950 text-gray-100 antialiased">
        <PortalHeader />
        <PortalBreadcrumbs />
        <div className="flex min-h-0 flex-1">
          <PortalSidebar />
          <main className="min-w-0 flex-1 md:ml-64">{children}</main>
        </div>
        <MobileNavigation />
      </div>
    </KeyboardShortcutsProvider>
  );
}
