/* Nuya — Mockup components for design review
   Renders both Current (as-is in the app) and Proposed (redesigned) variants
   of the main screens inside a lightweight phone frame.
*/

const { useState } = React;

// ─── Shared iconography (inline SVGs) ─────────────────────────────
const Ico = {
  home: (c='currentColor') => <svg width="18" height="18" viewBox="0 0 24 24" fill="none"><path d="M3 11l9-8 9 8v10a2 2 0 01-2 2h-4v-7h-6v7H5a2 2 0 01-2-2V11z" stroke={c} strokeWidth="1.8" strokeLinejoin="round"/></svg>,
  chart: (c='currentColor') => <svg width="18" height="18" viewBox="0 0 24 24" fill="none"><path d="M4 20V10M10 20V4M16 20v-8M22 20H2" stroke={c} strokeWidth="1.8" strokeLinecap="round"/></svg>,
  spark: (c='currentColor') => <svg width="18" height="18" viewBox="0 0 24 24" fill="none"><path d="M12 3l2 5 5 2-5 2-2 5-2-5-5-2 5-2 2-5zM20 14l1 2 2 1-2 1-1 2-1-2-2-1 2-1 1-2z" fill={c}/></svg>,
  cal: (c='currentColor') => <svg width="18" height="18" viewBox="0 0 24 24" fill="none"><rect x="3" y="5" width="18" height="16" rx="2" stroke={c} strokeWidth="1.8"/><path d="M3 10h18M8 3v4M16 3v4" stroke={c} strokeWidth="1.8" strokeLinecap="round"/></svg>,
  plus: (c='currentColor') => <svg width="18" height="18" viewBox="0 0 24 24" fill="none"><path d="M12 5v14M5 12h14" stroke={c} strokeWidth="2" strokeLinecap="round"/></svg>,
  heart: (c='currentColor') => <svg width="16" height="16" viewBox="0 0 24 24" fill={c} opacity="0.9"><path d="M12 21s-8-4.5-8-11a5 5 0 019-3 5 5 0 019 3c0 6.5-8 11-8 11h-2z"/></svg>,
  flask: (c='currentColor') => <svg width="16" height="16" viewBox="0 0 24 24" fill="none"><path d="M9 2v6L4 18a2 2 0 002 3h12a2 2 0 002-3l-5-10V2M9 2h6M8 14h8" stroke={c} strokeWidth="1.7"/></svg>,
  alert: (c='currentColor') => <svg width="16" height="16" viewBox="0 0 24 24" fill="none"><path d="M12 8v5M12 17v0" stroke={c} strokeWidth="2" strokeLinecap="round"/><circle cx="12" cy="12" r="9" stroke={c} strokeWidth="1.7"/></svg>,
  folder: (c='currentColor') => <svg width="16" height="16" viewBox="0 0 24 24" fill="none"><path d="M3 7a2 2 0 012-2h4l2 2h8a2 2 0 012 2v9a2 2 0 01-2 2H5a2 2 0 01-2-2V7z" stroke={c} strokeWidth="1.7"/></svg>,
  chevR: (c='currentColor') => <svg width="12" height="12" viewBox="0 0 24 24" fill="none"><path d="M9 5l7 7-7 7" stroke={c} strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/></svg>,
  bell: (c='currentColor') => <svg width="16" height="16" viewBox="0 0 24 24" fill="none"><path d="M6 9a6 6 0 0112 0c0 5 2 7 2 7H4s2-2 2-7zM10 20a2 2 0 004 0" stroke={c} strokeWidth="1.7"/></svg>,
  send: (c='currentColor') => <svg width="16" height="16" viewBox="0 0 24 24" fill="none"><path d="M3 12l18-9-6 18-3-9-9-0z" fill={c}/></svg>,
  search: (c='currentColor') => <svg width="16" height="16" viewBox="0 0 24 24" fill="none"><circle cx="11" cy="11" r="7" stroke={c} strokeWidth="1.8"/><path d="M20 20l-3.5-3.5" stroke={c} strokeWidth="1.8" strokeLinecap="round"/></svg>,
  pill: (c='currentColor') => <svg width="16" height="16" viewBox="0 0 24 24" fill="none"><rect x="3" y="8" width="18" height="8" rx="4" stroke={c} strokeWidth="1.7"/><path d="M12 8v8" stroke={c} strokeWidth="1.7"/></svg>,
};

