import { createFischereiApi } from '@kit/fischerei/api';
import {
  FischereiTabNavigation,
  FischereiDashboard,
} from '@kit/fischerei/components';
import { getSupabaseServerClient } from '@kit/supabase/server-client';

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

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

export default async function FischereiPage({ 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 = createFischereiApi(client);
  const stats = await api.getDashboardStats(acct.id);

  return (
    <CmsPageShell account={account} title="Fischerei">
      <FischereiTabNavigation account={account} activeTab="overview" />
      <FischereiDashboard stats={stats} account={account} />
    </CmsPageShell>
  );
}
