/* global React, INK, CREAM, PULSE, GENS, GradText, CTAButton, PCChip,
   Reveal, useReveal, SectionShell, GenBtn, SB_EASE */
// Create Image feature page — Reference to Image · Formats & Quality · Pipeline.
const { useState: cxS } = React;

const CIBadge = ({ label, bg = CREAM }) =>
  <div style={{ display: 'inline-flex', alignItems: 'center', gap: 8, marginBottom: 18, borderRadius: 9999, padding: '7px 14px', background: bg, boxShadow: 'inset 0 0 0 1px rgba(28,27,27,0.1)' }}>
    <span style={{ width: 7, height: 7, borderRadius: '50%', background: '#813CED' }} />
    <span style={{ fontSize: 11.5, fontWeight: 700, color: INK }}>{label}</span>
  </div>;

// ---------- § 01 — Reference to Image ----------
const RefToImageSection = () => {
  const [ref, on] = useReveal(0.35);
  return (
    <section style={{ background: '#fff', padding: '110px 56px' }}>
      <div style={{ maxWidth: 1140, margin: '0 auto', display: 'grid', gridTemplateColumns: '0.9fr 1.1fr', gap: 64, alignItems: 'center' }}>
        <div>
          <Reveal delay={90}>
            <h2 style={{ font: '800 52px/1 var(--font-sans)', letterSpacing: '-0.03em', color: INK, margin: '0 0 18px', textWrap: 'balance' }}>
              Seen the shot?<br /><GradText>Drop it in.</GradText>
            </h2>
          </Reveal>
          <Reveal delay={170}>
            <p style={{ fontSize: 17, lineHeight: 1.55, color: 'var(--text-secondary)', margin: '0 0 28px', maxWidth: 420 }}>
              Drag any photo into the composer — a pose you love, a framing, a light — and Sozee re-shoots it as your Character. The reference sets the scene; the prompt is optional.
            </p>
          </Reveal>
          <Reveal delay={250}><CTAButton>Join for free</CTAButton></Reveal>
          <Reveal delay={330}>
            <div style={{ marginTop: 26, fontSize: 13, color: 'var(--text-tertiary)' }}>
              Works with anything — a saved post, a photo from your camera roll, a past shot you want to run back.
            </div>
          </Reveal>
        </div>
        <Reveal delay={160} y={28}>
          <div ref={ref} style={{ transform: 'rotate(-1.3deg) perspective(1400px) rotateY(4deg)', borderRadius: 20, background: '#fff', boxShadow: '0 24px 48px rgba(28,27,27,0.14), inset 0 0 0 1px rgba(28,27,27,0.08)', padding: 20 }}>
            <div style={{ display: 'grid', gridTemplateColumns: '1fr 44px 1fr', gap: 10, alignItems: 'center', marginBottom: 16 }}>
              <div style={{ position: 'relative', borderRadius: 14, overflow: 'hidden', aspectRatio: '3/3.6' }}>
                <img loading="lazy" decoding="async" src="assets/shots/mirror.webp" alt="Reference" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover', objectPosition: 'center 12%',
                  filter: 'saturate(0.85)', opacity: on ? 1 : 0, transition: `opacity 0.6s ${SB_EASE}` }} />
                <span style={{ position: 'absolute', left: 9, bottom: 9, fontSize: 9, fontWeight: 700, letterSpacing: '0.06em', textTransform: 'uppercase', color: '#fff',
                  background: 'rgba(20,16,23,0.6)', backdropFilter: 'blur(6px)', borderRadius: 9999, padding: '3px 9px' }}>The reference</span>
              </div>
              <svg width="44" height="22" viewBox="0 0 40 20" style={{ justifySelf: 'center' }}>
                <line x1="2" y1="10" x2="32" y2="10" stroke="#813CED" strokeWidth="2" strokeDasharray="3 6" strokeLinecap="round" style={{ animation: 'sz-dash 1.2s linear infinite' }} />
                <path d="M30 4l8 6-8 6" fill="none" stroke="#813CED" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" />
              </svg>
              <div style={{ position: 'relative', borderRadius: 14, overflow: 'hidden', aspectRatio: '3/3.6' }}>
                <img loading="lazy" decoding="async" src="assets/create/out-mirror.webp" alt="Your Character" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover', objectPosition: 'center 16%',
                  opacity: on ? 1 : 0, filter: on ? 'none' : 'blur(12px)', transform: on ? 'scale(1)' : 'scale(1.04)',
                  transition: `opacity 0.7s ${SB_EASE} 350ms, filter 0.9s ${SB_EASE} 350ms, transform 1s ${SB_EASE} 350ms` }} />
                <span style={{ position: 'absolute', left: 9, bottom: 9, fontSize: 9, fontWeight: 700, letterSpacing: '0.06em', textTransform: 'uppercase', color: '#fff',
                  background: 'rgba(20,16,23,0.6)', backdropFilter: 'blur(6px)', borderRadius: 9999, padding: '3px 9px' }}>Your Character</span>
              </div>
            </div>
            <div style={{ display: 'flex', gap: 10, alignItems: 'center' }}>
              <span style={{ position: 'relative', width: 44, height: 44, borderRadius: 11, overflow: 'hidden', flexShrink: 0, boxShadow: 'inset 0 0 0 1px rgba(28,27,27,0.12)' }}>
                <img loading="lazy" decoding="async" src="assets/shots/mirror.webp" alt="" style={{ width: '100%', height: '100%', objectFit: 'cover', objectPosition: 'center 12%' }} />
                <span style={{ position: 'absolute', top: 2, right: 2, width: 14, height: 14, borderRadius: '50%', background: 'rgba(28,27,27,0.55)', display: 'grid', placeItems: 'center' }}>
                  <svg width="7" height="7" viewBox="0 0 16 16" fill="none"><path d="M4 4l8 8M12 4l-8 8" stroke="#fff" strokeWidth="2" strokeLinecap="round" /></svg>
                </span>
              </span>
              <div style={{ flex: 1, borderRadius: 12, background: 'rgb(235,231,231)', display: 'flex', alignItems: 'center', padding: '0 14px', height: 44, fontSize: 12.5, fontWeight: 500, color: INK }}>
                keep the pose, the framing and the light
              </div>
              <GenBtn active count={1} style={{ height: 44 }} />
            </div>
          </div>
        </Reveal>
      </div>
    </section>);
};

