/* shared.jsx — icons, glass primitives, mock data, brand mark */
/* eslint-disable */

// ─────────────────────────────────────────────────────────────
// Icons (line, 1.6px). Color via currentColor.
// ─────────────────────────────────────────────────────────────
const Icon = {
  music: (s = 16) => (
    <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.7" strokeLinecap="round" strokeLinejoin="round">
      <path d="M9 18V5l12-2v13"/><circle cx="6" cy="18" r="3"/><circle cx="18" cy="16" r="3"/>
    </svg>
  ),
  heart: (s = 16) => (
    <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.7" strokeLinecap="round" strokeLinejoin="round">
      <path d="M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78L12 21.23l8.84-8.84a5.5 5.5 0 0 0 0-7.78z"/>
    </svg>
  ),
  send: (s = 16) => (
    <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.7" strokeLinecap="round" strokeLinejoin="round">
      <path d="M22 2L11 13"/><path d="M22 2l-7 20-4-9-9-4 20-7z"/>
    </svg>
  ),
  search: (s = 16) => (
    <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.7" strokeLinecap="round" strokeLinejoin="round">
      <circle cx="11" cy="11" r="7"/><path d="M21 21l-4.3-4.3"/>
    </svg>
  ),
  check: (s = 16) => (
    <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
      <path d="M20 6L9 17l-5-5"/>
    </svg>
  ),
  x: (s = 16) => (
    <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.7" strokeLinecap="round" strokeLinejoin="round">
      <path d="M18 6L6 18M6 6l12 12"/>
    </svg>
  ),
  play: (s = 16) => (
    <svg width={s} height={s} viewBox="0 0 24 24" fill="currentColor">
      <path d="M6 4l14 8-14 8z"/>
    </svg>
  ),
  pause: (s = 16) => (
    <svg width={s} height={s} viewBox="0 0 24 24" fill="currentColor">
      <rect x="6" y="4" width="4" height="16" rx="0.6"/><rect x="14" y="4" width="4" height="16" rx="0.6"/>
    </svg>
  ),
  skip: (s = 16) => (
    <svg width={s} height={s} viewBox="0 0 24 24" fill="currentColor">
      <path d="M5 4l10 8-10 8z"/><rect x="17" y="4" width="2.4" height="16" rx="0.6"/>
    </svg>
  ),
  user: (s = 16) => (
    <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.7" strokeLinecap="round" strokeLinejoin="round">
      <circle cx="12" cy="8" r="4"/><path d="M4 21c0-4 4-7 8-7s8 3 8 7"/>
    </svg>
  ),
  arrow: (s = 16) => (
    <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.7" strokeLinecap="round" strokeLinejoin="round">
      <path d="M5 12h14M12 5l7 7-7 7"/>
    </svg>
  ),
  qr: (s = 16) => (
    <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round">
      <rect x="3" y="3" width="7" height="7"/><rect x="14" y="3" width="7" height="7"/>
      <rect x="3" y="14" width="7" height="7"/><path d="M14 14h3v3M21 14v3M14 21h7"/>
    </svg>
  ),
  sparkle: (s = 16) => (
    <svg width={s} height={s} viewBox="0 0 24 24" fill="currentColor">
      <path d="M12 2l1.8 6.2L20 10l-6.2 1.8L12 18l-1.8-6.2L4 10l6.2-1.8z"/>
    </svg>
  ),
  drag: (s = 14) => (
    <svg width={s} height={s} viewBox="0 0 24 24" fill="currentColor">
      <circle cx="9" cy="6" r="1.5"/><circle cx="15" cy="6" r="1.5"/>
      <circle cx="9" cy="12" r="1.5"/><circle cx="15" cy="12" r="1.5"/>
      <circle cx="9" cy="18" r="1.5"/><circle cx="15" cy="18" r="1.5"/>
    </svg>
  ),
  ban: (s = 16) => (
    <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.7" strokeLinecap="round" strokeLinejoin="round">
      <circle cx="12" cy="12" r="9"/><path d="M5.6 5.6l12.8 12.8"/>
    </svg>
  ),
  clock: (s = 16) => (
    <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.7" strokeLinecap="round" strokeLinejoin="round">
      <circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/>
    </svg>
  ),
  bolt: (s = 16) => (
    <svg width={s} height={s} viewBox="0 0 24 24" fill="currentColor">
      <path d="M13 2L4 14h7l-1 8 9-12h-7z"/>
    </svg>
  ),
};

