import type { Metadata } from "next";
import Link from "next/link";
import { locales } from "@/i18n/config";
import { getDictionary, getLocale } from "@/i18n/get-dictionary";
import { jobs } from "@/content/careers";
import { routes } from "@/lib/routes";
import { ArrowUpRightIcon } from "@/components/icons";
import { Footer } from "@/components/layout/footer/footer";
import { Header } from "@/components/layout/header/header";
import { CtaBanner, ctaBannerActionClass } from "@/components/shared/cta-banner";
import { NoRolesSection } from "@/features/career/empty/no-roles-section";
import { CareerHeroSection } from "@/features/career/hero/career-hero-section";
import { JobsSection } from "@/features/career/jobs/jobs-section";

export async function generateMetadata(): Promise<Metadata> {
  const { career, brand } = await getDictionary();
  return {
    title: `${career.metaTitle} | ${brand.name}`,
    alternates: { languages: Object.fromEntries(locales.map((l) => [l, `/${l}/career`])) },
  };
}

export default async function CareerPage() {
  const [locale, dict] = await Promise.all([getLocale(), getDictionary()]);
  const t = dict.career;
  const applyHref = routes.apply(locale);

  return (
    <>
      <Header locale={locale} nav={dict.nav} activeKey="career" />
      <main>
        {jobs.length === 0 ? (
          <NoRolesSection t={t} applyHref={applyHref} />
        ) : (
          <>
            <CareerHeroSection t={t.hero} />
            <JobsSection locale={locale} t={t} items={dict.catalog.jobs} />
            <CtaBanner
              titleId="career-banner-title"
              title={t.banner.title}
              description={t.banner.description}
              imageAlt={t.banner.imageAlt}
              action={
                <Link href={applyHref} className={ctaBannerActionClass}>
                  {t.sendApplication}
                  <ArrowUpRightIcon data-icon="inline-end" className="rtl:-scale-x-100" />
                </Link>
              }
            />
          </>
        )}
      </main>
      {/* Figma: 66px under the banner on the list; the empty state touches the footer. */}
      <Footer locale={locale} t={dict.footer} brandName={dict.brand.name} className={jobs.length === 0 ? "mt-0 md:mt-0 lg:mt-0" : "lg:mt-16"} />
    </>
  );
}
