// ─────────────────────────────────────────────────────────────────
// monogram.jsx — official AM monogram, brand-approved files
//
// Four artworks, all transparent PNGs, two resolutions each (1600 / 4000):
//   ┌──────────────┬─────────────────────────────────────────────────────┐
//   │ variant      │ usage                                               │
//   ├──────────────┼─────────────────────────────────────────────────────┤
//   │ "dourado"    │ default · gold foil · works on cream OR navy        │
//   │ "petroleo"   │ navy ink · for light/cream surfaces only            │
//   │ "branco"     │ white · for photos / saturated colour backgrounds   │
//   │ "preto"      │ black · for stationery, monochrome, embossing       │
//   └──────────────┴─────────────────────────────────────────────────────┘
//
// Pass `tone="auto"` to let the component pick based on the active mode:
//   light-mode body → "dourado"  (gold on cream)
//   dark-mode body  → "dourado"  (gold on navy)
// Use explicit variants when the surface is a photo (→ "branco") or when
// you want the navy-ink reading on a cream surface (→ "petroleo").
//
// Sizes ≥240px auto-load the 4000px file; smaller marks use 1600px.
// ─────────────────────────────────────────────────────────────────

const MONOGRAM_FILES = {
  dourado:  { 1600: 'assets/logo/AM_dourado_1600.png',  4000: 'assets/logo/AM_dourado_4000.png'  },
  petroleo: { 1600: 'assets/logo/AM_petroleo_1600.png', 4000: 'assets/logo/AM_petroleo_4000.png' },
  branco:   { 1600: 'assets/logo/AM_branco_1600.png',   4000: 'assets/logo/AM_branco_4000.png'   },
  preto:    { 1600: 'assets/logo/AM_preto_1600.png',    4000: 'assets/logo/AM_preto_4000.png'    },
};

function useMode() {
  const [mode, setMode] = React.useState(() =>
    document.body.classList.contains('mode-dark') ? 'dark' : 'light'
  );
  React.useEffect(() => {
    const ob = new MutationObserver(() => {
      setMode(document.body.classList.contains('mode-dark') ? 'dark' : 'light');
    });
    ob.observe(document.body, { attributes: true, attributeFilter: ['class'] });
    return () => ob.disconnect();
  }, []);
  return mode;
}

function Monogram({
  variant,           // optional explicit: 'dourado' | 'petroleo' | 'branco' | 'preto'
  tone = 'auto',     // legacy: 'auto' | 'dark' | 'light' — maps to variant if unset
  size = 80,
  style,
  className,
}) {
  const mode = useMode();
  // Resolve which artwork to use
  let v = variant;
  if (!v) {
    if (tone === 'dark') v = 'dourado';            // gold on dark
    else if (tone === 'light') v = 'dourado';      // gold on cream
    else v = mode === 'dark' ? 'dourado' : 'dourado'; // auto: gold by default
  }
  const set = MONOGRAM_FILES[v] || MONOGRAM_FILES.dourado;
  const src = size >= 240 ? set[4000] : set[1600];

  return (
    <img
      src={src}
      alt="Aura & Marcel"
      className={className}
      style={{
        width: size, height: size, objectFit: 'contain',
        display: 'block', userSelect: 'none', pointerEvents: 'none',
        ...style
      }}
      draggable="false"
    />
  );
}

// Small mark used in nav — same monogram, just smaller.
function NavMark({ size = 32, variant, tone }) {
  return <Monogram variant={variant} tone={tone} size={size} />;
}

// ─────────────────────────────────────────────────────────────────
// Gift placeholder illustrations — line drawings on tinted backgrounds.
// We don't have real product photos, so we draw delicate icons that
// suggest the item. Each kind returns a JSX <div> with role of an image.
// ─────────────────────────────────────────────────────────────────

const GIFT_BG_TINTS = [
['#F4EBDD', '#D8C8AD'], // marfim / papel
['#EDE2CC', '#C7B58F'], // beige
['#E8D9BE', '#B9965B'], // ouro soft
['#DCD2C0', '#A89572'], // pedra warm
['#F1E6D0', '#CFB58A']];