// ─── Phone shell ──────────────────────────────────────────────────
function Phone({ children, bg = 'white' }) {
  return (
    <div className="phone">
      <div className="notch" />
      <div className="screen" style={{ background: bg }}>
        <div style={{ height: 40 }} />
        {children}
      </div>
    </div>
  );
}

// ─── Tab bar (Current & Proposed) ────────────────────────────────
function TabBarCurrent({ active = 0 }) {
  const items = [Ico.home, Ico.chart, null, Ico.spark, Ico.cal];
  return (
    <div style={{
      position: 'absolute', left: 0, right: 0, bottom: 10,
      height: 64, display: 'flex', alignItems: 'center',
      justifyContent: 'space-around', padding: '0 14px',
      background: 'white', borderTop: '1px solid #f0ecdf',
    }}>
      {items.map((it, i) => {
        if (i === 2) return (
          <div key={i} style={{
            width: 48, height: 48, borderRadius: 24,
            background: '#402e94', display: 'flex', alignItems: 'center',
            justifyContent: 'center', marginTop: -28,
            boxShadow: '0 8px 20px rgba(64,46,148,0.35)',
          }}>{Ico.plus('white')}</div>
        );
        const on = i === active;
        return (
          <div key={i} style={{
            width: 40, height: 40, borderRadius: 20,
            background: on ? '#e8e3fb' : 'transparent',
            display: 'flex', alignItems: 'center', justifyContent: 'center',
            color: on ? '#402e94' : 'rgba(64,46,148,0.4)',
          }}>{it('currentColor')}</div>
        );
      })}
    </div>
  );
}

function TabBarProposed({ active = 0 }) {
  const items = [
    { i: Ico.home, l: 'Hoje' },
    { i: Ico.chart, l: 'Saúde' },
    null,
    { i: Ico.spark, l: 'Nuya' },
    { i: Ico.cal, l: 'Agenda' },
  ];
  return (
    <div style={{
      position: 'absolute', left: 14, right: 14, bottom: 18,
      height: 62, display: 'flex', alignItems: 'center',
      justifyContent: 'space-around', padding: '0 8px',
      background: 'rgba(255,255,255,0.85)',
      backdropFilter: 'blur(20px) saturate(160%)',
      WebkitBackdropFilter: 'blur(20px) saturate(160%)',
      borderRadius: 28,
      boxShadow: '0 18px 40px -10px rgba(26,16,51,0.22), 0 0 0 1px rgba(26,16,51,0.05)',
    }}>
      {items.map((it, i) => {
        if (i === 2) return (
          <div key={i} style={{
            width: 48, height: 48, borderRadius: 16,
            background: '#1a1033', display: 'flex', alignItems: 'center',
            justifyContent: 'center',
            boxShadow: '0 6px 14px rgba(26,16,51,0.3)',
          }}>{Ico.plus('#ffe4dc')}</div>
        );
        const on = i === active;
        return (
          <div key={i} style={{
            display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 2,
            color: on ? '#1a1033' : 'rgba(26,16,51,0.35)',
            fontSize: 9, fontWeight: 600, letterSpacing: '0.04em', textTransform: 'uppercase',
            fontFamily: 'JetBrains Mono, ui-monospace, monospace',
          }}>
            <div style={{ opacity: on ? 1 : 0.85 }}>{it.i('currentColor')}</div>
            <div>{it.l}</div>
          </div>
        );
      })}
    </div>
  );
}