// ---------- § 03 — Formats & quality ----------
const CI_FMT = [
  { src: GENS[1].src, ar: '4 / 5', w: 300, chip: '4:5 · Feed' },
  { src: GENS[3].src, ar: '9 / 16', w: 236, chip: '9:16 · Stories & Reels' },
  { src: GENS[0].src, ar: '4 / 5', w: 300, chip: '1K · 2K · 4K', badge: '4K' }];

const FormatsSection = () => (
  <section style={{ background: CREAM, padding: '110px 56px' }}>
    <div style={{ maxWidth: 1140, margin: '0 auto', textAlign: 'center' }}>
      <Reveal delay={90}>
        <h2 style={{ font: '800 52px/1 var(--font-sans)', letterSpacing: '-0.03em', color: INK, margin: '0 0 18px' }}>
          Every format<br /><GradText>the feed asks for.</GradText>
        </h2>
      </Reveal>
      <Reveal delay={170}>
        <p style={{ fontSize: 17, lineHeight: 1.55, color: 'var(--text-secondary)', margin: '0 auto 46px', maxWidth: 520 }}>
          Portrait for the feed, tall for Stories — one to four photos per run, rendered up to 4K. Pick the shape before you generate, not in a crop tool after.
        </p>
      </Reveal>
      <div style={{ display: 'flex', justifyContent: 'center', alignItems: 'flex-end', gap: 22 }}>
        {CI_FMT.map((f, i) =>
          <Reveal key={i} delay={200 + i * 110} y={26}>
            <div style={{ width: f.w }}>
              <div style={{ position: 'relative', borderRadius: 16, overflow: 'hidden', aspectRatio: f.ar, boxShadow: '0 20px 40px rgba(28,27,27,0.12)' }}>
                <img loading="lazy" decoding="async" src={f.src} alt="" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover', objectPosition: 'center 14%' }} />
                {f.badge && <span style={{ position: 'absolute', top: 10, right: 10, fontSize: 10.5, fontWeight: 800, letterSpacing: '0.06em', color: '#fff',
                  background: PULSE, borderRadius: 9999, padding: '4px 11px', boxShadow: '0 6px 16px -2px rgba(104,19,212,0.5)' }}>{f.badge}</span>}
              </div>
              <div style={{ marginTop: 12, fontSize: 12, fontWeight: 700, color: 'rgba(28,27,27,0.6)', letterSpacing: '0.04em' }}>{f.chip}</div>
            </div>
          </Reveal>
        )}
      </div>
    </div>
  </section>
);

