'use client';

import { ReactNode } from 'react';
import { usePathname } from 'next/navigation';
import { AdminSidebar } from './AdminSidebar';
import { TopBar } from './TopBar';

/**
 * Admin 外壳：登录页不渲染侧边栏与后台框架，
 * 其余 /admin/* 路由才套上 TopBar + 侧边栏布局。
 */
export function AdminShell({ children }: { children: ReactNode }) {
  const pathname = usePathname();

  // 登录页（以及其它无侧边栏的独立页）直接渲染内容
  if (pathname === '/admin/login') {
    return <>{children}</>;
  }

  return (
    <div className="flex min-h-screen flex-col bg-gray-50">
      <TopBar />
      <div className="flex flex-1">
        <AdminSidebar />
        <main className="flex-1 overflow-x-hidden">
          <div className="min-h-screen p-6 lg:p-8">{children}</div>
        </main>
      </div>
    </div>
  );
}
