// MODUS Logo system — 4 variants, all paired with the wordmark.
// Variant 1: Wordmark only (no mark) — the typographic answer.
// Variant 2: Square M monogram — solid, geometric.
// Variant 3: Bracket mark — [M] suggesting code / a slot for input.
// Variant 4: Slash mark — M/ suggesting "M is the operator".
// Tweaks pick which the site shows; nav uses the same variant for consistency.

const Logo = ({ variant = 'mono', size = 28, color, withWord = true }) => {
  const stroke = color || 'currentColor';
  const px = size;

  const Mark = () => {
    if (variant === 'wordmark') return null;

    if (variant === 'mono') {
      // Solid square with M cut into it — "the operator slot"
      return (
        <svg width={px} height={px} viewBox="0 0 32 32" fill="none" aria-hidden="true">
          <rect x="0" y="0" width="32" height="32" rx="6" fill={stroke}/>
          <path
            d="M7 23 V9 L12 9 L16 16 L20 9 L25 9 V23"
            stroke="var(--bg-base)"
            strokeWidth="2.4"
            strokeLinecap="square"
            strokeLinejoin="miter"
            fill="none"
          />
        </svg>
      );
    }

    if (variant === 'bracket') {
      // [M] — Mark in a code-style bracket pair
      return (
        <svg width={px * 1.2} height={px} viewBox="0 0 38 32" fill="none" aria-hidden="true">
          <path d="M5 6 L1 6 L1 26 L5 26" stroke={stroke} strokeWidth="2" fill="none" strokeLinecap="square"/>
          <path d="M33 6 L37 6 L37 26 L33 26" stroke={stroke} strokeWidth="2" fill="none" strokeLinecap="square"/>
          <path d="M9 23 V9 L14 9 L19 17 L24 9 L29 9 V23" stroke={stroke} strokeWidth="2.4" fill="none" strokeLinecap="square" strokeLinejoin="miter"/>
        </svg>
      );
    }

    if (variant === 'slash') {
      // M with a forward slash terminator — operator / parameter feel
      return (
        <svg width={px * 1.15} height={px} viewBox="0 0 36 32" fill="none" aria-hidden="true">
          <path d="M3 25 V7 L9 7 L15 17 L21 7 L27 7 V25" stroke={stroke} strokeWidth="2.6" fill="none" strokeLinecap="square" strokeLinejoin="miter"/>
          <path d="M28 28 L34 4" stroke="var(--accent)" strokeWidth="2.4" strokeLinecap="square"/>
        </svg>
      );
    }

    if (variant === 'dot') {
      // M with a leading accent dot — calm, signature mark
      return (
        <svg width={px * 1.15} height={px} viewBox="0 0 36 32" fill="none" aria-hidden="true">
          <circle cx="4" cy="22" r="3" fill="var(--accent)"/>
          <path d="M10 25 V7 L16 7 L21 17 L26 7 L32 7 V25" stroke={stroke} strokeWidth="2.6" fill="none" strokeLinecap="square" strokeLinejoin="miter"/>
        </svg>
      );
    }

    if (variant === 'rings') {
      // Concentric rings + node + connector — the "operational intelligence" mark
      return (
        <svg width={px * 1.15} height={px} viewBox="0 0 36 32" fill="none" aria-hidden="true">
          <circle cx="14" cy="16" r="13" stroke={stroke} strokeOpacity="0.25" strokeWidth="1" fill="none"/>
          <circle cx="14" cy="16" r="8.5"  stroke={stroke} strokeOpacity="0.55" strokeWidth="1" fill="none"/>
          <circle cx="14" cy="16" r="3.4"  fill="var(--accent)"/>
          <line x1="14" y1="16" x2="24" y2="6" stroke="var(--accent)" strokeWidth="1.2" strokeLinecap="round"/>
          <circle cx="24" cy="6" r="1.6" fill="var(--accent)"/>
        </svg>
      );
    }

    return null;
  };

  return (
    <span
      style={{
        display: 'inline-flex',
        alignItems: 'center',
        gap: variant === 'wordmark' ? 0 : 10,
        color: stroke,
        lineHeight: 1,
      }}
      aria-label="MODUS"
    >
      <Mark />
      {withWord && (
        <span
          style={{
            fontFamily: 'var(--font-sans)',
            fontWeight: 600,
            fontSize: `${px * 0.78}px`,
            letterSpacing: variant === 'wordmark' ? '-0.04em' : '-0.02em',
            color: stroke,
          }}
        >
          {variant === 'wordmark' ? (
            <>
              MODUS<span style={{ color: 'var(--accent)' }}>.</span>
            </>
          ) : (
            'MODUS'
          )}
        </span>
      )}
    </span>
  );
};

window.Logo = Logo;
