/* MissBetty mascot — soft lavender blob with a coral heart at chest.
   Same character at three scales: large, card, glyph.
   Exposed on window so other Babel scripts can use it. */

function HeartGlyph({ scale = 1, glow = true }) {
  // viewBox 24x24, heart centered at (12,12)
  return (
    <g transform={`scale(${scale})`} className={glow ? 'mb-heart-glow' : ''}>
      <path
        d="M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z"
        fill="#F4A88E"
      />
      <path
        d="M7 7.6 C 6 8.5, 6.6 10.5, 9 12.4"
        stroke="#FCD9C6"
        strokeWidth="1.2"
        fill="none"
        strokeLinecap="round"
        opacity="0.9"
      />
    </g>
  );
}

/** Big mascot — for welcome screen / hero moments. */
function MascotLarge({ size = 280, mouth = 'half-smile', className = '' }) {
  // body box 320x320, chest at (160, 205)
  return (
    <svg viewBox="0 0 320 320" width={size} height={size} className={className} aria-hidden="true">
      {/* floor shadow */}
      <ellipse cx="160" cy="298" rx="105" ry="8" fill="#3D2B3C" opacity="0.10" />
      {/* body */}
      <path
        d="M70 200 C 70 130, 110 95, 160 95 C 210 95, 250 130, 250 200 C 250 250, 220 285, 160 285 C 100 285, 70 250, 70 200 Z"
        fill="#B8A4C9"
      />
      <path d="M90 215 C 100 255, 130 280, 160 282 C 130 275, 110 245, 100 215 Z" fill="#A893C2" opacity=".55" />
      <ellipse cx="160" cy="135" rx="78" ry="62" fill="#B8A4C9" />
      <ellipse cx="135" cy="105" rx="34" ry="14" fill="#CDB9DA" opacity=".6" />
      {/* heart halo — outer ambient + tighter inner */}
      <circle cx="160" cy="208" r="58" fill="#F8C9B4" opacity="0.30" />
      <circle cx="160" cy="208" r="42" fill="#F8C9B4" opacity="0.65" className="mb-heart-glow" />
      {/* heart */}
      <g transform="translate(160,208)">
        <g transform="translate(-24,-24)">
          <HeartGlyph scale={2} />
        </g>
      </g>
      {/* cradling hands */}
      <path d="M120 220 C 116 198, 132 188, 142 200 C 138 215, 132 222, 124 224 Z" fill="#A893C2" />
      <path d="M200 220 C 204 198, 188 188, 178 200 C 182 215, 188 222, 196 224 Z" fill="#A893C2" />
      {/* eyes */}
      <ellipse cx="138" cy="135" rx="3.2" ry="4.2" fill="#3D2B3C" />
      <ellipse cx="182" cy="135" rx="3.2" ry="4.2" fill="#3D2B3C" />
      {/* eye glints */}
      <circle cx="139.2" cy="133.4" r="0.9" fill="#F8F2E7" />
      <circle cx="183.2" cy="133.4" r="0.9" fill="#F8F2E7" />
      {/* mouth */}
      {mouth === 'half-smile' && (
        <path d="M148 152 Q 160 158 172 152" stroke="#3D2B3C" strokeWidth="2.2" fill="none" strokeLinecap="round" />
      )}
      {mouth === 'flat' && (
        <path d="M150 153 L 170 153" stroke="#3D2B3C" strokeWidth="2.2" fill="none" strokeLinecap="round" />
      )}
      {mouth === 'thinking' && (
        <path d="M152 155 Q 160 152 168 155" stroke="#3D2B3C" strokeWidth="2.2" fill="none" strokeLinecap="round" />
      )}
      {/* blush */}
      <ellipse cx="118" cy="148" rx="9" ry="5" fill="#F4A88E" opacity=".35" />
      <ellipse cx="202" cy="148" rx="9" ry="5" fill="#F4A88E" opacity=".35" />
    </svg>
  );
}

/** Card-scale mascot — sits next to a message. */
function MascotCard({ size = 56, className = '' }) {
  return (
    <svg viewBox="0 0 64 64" width={size} height={size} className={className} aria-hidden="true">
      <ellipse cx="32" cy="36" rx="22" ry="22" fill="#B8A4C9" />
      <ellipse cx="32" cy="20" rx="17" ry="15" fill="#B8A4C9" />
      <circle cx="32" cy="37" r="15" fill="#F8C9B4" opacity="0.32" />
      <circle cx="32" cy="37" r="11.5" fill="#F8C9B4" opacity="0.65" className="mb-heart-glow" />
      <g transform="translate(32,37)">
        <g transform="translate(-9.6,-9.6)">
          <HeartGlyph scale={0.8} />
        </g>
      </g>
      <ellipse cx="26" cy="20" rx="1.2" ry="1.6" fill="#3D2B3C" />
      <ellipse cx="38" cy="20" rx="1.2" ry="1.6" fill="#3D2B3C" />
      <path d="M28 25 Q 32 27.5 36 25" stroke="#3D2B3C" strokeWidth="1.4" fill="none" strokeLinecap="round" />
    </svg>
  );
}

/** Tiny glyph — for nav rails, headers, fingerprint scale. */
function MascotGlyph({ size = 28, className = '' }) {
  return (
    <svg viewBox="0 0 40 40" width={size} height={size} className={className} aria-hidden="true">
      <ellipse cx="20" cy="22" rx="13" ry="14" fill="#B8A4C9" />
      <ellipse cx="20" cy="11" rx="10" ry="9" fill="#B8A4C9" />
      <circle cx="20" cy="23" r="7.5" fill="#F8C9B4" opacity="0.55" className="mb-heart-glow" />
      <g transform="translate(20,23)">
        <g transform="translate(-5.4,-5.4)">
          <HeartGlyph scale={0.45} />
        </g>
      </g>
      <circle cx="16.5" cy="11" r="0.9" fill="#3D2B3C" />
      <circle cx="23.5" cy="11" r="0.9" fill="#3D2B3C" />
      <path d="M17 14.5 Q 20 16 23 14.5" stroke="#3D2B3C" strokeWidth="0.9" fill="none" strokeLinecap="round" />
    </svg>
  );
}

/** Speech-bubble wrap that pairs the mascot with a contextual message. */
function MascotSays({ children, scale = 'card', mood = 'half-smile' }) {
  const Mascot = scale === 'large' ? MascotLarge : scale === 'glyph' ? MascotGlyph : MascotCard;
  const size = scale === 'large' ? 220 : scale === 'glyph' ? 32 : 56;
  return (
    <div className="flex items-start gap-3">
      <Mascot size={size} mouth={mood} />
      <div className="flex-1 pt-1">{children}</div>
    </div>
  );
}

Object.assign(window, { HeartGlyph, MascotLarge, MascotCard, MascotGlyph, MascotSays });