// ─────────────────────────────────────────────────────────────
// FSJA wordmark — drawn from the logo (drop/flame + 4-point star)
// ─────────────────────────────────────────────────────────────
function FSJAMark({ size = 32, mono = false }) {
  const navy = mono ? 'currentColor' : '#1B3A66';
  const burg = mono ? 'currentColor' : '#8B2332';
  const gold = mono ? 'currentColor' : '#E5A93A';
  return (
    <svg width={size} height={size} viewBox="0 0 100 100" fill="none" style={{ flexShrink: 0 }}>
      {/* burgundy droplet */}
      <path d="M38 28 C 30 38, 26 50, 32 62 C 36 70, 46 72, 50 64 C 54 56, 50 44, 42 36 Z" fill={burg}/>
      {/* navy swoop under */}
      <path d="M52 32 C 64 38, 72 50, 70 64 C 68 78, 54 86, 40 84 C 30 82, 22 76, 22 76 C 30 80, 42 78, 50 70 C 58 62, 60 48, 52 32 Z" fill={navy}/>
      {/* gold star (4-point) */}
      <path d="M44 8 L46.5 16 L54 18 L46.5 20 L44 28 L41.5 20 L34 18 L41.5 16 Z" fill={gold}/>
      <circle cx="44" cy="18" r="2" fill="#fff"/>
    </svg>
  );
}

// ─────────────────────────────────────────────────────────────
// Album-art placeholder — synthesized cover with gradient + bands
// ─────────────────────────────────────────────────────────────
function Cover({ seed = 0, size = 64, radius = 12 }) {
  // 6 hand-picked gradient pairs, brand-adjacent
  const palettes = [
    ['#8b2332', '#1b3a66'],
    ['#e5a93a', '#8b2332'],
    ['#1b3a66', '#0a1a2e'],
    ['#b88727', '#5a1620'],
    ['#6a8fbf', '#1b3a66'],
    ['#f3d27e', '#b88727'],
  ];
  const [a, b] = palettes[seed % palettes.length];
  const angle = (seed * 53) % 360;
  return (
    <div style={{
      width: size, height: size, borderRadius: radius,
      background: `linear-gradient(${angle}deg, ${a}, ${b})`,
      position: 'relative', overflow: 'hidden', flexShrink: 0,
      boxShadow: 'inset 0 1px 0 rgba(255,255,255,0.25), 0 4px 10px rgba(0,0,0,0.25)',
    }}>
      <div style={{
        position: 'absolute', inset: 0,
        background: `repeating-linear-gradient(${angle + 90}deg, transparent 0 ${size/8}px, rgba(255,255,255,0.08) ${size/8}px ${size/8 + 1}px)`,
      }}/>
      <div style={{
        position: 'absolute', top: '20%', left: '20%',
        width: '60%', height: '60%', borderRadius: '50%',
        background: `radial-gradient(circle at 30% 30%, rgba(255,255,255,0.5), transparent 60%)`,
      }}/>
    </div>
  );
}

// ─────────────────────────────────────────────────────────────
// Real scannable QR code — via qrserver.com API (no library)
// ─────────────────────────────────────────────────────────────
function RealQR({ url, size = 128 }) {
  if (!url) return <div style={{ width: size, height: size, background: 'rgba(0,0,0,0.05)', borderRadius: 4 }}/>;
  const src = `https://api.qrserver.com/v1/create-qr-code/?size=${size}x${size}&data=${encodeURIComponent(url)}&margin=2`;
  return <img src={src} width={size} height={size} style={{ display: 'block' }} alt="QR"/>;
}

