import { CustomerPageShell } from "@/app/customer/_components/customer-page-shell";

import { fetchAccessUsers } from "@/app/customer/_lib/admin/access-server-api";
import { getCustomerSessionContext } from "@/lib/frontend-auth/server";
import { UsersPageClient } from "./_components/users-page-client";

type PageProps = {
  params: Promise<{ tenant: string }>;
};

export default async function CustomerAdminUsersPage({ params }: Readonly<PageProps>) {
  const { tenant } = await params;
  const [result, session] = await Promise.all([
    fetchAccessUsers(tenant),
    getCustomerSessionContext(tenant),
  ]);

  return (
    <CustomerPageShell>
      <UsersPageClient
        tenant={tenant}
        initialUsers={result.data?.items ?? []}
        groups={result.data?.groups ?? []}
        initialErrorMessage={result.errorMessage}
        canManageUsers={Boolean(session.permissions.capabilities?.admin_users_manage)}
      />
    </CustomerPageShell>
  );
}
