import type { Locale } from "@/i18n/config";
import type { Dictionary } from "@/i18n/get-dictionary";
import { benefits, type Job } from "@/content/careers";
import { fill, timeAgo } from "@/lib/format";
import { routes } from "@/lib/routes";
import { Section } from "@/components/shared/section";
import { JobContent } from "./job-content";
import { JobCtaCard } from "./job-cta-card";
import { JobSidebar } from "./job-sidebar";

type JobBodySectionProps = {
  locale: Locale;
  job: Job;
  text: Dictionary["catalog"]["jobs"][Job["id"]];
  t: Dictionary["career"];
};

/** Job page body (Figma): content + sidebar (336px, 64px apart) on desktop, stacked below; then the apply card. */
export function JobBodySection({ locale, job, text, t }: JobBodySectionProps) {
  const d = t.details;
  return (
    <Section labelledBy="job-about" className="py-10">
      <div className="grid gap-16 lg:grid-cols-[minmax(0,1fr)_336px]">
        <JobContent labels={d} about={text.about} responsibilities={text.responsibilities} requirements={text.requirements} />
        <JobSidebar
          benefitsTitle={d.benefitsTitle}
          benefits={benefits.map((id) => ({ id, label: d.benefits[id] }))}
          facts={{
            location: [d.location, t.fullLocations[job.location]],
            type: [d.employmentType, t.types[job.type]],
            experience: [d.experience, fill(d.years, { n: job.experienceYears })],
            posted: [d.posted, timeAgo(locale, job.postedDaysAgo)],
          }}
        />
      </div>
      <div className="pt-16 lg:pt-0">
        <JobCtaCard title={d.ctaTitle} text={d.ctaText} applyLabel={d.apply} applyHref={routes.applyForJob(locale, job.slug)} />
      </div>
    </Section>
  );
}
