// v2-character.jsx — BigAndaa: expressive, character-led illustration
// Soft-geometric, brand colors (purple body, white face, sun/coral/sage props).

// expressions: 'happy' | 'wave' | 'wink' | 'caring' | 'sleepy' | 'think'
// holding: null | 'check' | 'list' | 'heart' | 'bell'
function BigAndaa({ size = 360, expression = 'happy', holding = 'check', style, className }) {
  const W = 360, H = 380;
  const s = size / W;

  const Eyes = () => {
    if (expression === 'wink') {
      return (
        <>
          <circle cx="150" cy="168" r="8" fill="#1A1A1F" />
          <path d="M196 168 q8 -8 16 0" stroke="#1A1A1F" strokeWidth="6" strokeLinecap="round" fill="none" />
        </>
      );
    }
    if (expression === 'sleepy') {
      return (
        <>
          <path d="M142 168 q8 -7 16 0" stroke="#1A1A1F" strokeWidth="6" strokeLinecap="round" fill="none" />
          <path d="M196 168 q8 -7 16 0" stroke="#1A1A1F" strokeWidth="6" strokeLinecap="round" fill="none" />
        </>
      );
    }
    if (expression === 'caring') {
      return (
        <>
          <ellipse cx="150" cy="170" rx="8" ry="9" fill="#1A1A1F" />
          <ellipse cx="204" cy="170" rx="8" ry="9" fill="#1A1A1F" />
          {/* soft cheeks */}
          <circle cx="128" cy="190" r="11" fill="#FF6B5B" opacity="0.5" />
          <circle cx="226" cy="190" r="11" fill="#FF6B5B" opacity="0.5" />
        </>
      );
    }
    // happy / wave / think default
    return (
      <>
        <circle cx="150" cy="168" r="8.5" fill="#1A1A1F" />
        <circle cx="204" cy="168" r="8.5" fill="#1A1A1F" />
        {/* sparkle in eye */}
        <circle cx="153" cy="165" r="2.4" fill="#fff" />
        <circle cx="207" cy="165" r="2.4" fill="#fff" />
      </>
    );
  };

  const Mouth = () => {
    if (expression === 'sleepy') return <ellipse cx="177" cy="200" rx="7" ry="9" fill="#1A1A1F" opacity="0.7" />;
    if (expression === 'think') return <circle cx="170" cy="200" r="6" fill="#1A1A1F" opacity="0.8" />;
    if (expression === 'caring') return <path d="M158 196 q19 16 38 0" stroke="#1A1A1F" strokeWidth="6" strokeLinecap="round" fill="none" />;
    // wide happy smile
    return <path d="M150 194 q27 26 54 0" stroke="#1A1A1F" strokeWidth="7" strokeLinecap="round" fill="none" />;
  };

  return (
    <svg width={size} height={size * H / W} viewBox={`0 0 ${W} ${H}`} fill="none" style={style} className={className}>
      {/* shadow ellipse */}
      <ellipse cx="180" cy="362" rx="92" ry="14" fill="#1A1A1F" opacity="0.07" />

      {/* left arm (behind body) */}
      {expression === 'wave' ? (
        <g style={{ transformOrigin: '92px 250px', animation: 'v2-wave 1.6s ease-in-out infinite' }}>
          <path d="M96 250 q-40 -28 -34 -78" stroke="#5B4FD9" strokeWidth="26" strokeLinecap="round" fill="none" />
          <circle cx="58" cy="168" r="18" fill="#FF6B5B" />
        </g>
      ) : (
        <>
          <path d="M96 252 q-34 6 -44 40" stroke="#5B4FD9" strokeWidth="26" strokeLinecap="round" fill="none" />
          <circle cx="50" cy="296" r="17" fill="#5B4FD9" />
        </>
      )}

      {/* right arm — holds prop */}
      <path d="M264 252 q34 4 46 36" stroke="#5B4FD9" strokeWidth="26" strokeLinecap="round" fill="none" />
      <circle cx="312" cy="292" r="17" fill="#5B4FD9" />

      {/* body */}
      <path d="M86 150 Q86 96 140 92 L220 92 Q274 96 274 150 L274 250 Q274 312 210 314 L150 314 Q86 312 86 250 Z" fill="#5B4FD9" />

      {/* face panel highlight */}
      <ellipse cx="180" cy="178" rx="62" ry="54" fill="#fff" opacity="0.10" />

      <Eyes />
      <Mouth />

      {/* prop held in right hand */}
      {holding === 'check' && (
        <g>
          <circle cx="312" cy="276" r="28" fill="#FFD23F" stroke="#1A1A1F" strokeWidth="3" />
          <path d="M299 277 l9 9 l16 -19" stroke="#1A1A1F" strokeWidth="7" strokeLinecap="round" strokeLinejoin="round" fill="none" />
        </g>
      )}
      {holding === 'heart' && (
        <path d="M312 262 c-10 -14 -32 -4 -32 12 c0 14 22 26 32 34 c10 -8 32 -20 32 -34 c0 -16 -22 -26 -32 -12 z" fill="#FF6B5B" stroke="#1A1A1F" strokeWidth="3" />
      )}
      {holding === 'bell' && (
        <g>
          <path d="M312 252 a18 18 0 0 1 18 18 v10 l4 6 h-44 l4 -6 v-10 a18 18 0 0 1 18 -18z" fill="#FFD23F" stroke="#1A1A1F" strokeWidth="3" />
          <circle cx="312" cy="292" r="4" fill="#1A1A1F" />
        </g>
      )}
      {holding === 'list' && (
        <g>
          <rect x="288" y="250" width="48" height="56" rx="7" fill="#FAF7F0" stroke="#1A1A1F" strokeWidth="3" />
          <path d="M298 266 h28 M298 278 h22 M298 290 h26" stroke="#7BC4A8" strokeWidth="4" strokeLinecap="round" />
        </g>
      )}

      {/* yellow check pin on body (logo signature) */}
      {holding !== 'check' && (
        <g>
          <circle cx="250" cy="288" r="22" fill="#FFD23F" stroke="#1A1A1F" strokeWidth="2.5" />
          <path d="M240 289 l7 7 l13 -15" stroke="#1A1A1F" strokeWidth="5.5" strokeLinecap="round" strokeLinejoin="round" fill="none" />
        </g>
      )}

      {/* little antenna with sparkle (AI signal) */}
      <line x1="180" y1="92" x2="180" y2="64" stroke="#5B4FD9" strokeWidth="6" strokeLinecap="round" />
      <g style={{ transformOrigin: '180px 56px', animation: 'v2-twinkle 2.4s ease-in-out infinite' }}>
        <path d="M180 44 l4 9 l9 4 l-9 4 l-4 9 l-4 -9 l-9 -4 l9 -4 z" fill="#FFD23F" stroke="#1A1A1F" strokeWidth="1.5" strokeLinejoin="round" />
      </g>

      {/* sleepy z's */}
      {expression === 'sleepy' && (
        <text x="288" y="120" fontFamily="DM Sans, sans-serif" fontSize="26" fontWeight="600" fill="#5B4FD9">z</text>
      )}
    </svg>
  );
}

