import { Metadata } from 'next';
import { getLocale, getTranslations } from 'next-intl/server';
import { notFound } from 'next/navigation';

import { getCreatorList } from '@/services/creators';
import { getInstitutionList } from '@/services/institutions';
import { getMetaAttributeList } from '@/services/meta';

import MultiStepEventSubmitForm from '@/components/events/MultiStepEventSubmitForm';

export default async function EventSubmitPage() {
  const locale = await getLocale();

  if (locale !== 'hu') {
    return notFound();
  }

  const [institutionList, categories, creatorOptions] = await Promise.all([
    getInstitutionList(),
    getMetaAttributeList(111),
    getCreatorList(),
  ]);
  const sortedCreatorOptions = creatorOptions.sort((left, right) =>
    (left.nev || left.alkotoAzonosito).localeCompare(right.nev || right.alkotoAzonosito, 'hu')
  );

  return (
    <div className="flex-1 w-full">
      <MultiStepEventSubmitForm
        institutionList={institutionList}
        categories={categories}
        creatorOptions={sortedCreatorOptions}
      />
    </div>
  );
}

export async function generateMetadata(): Promise<Metadata> {
  const t = await getTranslations('eventsPage.metaData');
  const canonical = '/esemeny-feltoltes';

  return {
    title: `${t('submitTitle')} - ${t('title')}`,
    description: '',
    alternates: {
      canonical,
    },
  };
}
