/* global React */
// bebe mascot — "Bo", a soft rounded studio creature. Premium + friendly.
// Drawn in SVG so it stays crisp. Eyes blink; body floats (gated by CSS).

const { useEffect, useState } = React;

function Mascot({ size = 300, blink = true }) {
  const [closed, setClosed] = useState(false);
  useEffect(() => {
    if (!blink) return;
    let t;
    const loop = () => {
      const next = 2600 + Math.random() * 3200;
      t = setTimeout(() => {
        setClosed(true);
        setTimeout(() => setClosed(false), 130);
        loop();
      }, next);
    };
    loop();
    return () => clearTimeout(t);
  }, [blink]);

  return (
    <svg width={size} height={size} viewBox="0 0 300 300" fill="none" aria-label="bebe mascot"
         style={{ overflow: "visible" }}>
      <defs>
        <radialGradient id="boBody" cx="42%" cy="34%" r="78%">
          <stop offset="0%" stopColor="#ffd0a8" />
          <stop offset="38%" stopColor="var(--accent-2, #ffb15c)" />
          <stop offset="100%" stopColor="var(--accent, #ff7a45)" />
        </radialGradient>
        <radialGradient id="boGlow" cx="50%" cy="50%" r="50%">
          <stop offset="0%" stopColor="var(--accent, #ff7a45)" stopOpacity="0.5" />
          <stop offset="100%" stopColor="var(--accent, #ff7a45)" stopOpacity="0" />
        </radialGradient>
        <linearGradient id="boShine" x1="0" y1="0" x2="0" y2="1">
          <stop offset="0%" stopColor="#ffffff" stopOpacity="0.55" />
          <stop offset="100%" stopColor="#ffffff" stopOpacity="0" />
        </linearGradient>
      </defs>

      {/* ambient glow */}
      <circle cx="150" cy="156" r="120" fill="url(#boGlow)" />

      {/* little feet */}
      <ellipse cx="124" cy="244" rx="20" ry="11" fill="var(--accent, #ff7a45)" opacity="0.9" />
      <ellipse cx="176" cy="244" rx="20" ry="11" fill="var(--accent, #ff7a45)" opacity="0.9" />

      {/* body — soft squircle */}
      <path d="M150 56
               C214 56 246 96 246 158
               C246 214 212 246 150 246
               C88 246 54 214 54 158
               C54 96 86 56 150 56 Z"
            fill="url(#boBody)" />
      {/* glossy top sheen */}
      <path d="M150 64 C198 64 228 92 234 138 C200 116 100 116 66 138 C72 92 102 64 150 64 Z"
            fill="url(#boShine)" opacity="0.7" />

      {/* antenna spark */}
      <line x1="150" y1="56" x2="150" y2="30" stroke="var(--accent, #ff7a45)" strokeWidth="4" strokeLinecap="round" />
      <g className="bo-spark">
        <circle cx="150" cy="22" r="8" fill="var(--mint, #5fe3b3)" />
        <circle cx="150" cy="22" r="8" fill="var(--mint, #5fe3b3)" opacity="0.4">
          <animate attributeName="r" values="8;14;8" dur="2.4s" repeatCount="indefinite" />
          <animate attributeName="opacity" values="0.4;0;0.4" dur="2.4s" repeatCount="indefinite" />
        </circle>
      </g>

      {/* face */}
      <g transform="translate(0, 6)">
        {/* eyes */}
        {closed ? (
          <>
            <path d="M112 150 q12 8 24 0" stroke="#3a1605" strokeWidth="5" strokeLinecap="round" fill="none" />
            <path d="M164 150 q12 8 24 0" stroke="#3a1605" strokeWidth="5" strokeLinecap="round" fill="none" />
          </>
        ) : (
          <>
            <ellipse cx="124" cy="150" rx="12" ry="14" fill="#2a1003" />
            <ellipse cx="176" cy="150" rx="12" ry="14" fill="#2a1003" />
            <circle cx="128" cy="145" r="4" fill="#fff" />
            <circle cx="180" cy="145" r="4" fill="#fff" />
          </>
        )}
        {/* blush */}
        <ellipse cx="104" cy="170" rx="11" ry="7" fill="#ff5a3c" opacity="0.35" />
        <ellipse cx="196" cy="170" rx="11" ry="7" fill="#ff5a3c" opacity="0.35" />
        {/* smile */}
        <path d="M138 176 q12 12 24 0" stroke="#3a1605" strokeWidth="5" strokeLinecap="round" fill="none" />
      </g>
    </svg>
  );
}

// Tiny product glyphs used in hero orbit + cards.
function Glyph({ kind, size = 22, color = "currentColor" }) {
  const s = { width: size, height: size, display: "block" };
  if (kind === "web") return (
    <svg viewBox="0 0 24 24" style={s} fill="none" stroke={color} strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
      <rect x="3" y="4" width="18" height="16" rx="2.5" /><path d="M3 9h18" /><circle cx="6.5" cy="6.5" r="0.6" fill={color} /><path d="M8 14h5" />
    </svg>
  );
  if (kind === "helm") return (
    <svg viewBox="0 0 24 24" style={s} fill="none" stroke={color} strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
      <rect x="3" y="3.5" width="7.5" height="7.5" rx="1.6" /><rect x="13.5" y="3.5" width="7.5" height="7.5" rx="1.6" /><rect x="3" y="13" width="7.5" height="7.5" rx="1.6" /><rect x="13.5" y="13" width="7.5" height="7.5" rx="1.6" />
    </svg>
  );
  if (kind === "scout") return (
    <svg viewBox="0 0 24 24" style={s} fill="none" stroke={color} strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
      <circle cx="11" cy="11" r="7" /><path d="m20 20-3.2-3.2" /><path d="M11 8v6M8 11h6" />
    </svg>
  );
  if (kind === "custom") return (
    <svg viewBox="0 0 24 24" style={s} fill="none" stroke={color} strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
      <path d="m8 6-5 6 5 6" /><path d="m16 6 5 6-5 6" /><path d="m13.5 4-3 16" />
    </svg>
  );
  return null;
}

Object.assign(window, { Mascot, Glyph });
