/* global React, INK, CREAM, PULSE, GENS, GradText, CTAButton, Reveal, useReveal, useCountUp, SB_EASE, PA_ACCENTS,
   MShell, MHead */
// Post & Analyze feature page — mobile layout (skews alternate right → left → right …).
const { useState: pmS } = React;

// eyebrows are hero-only on mobile — keep the heading, drop the pill
const MPABadgeHead = ({ title, sub }) => <MHead title={title} sub={sub} />;
const MPACard = ({ lean = 'right', children, pad = 12 }) => (
  <div style={{ borderRadius: 18, background: '#fff', boxShadow: '0 12px 32px rgba(28,27,27,0.10), inset 0 0 0 1px rgba(28,27,27,0.08)', padding: pad, marginTop: 26,
    transform: lean === 'left' ? 'rotate(-1.2deg) perspective(1200px) rotateY(3deg)' : 'rotate(1.2deg) perspective(1200px) rotateY(-3deg)' }}>{children}</div>
);

// hero
const MPA_QUEUE = [
  { src: GENS[7].src, p: 'Instagram', c: '#E1306C', time: 'Today · 9:00 AM', st: 'Queued' },
  { src: GENS[1].src, p: 'TikTok', c: '#1C1B1B', time: 'Today · 12:30 PM', st: 'Queued' },
  { src: GENS[3].src, p: 'Fanvue', c: '#1FB85A', time: 'Yesterday · 6:00 PM', st: 'Posted' }];
const MPA_BARS = [34, 52, 41, 68, 55, 88, 62];