// ─────────────────────────────────────────────────────────────
// QR code — simulated (not scannable, decorative, kept as fallback)
// ─────────────────────────────────────────────────────────────
function FakeQR({ size = 200, dark = '#0a1a2e', light = '#fff' }) {
  // Deterministic pseudo-random modules. 25x25 with finder pattern corners.
  const N = 25;
  const cells = React.useMemo(() => {
    const seed = (i, j) => ((i * 928371 + j * 12349 + i * j * 17) ^ 0x5a5a) & 1;
    const isFinder = (i, j) => {
      const inBox = (r, c) => i >= r && i < r + 7 && j >= c && j < c + 7;
      return inBox(0, 0) || inBox(0, N - 7) || inBox(N - 7, 0);
    };
    const finderOn = (i, j) => {
      const local = (r, c) => {
        const li = i - r, lj = j - c;
        if (li < 0 || lj < 0 || li > 6 || lj > 6) return false;
        if (li === 0 || li === 6 || lj === 0 || lj === 6) return true;
        if (li >= 2 && li <= 4 && lj >= 2 && lj <= 4) return true;
        return false;
      };
      return local(0, 0) || local(0, N - 7) || local(N - 7, 0);
    };
    const grid = [];
    for (let i = 0; i < N; i++) {
      const row = [];
      for (let j = 0; j < N; j++) {
        if (isFinder(i, j)) row.push(finderOn(i, j) ? 1 : 0);
        else row.push(seed(i, j));
      }
      grid.push(row);
    }
    return grid;
  }, []);
  const u = size / N;
  return (
    <svg width={size} height={size} viewBox={`0 0 ${size} ${size}`} style={{ display: 'block' }}>
      <rect width={size} height={size} fill={light}/>
      {cells.map((row, i) =>
        row.map((v, j) =>
          v ? <rect key={`${i}-${j}`} x={j * u} y={i * u} width={u} height={u} fill={dark}/> : null
        )
      )}
    </svg>
  );
}

// ─────────────────────────────────────────────────────────────
// Mock catalogue of song requests
// ─────────────────────────────────────────────────────────────
const REQUESTS = [
  { id: 1, title: 'La Bicicleta',           artist: 'Carlos Vives & Shakira', from: 'Marta',     to: 'Pablo',           note: 'Por nuestro primer baile en el patio.', votes: 14, cover: 0, status: 'playing' },
  { id: 2, title: 'Vivir Mi Vida',          artist: 'Marc Anthony',           from: 'Lucía',     to: 'Promoción 2026',  note: '¡Que nadie se quede sentado!',           votes: 21, cover: 1, status: 'next' },
  { id: 3, title: 'Color Esperanza',        artist: 'Diego Torres',           from: 'Padre Luis',to: 'Toda la comunidad',note: 'Para cerrar el curso con esperanza.',    votes: 33, cover: 2, status: 'queued' },
  { id: 4, title: 'Resistiré',              artist: 'Dúo Dinámico',           from: 'Abuela Carmen', to: 'Las voluntarias', note: 'Por todas las que no se rinden.',  votes: 12, cover: 3, status: 'queued' },
  { id: 5, title: 'Wake Me Up',             artist: 'Avicii',                 from: 'Jorge',     to: 'Hermanos pequeños',note: 'Por las noches de campamento.',          votes: 9,  cover: 4, status: 'pending' },
  { id: 6, title: 'La Flaca',               artist: 'Jarabe de Palo',         from: 'Ana',       to: 'Mi madre',         note: 'Gracias por aguantarme siempre.',        votes: 7,  cover: 5, status: 'pending' },
  { id: 7, title: 'Ojalá',                  artist: 'Silvio Rodríguez',       from: 'Anónimo',   to: 'M.',               note: '— ya sabes para quién es.',              votes: 4,  cover: 0, status: 'pending' },
  { id: 8, title: 'Eres Tú',                artist: 'Mocedades',              from: 'Coro FSJA', to: 'Los profesores',   note: 'Gracias por este curso.',                votes: 18, cover: 1, status: 'queued' },
  { id: 9, title: 'Mediterráneo',           artist: 'Joan Manuel Serrat',     from: 'Don Rafael',to: 'Los compañeros del 78', note: 'Salud y reencuentro.',           votes: 11, cover: 2, status: 'queued' },
  { id: 10,title: 'Bailando',               artist: 'Enrique Iglesias',       from: 'Sofía',     to: 'Mis amigas',       note: 'La nuestra de siempre.',                 votes: 16, cover: 3, status: 'pending' },
];

Object.assign(window, { Icon, FSJAMark, Cover, FakeQR, RealQR, REQUESTS });
