/* global React, INK, CREAM, PULSE, GENS, GradText, Reveal, useReveal, SB_EASE, MShell, MHead */
// Shared across the Creators solutions pages: ONE way creators make brand money — brands stock
// products, you post one, you're paid on views. The three Brands pages sit underneath as
// "here's how the brand side works" links.
const { useState: cbS } = React;

const CB_COPY = {
  influencer: {
    h1: 'One more way', h2: 'to get paid.',
    lede: 'Brands put their products into Sozee and pay creators for the views those posts earn. Choose a product, make your content with it, post it — you get paid on how it performs.',
    mLede: 'Brands put products into Sozee and pay for the views your post earns.',
    d: ['Sponsored products sit right next to your own wardrobe, each with its rate per thousand views. Pick what fits your feed — no pitching, no media kit, no emails.',
      'Generate as normal. The product renders into your content pixel-consistent, in your setting, at your angle — nothing about your look changes.',
      'Queue it with the rest of your week. Payment releases automatically once the post verifies, and a post that overperforms just pays more.'] },
  micro: {
    h1: 'Brand money', h2: 'before the follower count.',
    lede: 'You don’t need a big following to get paid. Brands put products into Sozee and pay for views, not audience size — so a small account making good content can start earning now.',
    mLede: 'Brands pay for views, not audience size — so a small account can start earning now.',
    d: ['The sponsored shelf is open to every creator. Nobody has to say yes to you first — the rate is posted and the same for everyone.',
      'Generate the set like any other post. The product lands in frame correctly, so your first sponsored shoot looks like your best one.',
      'Schedule it, post it, get paid per thousand views. Your first paid post can be your first good post.'] },
  ai: {
    h1: 'They post.', h2: 'You get paid.',
    lede: 'A character with an audience earns like a creator. Brands put products into Sozee and pay for views — so your characters can carry paid placements without a single shoot.',
    mLede: 'Brands pay for views — your characters carry paid placements without a shoot.',
    d: ['Pick a sponsored product from the library and assign it to whichever character fits the brand.',
      'It renders into their next set, pixel-consistent across every photo — identity lock holds, the product stays exact.',
      'Queue across characters and earn per thousand views. More personas posting means more inventory earning.'] },
  agency: {
    h1: 'A revenue line', h2: 'your roster isn’t billing yet.',
    lede: 'Brands put their products into Sozee and pay for the views each post earns. Every creator you manage can take paid placements — nothing to broker, and it lands in the same dashboard as their other numbers.',
    mLede: 'Brands pay for the views each post earns — paid placements for every creator you manage.',
    d: ['One sponsored library, your whole roster. Assign a product across creators in a single pass instead of brokering deals one by one.',
      'Each creator generates it on their own locked model, so the product is consistent and every creator still looks like themselves.',
      'Queue it from the same board and earn per thousand views — your highest performers earn proportionally, and it lands in one report.'] },
};

// the brand-side pages — the other half of this deal
const CB_BRAND_PAGES = [
  { t: 'UGC Campaigns', tag: 'Soon', href: '/ugc-campaigns', d: 'Brands run whole campaigns across the network' },
  { t: 'Brand Portal', tag: 'Soon', href: '/brand-portal', d: 'Where products and view rates get set' },
  { t: 'White Label', tag: 'Beta', href: '/white-label', d: 'Enterprise programs that cover your seat' },
];

const CBTag = ({ label, compact = false }) => {
  const beta = label === 'Beta';
  return <span style={{ borderRadius: 9999, padding: compact ? '2px 6px' : '2px 7px', fontSize: compact ? 7.5 : 8.5, fontWeight: 800, letterSpacing: '0.04em', textTransform: 'uppercase', whiteSpace: 'nowrap', flexShrink: 0,
    color: beta ? '#15803D' : 'var(--brand-purple-700)',
    background: beta ? 'rgba(34,197,94,0.12)' : 'var(--brand-purple-50)',
    boxShadow: `inset 0 0 0 1px ${beta ? 'rgba(34,197,94,0.3)' : 'var(--brand-purple-200)'}` }}>{label}</span>;
};

