import type { ComponentType } from "react";
import type { Dictionary } from "@/i18n/get-dictionary";
import { contactInfo } from "@/content/site";
import { MailIcon, MapPinIcon, PhoneIcon, type IconProps } from "@/components/icons";
import { IconBadge } from "@/components/shared/icon-badge";

type Detail = { icon: ComponentType<IconProps>; label: string; value: string; href?: string };

/** Phone / email / address list. Phone and email are links and always read LTR. */
export function ContactDetails({ t }: { t: Dictionary["home"]["contact"] }) {
  const details: Detail[] = [
    { icon: PhoneIcon, label: t.phoneLabel, value: contactInfo.phone, href: `tel:${contactInfo.phone.replace(/\s/g, "")}` },
    { icon: MailIcon, label: t.emailLabel, value: contactInfo.email, href: `mailto:${contactInfo.email}` },
    { icon: MapPinIcon, label: t.addressLabel, value: t.address },
  ];

  return (
    <ul className="flex flex-col gap-4 md:max-lg:flex-row md:max-lg:gap-3">
      {details.map(({ icon: Icon, label, value, href }) => (
        <li key={label} className="flex items-center gap-4 md:max-lg:gap-1">
          <IconBadge tone="primary-ghost" className="[&_svg]:size-4">
            <Icon />
          </IconBadge>
          <div>
            <p className="font-mono text-[11px] leading-[16.5px] tracking-[0.66px] text-dim uppercase">{label}</p>
            {href ? (
              <a href={href} dir="ltr" className="pt-0.5 text-sm leading-5 font-medium text-heading hover:text-white">
                {value}
              </a>
            ) : (
              <p className="pt-0.5 text-sm leading-5 font-medium text-heading">{value}</p>
            )}
          </div>
        </li>
      ))}
    </ul>
  );
}
