import type { ReactNode } from "react";
import type { Dictionary } from "@/i18n/get-dictionary";
import { PageBadge } from "@/components/shared/page-badge";
import { PageHeroBackground } from "@/components/shared/page-hero-background";
import { ApplicationForm } from "./application-form";

type ApplySectionProps = {
  t: Dictionary["apply"];
  formText: Dictionary["forms"];
  backgroundAlt: string;
  title: string;
  /** Job application: the job card on the start side. General application: none (the form is centred, 1000px). */
  sidebar?: ReactNode;
  /** Slug of the job applied for. */
  job?: string;
};

/**
 * Job Application pages (Figma "Apply"): badge, title, intro (plain text for a job, a box for the general one),
 * then the form card — beside the job card, or centred on its own.
 */
export function ApplySection({ t, formText, backgroundAlt, title, sidebar, job }: ApplySectionProps) {
  const form = (
    <div className="w-full min-w-0 overflow-hidden rounded-2xl border border-white/7 bg-primary/10">
      <div className="flex flex-col gap-2 border-b border-white/7 p-5">
        <h2 className="text-xl leading-7 font-semibold text-white">{t.form.title}</h2>
        <p className="text-sm leading-5 text-soft">{t.form.subtitle}</p>
      </div>
      <ApplicationForm t={t.form} formText={formText} job={job} />
    </div>
  );

  return (
    <section aria-labelledby="apply-title" className="relative isolate overflow-hidden pt-[100px] md:pt-[120px] lg:pt-[180px]">
      <PageHeroBackground alt={backgroundAlt} className="h-[600px] lg:h-[942px]" />
      <div className="container-site flex flex-col gap-10">
        <div className="flex flex-col items-start gap-5">
          <PageBadge>{t.badge}</PageBadge>
          <h1 id="apply-title" className="font-heading text-[32px] leading-10 font-bold text-white lg:text-6xl lg:leading-[60px] lg:tracking-[-1.5px]">
            {title}
          </h1>
          {sidebar && <p className="text-xs leading-5 text-soft lg:text-sm lg:leading-7">{t.introJob}</p>}
        </div>

        {sidebar ? (
          <div className="flex flex-col items-start gap-10 lg:flex-row">
            {sidebar}
            {form}
          </div>
        ) : (
          <>
            <p className="rounded-2xl border border-white/7 bg-white/10 p-5 text-xs leading-5 font-medium text-soft lg:text-sm lg:leading-6">{t.introGeneral}</p>
            <div className="mx-auto w-full max-w-[1000px]">{form}</div>
          </>
        )}
      </div>
    </section>
  );
}
