/* eslint-disable @next/next/no-img-element */

export const APP_LINK = "https://onelink.to/sendmn3.0";

type Store = {
  key: string;
  alt: string;
  badge: string; // black badge image (sub footer)
  pill: string; // light badge SVG (e.g. Alipay page)
  pillWidth: number; // SVG's natural width at 52px height
};

const STORES: Store[] = [
  {
    key: "appstore",
    alt: "Download on the App Store",
    badge:
      "https://ik.imagekit.io/eltrcapq6b/AppStore.png?updatedAt=1753866669711",
    pill: "/images/icons/AppStore.svg",
    pillWidth: 156,
  },
  {
    key: "googleplay",
    alt: "Get it on Google Play",
    badge:
      "https://ik.imagekit.io/eltrcapq6b/GooglePlay.png?updatedAt=1753866669763",
    pill: "/images/icons/GooglePlay.svg",
    pillWidth: 180,
  },
  {
    key: "appgallery",
    alt: "Explore it on AppGallery",
    badge:
      "https://ik.imagekit.io/eltrcapq6b/Badges.png?updatedAt=1753866669802",
    pill: "/images/icons/AppGallery.svg",
    pillWidth: 173,
  },
];

type Props = {
  /** "badge": black badge images (sub footer). "pill": light SVG badges. */
  variant?: "badge" | "pill";
  /** Wrapper classes (layout / alignment). */
  className?: string;
  /** Image height classes. */
  imgClassName?: string;
};

const AppDownloadButtons = ({
  variant = "badge",
  className = "flex gap-4",
  imgClassName,
}: Props) => {
  const isPill = variant === "pill";
  const imgClass =
    imgClassName ??
    (isPill ? "w-full h-auto sm:w-auto sm:h-[52px]" : "h-6 md:h-12");

  return (
    <div className={className}>
      {STORES.map((s) => (
        <a
          key={s.key}
          href={APP_LINK}
          target="_blank"
          rel="noopener noreferrer"
          // Pill on mobile: each badge grows in proportion to its natural
          // width, so all three fit one row at the same height.
          style={
            isPill
              ? ({ "--w": s.pillWidth } as React.CSSProperties)
              : undefined
          }
          className={`transition hover:-translate-y-0.5 ${
            isPill
              ? "min-w-0 flex-[var(--w)_1_0%] sm:flex-none rounded-lg hover:shadow-[0_6px_16px_rgba(0,210,255,0.18)] focus:outline-none focus-visible:ring-2 focus-visible:ring-whiteBlue"
              : "hover:opacity-90"
          }`}
        >
          <img
            src={isPill ? s.pill : s.badge}
            alt={s.alt}
            className={`block ${imgClass}`}
            loading="lazy"
          />
        </a>
      ))}
    </div>
  );
};

export default AppDownloadButtons;
