import AdminShell from './components/AdminShell.js';
import { protectAdmin } from './protect.js';
import { buildNavigationSections, buildBottomNavItems } from './navigation.js';
import { logoutAction } from '@zen/core/features/auth/actions';
import { getAppName } from '@zen/core';
import { getUserPermissions } from '@zen/core/users';
import './widgets/index.server.js';

export default async function AdminLayout({ children }) {
  const session = await protectAdmin();
  const appName = getAppName();
  const permissions = await getUserPermissions(session.user.id);
  const navigationSections = buildNavigationSections('/', permissions);
  const bottomNavItems = buildBottomNavItems('/');

  return (
    <AdminShell
      user={session.user}
      onLogout={logoutAction}
      appName={appName}
      navigationSections={navigationSections}
      bottomNavItems={bottomNavItems}
    >
      {children}
    </AdminShell>
  );
}
