import { getSupabaseServerClient } from '@kit/supabase/server-client';
import { createVerbandApi } from '@kit/verbandsverwaltung/api';
import { VerbandTabNavigation, VerbandDashboard } from '@kit/verbandsverwaltung/components';

import { CmsPageShell } from '~/components/cms-page-shell';
import { AccountNotFound } from '~/components/account-not-found';

interface PageProps {
  params: Promise<{ account: string }>;
}

export default async function VerbandPage({ params }: PageProps) {
  const { account } = await params;
  const client = getSupabaseServerClient();

  const { data: acct } = await client
    .from('accounts')
    .select('id')
    .eq('slug', account)
    .single();

  if (!acct) return <AccountNotFound />;

  const api = createVerbandApi(client);
  const stats = await api.getDashboardStats(acct.id);

  return (
    <CmsPageShell account={account} title="Verbandsverwaltung">
      <VerbandTabNavigation account={account} activeTab="overview" />
      <VerbandDashboard stats={stats} account={account} />
    </CmsPageShell>
  );
}
