// @ds-adherence-ignore -- device-frame mockups (raw px/hex for phone bezels & scaled-down screens, by design — mirrors the DS's own ios-frame.jsx). Brand colours flow through the C/FONT atoms.
// vote-screens.jsx — visual option mockups for the 5to9 voting page.
// Each fork shows two little phone screens (the real product UI for each option),
// built from the design-system app atoms on window (C, FONT, GROUP, Icon, Eyebrow).
// Exports to window: MiniPhone, Scene.
(function () {
  const { C, FONT, GROUP, Icon, Eyebrow } = window;
  const e = React.createElement;

  // category → group hue (ADR-016: colour encodes activity category)
  const CAT = {
    'Food & drink': 'ochre', 'Outdoors': 'teal', 'Culture': 'plum',
    'Nightlife': 'dusk', 'Wellness': 'sage', 'Social': 'clay',
  };

  // ── frame ──────────────────────────────────────────────────────────────
  function MiniPhone({ children }) {
    return (
      <div style={{ width: 250, background: '#15130F', borderRadius: 40, padding: 7,
        boxShadow: '0 18px 40px rgba(27,25,22,0.20), 0 2px 8px rgba(27,25,22,0.12)' }}>
        <div style={{ width: '100%', height: 432, background: C.paper, borderRadius: 33, overflow: 'hidden',
          position: 'relative', display: 'flex', flexDirection: 'column' }}>
          {/* status bar */}
          <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between',
            padding: '11px 18px 6px', flex: 'none' }}>
            <span style={{ fontFamily: FONT.mono, fontSize: 11, fontWeight: 600, color: C.ink }}>17:42</span>
            <div style={{ position: 'absolute', top: 9, left: '50%', transform: 'translateX(-50%)',
              width: 64, height: 17, borderRadius: 12, background: '#15130F' }} />
            <svg width="22" height="11" viewBox="0 0 22 11"><rect x="0.5" y="0.5" width="17" height="10" rx="2.5" stroke={C.ink} strokeOpacity="0.5" fill="none"/><rect x="2" y="2" width="13" height="7" rx="1.4" fill={C.ink}/><rect x="19" y="3.5" width="1.6" height="4" rx="0.8" fill={C.ink} fillOpacity="0.5"/></svg>
          </div>
          {/* content */}
          <div style={{ flex: 1, overflow: 'hidden', display: 'flex', flexDirection: 'column' }}>{children}</div>
          {/* home indicator */}
          <div style={{ flex: 'none', display: 'flex', justifyContent: 'center', padding: '6px 0 9px' }}>
            <div style={{ width: 96, height: 4, borderRadius: 3, background: 'rgba(27,25,22,0.22)' }} />
          </div>
        </div>
      </div>
    );
  }

  // ── shared bits ──────────────────────────────────────────────────────────
  const Pad = ({ children, style }) => <div style={{ padding: '4px 16px 8px', display: 'flex', flexDirection: 'column', gap: 11, ...style }}>{children}</div>;
  const Title = ({ children, size = 22, style }) => <div style={{ fontFamily: FONT.serif, fontSize: size, lineHeight: 1.08, letterSpacing: '-0.01em', color: C.ink, ...style }}>{children}</div>;
  const Body = ({ children, c = C.ink2, size = 12.5, style }) => <div style={{ fontFamily: FONT.sans, fontSize: size, lineHeight: 1.4, color: c, ...style }}>{children}</div>;
  const Mono = ({ children, c = C.ink3 }) => <span style={{ fontFamily: FONT.mono, fontSize: 11, color: c }}>{children}</span>;

  function Tile({ children, style }) {
    return <div style={{ background: C.surface, border: `1px solid ${C.line}`, borderRadius: 16, padding: 13,
      boxShadow: '0 1px 2px rgba(27,25,22,0.04)', ...style }}>{children}</div>;
  }
  function Chip({ label, hue, dot }) {
    const g = GROUP[hue];
    return (
      <span style={{ display: 'inline-flex', alignItems: 'center', gap: 5, background: g.soft, color: g.c,
        fontFamily: FONT.sans, fontSize: 11, fontWeight: 600, padding: '3px 9px', borderRadius: 999 }}>
        {dot && <span style={{ width: 7, height: 7, borderRadius: '50%', background: g.c }} />}{label}
      </span>
    );
  }
  function Av({ hue, ch }) {
    const g = GROUP[hue];
    return <span style={{ width: 22, height: 22, borderRadius: '50%', background: g.soft, color: g.c,
      fontFamily: FONT.sans, fontSize: 11, fontWeight: 700, display: 'inline-flex', alignItems: 'center',
      justifyContent: 'center', border: `1px solid ${C.surface}` }}>{ch}</span>;
  }

  // ── SCENES ────────────────────────────────────────────────────────────────
  const SCENES = {
    // COLOUR — same plans, coloured by GROUP
    'colour-group': () => (
      <Pad>
        <div><Eyebrow>Tonight</Eyebrow><Title size={20} style={{ marginTop: 3 }}>Pick your night</Title></div>
        {[['Padel + drinks', 'clay', 'Uni friends', '18:30'],
          ['Supper club', 'plum', 'Sanne\u2019s crew', '19:30'],
          ['Canal run', 'sage', 'Run club', '19:00']].map(([t, h, g, tm], i) => (
          <Tile key={i}>
            <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 7 }}>
              <Chip label={g} hue={h} dot /><Mono>{tm}</Mono>
            </div>
            <div style={{ fontFamily: FONT.sans, fontSize: 14.5, fontWeight: 600, color: C.ink }}>{t}</div>
          </Tile>
        ))}
        <Body c={C.ink3} size={11.5} style={{ textAlign: 'center', marginTop: 2 }}>Colour = who you&rsquo;re with</Body>
      </Pad>
    ),
    // COLOUR — same plans, coloured by CATEGORY
    'colour-category': () => (
      <Pad>
        <div><Eyebrow>Tonight</Eyebrow><Title size={20} style={{ marginTop: 3 }}>Pick your night</Title></div>
        {[['Natural-wine tasting', 'Food & drink', '18:30', ['clay', 'sage']],
          ['Bouldering at Klimmuur', 'Outdoors', '19:00', ['plum']],
          ['Jazz at Bimhuis', 'Culture', '20:30', ['dusk', 'ochre']]].map(([t, cat, tm, avs], i) => (
          <Tile key={i}>
            <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 7 }}>
              <Chip label={cat} hue={CAT[cat]} /><Mono>{tm}</Mono>
            </div>
            <div style={{ fontFamily: FONT.sans, fontSize: 14.5, fontWeight: 600, color: C.ink, marginBottom: 8 }}>{t}</div>
            <div style={{ display: 'flex' }}>{avs.map((a, j) => <span key={j} style={{ marginLeft: j ? -7 : 0 }}><Av hue={a} ch="" /></span>)}</div>
          </Tile>
        ))}
        <Body c={C.ink3} size={11.5} style={{ textAlign: 'center', marginTop: 2 }}>Colour = the kind of night</Body>
      </Pad>
    ),

    // CHAT — in-app thread
    'chat-inapp': () => (
      <Pad>
        <Tile>
          <Eyebrow>Friday · 19:30</Eyebrow>
          <div style={{ fontFamily: FONT.serif, fontSize: 18, color: C.ink, margin: '4px 0 8px' }}>Dinner at Chabrol</div>
          <div style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
            <Av hue="clay" ch="S" /><Av hue="plum" ch="J" /><Av hue="sage" ch="D" />
            <Body c={C.ink3} size={11.5}>you & 2 going</Body>
          </div>
        </Tile>
        <div style={{ display: 'flex', flexDirection: 'column', gap: 9, padding: '2px 2px' }}>
          {[['S', 'clay', 'running 10 late — start without me'], ['J', 'plum', 'np, grabbing the table']].map(([ch, h, m], i) => (
            <div key={i} style={{ display: 'flex', gap: 8, alignItems: 'flex-start' }}>
              <Av hue={h} ch={ch} />
              <div style={{ background: C.surface, border: `1px solid ${C.line}`, borderRadius: 13, borderTopLeftRadius: 4,
                padding: '8px 11px', fontFamily: FONT.sans, fontSize: 12.5, color: C.ink, lineHeight: 1.35 }}>{m}</div>
            </div>
          ))}
        </div>
        <div style={{ marginTop: 'auto', display: 'flex', alignItems: 'center', gap: 8, background: C.surface,
          border: `1px solid ${C.line}`, borderRadius: 999, padding: '8px 8px 8px 14px' }}>
          <Body c={C.ink4} size={12.5} style={{ flex: 1 }}>Message the group…</Body>
          <span style={{ width: 28, height: 28, borderRadius: '50%', background: C.twilight, color: '#fff',
            display: 'inline-flex', alignItems: 'center', justifyContent: 'center' }}><Icon name="arrow" size={15} /></span>
        </div>
      </Pad>
    ),
    // CHAT — keep it in WhatsApp
    'chat-whatsapp': () => (
      <Pad style={{ gap: 14 }}>
        <Tile>
          <Eyebrow>Friday · 19:30</Eyebrow>
          <div style={{ fontFamily: FONT.serif, fontSize: 18, color: C.ink, margin: '4px 0 8px' }}>Dinner at Chabrol</div>
          <div style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
            <Av hue="clay" ch="S" /><Av hue="plum" ch="J" /><Av hue="sage" ch="D" />
            <Body c={C.ink3} size={11.5}>you & 2 going</Body>
          </div>
        </Tile>
        <div style={{ flex: 1, display: 'flex', flexDirection: 'column', justifyContent: 'center', gap: 12, padding: '0 2px' }}>
          <button style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 9, background: C.surface,
            border: `1px solid ${C.lineStrong}`, borderRadius: 13, padding: '14px', fontFamily: FONT.sans, fontSize: 14,
            fontWeight: 600, color: C.ink, cursor: 'pointer' }}>
            <Icon name="share" size={17} style={{ color: C.ink2 }} />Discuss in WhatsApp
          </button>
          <Body c={C.ink3} size={12} style={{ textAlign: 'center', padding: '0 14px' }}>The chat stays where your group already is. Nothing new to check.</Body>
        </div>
      </Pad>
    ),

    // REFLECTION — yes, show me
    'reflect-yes': () => {
      const rows = [['Food & drink', 'ochre', 42], ['Outdoors', 'teal', 26], ['Culture', 'plum', 20], ['Nightlife', 'dusk', 12]];
      return (
        <Pad style={{ gap: 13 }}>
          <div><Eyebrow>Your 5-to-9 · Spring</Eyebrow><Title size={19} style={{ marginTop: 3 }}>Where the evenings went</Title></div>
          <Tile>
            <div style={{ display: 'flex', flexDirection: 'column', gap: 11 }}>
              {rows.map(([lab, h, pct], i) => (
                <div key={i}>
                  <div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: 4 }}>
                    <Body size={12} c={C.ink2}>{lab}</Body><Mono>{pct}%</Mono>
                  </div>
                  <div style={{ height: 7, borderRadius: 999, background: C.paperDeep, overflow: 'hidden' }}>
                    <div style={{ width: pct + '%', height: '100%', background: GROUP[h].c, borderRadius: 999 }} />
                  </div>
                </div>
              ))}
            </div>
          </Tile>
          <div style={{ display: 'flex', alignItems: 'center', gap: 7, justifyContent: 'center' }}>
            <Icon name="check" size={13} style={{ color: C.ink3 }} />
            <Body c={C.ink3} size={11.5}>11 nights out · 6 with friends · private to you</Body>
          </div>
        </Pad>
      );
    },
    // REFLECTION — no, keep it minimal
    'reflect-no': () => (
      <Pad style={{ flex: 1, justifyContent: 'center', alignItems: 'center', textAlign: 'center', gap: 14 }}>
        <Eyebrow>Tonight</Eyebrow>
        <div style={{ fontFamily: FONT.serif, fontSize: 27, lineHeight: 1.1, letterSpacing: '-0.01em', color: C.ink, maxWidth: 200 }}>
          Your evening&rsquo;s wide open. <span style={{ fontStyle: 'italic', color: C.ink2 }}>Good.</span>
        </div>
        <div style={{ width: 26, height: 1, background: C.lineStrong }} />
        <Body c={C.ink3} size={11.5}>No dashboards. No streaks. Nothing to check.</Body>
      </Pad>
    ),

    // ONBOARDING — drop me straight in
    'onb-straight': () => (
      <div style={{ display: 'flex', flexDirection: 'column', height: '100%' }}>
        <Pad style={{ flex: 1 }}>
          <div><Eyebrow>Monday · 2 June</Eyebrow><Title size={22} style={{ marginTop: 3 }}>Evening, Daan.</Title></div>
          <Tile>
            <div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: 9 }}>
              <Eyebrow>Your evening</Eyebrow><Mono c={C.ink2}>17:00–21:00 free</Mono>
            </div>
            <div style={{ position: 'relative', height: 7, background: C.paperDeep, borderRadius: 999 }}>
              <div style={{ position: 'absolute', left: 0, top: 0, bottom: 0, width: '29%', background: C.line, borderRadius: 999 }} />
              <div style={{ position: 'absolute', left: '29%', top: -4, width: 2, height: 15, background: C.amber, borderRadius: 2 }} />
              <div style={{ position: 'absolute', left: 'calc(29% - 3px)', top: -6, width: 7, height: 7, borderRadius: '50%', background: C.amber }} />
            </div>
          </Tile>
          <Tile style={{ boxShadow: '0 2px 8px rgba(27,25,22,0.06)' }}>
            <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 6 }}>
              <Eyebrow>Tonight · 1 of 3</Eyebrow><span style={{ fontFamily: FONT.sans, fontSize: 11, fontWeight: 600, color: C.go }}>fits 18:30</span>
            </div>
            <div style={{ fontFamily: FONT.serif, fontSize: 18, color: C.ink, marginBottom: 7 }}>Natural-wine tasting</div>
            <div style={{ display: 'flex', gap: 13, color: C.ink2, fontFamily: FONT.sans, fontSize: 12 }}>
              <span style={{ display: 'inline-flex', gap: 4, alignItems: 'center' }}><Icon name="pin" size={13} style={{ color: C.ink3 }} />Jordaan</span>
              <span style={{ display: 'inline-flex', gap: 4, alignItems: 'center' }}><Icon name="clock" size={13} style={{ color: C.ink3 }} />18:30</span>
            </div>
          </Tile>
        </Pad>
        <div style={{ display: 'flex', justifyContent: 'space-around', padding: '7px 12px 4px', borderTop: `1px solid ${C.line}`,
          background: 'rgba(253,251,246,0.9)' }}>
          {[['tonight', 'Tonight', true], ['plan', 'Plan'], ['groups', 'Groups']].map(([ic, lb, on]) => (
            <span key={ic} style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 3,
              color: on ? C.twilight : C.ink3 }}>
              <Icon name={ic} size={19} stroke={on ? 2.2 : 1.8} />
              <span style={{ fontFamily: FONT.sans, fontSize: 9.5, fontWeight: on ? 600 : 500 }}>{lb}</span>
            </span>
          ))}
        </div>
      </div>
    ),
    // ONBOARDING — walk me through it
    'onb-setup': () => (
      <Pad style={{ gap: 14, flex: 1 }}>
        <div style={{ display: 'flex', gap: 6, marginTop: 2 }}>
          {[0, 1, 2].map(i => <span key={i} style={{ height: 4, flex: 1, borderRadius: 999, background: i === 0 ? C.twilight : C.line }} />)}
        </div>
        <div><Eyebrow>Set up · step 1 of 3</Eyebrow><Title size={20} style={{ marginTop: 4 }}>Add your friend groups</Title></div>
        {[['Uni friends', 'clay', true], ['Climbing crew', 'teal', true]].map(([n, h, done], i) => (
          <Tile key={i} style={{ display: 'flex', alignItems: 'center', gap: 10, padding: '11px 13px' }}>
            <span style={{ width: 9, height: 9, borderRadius: '50%', background: GROUP[h].c }} />
            <div style={{ flex: 1, fontFamily: FONT.sans, fontSize: 13.5, fontWeight: 600, color: C.ink }}>{n}</div>
            <Icon name="check" size={15} style={{ color: C.go }} />
          </Tile>
        ))}
        <button style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 7, background: 'transparent',
          border: `1px dashed ${C.lineStrong}`, borderRadius: 14, padding: '11px', fontFamily: FONT.sans, fontSize: 13,
          fontWeight: 600, color: C.ink2, cursor: 'pointer' }}><Icon name="plus" size={15} />Add a group</button>
        <button style={{ marginTop: 'auto', background: C.twilight, color: '#fff', border: 'none', borderRadius: 12,
          padding: '13px', fontFamily: FONT.sans, fontSize: 14, fontWeight: 600, cursor: 'pointer' }}>Continue</button>
      </Pad>
    ),

    // PRIVACY — fully siloed
    'priv-siloed': () => (
      <Pad style={{ gap: 12 }}>
        <div style={{ display: 'flex', alignItems: 'center', gap: 7 }}>
          <span style={{ width: 9, height: 9, borderRadius: '50%', background: GROUP.clay.c }} />
          <Title size={18}>Uni friends</Title>
        </div>
        <Body c={C.ink3} size={11.5} style={{ marginTop: -4 }}>This week</Body>
        {[['Wed', null], ['Thu', ['Padel 18:30', 'clay']], ['Fri', null], ['Sat', ['Supper 19:30', 'clay']]].map(([d, ev], i) => (
          <div key={i} style={{ display: 'flex', gap: 10, alignItems: 'center' }}>
            <Mono c={C.ink3}>{d}</Mono>
            {ev
              ? <div style={{ flex: 1, background: GROUP[ev[1]].soft, color: GROUP[ev[1]].c, borderRadius: 10, padding: '9px 12px',
                  fontFamily: FONT.sans, fontSize: 12.5, fontWeight: 600 }}>{ev[0]}</div>
              : <div style={{ flex: 1, border: `1px dashed ${C.line}`, borderRadius: 10, padding: '9px 12px',
                  fontFamily: FONT.sans, fontSize: 12, color: C.ink4 }}>open</div>}
          </div>
        ))}
        <Body c={C.ink3} size={11.5} style={{ textAlign: 'center', marginTop: 2 }}>You only see this group&rsquo;s plans.</Body>
      </Pad>
    ),
    // PRIVACY — shared free/busy
    'priv-shared': () => (
      <Pad style={{ gap: 12 }}>
        <div style={{ display: 'flex', alignItems: 'center', gap: 7 }}>
          <span style={{ width: 9, height: 9, borderRadius: '50%', background: GROUP.clay.c }} />
          <Title size={18}>Uni friends</Title>
        </div>
        <Body c={C.ink3} size={11.5} style={{ marginTop: -4 }}>This week · + when you&rsquo;re busy elsewhere</Body>
        {[['Wed', ['Busy', 'grey']], ['Thu', ['Padel 18:30', 'clay']], ['Fri', ['Busy', 'grey']], ['Sat', ['Supper 19:30', 'clay']]].map(([d, ev], i) => (
          <div key={i} style={{ display: 'flex', gap: 10, alignItems: 'center' }}>
            <Mono c={C.ink3}>{d}</Mono>
            {ev[1] === 'grey'
              ? <div style={{ flex: 1, background: C.paperDeep, color: C.ink3, borderRadius: 10, padding: '9px 12px',
                  fontFamily: FONT.sans, fontSize: 12.5, fontWeight: 600, display: 'flex', justifyContent: 'space-between' }}>
                  <span>{ev[0]}</span><span style={{ fontSize: 10.5, color: C.ink4 }}>another group</span></div>
              : <div style={{ flex: 1, background: GROUP[ev[1]].soft, color: GROUP[ev[1]].c, borderRadius: 10, padding: '9px 12px',
                  fontFamily: FONT.sans, fontSize: 12.5, fontWeight: 600 }}>{ev[0]}</div>}
          </div>
        ))}
        <Body c={C.ink3} size={11.5} style={{ textAlign: 'center', marginTop: 2 }}>Groups see when — never with who.</Body>
      </Pad>
    ),

    // FIRST — calendar import
    'first-calendar': () => (
      <Pad style={{ gap: 11 }}>
        <div><Eyebrow>Your week</Eyebrow><Title size={19} style={{ marginTop: 3 }}>Find your free evenings</Title></div>
        {[['Mon', 'Work till 18:00', 'Free 18–21'], ['Tue', 'Gym 19:00', null], ['Wed', null, 'Free 17–21'], ['Thu', 'Call 20:00', 'Free 18–20']].map(([d, busy, free], i) => (
          <div key={i} style={{ display: 'flex', gap: 8, alignItems: 'stretch' }}>
            <Mono c={C.ink3} >{d}</Mono>
            <div style={{ flex: 1, display: 'flex', gap: 6 }}>
              {busy && <div style={{ background: C.paperDeep, color: C.ink3, borderRadius: 9, padding: '7px 9px',
                fontFamily: FONT.sans, fontSize: 11, fontWeight: 500 }}>{busy}</div>}
              {free && <div style={{ flex: 1, background: C.twilightSoft, color: C.twilight, borderRadius: 9, padding: '7px 9px',
                fontFamily: FONT.sans, fontSize: 11, fontWeight: 600 }}>{free}</div>}
            </div>
          </div>
        ))}
        <Body c={C.ink3} size={11} style={{ textAlign: 'center', marginTop: 2 }}>We only read busy blocks — never what or who.</Body>
      </Pad>
    ),
    // FIRST — discovery picks
    'first-picks': () => (
      <Pad style={{ gap: 11 }}>
        <div><Eyebrow>Tonight · Amsterdam-West</Eyebrow><Title size={19} style={{ marginTop: 3 }}>Three things to do</Title></div>
        {[['Natural-wine tasting', 'Jordaan', '18:30', 'Food & drink'], ['Bouldering', 'Oost', '19:00', 'Outdoors']].map(([t, w, tm, cat], i) => (
          <Tile key={i} style={{ boxShadow: i === 0 ? '0 2px 8px rgba(27,25,22,0.06)' : undefined }}>
            <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 7 }}>
              <Chip label={cat} hue={CAT[cat]} /><Mono>{i + 1} of 3</Mono>
            </div>
            <div style={{ fontFamily: FONT.serif, fontSize: 17, color: C.ink, marginBottom: 7 }}>{t}</div>
            <div style={{ display: 'flex', gap: 13, color: C.ink2, fontFamily: FONT.sans, fontSize: 12 }}>
              <span style={{ display: 'inline-flex', gap: 4, alignItems: 'center' }}><Icon name="pin" size={13} style={{ color: C.ink3 }} />{w}</span>
              <span style={{ display: 'inline-flex', gap: 4, alignItems: 'center' }}><Icon name="clock" size={13} style={{ color: C.ink3 }} />{tm}</span>
            </div>
          </Tile>
        ))}
        <button style={{ background: C.twilight, color: '#fff', border: 'none', borderRadius: 12, padding: '12px',
          fontFamily: FONT.sans, fontSize: 13.5, fontWeight: 600, cursor: 'pointer' }}>Put it on tonight</button>
      </Pad>
    ),
  };

  function Scene({ id }) {
    const S = SCENES[id];
    return S ? e(S) : null;
  }

  Object.assign(window, { MiniPhone, Scene });
})();
