// Shared visual atoms

const Crosshair = ({ size = 10, color = '#8BAFC7', style }) => (
  <svg width={size} height={size} viewBox="0 0 10 10" style={style}>
    <line x1="0" y1="5" x2="10" y2="5" stroke={color} strokeWidth="0.6" />
    <line x1="5" y1="0" x2="5" y2="10" stroke={color} strokeWidth="0.6" />
    <circle cx="5" cy="5" r="1.4" fill="none" stroke={color} strokeWidth="0.6" />
  </svg>
);

const Tick = ({ children, color = '#4E6A82' }) => (
  <span className="mono" style={{ color, fontSize: 10, letterSpacing: 0.08, textTransform: 'uppercase' }}>
    {children}
  </span>
);

// Section eyebrow label, like a chart axis
const Eyebrow = ({ id, title, right }) => (
  <div style={{
    display: 'flex', alignItems: 'baseline', gap: 12,
    padding: '0 0 14px', borderBottom: '1px solid #1B2740', marginBottom: 24,
  }}>
    <span className="mono" style={{ color: '#C9A84C', fontSize: 11, letterSpacing: 0.2, textTransform: 'uppercase' }}>
      {id}
    </span>
    <span style={{ flex: 1 }}>
      <span className="serif" style={{ color: '#E6ECF2', fontSize: 22, fontWeight: 400 }}>{title}</span>
    </span>
    {right && <span className="mono" style={{ color: '#4E6A82', fontSize: 10, letterSpacing: 0.15, textTransform: 'uppercase' }}>{right}</span>}
  </div>
);

// Instrument-panel readout block
const Readout = ({ label, value, sub, accent = '#E6ECF2', size = 32 }) => (
  <div style={{
    border: '1px solid #1B2740', background: 'rgba(19,26,43,0.5)',
    padding: '14px 16px', display: 'flex', flexDirection: 'column', gap: 6, minHeight: 110,
  }}>
    <div className="mono" style={{ color: '#4E6A82', fontSize: 10, letterSpacing: 0.18, textTransform: 'uppercase' }}>
      {label}
    </div>
    <div className="mono" style={{ color: accent, fontSize: size, fontWeight: 700, lineHeight: 1.05, letterSpacing: -0.5 }}>
      {value}
    </div>
    {sub && (
      <div className="mono" style={{ color: '#8BAFC7', fontSize: 10.5, letterSpacing: 0.06, opacity: 0.85 }}>
        {sub}
      </div>
    )}
  </div>
);

// Confidence pill
const Confidence = ({ level = 'high' }) => {
  const map = {
    high: { label: 'HIGH CONFIDENCE', color: '#74ADD1' },
    candidate: { label: 'CANDIDATE FINDING', color: '#FDAE61' },
    speculative: { label: 'SPECULATIVE', color: '#D73027' },
  };
  const c = map[level];
  return (
    <span className="mono" style={{
      display: 'inline-flex', alignItems: 'center', gap: 6,
      border: `1px solid ${c.color}66`, color: c.color, padding: '3px 7px',
      fontSize: 9, letterSpacing: 0.18, textTransform: 'uppercase',
    }}>
      <span style={{ width: 6, height: 6, background: c.color, borderRadius: '50%' }} />
      {c.label}
    </span>
  );
};

// Small horizontal ruler with mono tick labels
const HRule = ({ children, color = '#1B2740' }) => (
  <div style={{ display: 'flex', alignItems: 'center', gap: 8, color: '#4E6A82' }}>
    <span style={{ flex: 1, height: 1, background: color }} />
    {children && <span className="mono" style={{ fontSize: 10, letterSpacing: 0.18, textTransform: 'uppercase' }}>{children}</span>}
    <span style={{ flex: 1, height: 1, background: color }} />
  </div>
);

// Legend for the diverging temperature scale
const TempLegend = ({ width = 280, height = 8, min = -5, max = 5, ticks = [-5, -2.5, 0, 2.5, 5] }) => {
  const stops = [];
  for (let i = 0; i <= 40; i++) {
    const t = i / 40;
    const v = min + (max - min) * t;
    stops.push(`${window.anomalyColor(v)} ${(t * 100).toFixed(1)}%`);
  }
  return (
    <div style={{ display: 'flex', flexDirection: 'column', gap: 4 }}>
      <div style={{ width, height, background: `linear-gradient(to right, ${stops.join(',')})` }} />
      <div style={{ width, display: 'flex', justifyContent: 'space-between' }}>
        {ticks.map(t => (
          <span key={t} className="mono" style={{ color: '#4E6A82', fontSize: 9.5 }}>
            {t > 0 ? `+${t}` : t}°
          </span>
        ))}
      </div>
    </div>
  );
};

// Animated scanning line for "live" panels
const ScanLine = ({ color = 'rgba(139,175,199,0.10)' }) => (
  <div style={{
    position: 'absolute', inset: 0, overflow: 'hidden', pointerEvents: 'none',
  }}>
    <div style={{
      position: 'absolute', left: 0, right: 0, height: 80,
      background: `linear-gradient(to bottom, transparent, ${color}, transparent)`,
      animation: 'scan 8s linear infinite',
    }} />
  </div>
);

Object.assign(window, { Crosshair, Tick, Eyebrow, Readout, Confidence, HRule, TempLegend, ScanLine });