const MPAHero = () => {
  const [ref, on] = useReveal(0.25);
  return (
    <section style={{ background: CREAM, padding: '0 22px 56px' }}>
      <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', padding: '16px 0 30px' }}>
        <span style={{ display: 'inline-flex', alignItems: 'center', gap: 7 }}>
          <img loading="lazy" decoding="async" src="assets/logo-icon.png" alt="" style={{ width: 19, height: 19, objectFit: 'contain' }} />
          <span style={{ fontSize: 16, fontWeight: 800, letterSpacing: '-0.03em', color: INK }}>sozee</span>
        </span>
      </div>
      <div style={{ textAlign: 'center' }}>
        <Reveal>
          <div style={{ display: 'inline-flex', alignItems: 'center', gap: 7, marginBottom: 16, borderRadius: 9999, padding: '6px 12px', background: '#fff', boxShadow: 'inset 0 0 0 1px rgba(28,27,27,0.1)' }}>
            <a href="/" style={{ fontSize: 10.5, fontWeight: 600, color: 'rgba(28,27,27,0.55)' }}>Features</a>
            <span style={{ fontSize: 10, color: 'rgba(28,27,27,0.35)' }}>/</span>
            <span style={{ fontSize: 10.5, fontWeight: 700, color: INK }}>Post & Analyze</span>
          </div>
        </Reveal>
        <Reveal delay={90}>
          <h1 style={{ font: '800 44px/1 var(--font-sans)', letterSpacing: '-0.03em', color: INK, margin: '0 0 16px', textWrap: 'balance' }}>
            Queue it once.<br /><GradText>Watch it work.</GradText>
          </h1>
        </Reveal>
        <Reveal delay={170}>
          <p style={{ fontSize: 14.5, lineHeight: 1.58, color: 'var(--text-secondary)', margin: '0 0 24px' }}>
            One queue posts to six platforms while you make the next set — and every post comes back with numbers attached.
          </p>
        </Reveal>
        <Reveal delay={250} style={{ marginBottom: 34 }}><CTAButton size="sm">Start posting</CTAButton></Reveal>
      </div>
      <Reveal delay={200} y={26}>
        <div ref={ref} style={{ transform: 'rotate(1.2deg) perspective(1200px) rotateY(-3deg)', borderRadius: 20, background: '#fff', boxShadow: '0 20px 44px rgba(28,27,27,0.12), inset 0 0 0 1px rgba(28,27,27,0.08)', padding: 12 }}>
          <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: 9 }}>
            <span style={{ display: 'inline-flex', alignItems: 'center', gap: 6 }}>
              <span style={{ width: 17, height: 17, borderRadius: '50%', backgroundImage: `url(${GENS[0].src})`, backgroundSize: 'cover', backgroundPosition: 'center 15%' }} />
              <span style={{ fontSize: 11, fontWeight: 800, color: INK }}>This week · Scarlett</span>
            </span>
            <span style={{ fontSize: 8.5, fontWeight: 700, color: 'var(--brand-purple-700)', background: 'var(--brand-purple-50)', border: '1px solid var(--brand-purple-200)', borderRadius: 9999, padding: '2px 8px' }}>6 platforms</span>
          </div>
          <div style={{ display: 'flex', flexDirection: 'column', gap: 6, marginBottom: 10 }}>
            {MPA_QUEUE.map((r, i) =>
              <div key={r.p} style={{ display: 'flex', alignItems: 'center', gap: 8, borderRadius: 10, background: 'rgb(250,247,247)', boxShadow: 'inset 0 0 0 1px rgba(28,27,27,0.07)', padding: '6px 8px',
                opacity: on ? 1 : 0, transition: `opacity 0.45s ${SB_EASE} ${i * 90}ms` }}>
                <span style={{ width: 28, height: 28, borderRadius: 7, overflow: 'hidden', flexShrink: 0 }}>
                  <img loading="lazy" decoding="async" src={r.src} alt="" style={{ width: '100%', height: '100%', objectFit: 'cover', objectPosition: 'center 18%' }} /></span>
                <span style={{ flex: 1, minWidth: 0, textAlign: 'left' }}>
                  <span style={{ display: 'flex', alignItems: 'center', gap: 4, fontSize: 10, fontWeight: 700, color: INK }}>
                    <span style={{ width: 5, height: 5, borderRadius: '50%', background: r.c }} />{r.p}</span>
                  <span style={{ display: 'block', fontSize: 8.5, color: 'rgba(28,27,27,0.5)' }}>{r.time}</span>
                </span>
                <span style={{ fontSize: 8, fontWeight: 700, borderRadius: 9999, padding: '2px 8px',
                  color: r.st === 'Posted' ? '#15803D' : 'var(--brand-purple-700)',
                  background: r.st === 'Posted' ? 'rgba(34,197,94,0.12)' : 'var(--brand-purple-50)',
                  border: r.st === 'Posted' ? '1px solid rgba(34,197,94,0.3)' : '1px solid var(--brand-purple-200)' }}>{r.st}</span>
              </div>
            )}
          </div>
          <div style={{ borderRadius: 12, boxShadow: 'inset 0 0 0 1px rgba(28,27,27,0.1)', padding: '10px 11px' }}>
            <div style={{ display: 'flex', alignItems: 'baseline', justifyContent: 'space-between', marginBottom: 8 }}>
              <span style={{ fontSize: 8.5, fontWeight: 700, letterSpacing: '0.08em', textTransform: 'uppercase', color: 'var(--text-tertiary)' }}>Reach · 7 days</span>
              <span style={{ fontSize: 12.5, fontWeight: 800, color: INK }}>2.4M <span style={{ fontSize: 9, fontWeight: 700, color: '#15803D' }}>▲ 18%</span></span>
            </div>
            <div style={{ display: 'flex', alignItems: 'flex-end', gap: 5, height: 44 }}>
              {MPA_BARS.map((h, i) =>
                <span key={i} style={{ flex: 1, borderRadius: 4, height: on ? `${h}%` : '8%', transition: `height 0.7s ${SB_EASE} ${200 + i * 60}ms`,
                  background: i === 5 ? PULSE : 'rgb(235,231,231)' }} />)}
            </div>
          </div>
        </div>
      </Reveal>
    </section>);
};