// ═════════════════════════════════════════════════════════════════
// HOME — current
// ═════════════════════════════════════════════════════════════════
function HomeCurrent() {
  const Bubble = ({ bg, d, x, y }) => (
    <div style={{
      position: 'absolute', left: x, top: y,
      width: 30, height: 30, borderRadius: 15,
      background: bg, border: '2px solid white',
      display: 'flex', alignItems: 'center', justifyContent: 'center',
      color: '#402e94', boxShadow: '0 2px 4px rgba(0,0,0,0.05)',
      fontSize: 11,
    }}>•</div>
  );
  const Action = ({ bg, label, dark }) => (
    <div style={{
      width: '30%', aspectRatio: 1, borderRadius: 20,
      background: bg, padding: 10,
      display: 'flex', flexDirection: 'column', justifyContent: 'space-between',
      boxShadow: '0 1px 2px rgba(0,0,0,0.04)',
    }}>
      <div style={{
        width: 30, height: 30, borderRadius: 15,
        background: 'rgba(255,255,255,0.6)', border: '1px solid rgba(255,255,255,0.8)',
      }} />
      <div style={{ fontSize: 10, fontWeight: 600, color: dark ? 'white' : '#402e94', lineHeight: 1.15 }}>{label}</div>
    </div>
  );
  return (
    <div style={{ position: 'relative', height: '100%', padding: '0 18px' }}>
      {/* soft gradient header bg */}
      <div style={{
        position: 'absolute', top: -20, left: 0, right: 0, height: 180,
        background: '#e8e3fb', opacity: 0.22, borderRadius: 30,
      }} />
      {/* header */}
      <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginTop: 16 }}>
        <div style={{
          display: 'flex', alignItems: 'center', gap: 5,
          background: '#e8e3fb', borderRadius: 16, padding: '3px 10px 3px 3px',
          border: '1px solid #fbe2e2',
        }}>
          <div style={{ width: 18, height: 18, borderRadius: 9, background: '#402e94', color: 'white', fontSize: 10, fontWeight: 700, display: 'flex', alignItems: 'center', justifyContent: 'center' }}>S</div>
          <div style={{ fontSize: 11, fontWeight: 600, color: '#402e94' }}>Nuya</div>
        </div>
        <div style={{ width: 30, height: 30, borderRadius: 15, background: '#e8e3fb', border: '2px solid white', display: 'flex', alignItems: 'center', justifyContent: 'center', fontSize: 9, fontWeight: 700, color: '#402e94' }}>CA</div>
      </div>
      {/* greeting */}
      <div style={{ marginTop: 16 }}>
        <div style={{ fontSize: 22, fontWeight: 700, color: '#402e94', letterSpacing: '-0.02em' }}>Olá Cami</div>
        <div style={{ fontSize: 11, color: 'rgba(64,46,148,0.6)', marginTop: 2 }}>Como está sua saúde hoje?</div>
      </div>
      {/* 6 action grid */}
      <div style={{ display: 'flex', flexWrap: 'wrap', gap: 6, marginTop: 14 }}>
        <Action bg="#e8e3fb" label={"Importar\nexame"} />
        <Action bg="#402e94" label={"Chat\ncom IA"} dark />
        <Action bg="#fbf1d2" label="Resultados" />
        <Action bg="#dcefe0" label="Alertas" />
        <Action bg="#dde9f8" label="Biblioteca" />
        <Action bg="#fbe2e2" label="Calendário" />
      </div>
      {/* Health ring */}
      <div style={{
        position: 'relative', margin: '18px auto 0', width: 210, height: 210,
      }}>
        {/* ring */}
        <div style={{
          position: 'absolute', inset: 10, borderRadius: '50%',
          border: '12px solid #e8e3fb', opacity: 0.6,
        }} />
        {/* bubbles around */}
        {[
          {bg:'#fbf1d2', x:95, y:-2},  {bg:'#f5e6c4', x:150, y:12},
          {bg:'#dde9f8', x:188, y:58}, {bg:'#fbf1d2', x:188, y:128},
          {bg:'#dcefe0', x:150, y:174},{bg:'#fbe2e2', x:95, y:190},
          {bg:'#c8dce0', x:32, y:174}, {bg:'#dde9f8', x:-2, y:128},
        ].map((b,i)=><Bubble key={i} {...b}/>)}
        {/* center score */}
        <div style={{ position: 'absolute', inset: 0, display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center' }}>
          <div style={{ fontSize: 46, fontWeight: 700, color: '#402e94', letterSpacing: '-0.03em' }}>8.2</div>
          <div style={{ fontSize: 9, color: 'rgba(64,46,148,0.6)' }}>seu health score</div>
        </div>
      </div>
      <TabBarCurrent active={0}/>
    </div>
  );
}

