import type { Locale } from "@/i18n/config";
import type { Dictionary } from "@/i18n/get-dictionary";
import { jobs } from "@/content/careers";
import { fill, timeAgo } from "@/lib/format";
import { routes } from "@/lib/routes";
import { SectionHeading } from "@/components/shared/section-heading";
import { Section } from "@/components/shared/section";
import { JobCard } from "./job-card";

type JobsSectionProps = { locale: Locale; t: Dictionary["career"]; items: Dictionary["catalog"]["jobs"] };

/** "Find your next role": job cards, 3 per row on desktop (400px, 40px apart), 2 on tablets, 1 on phones. */
export function JobsSection({ locale, t, items }: JobsSectionProps) {
  return (
    <Section labelledBy="jobs-title">
      <SectionHeading id="jobs-title" label={t.list.label} title={t.list.title} />
      <ul className="grid gap-5 pt-10 md:grid-cols-2 lg:grid-cols-3 lg:gap-10">
        {jobs.map((job) => {
          const text = items[job.id];
          return (
            <li key={job.id}>
              <JobCard
                href={routes.job(locale, job.slug)}
                title={text.title}
                summary={text.summary}
                department={text.department}
                location={t.locations[job.location]}
                type={t.types[job.type]}
                posted={fill("{posted} {ago}", { posted: t.list.posted, ago: timeAgo(locale, job.postedDaysAgo) })}
                newLabel={job.isNew ? t.list.new : undefined}
                viewLabel={t.list.viewRole}
                color={job.color}
                textColor={job.textColor}
              />
            </li>
          );
        })}
      </ul>
    </Section>
  );
}