// § 02 Platforms
const MPA_PLATS = [
  { n: 'Instagram', c: '#E1306C', h: '@scarlett.day', on: true }, { n: 'TikTok', c: '#1C1B1B', h: '@scarlettday', on: true },
  { n: 'Fanvue', c: '#1FB85A', h: '@scarlett', on: true }, { n: 'Fansly', c: '#2699F7', h: '@scarlettday', on: false },
  { n: 'X', c: '#5B6470', h: '@scarlett_day', on: true }, { n: 'Reddit', c: '#FF4500', h: 'u/scarlettday', on: false }];

const MPAPlatforms = () => {
  const [plats, setPlats] = pmS(MPA_PLATS);
  return (
    <MShell bg="#fff">
      <MPABadgeHead label="Post & Analyze · Platforms" ac={PA_ACCENTS.Platforms} title={<span>Six platforms.<br /><GradText>One queue.</GradText></span>}
        sub="Connect each platform once per Character — one queued post fans out to everything that's on." />
      <MPACard lean="left">
        <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 7 }}>
          {plats.map((p, i) =>
            <div key={p.n} onClick={() => setPlats(ps => ps.map((x, j) => j === i ? { ...x, on: !x.on } : x))}
              style={{ display: 'flex', alignItems: 'center', gap: 7, borderRadius: 11, padding: '9px 9px', cursor: 'pointer', transition: 'all 0.2s',
                background: p.on ? '#fff' : 'rgb(250,247,247)', boxShadow: p.on ? `inset 0 0 0 1.5px ${p.c}` : 'inset 0 0 0 1px rgba(28,27,27,0.1)' }}>
              <span style={{ width: 24, height: 24, borderRadius: '50%', flexShrink: 0, display: 'grid', placeItems: 'center', background: p.on ? p.c : 'rgb(235,231,231)' }}>
                <span style={{ fontSize: 9.5, fontWeight: 800, color: p.on ? '#fff' : 'rgba(28,27,27,0.45)' }}>{p.n[0]}</span></span>
              <span style={{ flex: 1, minWidth: 0, textAlign: 'left' }}>
                <span style={{ display: 'block', fontSize: 10.5, fontWeight: 700, color: p.on ? INK : 'rgba(28,27,27,0.5)' }}>{p.n}</span>
                <span style={{ display: 'block', fontSize: 8, color: 'rgba(28,27,27,0.45)', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>{p.on ? p.h : 'Tap to connect'}</span>
              </span>
              <span style={{ width: 24, height: 14, borderRadius: 9999, flexShrink: 0, position: 'relative', background: p.on ? PULSE : 'rgb(222,217,217)', transition: 'all 0.2s' }}>
                <span style={{ position: 'absolute', top: 1.5, left: p.on ? 11.5 : 1.5, width: 11, height: 11, borderRadius: '50%', background: '#fff', boxShadow: '0 1px 3px rgba(0,0,0,0.25)', transition: `left 0.25s ${SB_EASE}` }} />
              </span>
            </div>
          )}
        </div>
      </MPACard>
    </MShell>);
};

// § 03 Analytics
const MPAKpi = ({ label, value, suffix = '', on, sub, div = 1 }) => {
  const raw = useCountUp(value, on);
  const v = raw / div;
  return (
    <div style={{ borderRadius: 11, background: 'rgb(250,247,247)', boxShadow: 'inset 0 0 0 1px rgba(28,27,27,0.07)', padding: '10px 11px', textAlign: 'left' }}>
      <div style={{ fontSize: 8, fontWeight: 700, letterSpacing: '0.08em', textTransform: 'uppercase', color: 'var(--text-tertiary)', marginBottom: 4 }}>{label}</div>
      <div style={{ fontSize: 17, fontWeight: 800, letterSpacing: '-0.02em', color: INK, fontVariantNumeric: 'tabular-nums' }}>
        {v >= 1000000 ? (v / 1000000).toFixed(1) + 'M' : v >= 1000 ? (v / 1000).toFixed(v >= 100000 ? 0 : 1) + 'k' : div > 1 ? v.toFixed(1) : v}{suffix}
        {sub && <span style={{ fontSize: 8.5, fontWeight: 700, color: '#15803D', marginLeft: 5 }}>{sub}</span>}
      </div>
    </div>);
};
const MPA_WK = [28, 44, 36, 61, 50, 84, 58];