// ---------- step 1: pick a product out of the brand library ----------
const CBLibrary = ({ h = 176 }) => {
  const [on, setOn] = cbS(false);
  return (
    <div style={{ height: h, background: 'rgb(246,243,242)', padding: '14px 14px 0', boxSizing: 'border-box' }}>
      <div style={{ borderRadius: '12px 12px 0 0', background: '#fff', boxShadow: '0 10px 24px rgba(28,27,27,0.10), inset 0 0 0 1px rgba(28,27,27,0.08)', padding: 11, height: '100%', boxSizing: 'border-box', display: 'flex', flexDirection: 'column', gap: 8 }}>
        <div style={{ display: 'flex', alignItems: 'baseline', justifyContent: 'space-between' }}>
          <span style={{ fontSize: 10.5, fontWeight: 700, color: INK }}>Brand library</span>
          <span style={{ fontSize: 8.5, fontWeight: 700, color: 'rgba(28,27,27,0.45)' }}>412 products</span>
        </div>
        <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 6, flex: 1, minHeight: 0 }}>
          {[['assets/control/collar-silver.png', '$3.00', true], ['assets/garments/top-velvet-emerald.webp', '$2.50'], ['assets/garments/shoe-stiletto-gold.webp', '$4.00']].map(([src, rate, sel], i) =>
            <span key={i} style={{ position: 'relative', borderRadius: 8, overflow: 'hidden', background: '#fff',
              boxShadow: sel ? '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: 'contain', padding: 6, boxSizing: 'border-box' }} />
              <span style={{ position: 'absolute', left: 3, bottom: 3, fontSize: 7, fontWeight: 800, color: sel ? 'var(--brand-purple-700)' : 'rgba(28,27,27,0.5)' }}>{rate}<span style={{ fontWeight: 600 }}>/1k</span></span>
              {sel && <span style={{ position: 'absolute', top: 3, right: 3, width: 11, height: 11, borderRadius: '50%', background: 'var(--brand-purple-600)', display: 'grid', placeItems: 'center', fontSize: 6.5, fontWeight: 800, color: '#fff' }}>✓</span>}
            </span>)}
        </div>
        <span onClick={() => setOn(true)} style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', borderRadius: 8, padding: '7px 0', cursor: 'pointer', transition: `all 0.25s ${SB_EASE}`,
          background: on ? 'rgba(34,197,94,0.12)' : PULSE, color: on ? '#15803D' : '#fff', fontSize: 8.5, fontWeight: 800, letterSpacing: '0.05em',
          boxShadow: on ? 'inset 0 0 0 1px rgba(34,197,94,0.3)' : '0 6px 16px -4px rgba(104,19,212,0.4)' }}>
          {on ? '✓ ADDED TO YOUR NEXT SET' : 'ADD TO YOUR NEXT SET'}</span>
      </div>
    </div>);
};

// ---------- step 2: generate with the product in frame ----------
const CBGenerate = ({ h = 176 }) => {
  const [ref, on] = useReveal(0.35);
  return (
    <div style={{ height: h, background: 'rgb(246,243,242)', padding: '14px 14px 0', boxSizing: 'border-box' }}>
      <div ref={ref} style={{ borderRadius: '12px 12px 0 0', background: '#fff', boxShadow: '0 10px 24px rgba(28,27,27,0.10), inset 0 0 0 1px rgba(28,27,27,0.08)', padding: 11, height: '100%', boxSizing: 'border-box', display: 'flex', flexDirection: 'column', gap: 8 }}>
        <div style={{ display: 'flex', alignItems: 'center', gap: 7 }}>
          <span style={{ width: 22, height: 22, borderRadius: 7, overflow: 'hidden', flexShrink: 0, background: '#fff', boxShadow: 'inset 0 0 0 1.5px var(--brand-purple-400)', position: 'relative' }}>
            <img loading="lazy" decoding="async" src="assets/control/collar-silver.png" alt="" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'contain', padding: 3, boxSizing: 'border-box' }} />
          </span>
          <span style={{ flex: 1, minWidth: 0, fontSize: 9, fontWeight: 600, color: INK, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>rooftop at golden hour, collar in frame</span>
          <span style={{ fontSize: 7.5, fontWeight: 800, letterSpacing: '0.05em', color: 'var(--brand-purple-700)', background: 'var(--brand-purple-50)', boxShadow: 'inset 0 0 0 1px var(--brand-purple-200)', borderRadius: 9999, padding: '2px 7px', flexShrink: 0 }}>LOCKED</span>
        </div>
        <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 6, flex: 1, minHeight: 0 }}>
          {['assets/shoot/brand-deal-1.webp', 'assets/shoot/brand-deal-2.webp', 'assets/shoot/brand-deal-3.webp'].map((src, i) =>
            <span key={src} style={{ position: 'relative', borderRadius: 8, overflow: 'hidden', background: 'rgb(240,236,235)' }}>
              <img loading="lazy" decoding="async" src={src} alt="" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover', objectPosition: 'center 16%',
                opacity: on ? 1 : 0, filter: on ? 'none' : 'blur(10px)', transition: `opacity 0.6s ${SB_EASE} ${200 + i * 130}ms, filter 0.8s ${SB_EASE} ${200 + i * 130}ms` }} />
            </span>)}
        </div>
        <span style={{ display: 'flex', alignItems: 'center', gap: 5, borderRadius: 8, background: 'rgb(250,247,247)', boxShadow: 'inset 0 0 0 1px rgba(28,27,27,0.07)', padding: '6px 9px' }}>
          <span style={{ width: 5, height: 5, borderRadius: '50%', background: 'var(--brand-purple-500)', flexShrink: 0 }} />
          <span style={{ fontSize: 8, fontWeight: 600, color: 'rgba(28,27,27,0.6)' }}>Your look, your setting — the product stays exact.</span>
        </span>
      </div>
    </div>);
};

