import { redirect } from 'next/navigation';
import { getCurrentAccount } from '@/lib/account';
import { ROUTES } from '@/lib/routes';
import { isVendorAccount } from '@/lib/vendor';
import { AccountNav } from '@/components/account/account-nav';
import { DashboardModeBanner } from '@/components/layout/dashboard-mode-banner';

// Shared "My Account" dashboard shell — left nav + content column, mirroring
// the vendor dashboard's own layout (src/app/vendor/layout.tsx) so both
// sides of a dual-role account feel like the same kind of dashboard. Every
// page under /account/* (profile, orders, inquiries, messages) renders as
// `children` here instead of building its own page shell.
export default async function AccountLayout({ children }: { children: React.ReactNode }) {
  const account = await getCurrentAccount();

  if (!account) {
    redirect(`${ROUTES.login}?redirect=${ROUTES.account}`);
    return;
  }

  return (
    <section className="bg-beige py-10">
      <div className="container-page">
        {isVendorAccount(account) && <DashboardModeBanner mode="customer" />}
        <div className="grid gap-8 lg:grid-cols-4">
          <AccountNav />
          <div className="lg:col-span-3">{children}</div>
        </div>
      </div>
    </section>
  );
}