function GiftIllustration({ kind, id }) {
  // deterministic tint based on id
  const tIdx = (id.charCodeAt(1) + id.charCodeAt(2)) % GIFT_BG_TINTS.length;
  const [bg, fg] = GIFT_BG_TINTS[tIdx];

  return (
    <div className="gift__img" style={{ background: `linear-gradient(160deg, ${bg} 0%, ${bg} 60%, ${fg}22 100%)` }}>
      <svg viewBox="0 0 200 150" preserveAspectRatio="xMidYMid meet"
      style={{ position: 'absolute', inset: 0, width: '100%', height: '100%' }}
      fill="none" stroke="#5A3B2C" strokeWidth="0.9" strokeLinecap="round" strokeLinejoin="round" opacity="0.7">
        <GiftIcon kind={kind} />
      </svg>
      {/* corner ornament */}
      <svg width="22" height="22" viewBox="0 0 22 22"
      style={{ position: 'absolute', right: 12, bottom: 12, color: '#B9965B', opacity: 0.85 }}>
        <text x="0" y="16" fontFamily="Cormorant Garamond, serif" fontSize="14" fontStyle="italic" fill="currentColor">am</text>
      </svg>
    </div>);

}

function GiftIcon({ kind }) {
  switch (kind) {
    case 'glassware':
      return (
        <g transform="translate(60 28)">
          <path d="M 0 0 Q 40 0 40 0 L 36 38 Q 36 56 20 60 Q 4 56 4 38 Z" />
          <line x1="20" y1="60" x2="20" y2="92" />
          <ellipse cx="20" cy="96" rx="14" ry="2" />
          <g transform="translate(54 12)">
            <path d="M 0 0 Q 32 0 32 0 L 30 30 Q 30 44 16 48 Q 2 44 2 30 Z" />
            <line x1="16" y1="48" x2="16" y2="78" />
            <ellipse cx="16" cy="82" rx="12" ry="2" />
          </g>
        </g>);

    case 'cookware':
      return (
        <g transform="translate(50 38)">
          <ellipse cx="50" cy="20" rx="48" ry="10" />
          <path d="M 2 20 L 8 70 Q 8 82 50 82 Q 92 82 92 70 L 98 20" />
          <ellipse cx="50" cy="68" rx="42" ry="6" opacity="0.5" />
          <line x1="34" y1="6" x2="34" y2="0" />
          <line x1="66" y1="6" x2="66" y2="0" />
        </g>);

    case 'espresso':
      return (
        <g transform="translate(64 22)">
          <rect x="0" y="20" width="72" height="60" rx="2" />
          <rect x="6" y="0" width="60" height="22" rx="1" />
          <circle cx="36" cy="50" r="10" />
          <circle cx="36" cy="50" r="5" />
          <line x1="14" y1="34" x2="58" y2="34" />
          <rect x="28" y="74" width="16" height="10" />
          <line x1="20" y1="82" x2="52" y2="82" />
        </g>);

    case 'bedding':
      return (
        <g transform="translate(40 50)">
          <path d="M 0 30 Q 0 0 60 0 Q 120 0 120 30 L 120 60 L 0 60 Z" />
          <line x1="0" y1="30" x2="120" y2="30" />
          <path d="M 20 12 Q 30 18 40 12" />
          <path d="M 80 12 Q 90 18 100 12" />
          <line x1="0" y1="60" x2="120" y2="60" />
          <line x1="0" y1="72" x2="120" y2="72" opacity="0.4" />
        </g>);

    case 'wine':
      return (
        <g transform="translate(60 24)">
          <rect x="0" y="0" width="80" height="100" rx="2" />
          <line x1="0" y1="22" x2="80" y2="22" />
          <line x1="0" y1="48" x2="80" y2="48" />
          <line x1="0" y1="74" x2="80" y2="74" />
          {[10, 30, 56].map((y) =>
          <g key={y} transform={`translate(0 ${y})`}>
              <ellipse cx="14" cy="10" rx="3" ry="2" />
              <ellipse cx="32" cy="10" rx="3" ry="2" />
              <ellipse cx="50" cy="10" rx="3" ry="2" />
              <ellipse cx="68" cy="10" rx="3" ry="2" />
            </g>
          )}
        </g>);

    case 'cutlery':
      return (
        <g transform="translate(70 24)">
          <path d="M 6 0 Q 6 14 10 22 L 10 100" />
          <path d="M 30 0 L 30 8 M 36 0 L 36 10 M 42 0 L 42 8 Q 42 18 36 22 L 36 100" />
          <path d="M 56 0 Q 70 0 70 16 Q 70 32 60 32 L 60 100" />
        </g>);

    case 'blender':
      return (
        <g transform="translate(72 16)">
          <path d="M 0 0 Q 28 -4 56 0 L 50 60 Q 28 64 6 60 Z" />
          <line x1="6" y1="20" x2="50" y2="20" />
          <line x1="8" y1="40" x2="48" y2="40" />
          <rect x="8" y="62" width="40" height="40" rx="2" />
          <circle cx="28" cy="84" r="2" />
          <line x1="14" y1="74" x2="42" y2="74" />
        </g>);

    case 'mixer':
      return (
        <g transform="translate(56 28)">
          <path d="M 8 0 Q 8 0 56 0 Q 88 0 88 32 L 78 40" />
          <rect x="0" y="60" width="96" height="14" rx="2" />
          <ellipse cx="48" cy="60" rx="30" ry="6" />
          <line x1="48" y1="60" x2="48" y2="38" />
          <path d="M 40 38 Q 48 50 56 38 Q 48 26 40 38 Z" />
          <line x1="0" y1="74" x2="96" y2="74" />
        </g>);

    case 'robot':
      return (
        <g transform="translate(40 40)">
          <ellipse cx="60" cy="34" rx="58" ry="30" />
          <ellipse cx="60" cy="32" rx="58" ry="30" opacity="0.4" />
          <circle cx="60" cy="32" r="20" />
          <circle cx="60" cy="32" r="10" />
          <circle cx="60" cy="32" r="3" />
        </g>);

    case 'towel':
      return (
        <g transform="translate(60 30)">
          <rect x="0" y="0" width="80" height="60" rx="1" />
          <rect x="10" y="20" width="80" height="60" rx="1" opacity="0.6" />
          <line x1="0" y1="12" x2="80" y2="12" />
          <line x1="0" y1="48" x2="80" y2="48" />
          <line x1="10" y1="32" x2="90" y2="32" opacity="0.6" />
          <line x1="10" y1="68" x2="90" y2="68" opacity="0.6" />
        </g>);

    case 'lamp':
      return (
        <g transform="translate(86 20)">
          <line x1="14" y1="0" x2="14" y2="14" />
          <circle cx="14" cy="20" r="6" />
          <line x1="14" y1="26" x2="14" y2="80" />
          <ellipse cx="14" cy="86" rx="20" ry="4" />
          <path d="M 0 14 Q 14 0 28 14" />
        </g>);

    // ─── HONEYMOON ───
    case 'dinner':
      return (
        <g transform="translate(40 30)">
          <circle cx="60" cy="40" r="34" />
          <circle cx="60" cy="40" r="24" opacity="0.5" />
          <path d="M 30 40 Q 30 10 36 6 L 36 36" />
          <path d="M 84 36 L 84 6 M 78 6 L 78 16 Q 78 22 84 22 M 90 6 L 90 16 Q 90 22 84 22" />
          <line x1="20" y1="90" x2="100" y2="90" />
        </g>);

    case 'dive':
      return (
        <g transform="translate(40 20)">
          <circle cx="60" cy="46" r="32" />
          <circle cx="60" cy="46" r="26" opacity="0.4" />
          <path d="M 28 46 Q 60 36 92 46" />
          <line x1="60" y1="14" x2="60" y2="6" />
          <path d="M 50 22 Q 60 20 70 22" />
          <circle cx="56" cy="42" r="2" fill="currentColor" />
          <circle cx="64" cy="42" r="2" fill="currentColor" />
        </g>);

    case 'catamaran':
      return (
        <g transform="translate(20 22)">
          <path d="M 80 60 L 0 60 L 12 78 L 148 78 L 160 60 L 100 60" />
          <line x1="90" y1="0" x2="90" y2="60" />
          <path d="M 90 6 L 50 56 L 90 56 Z" />
          <path d="M 90 6 L 130 56 L 90 56 Z" opacity="0.6" />
          <path d="M 0 86 Q 40 80 80 86 T 160 86" />
        </g>);

    case 'spa':
      return (
        <g transform="translate(40 30)">
          <path d="M 60 6 Q 36 22 36 46 Q 36 66 60 74 Q 84 66 84 46 Q 84 22 60 6 Z" />
          <path d="M 60 22 Q 50 30 50 42 Q 50 54 60 60" opacity="0.5" />
          <path d="M 60 22 Q 70 30 70 42 Q 70 54 60 60" opacity="0.5" />
          <line x1="60" y1="20" x2="60" y2="74" opacity="0.3" />
        </g>);

    case 'snorkel':
      return (
        <g transform="translate(30 40)">
          <path d="M 0 30 Q 30 20 60 30 T 130 30" />
          <path d="M 0 50 Q 30 40 60 50 T 130 50" opacity="0.5" />
          <circle cx="76" cy="14" r="10" />
          <line x1="86" y1="14" x2="118" y2="14" />
          <line x1="118" y1="14" x2="118" y2="2" />
          <path d="M 64 18 L 60 32" />
        </g>);

    case 'caves':
      return (
        <g transform="translate(30 26)">
          <path d="M 0 80 L 10 30 Q 30 4 60 4 Q 90 4 110 30 L 122 80 Z" />
          <path d="M 40 80 L 50 50 L 60 80" opacity="0.5" />
          <path d="M 70 80 L 80 60 L 90 80" opacity="0.5" />
          <line x1="20" y1="40" x2="22" y2="50" />
          <line x1="100" y1="42" x2="98" y2="52" />
        </g>);

    case 'boat':
      return (
        <g transform="translate(20 30)">
          <path d="M 0 50 L 160 50 L 144 80 L 16 80 Z" />
          <rect x="40" y="20" width="80" height="30" rx="2" />
          <line x1="50" y1="30" x2="110" y2="30" />
          <line x1="50" y1="40" x2="110" y2="40" />
          <path d="M 0 90 Q 40 84 80 90 T 160 90" />
        </g>);

    case 'massage':
      return (
        <g transform="translate(30 40)">
          <line x1="0" y1="50" x2="130" y2="50" />
          <line x1="10" y1="60" x2="10" y2="80" />
          <line x1="120" y1="60" x2="120" y2="80" />
          <path d="M 16 40 Q 30 28 50 32 L 110 32 Q 124 32 124 50" />
          <circle cx="40" cy="22" r="8" />
          <line x1="50" y1="20" x2="74" y2="22" />
        </g>);

    case 'plane':
      return (
        <g transform="translate(30 30)">
          <path d="M 60 6 L 70 60 L 130 70 L 130 78 L 70 76 L 64 90 L 80 100 L 80 106 L 60 100 L 40 106 L 40 100 L 56 90 L 50 76 L -10 78 L -10 70 L 50 60 Z" />
        </g>);

    case 'suite':
      return (
        <g transform="translate(20 20)">
          <rect x="0" y="20" width="160" height="80" />
          <rect x="20" y="40" width="40" height="40" />
          <rect x="80" y="40" width="40" height="40" />
          <rect x="0" y="0" width="160" height="20" />
          <line x1="40" y1="40" x2="40" y2="80" />
          <line x1="100" y1="40" x2="100" y2="80" />
        </g>);

    case 'horse':
      return (
        <g transform="translate(30 30)">
          <path d="M 10 80 L 16 50 Q 20 30 50 30 L 90 30 Q 110 30 116 18 L 120 8 Q 124 14 122 24 L 120 38 Q 116 50 100 50 L 96 80 M 60 50 L 56 80 M 70 50 L 74 80 M 30 50 L 26 80" />
          <circle cx="116" cy="14" r="2" fill="currentColor" />
        </g>);

    case 'rum':
      return (
        <g transform="translate(64 18)">
          <rect x="6" y="20" width="40" height="80" rx="2" />
          <rect x="14" y="0" width="24" height="22" rx="1" />
          <rect x="10" y="36" width="32" height="18" />
          <line x1="14" y1="42" x2="38" y2="42" opacity="0.5" />
          <line x1="14" y1="48" x2="32" y2="48" opacity="0.5" />
        </g>);

    default:
      return (
        <g transform="translate(60 28)">
          <rect x="0" y="20" width="80" height="60" />
          <path d="M 0 20 L 40 0 L 80 20" />
          <line x1="40" y1="0" x2="40" y2="80" opacity="0.4" />
        </g>);

  }
}

Object.assign(window, { Monogram, NavMark, GiftIllustration });