import Link from 'next/link';
import { redirect } from 'next/navigation';

import { CaretRightIcon } from '@radix-ui/react-icons';
import { Scale } from 'lucide-react';

import { MedReportLogo } from '@kit/shared/components/med-report-logo';
import SelectAnalysisPackages from '@kit/shared/components/select-analysis-packages';
import { pathsConfig } from '@kit/shared/config';
import { Button } from '@kit/ui/button';
import { Trans } from '@kit/ui/trans';

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

import ComparePackagesModal from '../home/(user)/_components/compare-packages-modal';
import { loadAnalysisPackages } from '../home/(user)/_lib/server/load-analysis-packages';

export const generateMetadata = async () => {
  const { t } = await createI18nServerInstance();

  return {
    title: t('marketing:pricing'),
  };
};

async function SelectPackagePage() {
  const { analysisPackageElements, analysisPackages, countryCode } =
    await loadAnalysisPackages();

  if (analysisPackageElements.length === 0) {
    return redirect(pathsConfig.app.home);
  }

  return (
    <div className="container mx-auto my-24 flex flex-col items-center space-y-12">
      <MedReportLogo />
      <div className="space-y-3 text-center">
        <h3>
          <Trans i18nKey={'marketing:selectPackage'} />
        </h3>
        <ComparePackagesModal
          analysisPackages={analysisPackages}
          analysisPackageElements={analysisPackageElements}
          triggerElement={
            <Button variant="secondary" className="gap-2">
              <Trans i18nKey={'marketing:comparePackages'} />
              <Scale className="size-4 stroke-[1.5px]" />
            </Button>
          }
        />
      </div>
      <SelectAnalysisPackages
        analysisPackages={analysisPackages}
        countryCode={countryCode}
      />
      <div className="flex justify-center">
        <Link href={pathsConfig.app.home}>
          <Button variant="secondary" className="align-center">
            <Trans i18nKey="marketing:notInterestedInAudit" />{' '}
            <CaretRightIcon className="size-4" />
          </Button>
        </Link>
      </div>
    </div>
  );
}

export default withI18n(SelectPackagePage);