// ---------- § 05 — Where the image goes next ----------
const CI_NEXT = [
  { t: 'Photo Shoot', d: 'Pick the best photo — Sozee shoots a locked set of ten around it. Same outfit, same room.', kind: 'shoot', tag: 'Turn 1 into 10', href: '/#05 Photo Shoot' },
  { t: 'Create Video', d: 'Make it move — same scene, same outfit, with her voice on the track.', kind: 'video', tag: 'Direct the take', href: '/create-video' },
  { t: 'The Scheduler', d: 'Queue it to six platforms straight from the board. Posted while you make the next set.', kind: 'sched', tag: 'Queued · IG · 9:00', href: '/#11 Scheduler' }];

const PIPE_PANEL = { borderRadius: 12, background: '#fff', boxShadow: '0 10px 24px rgba(28,27,27,0.10), inset 0 0 0 1px rgba(28,27,27,0.08)', padding: 10, height: '100%', boxSizing: 'border-box', display: 'flex', flexDirection: 'column' };
const PIPE_ROWS = [
  { src: 'assets/gen/beach-pool.png', p: 'Instagram', time: '9:00 AM', st: 'Queued' },
  { src: 'assets/shoot/set-2.webp', p: 'TikTok', time: '12:30 PM', st: 'Queued' },
  { src: 'assets/create/out-garden.webp', p: 'OnlyFans', time: 'Yesterday', st: 'Posted' }];

