import Link from "next/link";
import type { CSSProperties } from "react";
import { ArrowRightIcon, BriefcaseIcon, ClockIcon, MapPinOutlineIcon } from "@/components/icons";

type JobCardProps = {
  href: string;
  title: string;
  summary: string;
  department: string;
  location: string;
  type: string;
  /** e.g. "Posted 2 days ago" */
  posted: string;
  /** "NEW" badge text, if the job is new. */
  newLabel?: string;
  viewLabel: string;
  color: string;
  textColor: string;
};

/**
 * Job card (Figma "Career" list): icon + NEW badge, title, summary, department badge, place and type,
 * then a divider with the posting date and "View role".
 * data-figma-small-text: the 10px "NEW" and date come from the design.
 */
export function JobCard({ href, title, summary, department, location, type, posted, newLabel, viewLabel, color, textColor }: JobCardProps) {
  return (
    <article
      data-figma-small-text
      style={{ "--job": color, "--job-text": textColor } as CSSProperties}
      className="flex h-full min-h-64 flex-col overflow-hidden rounded-3xl border border-white/7 bg-primary/10 font-heading"
    >
      <div className="flex flex-col gap-4 p-5">
        <div className="flex items-start justify-between">
          <span className="flex size-12 items-center justify-center rounded-full border border-white/5 bg-(--job)/20 text-(--job-text)">
            <BriefcaseIcon className="size-[22px]" />
          </span>
          {newLabel && (
            <span className="rounded-full border border-accent-teal/25 bg-accent-teal/10 px-2 py-0.5 text-[10px] leading-[13.5px] font-medium tracking-[1.08px] text-accent-teal uppercase">
              {newLabel}
            </span>
          )}
        </div>
        <div>
          <h3 className="text-lg leading-7 font-semibold text-white">{title}</h3>
          <p className="pt-2 text-sm leading-5 text-subtle">{summary}</p>
        </div>
      </div>

      <div className="flex flex-col items-start gap-4 px-5">
        <span className="rounded-full border border-(--job)/25 bg-(--job)/10 px-2.5 py-1 text-xs leading-[15px] font-medium text-(--job-text)">
          {department}
        </span>
        <p className="flex gap-4 text-xs leading-[16.5px] text-subtle">
          <span className="flex items-center gap-1.5">
            <MapPinOutlineIcon className="size-4 shrink-0" />
            {location}
          </span>
          <span className="flex items-center gap-1.5">
            <ClockIcon className="size-4 shrink-0" />
            {type}
          </span>
        </p>
      </div>

      <div className="mt-auto pt-4">
        <div className="flex items-center justify-between border-t border-divider px-5 pt-6 pb-3">
          <p className="text-[10px] leading-[15px] text-soft">{posted}</p>
          <Link
            href={href}
            prefetch
            className="flex items-center gap-1.5 rounded-full border border-accent-violet/35 bg-accent-violet/10 px-2.5 py-1 text-xs leading-[15px] font-medium text-accent-violet-pale transition hover:bg-accent-violet/25"
          >
            {viewLabel}
            <ArrowRightIcon className="size-[18px] shrink-0 rtl:-scale-x-100" />
          </Link>
        </div>
      </div>
    </article>
  );
}
