// Splat — a little green blob. Shape is consistent across expressions; only eyes + mouth change.
// He's the "sticker with outline" variant from the question.

const SplatBody = ({ fill = "#5FBF5F", outline = "#0F1F2C", shadow = "#2F8C3A" }) => (
  <g>
    {/* undershadow inside the blob to give him volume */}
    <path
      d="M18 44 Q12 20 40 16 Q68 20 62 44 Q64 52 58 52 Q50 48 40 52 Q30 48 22 52 Q16 52 18 44 Z"
      fill={shadow}
      opacity="0.35"
      transform="translate(0,2)"
    />
    <path
      d="M18 44 Q12 20 40 16 Q68 20 62 44 Q64 52 58 52 Q50 48 40 52 Q30 48 22 52 Q16 52 18 44 Z"
      fill={fill}
      stroke={outline}
      strokeWidth="2"
      strokeLinejoin="round"
    />
    {/* highlight */}
    <ellipse cx="28" cy="26" rx="5" ry="3" fill="white" opacity="0.55" transform="rotate(-20 28 26)" />
    {/* little antenna */}
    <circle cx="40" cy="13" r="1.8" fill={shadow} />
    <line x1="40" y1="13" x2="40" y2="17" stroke={shadow} strokeWidth="1.3" />
  </g>
);

const SplatEyes = ({ expression = "happy" }) => {
  // shared eye socket
  const sockets = (
    <>
      <ellipse cx="33" cy="30" rx="5" ry="6" fill="white" stroke="#0F1F2C" strokeWidth="1.6" />
      <ellipse cx="47" cy="30" rx="5" ry="6" fill="white" stroke="#0F1F2C" strokeWidth="1.6" />
    </>
  );
  switch (expression) {
    case "wink":
      return (
        <>
          <ellipse cx="33" cy="30" rx="5" ry="6" fill="white" stroke="#0F1F2C" strokeWidth="1.6" />
          <path d="M42 30 Q47 27 52 30" stroke="#0F1F2C" strokeWidth="2" fill="none" strokeLinecap="round" />
          <circle cx="33" cy="31" r="2" fill="#0F1F2C" />
          <circle cx="32" cy="30" r="0.8" fill="white" />
        </>
      );
    case "sleepy":
      return (
        <>
          <path d="M28 30 Q33 33 38 30" stroke="#0F1F2C" strokeWidth="2" fill="none" strokeLinecap="round" />
          <path d="M42 30 Q47 33 52 30" stroke="#0F1F2C" strokeWidth="2" fill="none" strokeLinecap="round" />
        </>
      );
    case "surprised":
      return (
        <>
          {sockets}
          <circle cx="33" cy="30" r="2.8" fill="#0F1F2C" />
          <circle cx="47" cy="30" r="2.8" fill="#0F1F2C" />
          <circle cx="32" cy="29" r="1" fill="white" />
          <circle cx="46" cy="29" r="1" fill="white" />
        </>
      );
    case "thinking":
      return (
        <>
          {sockets}
          <circle cx="34" cy="31" r="2" fill="#0F1F2C" />
          <circle cx="48" cy="31" r="2" fill="#0F1F2C" />
          <circle cx="33" cy="30" r="0.7" fill="white" />
          <circle cx="47" cy="30" r="0.7" fill="white" />
        </>
      );
    case "reading":
      return (
        <>
          {/* little glasses */}
          <circle cx="33" cy="30" r="5.5" fill="white" stroke="#0F1F2C" strokeWidth="1.6" />
          <circle cx="47" cy="30" r="5.5" fill="white" stroke="#0F1F2C" strokeWidth="1.6" />
          <line x1="38.5" y1="30" x2="41.5" y2="30" stroke="#0F1F2C" strokeWidth="1.6" />
          <circle cx="33" cy="30" r="2" fill="#0F1F2C" />
          <circle cx="47" cy="30" r="2" fill="#0F1F2C" />
        </>
      );
    case "happy":
    default:
      return (
        <>
          {sockets}
          <circle cx="33" cy="31" r="2.2" fill="#0F1F2C" />
          <circle cx="47" cy="31" r="2.2" fill="#0F1F2C" />
          <circle cx="32" cy="30" r="0.9" fill="white" />
          <circle cx="46" cy="30" r="0.9" fill="white" />
        </>
      );
  }
};

const SplatMouth = ({ expression = "happy" }) => {
  switch (expression) {
    case "wink":
    case "happy":
      return <path d="M32 40 Q40 46 48 40" stroke="#0F1F2C" strokeWidth="2" fill="none" strokeLinecap="round" />;
    case "surprised":
      return <ellipse cx="40" cy="42" rx="3" ry="4" fill="#0F1F2C" />;
    case "thinking":
      return <path d="M34 42 L44 42" stroke="#0F1F2C" strokeWidth="2" strokeLinecap="round" />;
    case "sleepy":
      return <path d="M36 42 Q40 44 44 42" stroke="#0F1F2C" strokeWidth="1.5" fill="none" strokeLinecap="round" />;
    case "reading":
      return <path d="M35 42 Q40 45 45 42" stroke="#0F1F2C" strokeWidth="1.8" fill="none" strokeLinecap="round" />;
    default:
      return <path d="M32 40 Q40 46 48 40" stroke="#0F1F2C" strokeWidth="2" fill="none" strokeLinecap="round" />;
  }
};

const SplatCheeks = () => (
  <>
    <ellipse cx="24" cy="38" rx="3" ry="2" fill="#F26B4A" opacity="0.55" />
    <ellipse cx="56" cy="38" rx="3" ry="2" fill="#F26B4A" opacity="0.55" />
  </>
);

const Splat = ({ size = 120, expression = "happy", fill = "#5FBF5F", cheeks = true, className = "", style = {} }) => (
  <svg
    viewBox="0 0 80 60"
    width={size}
    height={size * 0.75}
    className={className}
    style={style}
    aria-hidden="true"
  >
    <SplatBody fill={fill} />
    {cheeks && <SplatCheeks />}
    <SplatEyes expression={expression} />
    <SplatMouth expression={expression} />
  </svg>
);

// Tiny splat for inline use
const SplatBadge = ({ size = 28, expression = "happy" }) => (
  <svg viewBox="0 0 80 60" width={size} height={size * 0.75}>
    <SplatBody />
    <SplatEyes expression={expression} />
    <SplatMouth expression={expression} />
  </svg>
);

Object.assign(window, { Splat, SplatBadge });