const MPAAnalytics = () => {
  const [ref, on] = useReveal(0.35);
  return (
    <MShell>
      <MPABadgeHead label="Post & Analyze · Analytics" ac={PA_ACCENTS.Analytics} title={<span>Proof,<br /><GradText>not vibes.</GradText></span>}
        sub="Reach, followers, engagement and posts shipped — one dashboard across every platform." />
      <MPACard lean="right">
        <div ref={ref}>
          <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 7, marginBottom: 9 }}>
            <MPAKpi label="Reach" value={2400000} on={on} sub="▲ 18%" />
            <MPAKpi label="New followers" value={12800} on={on} sub="▲ 9%" />
            <MPAKpi label="Engagement" value={48} div={10} suffix="%" on={on} />
            <MPAKpi label="Posts shipped" value={23} on={on} />
          </div>
          <div style={{ borderRadius: 11, background: 'rgb(250,247,247)', boxShadow: 'inset 0 0 0 1px rgba(28,27,27,0.07)', padding: '10px 11px' }}>
            <div style={{ fontSize: 8, fontWeight: 700, letterSpacing: '0.08em', textTransform: 'uppercase', color: 'var(--text-tertiary)', marginBottom: 8, textAlign: 'left' }}>Reach by day</div>
            <div style={{ display: 'flex', alignItems: 'flex-end', gap: 5, height: 58 }}>
              {MPA_WK.map((h, i) =>
                <span key={i} style={{ flex: 1, borderRadius: 4, height: on ? `${h}%` : '8%', transition: `height 0.7s ${SB_EASE} ${150 + i * 60}ms`,
                  background: i === 5 ? PULSE : 'rgb(230,225,225)' }} />)}
            </div>
            <div style={{ display: 'flex', justifyContent: 'space-between', marginTop: 4 }}>
              {['M', 'T', 'W', 'T', 'F', 'S', 'S'].map((d, i) => <span key={i} style={{ flex: 1, textAlign: 'center', fontSize: 7.5, fontWeight: 600, color: 'rgba(28,27,27,0.4)' }}>{d}</span>)}
            </div>
          </div>
          <div style={{ display: 'flex', gap: 10, marginTop: 9, justifyContent: 'center' }}>
            <span style={{ display: 'inline-flex', alignItems: 'center', gap: 4, fontSize: 8.5, fontWeight: 600, color: 'rgba(28,27,27,0.6)' }}>
              <span style={{ width: 6, height: 6, borderRadius: 2, background: PULSE }} />Sozee · 82%</span>
            <span style={{ display: 'inline-flex', alignItems: 'center', gap: 4, fontSize: 8.5, fontWeight: 600, color: 'rgba(28,27,27,0.6)' }}>
              <span style={{ width: 6, height: 6, borderRadius: 2, background: 'rgb(213,208,208)' }} />You · 18%</span>
          </div>
        </div>
      </MPACard>
    </MShell>);
};

// § 04 Receipts
const MPA_POSTS = [
  { src: 'assets/pa/post-1.png', p: 'Instagram', c: '#E1306C', t: 'Tue · 9:00', likes: '12.4k', sz: true },
  { src: 'assets/pa/post-2.png', p: 'TikTok', c: '#1C1B1B', t: 'Tue · 12:30', likes: '48.1k', sz: true },
  { src: 'assets/pa/post-4.png', p: 'X', c: '#5B6470', t: 'Sun · 8:00', likes: '9.7k', sz: false }];