// Small peeking head — for margins / corners
function AndaaPeek({ size = 80, expression = 'happy', style }) {
  return (
    <svg width={size} height={size} viewBox="0 0 120 120" fill="none" style={style}>
      <path d="M24 56 Q24 26 60 24 L60 24 Q96 26 96 56 L96 80 Q96 104 60 104 Q24 104 24 80 Z" fill="#5B4FD9" />
      <circle cx="48" cy="58" r="6" fill="#1A1A1F" />
      <circle cx="74" cy="58" r="6" fill="#1A1A1F" />
      <circle cx="50" cy="56" r="1.8" fill="#fff" />
      <circle cx="76" cy="56" r="1.8" fill="#fff" />
      <path d="M48 74 q12 14 26 0" stroke="#1A1A1F" strokeWidth="5" strokeLinecap="round" fill="none" />
      <circle cx="92" cy="94" r="14" fill="#FFD23F" stroke="#1A1A1F" strokeWidth="2" />
      <path d="M86 95 l4 4 l8 -9" stroke="#1A1A1F" strokeWidth="3.5" strokeLinecap="round" strokeLinejoin="round" fill="none" />
    </svg>
  );
}

// inject character keyframes once
if (typeof document !== 'undefined' && !document.getElementById('v2-char-kf')) {
  const st = document.createElement('style');
  st.id = 'v2-char-kf';
  st.textContent = `
    @keyframes v2-wave { 0%,100%{transform:rotate(0)} 25%{transform:rotate(-14deg)} 60%{transform:rotate(8deg)} }
    @keyframes v2-twinkle { 0%,100%{transform:scale(1) rotate(0); opacity:1} 50%{transform:scale(1.25) rotate(20deg); opacity:0.8} }
    @media (prefers-reduced-motion: reduce){ [style*="v2-wave"],[style*="v2-twinkle"]{animation:none !important} }
  `;
  document.head.appendChild(st);
}

Object.assign(window, { BigAndaa, AndaaPeek });
