// SecurityV0 brand mark explorations
const SLATE = "#565e74";
const SLATE_DIM = "#373f54";
const TEAL = "#006b62";
const RED = "#ba1d1d";

function MarkBracket({ size = 56, color = "#fff", bg = SLATE }) {
  // Bracket monogram — [S] in code-style brackets, signaling the "V0" / engineering posture
  return (
    <svg width={size} height={size} viewBox="0 0 56 56" aria-hidden="true">
      <rect width="56" height="56" rx="8" fill={bg}/>
      <path d="M14 14 H20 V18 H18 V38 H20 V42 H14 Z" fill={color}/>
      <path d="M42 14 H36 V18 H38 V38 H36 V42 H42 Z" fill={color}/>
      <text x="28" y="36" textAnchor="middle" fontFamily="Inter, sans-serif" fontWeight="700" fontSize="20" fill={color}>S</text>
    </svg>
  );
}

function MarkBracketV0Upper({ size = 56, color = "#fff", bg = SLATE }) {
  // [V0] — uppercase, tighter, more architectural
  return (
    <svg width={size} height={size} viewBox="0 0 56 56" aria-hidden="true">
      <rect width="56" height="56" rx="8" fill={bg}/>
      <path d="M10 14 H16 V18 H14 V38 H16 V42 H10 Z" fill={color}/>
      <path d="M46 14 H40 V18 H42 V38 H40 V42 H46 Z" fill={color}/>
      <text x="28" y="35.5" textAnchor="middle" fontFamily="Inter, sans-serif" fontWeight="700" fontSize="18" fill={color} letterSpacing="-0.5">V0</text>
    </svg>
  );
}

function MarkBracketV0Lower({ size = 56, color = "#fff", bg = SLATE }) {
  // [v0] — lowercase, softer, reads as code/version literal
  return (
    <svg width={size} height={size} viewBox="0 0 56 56" aria-hidden="true">
      <rect width="56" height="56" rx="8" fill={bg}/>
      <path d="M10 14 H16 V18 H14 V38 H16 V42 H10 Z" fill={color}/>
      <path d="M46 14 H40 V18 H42 V38 H40 V42 H46 Z" fill={color}/>
      <text x="28" y="35.5" textAnchor="middle" fontFamily="JetBrains Mono, ui-monospace, monospace" fontWeight="600" fontSize="16" fill={color}>v0</text>
    </svg>
  );
}

function MarkShield({ size = 56, color = "#fff", bg = SLATE }) {
  // Layered shield — two offset shields suggest "defense in depth"
  return (
    <svg width={size} height={size} viewBox="0 0 56 56" aria-hidden="true">
      <rect width="56" height="56" rx="8" fill={bg}/>
      <path d="M14 16 L28 12 L42 16 V30 C42 38 28 44 28 44 C28 44 14 38 14 30 Z" fill="none" stroke={color} strokeWidth="2" opacity="0.4"/>
      <path d="M18 19 L28 16 L38 19 V30 C38 36 28 40 28 40 C28 40 18 36 18 30 Z" fill={color}/>
      <text x="28" y="32" textAnchor="middle" fontFamily="Inter, sans-serif" fontWeight="700" fontSize="14" fill={bg}>V0</text>
    </svg>
  );
}

function MarkOrbit({ size = 56, color = "#fff", bg = SLATE }) {
  // Orbit — V0 with a circling dot, suggests scanning / monitoring loop
  return (
    <svg width={size} height={size} viewBox="0 0 56 56" aria-hidden="true">
      <rect width="56" height="56" rx="8" fill={bg}/>
      <circle cx="28" cy="28" r="14" fill="none" stroke={color} strokeWidth="1.5" opacity="0.35"/>
      <circle cx="42" cy="28" r="2.5" fill={color}/>
      <text x="28" y="34" textAnchor="middle" fontFamily="Inter, sans-serif" fontWeight="700" fontSize="16" fill={color}>V0</text>
    </svg>
  );
}

function MarkWordmark({ size = 56, color = "#fff", bg = SLATE }) {
  // Just a rounded square with S/V0
  return (
    <svg width={size} height={size} viewBox="0 0 56 56" aria-hidden="true">
      <rect width="56" height="56" rx="14" fill={bg}/>
      <text x="28" y="34" textAnchor="middle" fontFamily="Inter, sans-serif" fontWeight="800" fontSize="22" fill={color} letterSpacing="-1">S</text>
    </svg>
  );
}

function MarkStacked({ size = 56, color = "#fff", bg = SLATE }) {
  // Two stacked blocks — "layered" posture
  return (
    <svg width={size} height={size} viewBox="0 0 56 56" aria-hidden="true">
      <rect width="56" height="56" rx="6" fill={bg}/>
      <rect x="12" y="12" width="32" height="14" rx="2" fill={color} opacity="0.45"/>
      <rect x="12" y="30" width="32" height="14" rx="2" fill={color}/>
      <text x="28" y="40.5" textAnchor="middle" fontFamily="Inter, sans-serif" fontWeight="700" fontSize="11" fill={bg}>V0</text>
    </svg>
  );
}

