import { createTeamAccountsApi } from '@/packages/features/team-accounts/src/server/api';
import { getSupabaseServerClient } from '@/packages/supabase/src/clients/server-client';

import { PageBody } from '@kit/ui/page';

import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
import { withI18n } from '~/lib/i18n/with-i18n';


import HealthBenefitForm from './_components/health-benefit-form';

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

export const generateMetadata = async () => {
  const i18n = await createI18nServerInstance();
  const title = i18n.t('teams:billing.pageTitle');

  return {
    title,
  };
};

async function TeamAccountBillingPage({ params }: TeamAccountBillingPageProps) {
  const accountSlug = (await params).account;
  const client = getSupabaseServerClient();
  const api = createTeamAccountsApi(client);

  const account = await api.getTeamAccount(accountSlug);
  const companyParams = await api.getTeamAccountParams(account.id);
  const { members } = await api.getMembers(accountSlug);

  return (
    <PageBody>
      <HealthBenefitForm
        account={account}
        companyParams={companyParams}
        employeeCount={members.length}
      />
    </PageBody>
  );
}

export default withI18n(TeamAccountBillingPage);
