import { redirect } from 'next/navigation';

import { pathsConfig } from '@kit/shared/config';
import { getSupabaseServerClient } from '@kit/supabase/server-client';

import { withI18n } from '~/lib/i18n/with-i18n';
import {
  PageViewAction,
  createPageViewLog,
} from '~/lib/services/audit/pageView.service';

import MembershipConfirmationNotification from './_components/membership-confirmation-notification';

async function MembershipConfirmation() {
  const client = getSupabaseServerClient();

  const {
    data: { user },
  } = await client.auth.getUser();

  if (!user?.id) {
    redirect(pathsConfig.app.home);
  }
  await createPageViewLog({
    accountId: user.id,
    action: PageViewAction.REGISTRATION_SUCCESS,
  });

  return <MembershipConfirmationNotification userId={user.id} />;
}

export default withI18n(MembershipConfirmation);