// ---------- step 3: schedule, post, earn ----------
const CBEarnings = ({ h = 176 }) => {
  const [ref, on] = useReveal(0.35);
  return (
    <div style={{ height: h, background: 'rgb(246,243,242)', padding: '14px 14px 0', boxSizing: 'border-box' }}>
      <div ref={ref} style={{ borderRadius: '12px 12px 0 0', background: '#fff', boxShadow: '0 10px 24px rgba(28,27,27,0.10), inset 0 0 0 1px rgba(28,27,27,0.08)', padding: 11, height: '100%', boxSizing: 'border-box', display: 'flex', flexDirection: 'column', gap: 8 }}>
        <div style={{ display: 'flex', alignItems: 'baseline', justifyContent: 'space-between' }}>
          <span style={{ fontSize: 10.5, fontWeight: 700, color: INK }}>Queued · posted Tue 9:00 PM</span>
          <span style={{ fontSize: 8.5, fontWeight: 700, color: 'rgba(28,27,27,0.45)' }}>$3.00 / 1k views</span>
        </div>
        <div style={{ display: 'flex', flexDirection: 'column', gap: 6, flex: 1, minHeight: 0, justifyContent: 'center' }}>
          {[['Views', 100, '184k'], ['Earned', 62, '$552']].map(([l, w, v], i) =>
            <span key={l} style={{ display: 'grid', gridTemplateColumns: '42px 1fr 40px', alignItems: 'center', gap: 7 }}>
              <span style={{ fontSize: 8.5, fontWeight: 600, color: 'var(--text-secondary)' }}>{l}</span>
              <span style={{ height: 14, borderRadius: 5, background: 'rgb(240,236,235)', overflow: 'hidden' }}>
                <span style={{ display: 'block', height: '100%', borderRadius: 5, background: PULSE, width: on ? `${w}%` : '3%', transition: `width 0.9s ${SB_EASE} ${i * 140}ms` }} /></span>
              <span style={{ fontSize: 9, fontWeight: 800, color: INK, textAlign: 'right', fontVariantNumeric: 'tabular-nums' }}>{v}</span>
            </span>)}
        </div>
        <span style={{ display: 'flex', alignItems: 'center', gap: 5, borderRadius: 8, background: 'rgb(250,247,247)', boxShadow: 'inset 0 0 0 1px rgba(28,27,27,0.07)', padding: '6px 9px' }}>
          <span style={{ width: 5, height: 5, borderRadius: '50%', background: '#22C55E', flexShrink: 0 }} />
          <span style={{ fontSize: 8, fontWeight: 600, color: 'rgba(28,27,27,0.6)' }}>Paid automatically once the post verifies.</span>
        </span>
      </div>
    </div>);
};

