'use client';

import { useSidebar } from '@/app/(protected)/(basic)/_hooks/use-sidebar';
import { AdminFooter } from './admin-footer';
import { AdminHeader } from './admin-header';
import { AdminSidebar } from './admin-sidebar';

interface AdminShellProps {
  children: React.ReactNode;
  /** 헤더 프로필에 표시할 관리자 이름 — 세션을 읽는 상위 Server Component가 넘긴다. */
  adminName: string;
}

/**
 * Basic 레이아웃의 상호작용 경계 — 헤더·사이드바·풋터를 조립하고 사이드바 상태(useSidebar)를
 * 소유한다. page 콘텐츠(children)는 상위 Server Component가 렌더한 결과를 props로 그대로
 * 통과시켜 RSC를 유지한다 — 이 컴포넌트 자신은 children의 내용을 알거나 가공하지 않는다.
 */
export function AdminShell({ children, adminName }: AdminShellProps) {
  const sidebar = useSidebar();

  return (
    <div className="flex min-h-screen flex-col">
      <AdminHeader adminName={adminName} />
      <div className="flex flex-1">
        <AdminSidebar
          isMobileOpen={sidebar.isMobileOpen}
          isDesktopCollapsed={sidebar.isDesktopCollapsed}
          onCloseMobile={sidebar.closeMobile}
        />
        <div className="flex flex-1 flex-col">
          <main className="flex flex-1 flex-col">{children}</main>
          <AdminFooter />
        </div>
      </div>
    </div>
  );
}
