"use client";

import Image from "next/image";

/**
 * The achievement counters' colours, keyed by which counter they belong to.
 *
 * The volunteer and organizer profiles show different counters — hours are
 * shared, then the organizer has volunteer / learn-&-serve / sponsored and the
 * volunteer has opportunities / certificates — so both sets live here. The
 * palette positions overlap by design: a profile only ever renders one set, and
 * the Nth card is the same colour on both.
 *
 * Class names are spelled out in full rather than interpolated — Tailwind only
 * extracts literal strings, so `border-${x}` would never make it into the CSS.
 */
export const STAT_COLORS = {
  hours: { border: "border-primary-501", text: "text-primary-501" },
  volunteer: { border: "border-primary-502", text: "text-primary-502" },
  learnServe: { border: "border-primary-503", text: "text-primary-503" },
  sponsored: { border: "border-primary-504", text: "text-primary-504" },
  opportunities: { border: "border-primary-502", text: "text-primary-502" },
  certificates: { border: "border-primary-503", text: "text-primary-503" },
} as const;

/**
 * One achievement counter card.
 *
 * Shared by `VolunteerBackgroundInformation` and
 * `OrganizerBackgroundInformation`, which each had their own identical copy.
 * The height is a prop because the two profiles size their rows differently.
 */
export default function ProfileStatCard({
  icon,
  alt,
  value,
  label,
  color,
  heightClass,
  labelHeightClass = "",
}: {
  icon: string;
  alt: string;
  value: string | number;
  label: string;
  color: keyof typeof STAT_COLORS;
  heightClass: string;
  labelHeightClass?: string;
}) {
  const { border, text } = STAT_COLORS[color];
  return (
    <div
      className={`${heightClass} border-[3px] ${border} p-4 items-center flex flex-col shadow-[0px_4px_4px_0px_rgba(0,0,0,0.25)] rounded-tl-none rounded-tr-[40px] rounded-bl-[40px] rounded-br-[40px]`}
    >
      <div className="flex flex-col items-center">
        <Image
          className="h-[48px] w-auto mb-2"
          src={icon}
          alt={alt}
          width={60}
          height={60}
        />
        <h3 className={`text-[30px] font-bold ${text} text-center`}>{value}</h3>
        <p
          className={`${text} font-semibold 2xl:text-base lg:text-sm pt-2 text-center ${labelHeightClass}`}
        >
          {label}
        </p>
      </div>
    </div>
  );
}