const MPAReceipts = () => (
  <MShell bg="#fff">
    <MPABadgeHead label="Post & Analyze · Receipts" ac={PA_ACCENTS.Receipts} title={<span>Every post,<br /><GradText>receipts attached.</GradText></span>}
      sub="Each post comes back with its own numbers — and a tag for who shipped it." />
    <MPACard lean="left" pad={10}>
      <div style={{ display: 'flex', flexDirection: 'column', gap: 6 }}>
        {MPA_POSTS.map((r) =>
          <div key={r.p} style={{ display: 'flex', alignItems: 'center', gap: 8, borderRadius: 10, background: 'rgb(250,247,247)', boxShadow: 'inset 0 0 0 1px rgba(28,27,27,0.07)', padding: '7px 8px' }}>
            <span style={{ width: 32, height: 32, borderRadius: 8, overflow: 'hidden', flexShrink: 0 }}>
              <img loading="lazy" decoding="async" src={r.src} alt="" style={{ width: '100%', height: '100%', objectFit: 'cover', objectPosition: 'center 18%' }} /></span>
            <span style={{ flex: 1, minWidth: 0, textAlign: 'left' }}>
              <span style={{ display: 'flex', alignItems: 'center', gap: 4, fontSize: 10, fontWeight: 700, color: INK }}>
                <span style={{ width: 5, height: 5, borderRadius: '50%', background: r.c }} />{r.p}
                <span style={{ fontSize: 8.5, fontWeight: 600, color: 'rgba(28,27,27,0.45)' }}>· {r.t}</span></span>
              <span style={{ display: 'block', fontSize: 9, fontWeight: 600, color: 'rgba(28,27,27,0.6)', marginTop: 2 }}>♥ {r.likes}</span>
            </span>
            {r.sz ?
              <span style={{ fontSize: 7.5, fontWeight: 700, color: 'var(--brand-purple-700)', background: 'var(--brand-purple-50)', border: '1px solid var(--brand-purple-200)', borderRadius: 9999, padding: '2px 7px', flexShrink: 0 }}>✦ Sozee-posted</span> :
              <span style={{ fontSize: 7.5, fontWeight: 700, color: 'rgba(28,27,27,0.45)', boxShadow: 'inset 0 0 0 1px rgba(28,27,27,0.12)', borderRadius: 9999, padding: '2px 7px', flexShrink: 0 }}>By you</span>}
          </div>
        )}
      </div>
    </MPACard>
  </MShell>
);

// § 05 pipeline
const MPA_NEXT = [
  { t: 'Create Image', d: 'The sets that fill the queue.', kind: 'image', href: '/create-image' },
  { t: 'Create Video', d: 'Reels and TikToks with her voice.', kind: 'video', href: '/create-video' },
  { t: 'Editing Suite', d: 'Fix the photo before it ships.', kind: 'edit', href: '/editing-suite' }];

const MPAPipeMedia = ({ kind }) => (
  <div style={{ width: 96, borderRadius: 11, overflow: 'hidden', flexShrink: 0, aspectRatio: '4/4.4', background: '#fff', boxShadow: 'inset 0 0 0 1px rgba(28,27,27,0.08)', padding: 5, boxSizing: 'border-box', display: 'flex', flexDirection: 'column', gap: 4 }}>
    {kind === 'image' && <React.Fragment>
      <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 4, flex: 1, minHeight: 0 }}>
        {['assets/create/out-mirror.webp', 'assets/create/out-garden.webp'].map((src, i) =>
          <span key={src} style={{ position: 'relative', borderRadius: 5, overflow: 'hidden', boxShadow: i === 0 ? '0 0 0 1.5px var(--brand-purple-500)' : 'inset 0 0 0 1px rgba(28,27,27,0.08)' }}>
            <img loading="lazy" decoding="async" src={src} alt="" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover', objectPosition: 'center 20%' }} /></span>)}
      </div>
      <span style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 3, borderRadius: 6, padding: '4px 0', background: PULSE, color: '#fff', fontSize: 6.5, fontWeight: 800, letterSpacing: '0.05em' }}>GENERATE ✦</span>
    </React.Fragment>}
    {kind === 'video' &&
      <span style={{ position: 'relative', flex: 1, minHeight: 0, borderRadius: 6, overflow: 'hidden', background: 'rgb(246,243,242)', display: 'block' }}>
        <video src="assets/video/explore-2.mp4" autoPlay muted loop playsInline preload="metadata" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover' }} />
      </span>}
    {kind === 'edit' &&
      <span style={{ position: 'relative', flex: 1, minHeight: 0, borderRadius: 6, overflow: 'hidden', background: 'rgb(246,243,242)', display: 'block' }}>
        <img loading="lazy" decoding="async" src="assets/edits/color.webp" alt="" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover', objectPosition: 'center 10%' }} />
        <span style={{ position: 'absolute', top: 0, bottom: 0, left: '50%', width: 1.5, background: '#fff', boxShadow: '0 0 6px rgba(0,0,0,0.3)' }} />
      </span>}
  </div>
);