const PipeMedia = ({ kind }) => (
  <div style={{ height: 210, background: 'rgb(246,243,242)', padding: '16px 16px 0', boxSizing: 'border-box' }}>
    {kind === 'shoot' &&
      <div style={{ ...PIPE_PANEL, borderRadius: '12px 12px 0 0' }}>
        <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: 8 }}>
          <span style={{ fontSize: 10.5, fontWeight: 700, color: INK }}>Lazy morning · set</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', whiteSpace: 'nowrap' }}>10 shots</span>
        </div>
        <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 6, flex: 1, minHeight: 0 }}>
          {[1, 2, 3, 4, 5, 6].map((n, i) =>
            <div key={n} style={{ position: 'relative', borderRadius: 7, overflow: 'hidden', boxShadow: i === 0 ? '0 0 0 2px var(--brand-purple-500)' : 'inset 0 0 0 1px rgba(28,27,27,0.08)' }}>
              <img loading="lazy" decoding="async" src={`assets/shoot/set-${n}.webp`} alt="" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover', objectPosition: 'center 20%' }} />
              {i === 0 && <span style={{ position: 'absolute', top: 3, left: 3, width: 12, height: 12, borderRadius: '50%', background: 'var(--brand-purple-500)', display: 'grid', placeItems: 'center' }}>
                <svg width="7" height="7" viewBox="0 0 16 16" fill="none"><path d="M3 8.5l3.2 3L13 5" stroke="#fff" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round" /></svg></span>}
            </div>
          )}
        </div>
      </div>}
    {kind === 'video' &&
      <div style={{ ...PIPE_PANEL, borderRadius: '12px 12px 0 0' }}>
        <div style={{ position: 'relative', flex: 1, minHeight: 0, borderRadius: 8, overflow: 'hidden', background: 'rgb(246,243,242)', marginBottom: 8 }}>
          <video src="assets/video/explore-1.mp4" autoPlay muted loop playsInline preload="metadata" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover', objectPosition: 'center 12%' }} />
          <span style={{ position: 'absolute', left: 7, bottom: 7, display: 'inline-flex', alignItems: 'center', gap: 4, fontSize: 8.5, fontWeight: 700, color: '#fff', background: 'rgba(28,27,27,0.55)', backdropFilter: 'blur(6px)', borderRadius: 9999, padding: '3px 8px' }}>
            <svg width="6" height="7" viewBox="0 0 8 10" fill="#fff"><path d="M0 0l8 5-8 5z" /></svg>0:08</span>
        </div>
        <div style={{ display: 'flex', gap: 7, alignItems: 'center' }}>
          <span style={{ flex: 1, borderRadius: 8, background: 'rgb(235,231,231)', padding: '7px 10px', fontSize: 9.5, fontWeight: 500, color: 'rgba(28,27,27,0.75)', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>make it move — same scene, same outfit</span>
          <span style={{ display: 'inline-flex', alignItems: 'center', gap: 4, borderRadius: 8, padding: '7px 11px', background: PULSE, color: '#fff', fontSize: 8.5, fontWeight: 800, letterSpacing: '0.05em' }}>GENERATE <span style={{ fontSize: 8 }}>✦</span></span>
        </div>
      </div>}
    {kind === 'sched' &&
      <div style={{ ...PIPE_PANEL, borderRadius: '12px 12px 0 0', gap: 6 }}>
        <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: 2 }}>
          <span style={{ fontSize: 10.5, fontWeight: 700, color: INK }}>This week</span>
          <span style={{ fontSize: 8.5, fontWeight: 700, color: 'rgba(28,27,27,0.5)' }}>Scarlett · 6 platforms</span>
        </div>
        {PIPE_ROWS.map((r) =>
          <div key={r.p} style={{ display: 'flex', alignItems: 'center', gap: 8, borderRadius: 9, background: 'rgb(250,247,247)', boxShadow: 'inset 0 0 0 1px rgba(28,27,27,0.07)', padding: '6px 8px', flex: 1, minHeight: 0 }}>
            <span style={{ width: 26, height: 26, borderRadius: 7, overflow: 'hidden', flexShrink: 0 }}>
              <img loading="lazy" decoding="async" src={r.src} alt="" style={{ width: '100%', height: '100%', objectFit: 'cover', objectPosition: 'center 20%' }} /></span>
            <span style={{ flex: 1, minWidth: 0 }}>
              <span style={{ display: 'block', fontSize: 9.5, fontWeight: 700, color: INK }}>{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>
);

const PipelineSection = () => (
  <section style={{ background: '#fff', padding: '110px 56px' }}>
    <div style={{ maxWidth: 1140, margin: '0 auto' }}>
      <div style={{ display: 'flex', alignItems: 'flex-end', justifyContent: 'space-between', gap: 40, flexWrap: 'wrap', marginBottom: 46 }}>
        <div style={{ maxWidth: 560 }}>
          <Reveal delay={90}>
            <h2 style={{ font: '800 52px/1 var(--font-sans)', letterSpacing: '-0.03em', color: INK, margin: '0 0 16px', textWrap: 'balance' }}>
              One image is<br /><GradText>just the start.</GradText>
            </h2>
          </Reveal>
          <Reveal delay={170}>
            <p style={{ fontSize: 17, lineHeight: 1.55, color: 'var(--text-secondary)', margin: 0 }}>
              Every photo lands on a board wired into the rest of the studio.
            </p>
          </Reveal>
        </div>
        <Reveal delay={240} style={{ paddingBottom: 8 }}>
          <a href="/" style={{ fontSize: 13.5, fontWeight: 600, color: 'var(--brand-purple-700)' }}>See the full tour →</a>
        </Reveal>
      </div>
      <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 18 }}>
        {CI_NEXT.map((c, i) =>
          <Reveal key={c.t} delay={i * 110} y={26}>
            <a href={c.href} style={{ display: 'block', borderRadius: 18, overflow: 'hidden', background: CREAM, boxShadow: 'inset 0 0 0 1px rgba(28,27,27,0.08)', color: 'inherit',
              transform: `rotate(${i === 1 ? 1 : -1}deg) perspective(1200px) rotateY(${i === 1 ? -2 : 2}deg)` }}>
              <PipeMedia kind={c.kind} />
              <div style={{ padding: '18px 20px 22px' }}>
                <div style={{ fontSize: 17, fontWeight: 700, letterSpacing: '-0.01em', color: INK, marginBottom: 7 }}>{c.t}</div>
                <div style={{ fontSize: 13.5, lineHeight: 1.5, color: 'var(--text-secondary)' }}>{c.d}</div>
              </div>
            </a>
          </Reveal>
        )}
      </div>
    </div>
  </section>
);

Object.assign(window, { RefToImageSection, FormatsSection, PipelineSection });
