import { getTranslations } from 'next-intl/server';

import { createMemberManagementApi } from '@kit/member-management/api';
import { DuesCategoryManager } from '@kit/member-management/components';
import { getSupabaseServerClient } from '@kit/supabase/server-client';

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

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

export default async function DuesPage({ params }: Props) {
  const { account } = await params;
  const t = await getTranslations('members');
  const client = getSupabaseServerClient();
  const { data: acct } = await client
    .from('accounts')
    .select('id')
    .eq('slug', account)
    .single();
  if (!acct) return <AccountNotFound />;

  const api = createMemberManagementApi(client);
  const categories = await api.listDuesCategories(acct.id);

  return (
    <CmsPageShell
      account={account}
      title={t('dues.title')}
      description={t('dues.subtitle')}
    >
      <DuesCategoryManager categories={categories} accountId={acct.id} />
    </CmsPageShell>
  );
}
