type SocialLinks = {
  facebook?: string;
  tiktok?: string;
  youtube?: string;
  whatsapp?: string;
  twitter?: string;
  linkedin?: string;
};

const ICON_PATHS: Record<keyof SocialLinks, { viewBox: string; path: string; label: string }> = {
  facebook: {
    viewBox: "0 0 24 24",
    label: "Facebook",
    path: "M22 12.06C22 6.51 17.52 2 12 2S2 6.51 2 12.06c0 5 3.66 9.15 8.44 9.94v-7.03H7.9v-2.91h2.54V9.85c0-2.51 1.49-3.9 3.77-3.9 1.09 0 2.24.2 2.24.2v2.46h-1.26c-1.24 0-1.63.77-1.63 1.56v1.89h2.78l-.44 2.91h-2.34V22c4.78-.79 8.44-4.94 8.44-9.94Z",
  },
  tiktok: {
    viewBox: "0 0 24 24",
    label: "TikTok",
    path: "M16.6 5.82c-.9-.98-1.4-2.26-1.4-3.6h-3.2v13.44a2.6 2.6 0 1 1-1.83-2.48V9.9a5.8 5.8 0 1 0 5.03 5.75V9.28a7.8 7.8 0 0 0 4.6 1.48V7.56a4.6 4.6 0 0 1-3.2-1.74Z",
  },
  youtube: {
    viewBox: "0 0 24 24",
    label: "YouTube",
    path: "M23.5 7.2s-.23-1.64-.94-2.36c-.9-.95-1.9-.95-2.36-1.01C16.9 3.5 12 3.5 12 3.5h-.01s-4.9 0-8.2.33c-.46.06-1.46.06-2.36 1.01-.71.72-.94 2.36-.94 2.36S.2 9.14.2 11.08v1.72c0 1.94.28 3.88.28 3.88s.23 1.64.94 2.36c.9.95 2.08.92 2.6 1.02 1.9.18 8 .24 8 .24s4.9-.01 8.2-.34c.46-.06 1.46-.06 2.36-1.01.71-.72.94-2.36.94-2.36s.28-1.94.28-3.88v-1.72c0-1.94-.28-3.88-.28-3.88ZM9.6 15.1V7.9l6.4 3.6-6.4 3.6Z",
  },
  whatsapp: {
    viewBox: "0 0 24 24",
    label: "WhatsApp",
    path: "M12.04 2C6.58 2 2.13 6.45 2.13 11.91c0 1.75.46 3.45 1.32 4.95L2.05 22l5.28-1.38a9.9 9.9 0 0 0 4.71 1.2h.01c5.46 0 9.9-4.45 9.9-9.91C21.96 6.45 17.5 2 12.04 2Zm5.8 14.02c-.24.68-1.4 1.3-1.93 1.35-.5.05-1.05.24-3.54-.74-2.99-1.19-4.9-4.24-5.05-4.44-.15-.2-1.2-1.6-1.2-3.05 0-1.45.76-2.16 1.03-2.46.27-.3.6-.37.8-.37.2 0 .4 0 .58.01.19.01.44-.07.68.53.24.6.83 2.06.9 2.21.07.15.12.33.02.53-.1.2-.15.32-.3.5-.15.17-.31.39-.44.52-.15.15-.3.31-.13.6.17.3.76 1.26 1.64 2.04 1.13 1 2.08 1.32 2.38 1.47.3.15.47.13.65-.08.17-.2.73-.86.93-1.15.2-.3.4-.24.66-.15.27.1 1.72.81 2.02.96.3.15.5.22.57.35.08.13.08.72-.16 1.4Z",
  },
  twitter: {
    viewBox: "0 0 24 24",
    label: "Twitter / X",
    path: "M18.24 2.75h3.3l-7.2 8.23 8.47 11.27h-6.63l-5.2-6.8-5.94 6.8H1.73l7.7-8.8L1.3 2.75h6.8l4.7 6.22 5.44-6.22Zm-1.16 17.5h1.83L6.02 4.6H4.05l13.03 15.65Z",
  },
  linkedin: {
    viewBox: "0 0 24 24",
    label: "LinkedIn",
    path: "M20.45 20.45h-3.55v-5.57c0-1.33-.03-3.04-1.85-3.04-1.85 0-2.13 1.44-2.13 2.94v5.67H9.37V9h3.41v1.56h.05c.48-.9 1.64-1.85 3.37-1.85 3.6 0 4.27 2.37 4.27 5.46v6.28ZM5.34 7.43a2.06 2.06 0 1 1 0-4.12 2.06 2.06 0 0 1 0 4.12Zm1.78 13.02H3.56V9h3.56v11.45ZM22.22 0H1.77C.79 0 0 .77 0 1.73v20.54C0 23.23.79 24 1.77 24h20.45c.98 0 1.78-.77 1.78-1.73V1.73C24 .77 23.2 0 22.22 0Z",
  },
};

const SIZE_MAP: Record<string, { box: string; icon: number }> = {
  sm: { box: "w-6 h-6", icon: 12 },
  md: { box: "w-8 h-8", icon: 16 },
  lg: { box: "w-11 h-11", icon: 20 },
};

export default function SocialIcons({ links, color = "#dc2626", size = "md" }: { links: SocialLinks; color?: string; size?: string }) {
  const active = (Object.keys(ICON_PATHS) as (keyof SocialLinks)[]).filter((k) => links[k]);
  if (active.length === 0) return null;
  const { box, icon: iconPx } = SIZE_MAP[size] || SIZE_MAP.md;

  return (
    <div className="flex items-center gap-2">
      {active.map((key) => {
        const icon = ICON_PATHS[key];
        return (
          <a
            key={key}
            href={links[key]}
            target="_blank"
            rel="noopener noreferrer"
            aria-label={icon.label}
            title={icon.label}
            className={`${box} rounded-full flex items-center justify-center shrink-0 transition-transform hover:scale-110`}
            style={{ backgroundColor: color }}
          >
            <svg viewBox={icon.viewBox} width={iconPx} height={iconPx} fill="#ffffff">
              <path d={icon.path} />
            </svg>
          </a>
        );
      })}
    </div>
  );
}
