import { AdminUsersPageQuery } from '@/lib/page-queries/AdminUsersPageQuery';
import { AdminUsersWrapper } from '@/client-wrapper/AdminUsersWrapper';
import { ErrorBanner } from '@/ui/ErrorBanner';

export default async function AdminUsersPage() {
  // Execute PageQuery using static method
  const result = await AdminUsersPageQuery.execute();

  // Handle errors
  if (result.isErr()) {
    const error = result.getError();
    if (error === 'notFound') {
      return (
        <ErrorBanner
          title="Access Denied"
          message="You must be logged in as an Owner or Admin"
          variant="error"
        />
      );
    }
    return (
      <ErrorBanner
        title="Load Failed"
        message={`Failed to load users: ${error}`}
        variant="error"
      />
    );
  }

  const output = result.unwrap();

  // Pass to client wrapper for UI interactions
  return <AdminUsersWrapper viewData={output} />;
}