const MPAPipeline = () => (
  <MShell>
    <MHead title={<span>The queue eats<br /><GradText>what the studio makes.</GradText></span>}
      sub="Everything upstream lands on the board, ready to schedule." />
    <div style={{ display: 'flex', flexDirection: 'column', gap: 12, marginTop: 28 }}>
      {MPA_NEXT.map((c, i) =>
        <Reveal key={c.t} delay={i * 90} y={20}>
          <a href={c.href} style={{ display: 'flex', gap: 12, borderRadius: 16, overflow: 'hidden', background: '#fff', boxShadow: 'inset 0 0 0 1px rgba(28,27,27,0.08)', color: 'inherit', padding: 10, transform: `rotate(${i % 2 ? 0.9 : -0.9}deg)` }}>
            <MPAPipeMedia kind={c.kind} />
            <div style={{ minWidth: 0, alignSelf: 'center' }}>
              <div style={{ fontSize: 14.5, fontWeight: 700, letterSpacing: '-0.01em', color: INK, marginBottom: 4 }}>{c.t}</div>
              <div style={{ fontSize: 11.5, lineHeight: 1.5, color: 'var(--text-secondary)' }}>{c.d}</div>
            </div>
          </a>
        </Reveal>
      )}
    </div>
    <Reveal delay={280} style={{ textAlign: 'center', marginTop: 20 }}>
      <a href="/" style={{ fontSize: 12.5, fontWeight: 600, color: 'var(--brand-purple-700)' }}>See the full tour →</a>
    </Reveal>
  </MShell>
);

const MPAPage = () => (
  <React.Fragment>
    <div style={{ fontFamily: 'var(--font-sans)', maxWidth: 430, margin: '0 auto', boxShadow: '0 0 0 1px rgba(28,27,27,0.06), 0 0 60px rgba(28,27,27,0.08)', overflow: 'clip' }}>
      <div data-screen-label="Hero — Post & Analyze"><MPAHero /></div>
      <div data-screen-label="01 The Scheduler"><window.MSchedSection /></div>
      <div data-screen-label="02 Platforms"><MPAPlatforms /></div>
      <div data-screen-label="03 Analytics"><MPAAnalytics /></div>
      <div data-screen-label="04 Receipts"><MPAReceipts /></div>
      <div data-screen-label="05 Before the post"><MPAPipeline /></div>
      <div data-screen-label="06 Pricing"><window.MPricingSection /></div>
      <div data-screen-label="07 FAQ"><window.MFAQSection /></div>
      <div data-screen-label="CTA + Footer"><window.MFinalSection /></div>
    </div>
    <window.MCISticky />
    <window.SozeeNavMobile siteHref="/" localLabels={{ '/post-analyze': 'Hero — Post & Analyze', '11 Scheduler': '01 The Scheduler', '15 Pricing': '06 Pricing', '16 FAQ': '07 FAQ' }} />
  </React.Fragment>
);

Object.assign(window, { MPAPage });
