"use client";

import Image from "next/image";
import type { SponsorTile } from "@/features/partners/sponsorRecord";

/**
 * One sponsor's logo on the partners page.
 *
 * Two identical copies of this markup sat in `Partner.tsx`, one inside the
 * carousel and one in the flat row, differing only in the wrapper's padding —
 * which is why the wrapper class is the single prop.
 *
 * Both copies rendered `<img src={sponsor.logo}>` with `logo` declared `string`
 * while the resource returns `null` whenever no logo was uploaded: that renders
 * an `<img>` with no `src`, which the browser resolves against the current URL
 * and draws as a broken image. A sponsor with no logo now renders nothing at
 * all, which is what the design shows.
 *
 * `next/image` with `unoptimized` rather than a bare `<img>`: the project sets
 * `images.unoptimized: true` globally, so this is the same single request to the
 * same URL, and it keeps the warning surface honest without changing the
 * optimization policy. Width and height are the rendered box so the element
 * reserves its space instead of reflowing the row as logos arrive.
 */
export default function SponsorLogo({
  sponsor,
  wrapperClassName,
}: {
  sponsor: SponsorTile;
  wrapperClassName: string;
}) {
  if (!sponsor.logo) return null;

  return (
    <div className={`${wrapperClassName} flex-col gap-3`}>
      <Image
        src={sponsor.logo}
        /* The organization name is the only description there is; an empty alt
           when even that is missing is better than the string "null logo". */
        alt={sponsor.name ? `${sponsor.name} logo` : ""}
        width={120}
        height={80}
        className="object-contain w-[96px] h-[64px] sm:w-[120px] sm:h-[80px]"
        unoptimized
      />
    </div>
  );
}