function MarkNotch({ size = 56, color = "#fff", bg = SLATE }) {
  // Notch / chevron — "v" of V0 cut into a square
  return (
    <svg width={size} height={size} viewBox="0 0 56 56" aria-hidden="true">
      <path d="M0 0 H56 V56 H0 Z M28 8 L18 28 H38 Z" fill={bg} fillRule="evenodd"/>
      <path d="M18 28 L28 8 L38 28" fill="none" stroke={color} strokeWidth="2.5"/>
      <text x="28" y="46" textAnchor="middle" fontFamily="Inter, sans-serif" fontWeight="700" fontSize="11" fill={color} letterSpacing="0.5">SV0</text>
    </svg>
  );
}

const MARK_COMPONENTS = {
  bracket: MarkBracket,
  bracketV0Upper: MarkBracketV0Upper,
  bracketV0Lower: MarkBracketV0Lower,
  shield: MarkShield,
  orbit: MarkOrbit,
  wordmark: MarkWordmark,
  stacked: MarkStacked,
  notch: MarkNotch,
};

const MARK_META = {
  bracket: { name: "Bracket monogram [S]", note: "Code-style brackets · engineering posture", tag: "[ S ]" },
  bracketV0Upper: { name: "Bracket [V0] · uppercase", note: "Architectural, tighter — reads as a label", tag: "[ V0 ]" },
  bracketV0Lower: { name: "Bracket [v0] · lowercase mono", note: "Code-literal version cue · monospace", tag: "[ v0 ]" },
  shield: { name: "Layered shield", note: "Defense-in-depth, two offset shields", tag: "shield · V0" },
  orbit: { name: "Orbit", note: "V0 with scanning dot — continuous monitoring", tag: "V0 ●" },
  wordmark: { name: "Wordmark only", note: "Soft square, single letter — calmest option", tag: "S" },
  stacked: { name: "Stacked block", note: "Two layers — posture/evidence stack", tag: "▭ ▭" },
  notch: { name: "Notch / chevron", note: "Negative-space V cut from a block", tag: "△ SV0" },
};

function Wordmark({ color = "#0b0f10", muted = "#717c82", size = 22 }) {
  // SecurityV0 — two-tone wordmark: SecurityV in solid, 0 in muted (or vice versa)
  return (
    <span style={{
      fontFamily: 'Inter, sans-serif',
      fontWeight: 700,
      fontSize: size,
      letterSpacing: '-0.015em',
      color,
      lineHeight: 1,
      display: 'inline-flex',
      alignItems: 'baseline',
      gap: 0,
    }}>
      <span>Security</span>
      <span style={{ color: muted, fontWeight: 600 }}>V0</span>
    </span>
  );
}

function BrandCard({ variant, risk }) {
  const Mark = MARK_COMPONENTS[variant];
  const meta = MARK_META[variant];
  const RiskBadge = window.RiskBadge;
  return (
    <div style={{ display: 'grid', gridTemplateRows: '1fr 1fr', height: '100%' }}>
      {/* Light */}
      <div className="bm-card">
        <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
          <div className="bm-name">{meta.name} · light</div>
          {risk && RiskBadge && <RiskBadge level={risk} />}
        </div>
        <div className="bm-stage">
          <div className="bm-row">
            <Mark size={72} color="#fff" bg={SLATE} />
            <Wordmark color="#0b0f10" muted="#717c82" size={26} />
          </div>
        </div>
        <div className="bm-meta">
          <span>{meta.note}</span>
          <span className="bm-tag">{meta.tag}</span>
        </div>
      </div>
      {/* Dark */}
      <div className="bm-card dark">
        <div className="bm-name" style={{ color: '#9a9d9f' }}>{meta.name} · dark</div>
        <div className="bm-stage">
          <div className="bm-row">
            <Mark size={72} color="#0b0f10" bg="#d9e4ea" />
            <Wordmark color="#f7f9fb" muted="#9a9d9f" size={26} />
          </div>
        </div>
        <div className="bm-meta">
          <div className="swatch-row">
            <div className="swatch" style={{ background: SLATE }} title="primary" />
            <div className="swatch" style={{ background: SLATE_DIM }} title="primary-dim" />
            <div className="swatch" style={{ background: TEAL }} title="secondary" />
            <div className="swatch" style={{ background: RED }} title="critical" />
            <div className="swatch" style={{ background: '#0b0f10' }} title="inverse" />
          </div>
          <span className="bm-tag" style={{ color: '#9a9d9f' }}>{meta.tag}</span>
        </div>
      </div>
    </div>
  );
}

Object.assign(window, { BrandCard, MarkBracket, MarkBracketV0Upper, MarkBracketV0Lower, MarkShield, MarkOrbit, MarkWordmark, MarkStacked, MarkNotch, Wordmark });