// ---------- desktop ----------
const BrandDealsSection = ({ bg = '#fff', audience = 'influencer' }) => {
  const c = CB_COPY[audience] || CB_COPY.influencer;
  const cardBg = bg === '#fff' ? CREAM : '#fff';
  const steps = [['Select a sponsored product from the outfit library', c.d[0], <CBLibrary key="l" />],
    ['Generate content in the promoted product', c.d[1], <CBGenerate key="g" />],
    ['Schedule, post it, and earn', c.d[2], <CBEarnings key="e" />]];
  return (
    <section style={{ background: bg, padding: '110px 56px' }}>
      <div style={{ maxWidth: 1140, margin: '0 auto' }}>
        <div style={{ textAlign: 'center', marginBottom: 46 }}>
          <Reveal>
            <div style={{ display: 'inline-flex', alignItems: 'center', gap: 8, marginBottom: 18, borderRadius: 9999, padding: '7px 14px', background: 'var(--brand-purple-50)', boxShadow: 'inset 0 0 0 1px var(--brand-purple-200)' }}>
              <span style={{ width: 7, height: 7, borderRadius: '50%', background: 'var(--brand-purple-500)' }} />
              <span style={{ fontSize: 11.5, fontWeight: 800, letterSpacing: '0.08em', textTransform: 'uppercase', color: 'var(--brand-purple-700)' }}>Coming soon</span>
            </div>
          </Reveal>
          <Reveal delay={90}>
            <h2 style={{ font: '800 52px/1 var(--font-sans)', letterSpacing: '-0.03em', color: INK, margin: '0 0 18px', textWrap: 'balance' }}>
              {c.h1}<br /><GradText>{c.h2}</GradText>
            </h2>
          </Reveal>
          <Reveal delay={170}>
            <p style={{ fontSize: 17, lineHeight: 1.55, color: 'var(--text-secondary)', margin: '0 auto', maxWidth: 560 }}>{c.lede}</p>
          </Reveal>
        </div>
        <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 16 }}>
          {steps.map(([t, d, media], i) =>
            <Reveal key={t} delay={i * 110} y={24}>
              <div style={{ borderRadius: 18, overflow: 'hidden', background: cardBg, boxShadow: 'inset 0 0 0 1px rgba(28,27,27,0.08)',
                transform: `rotate(${i % 2 ? 1 : -1}deg) perspective(1300px) rotateY(${i % 2 ? -2 : 2}deg)` }}>
                {media}
                <div style={{ padding: '18px 20px 22px' }}>
                  <div style={{ display: 'flex', alignItems: 'flex-start', gap: 9, marginBottom: 7 }}>
                    <span style={{ width: 21, height: 21, borderRadius: '50%', background: PULSE, display: 'grid', placeItems: 'center', fontSize: 9.5, fontWeight: 800, color: '#fff', flexShrink: 0, marginTop: 1 }}>{i + 1}</span>
                    <span style={{ fontSize: 15.5, fontWeight: 700, letterSpacing: '-0.01em', lineHeight: 1.25, color: INK }}>{t}</span>
                  </div>
                  <div style={{ fontSize: 12.5, lineHeight: 1.5, color: 'var(--text-secondary)' }}>{d}</div>
                </div>
              </div>
            </Reveal>)}
        </div>
        <Reveal delay={340} y={18}>
          <div style={{ marginTop: 18, borderRadius: 16, background: cardBg, boxShadow: 'inset 0 0 0 1px rgba(28,27,27,0.08)', padding: '20px 22px', display: 'grid', gridTemplateColumns: 'minmax(130px, 190px) minmax(0, 1fr)', gap: 22, alignItems: 'center' }}>
            <div>
              <div style={{ fontSize: 10, fontWeight: 800, letterSpacing: '0.1em', textTransform: 'uppercase', color: 'var(--brand-purple-700)', marginBottom: 5 }}>For brands</div>
              <div style={{ fontSize: 12.5, lineHeight: 1.45, color: 'var(--text-secondary)' }}>How the other side of this works</div>
            </div>
            <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(175px, 1fr))', gap: 10 }}>
              {CB_BRAND_PAGES.map(p =>
                <a key={p.t} href={p.href} style={{ display: 'block', borderRadius: 12, background: bg === '#fff' ? '#fff' : CREAM, boxShadow: 'inset 0 0 0 1px rgba(28,27,27,0.09)', padding: '12px 14px', color: 'inherit' }}>
                  <span style={{ display: 'flex', alignItems: 'center', gap: 7, marginBottom: 3 }}>
                    <span style={{ fontSize: 13, fontWeight: 700, letterSpacing: '-0.01em', color: INK, whiteSpace: 'nowrap', flexShrink: 0 }}>{p.t}</span>
                    <CBTag label={p.tag} />
                    <svg width="10" height="10" viewBox="0 0 16 16" fill="none" style={{ opacity: 0.4, marginLeft: 'auto', flexShrink: 0 }}><path d="M4 12L12 4M6.5 4H12v5.5" stroke={INK} strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" /></svg>
                  </span>
                  <span style={{ display: 'block', fontSize: 11, lineHeight: 1.45, color: 'var(--text-tertiary)' }}>{p.d}</span>
                </a>)}
            </div>
          </div>
        </Reveal>
      </div>
    </section>);
};

