// Frank — the Frankly English mascot. Black cat with cyan round glasses and
// over-ear headphones. Modeled on the reference logo, but toned down for an
// adult audience: smaller alert eyes (not kawaii saucers), tighter linework,
// subtle closed-mouth smile, no tongue.
//
//   <Frank size={120} mood="happy" />
//
// Two exports:
//   Frank      — full head with headphones (use ≥ 56px)
//   FrankMark  — head + glasses only, no headphones (use ≤ 36px for logo)

const FRANK_BODY = "#0F1024";        // near-black with cool tint
const FRANK_GLASS = "#22D3EE";       // cyan rim
const FRANK_GLASS_DEEP = "#0E7490";  // deep cyan for hinge / nosebridge highlight
const FRANK_EAR_PINK = "#FB7185";    // soft coral
const FRANK_NOSE = "#FB7185";
const FRANK_HP_STAR = "#FBBF24";

function FrankEyes({ mood }) {
  const eyeWhite = "#FFFFFF";
  const pupil = FRANK_BODY;
  if (mood === "happy") {
    // Closed, gently upward — set as smiley arcs INSIDE the glasses lenses
    return (
      <>
        <path d="M -22 -1 q 7 -6 14 0" stroke={pupil} strokeWidth="2.4" strokeLinecap="round" fill="none" />
        <path d="M  8 -1 q 7 -6 14 0" stroke={pupil} strokeWidth="2.4" strokeLinecap="round" fill="none" />
      </>
    );
  }
  if (mood === "wow") {
    return (
      <>
        <circle cx="-15" cy="0" r="5" fill={eyeWhite} />
        <circle cx="-14" cy="1" r="3" fill={pupil} />
        <circle cx="-12.5" cy="-0.6" r="0.9" fill={eyeWhite} />
        <circle cx="15" cy="0" r="5" fill={eyeWhite} />
        <circle cx="16" cy="1" r="3" fill={pupil} />
        <circle cx="17.5" cy="-0.6" r="0.9" fill={eyeWhite} />
      </>
    );
  }
  if (mood === "sad") {
    return (
      <>
        <path d="M -22 2 q 7 6 14 0" stroke={pupil} strokeWidth="2.4" strokeLinecap="round" fill="none" />
        <path d="M  8 2 q 7 6 14 0" stroke={pupil} strokeWidth="2.4" strokeLinecap="round" fill="none" />
      </>
    );
  }
  // think — alert, smaller eyes
  return (
    <>
      <ellipse cx="-15" cy="0" rx="3" ry="3.5" fill={pupil} />
      <circle cx="-13.7" cy="-1" r="0.9" fill={eyeWhite} />
      <ellipse cx="15" cy="0" rx="3" ry="3.5" fill={pupil} />
      <circle cx="16.3" cy="-1" r="0.9" fill={eyeWhite} />
    </>
  );
}

function FrankMouth({ mood }) {
  if (mood === "wow") {
    return <ellipse cx="0" cy="22" rx="3.2" ry="2.8" fill={FRANK_BODY} />;
  }
  if (mood === "sad") {
    return <path d="M -6 24 q 6 -5 12 0" stroke={FRANK_BODY} strokeWidth="1.8" strokeLinecap="round" fill="none" />;
  }
  // happy / think — closed-mouth dignified smile (two curves from nose)
  return (
    <>
      <path d="M 0 20 q -4 4 -8 2.5" stroke={FRANK_BODY} strokeWidth="1.8" strokeLinecap="round" fill="none" />
      <path d="M 0 20 q  4 4  8 2.5" stroke={FRANK_BODY} strokeWidth="1.8" strokeLinecap="round" fill="none" />
    </>
  );
}

