"use client";

import Image from "next/image";
import { useTranslation } from "react-i18next";
import { asset } from "./volunteerProfileDisplay";

/**
 * The social-media row on a profile's "about" panel.
 *
 * Shared by `VolunteerBackgroundInformation` and
 * `OrganizerBackgroundInformation`, which held identical copies apart from two
 * class names — hence the two class props. Distinct from `ProfileSocialLinks`,
 * which serves the public-profile achievements panel with different markup
 * (its own wrapper, "Twitter" rather than "X", and an empty `alt`). Renders nothing when the profile has
 * set no links at all, which is why the whole block including its heading lives
 * in here rather than at the call sites.
 */
export default function BackgroundSocialLinks({
  facebook_link,
  twitter_link,
  whatsapp_link,
  instagram_link,
  linkedin_link,
  wrapperClassName,
  linkClassName,
}: {
  facebook_link?: string | null;
  twitter_link?: string | null;
  whatsapp_link?: string | null;
  instagram_link?: string | null;
  linkedin_link?: string | null;
  wrapperClassName?: string;
  linkClassName?: string;
}) {
  const { t } = useTranslation();

  const socialLinks: Array<[string | null | undefined, string, string]> = [
    [facebook_link, asset("profile/facebook.svg"), "Facebook"],
    [twitter_link, asset("profile/twitter.svg"), "X"],
    [whatsapp_link, asset("profile/whatsapp.svg"), "WhatsApp"],
    [instagram_link, asset("profile/instagram.svg"), "Instagram"],
    [linkedin_link, asset("profile/linkdin.svg"), "LinkedIn"],
  ];
  const hasSocialLinks = socialLinks.some(([href]) => Boolean(href));

  if (!hasSocialLinks) return null;

  return (
    <div className={wrapperClassName}>
      <h3 className="font-bold inline-block text-primary-5 text-lg laptopmain:text-xl xss:text-base">
        {t("COMMON.SOCIAL_MEDIA")}
      </h3>
      <div className="mt-3 flex gap-3 lg:pb-0 md:pb-11 pb-11">
        {socialLinks.map(([href, icon, label]) =>
          href ? (
            <a
              key={label}
              href={href}
              target="_blank"
              rel="noopener noreferrer"
              className={linkClassName}
              aria-label={label}
            >
              <Image
                className="w-[31px] h-[31px]"
                src={icon}
                alt={label}
                width={31}
                height={31}
              />
            </a>
          ) : null
        )}
      </div>
    </div>
  );
}
