import AdminPageClient from './AdminPage.client.js';
import { protectAdmin } from './protect.js';
import { collectWidgetData } from './registry.js';
import { getAppConfig, getPublicBaseUrl } from '@zen/core';
import { isDevkitEnabled } from '../../shared/lib/appConfig.js';
import { getUserPermissions } from '@zen/core/users';

export default async function AdminPage({ params }) {
  const resolvedParams = await params;
  const session = await protectAdmin();
  const [widgetData, permissions] = await Promise.all([
    collectWidgetData(),
    getUserPermissions(session.user.id),
  ]);
  const appConfig = { ...getAppConfig(), siteUrl: getPublicBaseUrl() };
  const devkitEnabled = isDevkitEnabled();
  const user = { ...session.user, permissions };

  return (
    <AdminPageClient
      params={resolvedParams}
      user={user}
      widgetData={widgetData}
      appConfig={appConfig}
      devkitEnabled={devkitEnabled}
    />
  );
}
