import Link from "next/link";

type LogoSize = "sm" | "md" | "lg" | "xl";

interface LogoProps {
  size?: LogoSize;
  href?: string | null;
  className?: string;
}

// 高度由 size 控制，宽度按 logo.png 实际比例（约 5.41:1，单行 CYBER STAR + 星环）自适应
const HEIGHT_PX: Record<LogoSize, number> = {
  sm: 24,
  md: 44,
  lg: 64,
  xl: 88,
};

export default function Logo({
  size = "md",
  href = "/",
  className = "",
}: LogoProps) {
  const h = HEIGHT_PX[size];

  // 用原生 <img> 绕开 Next/Image 的格式转换 —— 某些环境下 sharp 把透明 PNG
  // 转 webp/avif 时会铺白底，导致 logo 在深色 nav 上出现白色矩形。
  const inner = (
    <img
      src="/logo.png"
      alt="CYBER STAR"
      decoding="async"
      draggable={false}
      style={{
        height: `${h}px`,
        width: "auto",
        background: "transparent",
        // 保留紫色辉光，但 drop-shadow 不会引入白底
        filter: "drop-shadow(0 0 14px rgba(139,92,246,0.4))",
      }}
      className={`block select-none ${className}`}
    />
  );

  if (!href) return inner;
  return (
    <Link
      href={href}
      className="inline-flex items-center hover:opacity-90 transition-opacity"
      aria-label="CYBER STAR · 首页"
      style={{ background: "transparent" }}
    >
      {inner}
    </Link>
  );
}
