/* global React, INK, CREAM, PULSE, GENS, GradText, CTAButton, Reveal, SB_EASE */
// Mobile site shared bits — compact heads, phone chrome, sheet chrome (anatomy from Studio · Mobile V2).

const MPill = ({ children, active, dark, onClick, style }) => (
  <span onClick={onClick} style={{ borderRadius: 9999, padding: '7px 12px', fontSize: 11.5, fontWeight: active ? 700 : 600, cursor: 'pointer', whiteSpace: 'nowrap',
    background: active ? (dark ? '#fff' : INK) : dark ? 'rgba(255,255,255,0.08)' : 'rgb(246,243,242)',
    boxShadow: active ? 'none' : dark ? 'inset 0 0 0 1px rgba(255,255,255,0.16)' : 'inset 0 0 0 1px rgba(28,27,27,0.08)',
    color: active ? (dark ? INK : '#fff') : dark ? 'rgba(255,255,255,0.7)' : 'rgba(28,27,27,0.7)', transition: 'all 0.18s', ...style }}>{children}</span>
);
const MPillP = ({ children, active, onClick, style }) => (
  <span onClick={onClick} style={{ borderRadius: 9999, padding: '7px 12px', fontSize: 11.5, fontWeight: 600, cursor: 'pointer', whiteSpace: 'nowrap',
    background: active ? 'var(--brand-purple-50)' : 'rgb(246,243,242)',
    boxShadow: active ? 'inset 0 0 0 1.5px var(--brand-purple-400)' : 'inset 0 0 0 1px rgba(28,27,27,0.08)',
    color: active ? 'var(--brand-purple-700)' : 'rgba(28,27,27,0.7)', transition: 'all 0.18s', ...style }}>{children}</span>
);

const MShell = ({ children, dark = false, bg, pad = '56px 22px' }) => (
  <section style={{ background: bg || (dark ? '#141017' : CREAM), padding: pad }}>{children}</section>
);

// horizontally scrollable chip rail
const MRail = ({ children, style }) => (
  <div className="m-nosb" style={{ display: 'flex', gap: 7, overflowX: 'auto', margin: '0 -22px', padding: '0 22px', ...style }}>{children}</div>
);

const MHead = ({ title, sub, dark = false, center = true }) => (
  <div style={{ textAlign: center ? 'center' : 'left' }}>
    <Reveal delay={60}>
      <h2 style={{ font: '800 34px/1.04 var(--font-sans)', letterSpacing: '-0.03em', color: dark ? '#fff' : INK, margin: '0 0 14px', textWrap: 'balance' }}>{title}</h2>
    </Reveal>
    <Reveal delay={140}>
      <p style={{ fontSize: 14.5, lineHeight: 1.58, color: dark ? 'rgba(255,255,255,0.78)' : 'var(--text-secondary)', margin: 0 }}>{sub}</p>
    </Reveal>
  </div>
);

const MCopyHead = ({ k, dark = false, center = true, cta = true }) => {
  const c = window.useCopy(k);
  return (
    <div style={{ textAlign: center ? 'center' : 'left' }}>
      <MHead title={c.title} sub={c.sub} dark={dark} center={center} />
      {cta && <Reveal delay={220} style={{ marginTop: 22 }}><CTAButton size="sm">{c.cta}</CTAButton></Reveal>}
    </div>
  );
};

// slim phone frame — the product chrome for every app mockup on the mobile site
const MPhone = ({ children, w = 292, ratio = '9 / 19', bg = CREAM, style }) => (
  <div style={{ position: 'relative', width: w, maxWidth: '100%', aspectRatio: ratio, borderRadius: 40, background: '#141017',
    padding: 9, boxSizing: 'border-box', boxShadow: '0 24px 48px rgba(28,27,27,0.22), inset 0 0 0 1.5px rgba(255,255,255,0.08)', margin: '0 auto', ...style }}>
    <div style={{ position: 'relative', width: '100%', height: '100%', borderRadius: 32, overflow: 'hidden', background: bg, display: 'flex', flexDirection: 'column' }}>
      {children}
      <span style={{ position: 'absolute', top: 8, left: '50%', transform: 'translateX(-50%)', width: 74, height: 20, borderRadius: 9999, background: '#141017', zIndex: 30 }} />
    </div>
  </div>
);

const MAppHeader = ({ pad = '14px 15px 8px' }) => (
  <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', padding: pad, flexShrink: 0 }}>
    <span style={{ display: 'inline-flex', alignItems: 'center', gap: 6 }}>
      <img loading="lazy" decoding="async" src="assets/logo-icon.png" alt="" style={{ width: 16, height: 16, objectFit: 'contain' }} />
      <span style={{ fontSize: 14, fontWeight: 800, letterSpacing: '-0.03em', color: INK }}>sozee</span>
    </span>
    <span style={{ display: 'inline-flex', alignItems: 'center', gap: 4, background: 'rgb(235,231,231)', borderRadius: 9999, padding: '4px 9px' }}>
      <span style={{ fontSize: 9, color: 'rgb(245,165,36)' }}>⚡</span>
      <span style={{ fontSize: 9.5, fontWeight: 700, color: INK }}>9.38k</span>
    </span>
  </div>
);