function FrankHead({ mood }) {
  return (
    <>
      {/* Ears — pointed triangles */}
      <polygon points="-40,-24 -26,-56 -10,-28" fill={FRANK_BODY} />
      <polygon points="40,-24 26,-56 10,-28" fill={FRANK_BODY} />
      {/* Inner ear — pink, slightly inset */}
      <polygon points="-32,-28 -26,-48 -17,-30" fill={FRANK_EAR_PINK} />
      <polygon points="32,-28 26,-48 17,-30" fill={FRANK_EAR_PINK} />

      {/* Head — slightly wider than tall for an adult silhouette */}
      <ellipse cx="0" cy="2" rx="42" ry="40" fill={FRANK_BODY} />

      {/* Glasses — two cyan rings + bridge.
          The rims sit on top of the head fill, the lenses are intentionally
          transparent so the eyes (drawn next) read as "behind" them. */}
      <g fill="none" stroke={FRANK_GLASS} strokeWidth="2.8">
        <circle cx="-15" cy="0" r="13" />
        <circle cx="15"  cy="0" r="13" />
        <line x1="-2" y1="0" x2="2" y2="0" strokeLinecap="round" />
      </g>
      {/* Tiny glasses highlight — top-left of each lens for a glassy hint */}
      <path d="M -22 -5 q 2 -4 6 -4" stroke="rgba(255,255,255,0.55)" strokeWidth="1.4" fill="none" strokeLinecap="round" />
      <path d="M 8 -5 q 2 -4 6 -4"   stroke="rgba(255,255,255,0.55)" strokeWidth="1.4" fill="none" strokeLinecap="round" />

      {/* Eyes — inside the glasses */}
      <FrankEyes mood={mood} />

      {/* Nose — small pink triangle/dot */}
      <path d="M -2.5 15 L 2.5 15 L 0 18 Z" fill={FRANK_NOSE} />

      {/* Mouth */}
      <FrankMouth mood={mood} />
    </>
  );
}

function Frank({ size = 120, mood = "happy", style = {} }) {
  return (
    <svg
      viewBox="-70 -68 140 110"
      width={size}
      height={size * (110 / 140)}
      style={style}
      aria-hidden="true"
    >
      {/* Headphone band — arc over the head, drawn BEHIND the ears so they
          sit on top of it like real headphones over cat ears. */}
      <path
        d="M -48 -22 C -48 -64, 48 -64, 48 -22"
        stroke={FRANK_GLASS}
        strokeWidth="5.5"
        strokeLinecap="round"
        fill="none"
      />
      <path
        d="M -48 -22 C -48 -64, 48 -64, 48 -22"
        stroke={FRANK_GLASS_DEEP}
        strokeWidth="2"
        strokeLinecap="round"
        fill="none"
        opacity="0.5"
      />

      {/* Head + face */}
      <FrankHead mood={mood} />

      {/* Headphone cups — sit ON the head, after, so they overlap the ear
          base. Right cup carries the small star detail. */}
      <g>
        <circle cx="-46" cy="-6" r="11.5" fill={FRANK_GLASS} />
        <circle cx="-46" cy="-6" r="6"    fill={FRANK_GLASS_DEEP} />
        <circle cx="46"  cy="-6" r="11.5" fill={FRANK_GLASS} />
        <circle cx="46"  cy="-6" r="6"    fill={FRANK_GLASS_DEEP} />
        {/* Star on right cup */}
        <polygon
          points="46,-10 47.2,-7.2 50.2,-6.8 48,-4.8 48.6,-1.8 46,-3.2 43.4,-1.8 44,-4.8 41.8,-6.8 44.8,-7.2"
          fill={FRANK_HP_STAR}
        />
      </g>
    </svg>
  );
}

// Small-size variant: drop the headphones (their detail muddies at < 36px),
// keep ears + glasses so the brand mark still reads as "cat with glasses".
function FrankMark({ size = 22, style = {} }) {
  return (
    <svg
      viewBox="-60 -65 120 110"
      width={size}
      height={size * (110 / 120)}
      style={style}
      aria-hidden="true"
    >
      {/* Ears */}
      <polygon points="-40,-22 -26,-58 -10,-26" fill={FRANK_BODY} />
      <polygon points="40,-22 26,-58 10,-26" fill={FRANK_BODY} />
      <polygon points="-32,-26 -26,-50 -17,-28" fill={FRANK_EAR_PINK} />
      <polygon points="32,-26 26,-50 17,-28" fill={FRANK_EAR_PINK} />

      {/* Head */}
      <ellipse cx="0" cy="4" rx="44" ry="40" fill={FRANK_BODY} />

      {/* Glasses — slightly chunkier stroke at tiny sizes so they survive */}
      <g fill="none" stroke={FRANK_GLASS} strokeWidth="3.2">
        <circle cx="-16" cy="2" r="13" />
        <circle cx="16"  cy="2" r="13" />
        <line x1="-3" y1="2" x2="3" y2="2" strokeLinecap="round" />
      </g>
      {/* Closed-eye smile arcs inside glasses */}
      <path d="M -23 1 q 7 -5 14 0" stroke={FRANK_BODY} strokeWidth="2.6" strokeLinecap="round" fill="none" />
      <path d="M  9 1 q 7 -5 14 0"  stroke={FRANK_BODY} strokeWidth="2.6" strokeLinecap="round" fill="none" />

      {/* Nose */}
      <path d="M -2.5 17 L 2.5 17 L 0 20 Z" fill={FRANK_NOSE} />
    </svg>
  );
}

window.Frank = Frank;
window.FrankMark = FrankMark;
