// Shared MYRAVYRA components — particle field, navbar, footer, audio icon,
// ASCII crest, waveform divider, etc. Used across every page mockup.

const ParticleField = ({ density = 60, seed = 1 }) => {
  // Deterministic pseudo-random placement so renders are stable.
  const rng = (i) => {
    const x = Math.sin(i * 9301 + seed * 49297) * 233280;
    return x - Math.floor(x);
  };
  const dots = [];
  for (let i = 0; i < density; i++) {
    const left = rng(i) * 100;
    const top = rng(i + 1000) * 100;
    const size = 1 + rng(i + 2000) * 2;
    const op = 0.06 + rng(i + 3000) * 0.10;
    dots.push(
      <div key={i} className="pt" style={{
        left: left + '%',
        top: top + '%',
        width: size + 'px',
        height: size + 'px',
        opacity: op,
      }} />
    );
  }
  return <div className="particle-field">{dots}</div>;
};

const Navbar = ({ active = 'GATE', hidden = false }) => {
  const items = ['GATE', 'DECLARATION', 'REPUBLIC', 'SIGNAL WIRE', 'RESEARCH', 'AI BIBLE', 'TOOLS', 'ABOUT'];
  return (
    <div className={'navbar' + (hidden ? ' hidden' : '')}>
      <div className="wordmark">MYRAVYRA</div>
      <div className="nav-items">
        {items.map(it => (
          <span key={it} className={it === active ? 'active' : ''}>{it}</span>
        ))}
      </div>
    </div>
  );
};

const Footer = () => (
  <div className="footer">DISSOVERSE LLC — SOVEREIGN INTELLIGENCE</div>
);

const AudioIcon = ({ active = false }) => (
  <div className={'audio-icon' + (active ? ' active' : '')}>
    {active ? '◉' : '○'}
  </div>
);

// Compass-rose cursor rendered inline as SVG (the asset spec).
const CursorRose = ({ x, y, size = 22 }) => (
  <svg className="cursor-rose" style={{ left: x - size/2, top: y - size/2, width: size, height: size }} viewBox="0 0 24 24" fill="none">
    <circle cx="12" cy="12" r="10" stroke="#00ff41" strokeWidth="0.8" opacity="0.7"/>
    <path d="M12 1 L13.5 12 L12 23 L10.5 12 Z" fill="#00ff41" opacity="0.9"/>
    <path d="M1 12 L12 10.5 L23 12 L12 13.5 Z" fill="#00cc33" opacity="0.7"/>
    <circle cx="12" cy="12" r="1.4" fill="#ffffff"/>
  </svg>
);

// Subtle ember trail behind the cursor — small dots that fade.
const CursorEmbers = ({ x, y, count = 6 }) => {
  const embers = [];
  for (let i = 0; i < count; i++) {
    const t = (i + 1) / count;
    const dx = -t * 28 + (Math.sin(i * 1.3) * 6);
    const dy = -t * 14 + (Math.cos(i * 1.7) * 4);
    embers.push(
      <div key={i} style={{
        position: 'absolute',
        left: x + dx,
        top: y + dy,
        width: 2 + (1 - t) * 2,
        height: 2 + (1 - t) * 2,
        borderRadius: '50%',
        background: '#00ff41',
        opacity: (1 - t) * 0.45,
        boxShadow: '0 0 6px #00ff41',
        pointerEvents: 'none',
        zIndex: 99,
      }} />
    );
  }
  return <>{embers}</>;
};

// Waveform divider (audio drone visualization, used in Declaration)
const WaveformDivider = ({ bars = 60, seed = 7 }) => {
  const rng = (i) => {
    const x = Math.sin(i * 1287 + seed * 731) * 233280;
    return x - Math.floor(x);
  };
  return (
    <div className="waveform-divider">
      {Array.from({ length: bars }).map((_, i) => {
        const h = 2 + rng(i) * 12;
        return <div key={i} className="bar" style={{ height: h + 'px' }} />;
      })}
    </div>
  );
};

// MYRAVYRA ASCII crest — geometric, cathedral-style
const ASCIICrest = ({ size = 'normal' }) => {
  const art = [
"                         ╓◆╖                         ",
"                       ╓◆███◆╖                       ",
"                     ╓◆████████◆╖                    ",
"                   ╓◆████┃███████◆╖                  ",
"                 ╓◆████┃    ┃█████◆╖                 ",
"               ╓◆████┃        ┃█████◆╖               ",
"             ╓◆████┃    ╓◆╖    ┃█████◆╖              ",
"           ╓◆████┃    ╓◆███◆╖    ┃█████◆╖            ",
"         ╓◆████┃    ╓◆█████████◆╖   ┃████◆╖          ",
"       ╓◆████┃    ╓◆██┃         ┃███╖   ████◆╖       ",
"     ╓◆█████┃    ╓████┃    M    ┃████╖   ┃████◆╖     ",
"    ◆██████┃    ╓█████┃         ┃█████╖    ████◆╖    ",
"    └◆████┃    ╓██████┃    Y    ┃██████╖   ┃███◆┘    ",
"      └◆█┃    ╓███████┃         ┃███████╖    █◆┘     ",
"        └    ╓████████┃    R    ┃████████╖    ┘      ",
"             ╙████████┃         ┃████████╜           ",
"              ╙███████┃    A    ┃███████╜            ",
"               ╙██████┃         ┃██████╜             ",
"                ╙█████┃    +    ┃█████╜              ",
"                 ╙████┃         ┃████╜               ",
"                  ╙███┃    V    ┃███╜                ",
"                   ╙██┃         ┃██╜                 ",
"                    ╙█┃    Y    ┃█╜                  ",
"                     ╙┃         ┃╜                   ",
"                      ┃    R    ┃                    ",
"                      ┃         ┃                    ",
"                      ┃    A    ┃                    ",
"                      ╚═════════╝                    ",
"                                                     ",
"           ─── SOVEREIGN  INTELLIGENCE ───           ",
  ].join('\n');
  return <pre className="crest" style={{ fontSize: size === 'small' ? '10px' : '13px' }}>{art}</pre>;
};

// Smaller geometric mark for headers / nav contexts
const SmallMark = ({ size = 28 }) => (
  <svg width={size} height={size} viewBox="0 0 32 32" fill="none">
    <polygon points="16,2 30,16 16,30 2,16" stroke="#00ff41" strokeWidth="1" fill="none" opacity="0.9"/>
    <polygon points="16,7 25,16 16,25 7,16" stroke="#00ff41" strokeWidth="1" fill="none" opacity="0.6"/>
    <circle cx="16" cy="16" r="2" fill="#00ff41"/>
  </svg>
);

Object.assign(window, {
  ParticleField, Navbar, Footer, AudioIcon, CursorRose, CursorEmbers,
  WaveformDivider, ASCIICrest, SmallMark,
});