// sheet chrome — "Choose your source" anatomy: title + sub + close, body, Back · dots · Continue footer
const MSheet = ({ title, sub, children, style }) => (
  <div style={{ borderRadius: 20, background: '#fff', boxShadow: '0 12px 32px rgba(28,27,27,0.10), inset 0 0 0 1px rgba(28,27,27,0.08)', padding: '15px 14px 12px', boxSizing: 'border-box', ...style }}>
    <div style={{ display: 'flex', alignItems: 'flex-start', justifyContent: 'space-between', gap: 8, marginBottom: sub ? 4 : 10 }}>
      <span style={{ fontSize: 15.5, fontWeight: 800, letterSpacing: '-0.01em', color: INK }}>{title}</span>
      <span style={{ width: 22, height: 22, borderRadius: '50%', background: 'rgb(246,243,242)', display: 'grid', placeItems: 'center', flexShrink: 0, cursor: 'pointer' }}>
        <svg width="9" height="9" viewBox="0 0 16 16" fill="none"><path d="M4 4l8 8M12 4l-8 8" stroke="rgba(28,27,27,0.6)" strokeWidth="1.9" strokeLinecap="round"/></svg>
      </span>
    </div>
    {sub && <div style={{ fontSize: 11, lineHeight: 1.5, color: 'var(--text-secondary)', marginBottom: 11 }}>{sub}</div>}
    {children}
  </div>
);

const MSheetFooter = ({ step = 1, of = 4, cta = 'Continue', gen = false, style }) => (
  <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 8, borderTop: '1px solid rgba(28,27,27,0.07)', paddingTop: 10, marginTop: 12, ...style }}>
    <span style={{ borderRadius: 9999, padding: '8px 13px', fontSize: 11, fontWeight: 700, color: 'rgba(28,27,27,0.65)', boxShadow: 'inset 0 0 0 1px rgba(28,27,27,0.14)', cursor: 'pointer', whiteSpace: 'nowrap', flexShrink: 0 }}>Back</span>
    <span style={{ display: 'inline-flex', gap: 3 }}>
      {Array.from({ length: of }).map((_, i) => (
        <span key={i} style={{ width: i === step - 1 ? 12 : 4, height: 4, borderRadius: 9999, background: i === step - 1 ? 'var(--brand-purple-500)' : 'rgba(28,27,27,0.18)', transition: `all 0.3s ${SB_EASE}` }} />
      ))}
    </span>
    <span style={{ display: 'inline-flex', alignItems: 'center', gap: 5, borderRadius: 9999, padding: '9px 13px', background: PULSE, color: '#fff', whiteSpace: 'nowrap', flexShrink: 0,
      fontSize: 10, fontWeight: 700, letterSpacing: '0.03em', textTransform: 'uppercase', cursor: 'pointer', boxShadow: '0 8px 20px -4px rgba(104,19,212,0.45)' }}>
      {cta}
      {gen ? <span style={{ padding: '2px 6px', borderRadius: 9999, background: 'rgba(255,255,255,0.22)', fontSize: 9, textTransform: 'none', letterSpacing: 0 }}>⚡150</span>
        : <svg width="10" height="10" viewBox="0 0 16 16" fill="none"><path d="M6 3.5L10.5 8 6 12.5" stroke="#fff" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"/></svg>}
    </span>
  </div>
);

// full-width gradient GENERATE pill — from the mobile Compose sheet
const MGenerate = ({ label = 'Generate', count, cost = '0.50', active = true }) => (
  <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 8, borderRadius: 9999, height: 40, cursor: 'pointer',
    background: active ? PULSE : 'rgb(235,231,231)', transition: `all 0.4s ${SB_EASE}`,
    boxShadow: active ? '0 8px 20px -4px rgba(104,19,212,0.45)' : 'none' }}>
    <span style={{ fontSize: 11.5, fontWeight: 700, letterSpacing: '0.06em', textTransform: 'uppercase', color: active ? '#fff' : 'rgba(28,27,27,0.55)' }}>✦ {label}</span>
    {count && <span style={{ display: 'inline-flex', gap: 4 }}>
      <span style={{ padding: '2px 7px', borderRadius: 9999, background: active ? 'rgba(255,255,255,0.22)' : 'rgba(28,27,27,0.08)', fontSize: 9.5, fontWeight: 700, color: active ? '#fff' : 'rgba(28,27,27,0.55)' }}>×{count}</span>
      <span style={{ padding: '2px 7px', borderRadius: 9999, background: active ? 'rgba(255,255,255,0.22)' : 'rgba(28,27,27,0.08)', fontSize: 9.5, fontWeight: 700, color: active ? '#fff' : 'rgba(28,27,27,0.55)' }}>⚡ {cost}</span>
    </span>}
  </div>
);

Object.assign(window, { MPill, MPillP, MShell, MRail, MHead, MCopyHead, MPhone, MAppHeader, MSheet, MSheetFooter, MGenerate });