// ---------- mobile ----------
const MBrandDealsSection = ({ bg = '#fff', audience = 'influencer' }) => {
  const c = CB_COPY[audience] || CB_COPY.influencer;
  const cardBg = bg === '#fff' ? CREAM : '#fff';
  const steps = [['Select a sponsored product from the outfit library', c.d[0], <CBLibrary key="l" h={168} />],
    ['Generate content in the promoted product', c.d[1], <CBGenerate key="g" h={168} />],
    ['Schedule, post it, and earn', c.d[2], <CBEarnings key="e" h={168} />]];
  return (
    <MShell bg={bg}>
      <Reveal style={{ textAlign: 'center' }}>
        <div style={{ display: 'inline-flex', alignItems: 'center', gap: 6, marginBottom: 14, borderRadius: 9999, padding: '5px 11px', background: 'var(--brand-purple-50)', boxShadow: 'inset 0 0 0 1px var(--brand-purple-200)' }}>
          <span style={{ width: 6, height: 6, borderRadius: '50%', background: 'var(--brand-purple-500)' }} />
          <span style={{ fontSize: 10, fontWeight: 800, letterSpacing: '0.08em', textTransform: 'uppercase', color: 'var(--brand-purple-700)' }}>Coming soon</span>
        </div>
      </Reveal>
      <MHead title={<span>{c.h1}<br /><GradText>{c.h2}</GradText></span>} sub={c.mLede} />
      <div style={{ display: 'flex', flexDirection: 'column', gap: 12, marginTop: 26 }}>
        {steps.map(([t, d, media], i) =>
          <Reveal key={t} delay={i * 100} y={20}>
            <div style={{ borderRadius: 15, overflow: 'hidden', background: cardBg, boxShadow: 'inset 0 0 0 1px rgba(28,27,27,0.08)', textAlign: 'left',
              transform: `rotate(${i % 2 ? 0.9 : -0.9}deg)` }}>
              {media}
              <div style={{ padding: '14px 15px 16px' }}>
                <div style={{ display: 'flex', alignItems: 'flex-start', gap: 7, marginBottom: 5 }}>
                  <span style={{ width: 18, height: 18, borderRadius: '50%', background: PULSE, display: 'grid', placeItems: 'center', fontSize: 8.5, fontWeight: 800, color: '#fff', flexShrink: 0, marginTop: 1 }}>{i + 1}</span>
                  <span style={{ fontSize: 13, fontWeight: 700, letterSpacing: '-0.01em', lineHeight: 1.3, color: INK }}>{t}</span>
                </div>
                <div style={{ fontSize: 11.5, lineHeight: 1.5, color: 'var(--text-secondary)' }}>{d}</div>
              </div>
            </div>
          </Reveal>)}
      </div>
      <Reveal delay={320} y={16}>
        <div style={{ marginTop: 14, borderRadius: 14, background: cardBg, boxShadow: 'inset 0 0 0 1px rgba(28,27,27,0.08)', padding: '14px 13px', textAlign: 'left' }}>
          <div style={{ fontSize: 9, fontWeight: 800, letterSpacing: '0.1em', textTransform: 'uppercase', color: 'var(--brand-purple-700)', marginBottom: 9 }}>For brands</div>
          <div style={{ display: 'flex', flexDirection: 'column', gap: 6 }}>
            {CB_BRAND_PAGES.map(p =>
              <a key={p.t} href={p.href} style={{ display: 'flex', alignItems: 'center', gap: 7, borderRadius: 10, background: bg === '#fff' ? '#fff' : CREAM, boxShadow: 'inset 0 0 0 1px rgba(28,27,27,0.09)', padding: '9px 11px', color: 'inherit' }}>
                <span style={{ fontSize: 11.5, fontWeight: 700, color: INK, whiteSpace: 'nowrap', flexShrink: 0 }}>{p.t}</span>
                <CBTag label={p.tag} compact />
                <span style={{ marginLeft: 'auto', fontSize: 12, fontWeight: 700, color: 'var(--brand-purple-700)', flexShrink: 0 }}>→</span>
              </a>)}
          </div>
        </div>
      </Reveal>
    </MShell>);
};

Object.assign(window, { BrandDealsSection, MBrandDealsSection, CB_BRAND_PAGES });