// ═════════════════════════════════════════════════════════════════
// HOME — proposed
// ═════════════════════════════════════════════════════════════════
function HomeProposed() {
  return (
    <div style={{ position: 'relative', height: '100%', padding: '0 20px', color: '#1a1033', background: '#fbf9f4' }}>
      {/* header */}
      <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginTop: 14 }}>
        <div>
          <div style={{ fontFamily: 'JetBrains Mono, monospace', fontSize: 9, letterSpacing: '0.14em', textTransform: 'uppercase', color: 'rgba(26,16,51,0.4)' }}>
            Terça · 21 Abr
          </div>
          <div style={{ fontFamily: 'Fraunces, Georgia, serif', fontSize: 26, fontWeight: 400, letterSpacing: '-0.02em', marginTop: 2 }}>
            Bom dia, <span style={{ fontStyle: 'italic', color: '#402e94' }}>Cami</span>
          </div>
        </div>
        <div style={{
          width: 38, height: 38, borderRadius: 19,
          background: 'white', border: '1px solid rgba(26,16,51,0.1)',
          display: 'flex', alignItems: 'center', justifyContent: 'center',
          fontSize: 11, fontWeight: 600, color: '#1a1033',
        }}>CA</div>
      </div>

      {/* Hero: Health score — big, one thing */}
      <div style={{
        marginTop: 16, borderRadius: 24, padding: '18px 20px 18px',
        background: 'linear-gradient(155deg, #1a1033 0%, #2d1d5c 70%, #402e94 100%)',
        color: 'white', position: 'relative', overflow: 'hidden',
      }}>
        <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
          <div style={{ fontFamily: 'JetBrains Mono, monospace', fontSize: 9, letterSpacing: '0.14em', textTransform: 'uppercase', opacity: 0.5 }}>
            Health score
          </div>
          <div style={{ fontSize: 9, opacity: 0.7, display: 'flex', alignItems: 'center', gap: 4 }}>
            <span style={{ width: 5, height: 5, borderRadius: 3, background: '#7dd3a8' }} /> Estável
          </div>
        </div>
        <div style={{ display: 'flex', alignItems: 'baseline', gap: 10, marginTop: 4 }}>
          <div style={{ fontFamily: 'Fraunces, Georgia, serif', fontSize: 64, fontWeight: 300, letterSpacing: '-0.04em', lineHeight: 1 }}>8.2</div>
          <div style={{ fontSize: 12, opacity: 0.6 }}>/ 10</div>
          <div style={{ marginLeft: 'auto', fontSize: 11, opacity: 0.75 }}>+0.3 vs mês</div>
        </div>
        {/* system strip */}
        <div style={{ display: 'flex', gap: 4, marginTop: 14, height: 6 }}>
          {[0.9,0.82,0.75,0.88,0.65,0.9,0.78,0.85].map((v,i)=>(
            <div key={i} style={{ flex: 1, background: `rgba(255,228,220,${v*0.95})`, borderRadius: 3 }} />
          ))}
        </div>
        <div style={{ display: 'flex', justifyContent: 'space-between', fontSize: 8, marginTop: 6, opacity: 0.55, fontFamily: 'JetBrains Mono, monospace' }}>
          <span>IMUN</span><span>CARD</span><span>MUSC</span><span>DNA</span>
          <span>PULM</span><span>NERV</span><span>DIG</span><span>HORM</span>
        </div>
      </div>

      {/* Quick primary actions — 2 only, prioritized */}
      <div style={{ display: 'flex', gap: 8, marginTop: 12 }}>
        <div style={{
          flex: 2, borderRadius: 16, padding: '12px 14px',
          background: 'white', border: '1px solid rgba(26,16,51,0.08)',
          display: 'flex', alignItems: 'center', gap: 10,
        }}>
          <div style={{ width: 32, height: 32, borderRadius: 10, background: '#ff7a5c', display:'flex', alignItems:'center', justifyContent:'center', color: 'white' }}>
            {Ico.plus('white')}
          </div>
          <div>
            <div style={{ fontSize: 12, fontWeight: 600 }}>Importar exame</div>
            <div style={{ fontSize: 10, color: 'rgba(26,16,51,0.55)' }}>Foto, PDF ou galeria</div>
          </div>
        </div>
        <div style={{
          flex: 1, borderRadius: 16, padding: '12px',
          background: '#1a1033', color: 'white',
          display: 'flex', flexDirection: 'column', justifyContent: 'space-between',
        }}>
          <div>{Ico.spark('#ffe4dc')}</div>
          <div style={{ fontSize: 11, fontWeight: 600 }}>Pergunte<br/>à Nuya</div>
        </div>
      </div>

      {/* Today — what matters now */}
      <div style={{ marginTop: 18 }}>
        <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'baseline', marginBottom: 8 }}>
          <div style={{ fontFamily: 'JetBrains Mono, monospace', fontSize: 10, letterSpacing: '0.14em', textTransform: 'uppercase', color: 'rgba(26,16,51,0.5)' }}>Hoje</div>
          <div style={{ fontSize: 10, color: 'rgba(26,16,51,0.45)' }}>3 itens</div>
        </div>
        <div style={{ display: 'flex', flexDirection: 'column', gap: 6 }}>
          {[
            { t: '08:00', title: 'Losartana 50mg', sub: 'após café', icon: Ico.pill, accent: '#ff7a5c', done: true },
            { t: '14:30', title: 'Dra. Helena · Endócrino', sub: 'Hospital Sírio', icon: Ico.heart, accent: '#402e94' },
            { t: '21:00', title: 'Vitamina D', sub: '1 cápsula', icon: Ico.pill, accent: '#d4a520' },
          ].map((r, i) => (
            <div key={i} style={{
              display: 'flex', alignItems: 'center', gap: 10,
              background: 'white', borderRadius: 14, padding: '10px 12px',
              border: '1px solid rgba(26,16,51,0.06)',
              opacity: r.done ? 0.55 : 1,
            }}>
              <div style={{ fontFamily: 'JetBrains Mono, monospace', fontSize: 11, color: r.done ? 'rgba(26,16,51,0.4)' : '#1a1033', fontWeight: 600, textDecoration: r.done ? 'line-through' : 'none' }}>{r.t}</div>
              <div style={{ width: 1, height: 22, background: 'rgba(26,16,51,0.08)' }} />
              <div style={{ flex: 1 }}>
                <div style={{ fontSize: 12, fontWeight: 600, letterSpacing: '-0.01em' }}>{r.title}</div>
                <div style={{ fontSize: 10, color: 'rgba(26,16,51,0.5)' }}>{r.sub}</div>
              </div>
              <div style={{ width: 4, height: 22, background: r.accent, borderRadius: 2 }} />
            </div>
          ))}
        </div>
      </div>
      <TabBarProposed active={0}/>
    </div>
  );
}

Object.assign(window, { Phone, HomeCurrent, HomeProposed, Ico, TabBarCurrent, TabBarProposed });
