import type { ComponentType } from "react";
import type { BenefitId } from "@/content/careers";
import {
  BriefcaseIcon,
  CalendarIcon,
  ClockIcon,
  GraduationCapIcon,
  HealthIcon,
  LaptopIcon,
  MapPinOutlineIcon,
  OfficeIcon,
  SalaryIcon,
  type IconProps,
} from "@/components/icons";

const benefitIcons: Record<BenefitId, ComponentType<IconProps>> = {
  salary: SalaryIcon,
  health: HealthIcon,
  flexible: LaptopIcon,
  learning: GraduationCapIcon,
  workspace: OfficeIcon,
};

type JobSidebarProps = {
  benefitsTitle: string;
  benefits: { id: BenefitId; label: string }[];
  facts: { location: [string, string]; type: [string, string]; experience: [string, string]; posted: [string, string] };
};

/** Job page sidebar (Figma): benefits with icons, then location / type / experience / posting date. */
export function JobSidebar({ benefitsTitle, benefits, facts }: JobSidebarProps) {
  const factRows = [
    { icon: MapPinOutlineIcon, fact: facts.location },
    { icon: ClockIcon, fact: facts.type },
    { icon: BriefcaseIcon, fact: facts.experience },
    { icon: CalendarIcon, fact: facts.posted },
  ];

  return (
    <aside className="font-heading lg:border-s lg:border-divider lg:ps-10">
      <h2 className="text-xl leading-7 font-semibold text-white">{benefitsTitle}</h2>
      <ul className="flex flex-col gap-5 pt-6">
        {benefits.map(({ id, label }) => {
          const Icon = benefitIcons[id];
          return (
            <li key={id} className="flex items-center gap-3 text-sm leading-5 text-soft">
              <Icon className="size-[17px] shrink-0" />
              {label}
            </li>
          );
        })}
      </ul>
      <dl className="mt-10 flex flex-col gap-7 border-t border-divider pt-8">
        {factRows.map(({ icon: Icon, fact: [label, value] }) => (
          <div key={label}>
            <dt className="text-sm leading-5 font-medium text-primary-lighter">{label}</dt>
            <dd className="flex items-center gap-3 pt-2 text-sm leading-5 text-soft">
              <Icon className="size-4 shrink-0" />
              {value}
            </dd>
          </div>
        ))}
      </dl>
    </aside>
  );
}
