// WaxSeal.jsx — a wax-puck rendering of the seal.
// Used on bottle necks, certificates, and end-of-page sign-offs.

const WaxSeal = ({ size = 180, color = 'wax' }) => {
  // color: 'wax' (copper-deep wax) | 'mead' (mead-deep) | 'gold' (gold foil)
  const palette = {
    wax:  { fill: '#5E2F1A', edge: '#3A1B0E', glaze: 'rgba(212, 100, 50, 0.20)', ink: '#E8DCC0' },
    mead: { fill: '#8A5A1F', edge: '#4A2D0A', glaze: 'rgba(212, 162, 75, 0.20)', ink: '#E8DCC0' },
    gold: { fill: '#B08840', edge: '#5E4A20', glaze: 'rgba(232, 200, 120, 0.30)', ink: '#0E0C09' },
  }[color];

  const r = size / 2;

  return (
    <div style={{ width: size, height: size, position: 'relative' }}>
      {/* Drip-edge wax shape (slightly irregular blob behind seal) */}
      <svg viewBox="0 0 200 200" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%' }}>
        <defs>
          <radialGradient id={`wax-grad-${color}`} cx="0.35" cy="0.35" r="0.7">
            <stop offset="0" stopColor={palette.glaze} stopOpacity="1"/>
            <stop offset="0.4" stopColor="rgba(255,255,255,0)" stopOpacity="0"/>
          </radialGradient>
          <filter id={`wax-rough-${color}`}>
            <feTurbulence type="fractalNoise" baseFrequency="0.9" numOctaves="2" seed="3"/>
            <feDisplacementMap in="SourceGraphic" scale="3"/>
          </filter>
        </defs>
        {/* Irregular wax blob */}
        <path d="M100 6
                 C 145 8 188 38 192 92
                 C 196 145 162 188 108 192
                 C 56 196 12 162 8 108
                 C 4 56 38 4 100 6 Z"
              fill={palette.fill}
              filter={`url(#wax-rough-${color})`}/>
        {/* Edge ring (darker) */}
        <circle cx="100" cy="100" r="93" fill="none" stroke={palette.edge} strokeWidth="1.5" opacity="0.85"/>
        {/* Inner ring (engraved) */}
        <circle cx="100" cy="100" r="86" fill="none" stroke={palette.ink} strokeWidth="0.75" opacity="0.6"/>
        {/* Specular highlight */}
        <ellipse cx="78" cy="74" rx="36" ry="22" fill={`url(#wax-grad-${color})`} opacity="0.9"/>

        {/* Curved type top */}
        <defs>
          <path id={`seal-top-${color}`} d="M 100,100 m -69,0 a 69,69 0 1,1 138,0"/>
          <path id={`seal-bot-${color}`} d="M 100,100 m -78,0 a 78,78 0 1,0 156,0"/>
        </defs>
        <text fontFamily="IM Fell English SC, serif" fontSize="10" letterSpacing="2" fill={palette.ink}>
          <textPath href={`#seal-top-${color}`} startOffset="50%" textAnchor="middle">HEXQUEEN · SOMERSET HONEY HOUSE</textPath>
        </text>
        <text fontFamily="IM Fell English SC, serif" fontSize="9" letterSpacing="2.5" fill={palette.ink}>
          <textPath href={`#seal-bot-${color}`} startOffset="50%" textAnchor="middle">· COPPER APIARY · EST MMXIX ·</textPath>
        </text>

        {/* Centered hexagon monogram, embossed — V4-A bee sigil */}
        <g transform="translate(50, 50) scale(0.83)" stroke={palette.ink} strokeWidth="1.6" fill="none" strokeLinecap="square">
          {/* Hexagon outer */}
          <path d="M60 6 L106 33 L106 87 L60 114 L14 87 L14 33 Z" strokeLinejoin="miter"/>
          {/* Hexagon inner hairline */}
          <path d="M60 14 L99 37 L99 83 L60 106 L21 83 L21 37 Z" strokeWidth="0.6" opacity="0.55"/>
          {/* Spine */}
          <path d="M60 30 L60 100" strokeWidth="3"/>
          {/* Antennae chevron */}
          <path d="M48 30 L60 22 L72 30" strokeWidth="2.2" strokeLinejoin="miter"/>
          {/* Wing-arms */}
          <path d="M60 56 L40 76 M60 56 L80 76" strokeWidth="2.4"/>
          {/* Abdomen stripes */}
          <path d="M50 82 L70 82 M50 90 L70 90" strokeWidth="1.8"/>
          {/* V-tail */}
          <path d="M60 96 L54 108 M60 96 L66 108" strokeWidth="2.2"/>
        </g>
      </svg>
    </div>
  );
};

window.WaxSeal = WaxSeal;
