"use client";

import Image from "next/image";
import { useTranslation } from "react-i18next";
import { asset, type ProfileData } from "./commonProfileTypes";

/** The profile's social links, shown only for the networks that are set. */
export default function SocialLinks({ profile }: { profile: ProfileData }) {
  const { t } = useTranslation();
  const links = [
    [profile.facebook_link, "profile/facebook.svg", "Facebook"],
    [profile.twitter_link, "profile/twitter.svg", "Twitter"],
    [profile.whatsapp_link, "profile/whatsapp.svg", "WhatsApp"],
    [profile.instagram_link, "profile/instagram.svg", "Instagram"],
    [profile.linkedin_link, "profile/linkdin.svg", "LinkedIn"],
  ] as const;
  if (!links.some(([href]) => href)) return null;

  return (
    <div className="pb-5">
      <h3 className="text-lg font-bold text-primary-5">
        {t("COMMON.SOCIAL_MEDIA")}
      </h3>
      <div className="mt-3 flex gap-3">
        {links.map(([href, icon, label]) =>
          href ? (
            <a
              key={label}
              href={href}
              target="_blank"
              rel="noopener noreferrer"
              aria-label={label}
            >
              <Image src={asset(icon)} alt="" width={31} height={31} />
            </a>
          ) : null
        )}
      </div>
    </div>
  );
}
