// The Examples page, organised by what a customer wants to DO, not by tool name.
// ExGoalNav replaces the old 13-line contents list with six plain goals; ExGoal
// is the header band that opens each group and says, in one row, what you bring,
// what you get back and what it uses. The chapters underneath are unchanged.

const EX_GOALS = [
  { id: 'goal-product', card: 'Put my product in a photo', cta: 'Put your own product in a real photo.', n: '01', want: 'Put my product in a real photo', line: 'Upload your product. Get it in a real photograph.', tool: 'Product placement',
    bring: 'One photo of your product', get: 'Your product in a real photograph from our library, or your own', uses: '100 credits an image',
    img: 'assets/g-face-wash.jpg' },
  { id: 'goal-clothing', card: 'Show clothing on a model', cta: 'See your clothing on a model.', n: '02', want: 'Show my clothing on a model', line: 'Upload an outfit. See it worn, on one model or six.', tool: 'Campaigns',
    bring: 'A photo of a garment or a full outfit', get: 'It worn by a model you choose: one shot, six body shapes, or fifty outfits in a run', uses: '100 credits an image',
    img: 'assets/everybody/cs-blue-2.jpg', pos: 'center bottom' },
  { id: 'goal-model', card: 'Change the model', cta: 'Cast your own model.', n: '03', want: 'Change the model in a photo', line: 'Pick a library photo. Swap in the model you want.', tool: 'Model swap',
    bring: 'Any photo from the library', get: 'The same scene and light, with one of 200+ models, or your own', uses: '100 credits an image',
    img: 'assets/g-beverly-hills.jpg' },
  { id: 'goal-more', card: 'Turn one image into a set', cta: 'Turn one image into a set.', n: '04', want: 'Turn one image into a set', line: 'Start with one image. Get new angles and close-ups.', tool: 'Presets',
    bring: 'One image, yours or ours', get: 'New angles, crops, close-ups and moments that read as the same shoot', uses: '100 credits an image',
    img: 'assets/g-cowgirl-guitar.jpg' },
  { id: 'goal-finish', card: 'Make it look less like AI', cta: 'Give your images a film finish.', n: '05', want: 'Make it look less like AI', line: 'Tap a film look. 86 to choose from, all free.', tool: 'Film finish',
    bring: 'Any image you have made', get: 'The same image in one of 86 film looks, grains, light leaks and textures', uses: 'Free',
    img: 'assets/filmfinish/goldenhour.jpg' },
  { id: 'goal-motion', card: 'Add motion and music', cta: 'Add motion and music.', n: '06', want: 'Add motion and music', line: 'Turn stills into a short reel, with music to match.', tool: 'Video and Sound Studio',
    bring: 'One to three still images, or a mood', get: 'A short moving reel, and original music to go under it', uses: 'From 150 credits a clip',
    img: 'assets/video-still.jpg' },
];

// The pages set <base href="/landing/">, so a bare "#id" link would leave the page and 404.
// Anchor links have to carry the current path.
const exGoalHref = (id) => `${window.location.pathname}${window.location.search}#${id}`;

// Jump straight there. A smooth scroll over a page this long gets cut short when
// images load on the way down and move everything, so it can look like nothing happened.
function exGoalJump(e, id) {
  const el = document.getElementById(id);
  if (!el) return;
  e.preventDefault();
  const go = () => window.scrollTo(0, el.getBoundingClientRect().top + window.scrollY - 70);
  go();
  // once more after late images have settled
  setTimeout(go, 350);
  try { history.replaceState(null, '', exGoalHref(id)); } catch (err) {}
}

function ExGoalNav() {
  return (
    <section className="ps-section" data-mobile-pad="true" style={{ background: 'var(--cream)', padding: '96px 48px 72px' }}>
      <div style={{ maxWidth: 1320, margin: '0 auto' }}>
        <div style={{ fontFamily: '"La Villa", sans-serif', fontSize: 11, letterSpacing: '0.28em', textTransform: 'uppercase', color: 'var(--fg-2)', marginBottom: 18 }}>Start here</div>
        <h2 className="celestial" style={{ fontSize: 'clamp(38px,4.6vw,72px)', color: 'var(--cocoa)', margin: '0 0 44px' }}>What do you want to make?</h2>
        <div className="ex-goal-grid">
          {EX_GOALS.map((g) => (
            <a key={g.id} href={exGoalHref(g.id)} className="ex-goal-card" onClick={(e) => exGoalJump(e, g.id)}>
              <span className="ex-goal-thumb"><img src={g.img} alt="" loading="lazy" style={g.pos ? { objectPosition: g.pos } : undefined} /></span>
              <span style={{ display: 'block', fontFamily: '"La Villa", sans-serif', fontSize: 10.5, letterSpacing: '0.22em', color: 'var(--fg-2)', marginTop: 14 }}>{g.n}</span>
              <span className="ex-goal-card-t">{g.card}</span>
            </a>
          ))}
        </div>
      </div>
      <style>{`
        .ex-goal-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 18px; }
        .ex-goal-card { display: block; text-decoration: none; }
        .ex-goal-card-t { display: block; margin-top: 6px; font-family: "La Villa", sans-serif; font-size: 11.5px; letter-spacing: 0.07em; text-transform: uppercase; color: var(--cocoa); white-space: nowrap; }
        .ex-goal-thumb { display: block; aspect-ratio: 4 / 5; overflow: hidden; background: var(--cream-deep); }
        .ex-goal-thumb img { width: 100%; height: 100%; object-fit: cover; object-position: center top; display: block; transition: transform 500ms ease; }
        .ex-goal-card:hover .ex-goal-thumb img { transform: scale(1.03); }
        @media (max-width: 1100px) { .ex-goal-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 26px 14px; } }
        @media (max-width: 620px) { .ex-goal-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px 12px; } }
      `}</style>
    </section>
  );
}

// The header for each group: a big outlined numeral and the goal in plain type,
// so the six groups read as six separate parts and not one long scroll.
function ExGoal({ id }) {
  const g = EX_GOALS.find((x) => x.id === id);
  if (!g) return null;
  return (
    <section id={g.id} className="ps-section ex-goal-band" data-mobile-pad="true">
      <div className="ex-goal-band-in">
        <div className="ex-goal-num">{g.n}</div>
        <h2 className="ex-goal-h">{g.want}</h2>
        <p className="ex-goal-line">{g.line}</p>
        <div className="ex-goal-uses">{g.uses}</div>
      </div>
    </section>
  );
}

// A call to action that closes each group.
function ExGoalCTA({ id }) {
  const g = EX_GOALS.find((x) => x.id === id);
  if (!g) return null;
  return (
    <section className="ps-section ex-goal-cta" data-mobile-pad="true">
      <div className="ex-goal-cta-in">
        <div>
          <div className="ex-goal-cta-h">{g.cta}</div>
        </div>
        <div className="ex-goal-cta-btns">
          <a href="/dashboard/product-studio" className="ex-btn ex-btn-solid">Open the Studio <span aria-hidden="true">&rarr;</span></a>
          <a href="/free-try" className="ex-btn">Try it free</a>
        </div>
      </div>
    </section>
  );
}

// Floating "back to the top" button, shown once you are well down the page.
function ExBackToTop() {
  const [show, setShow] = React.useState(false);
  React.useEffect(() => {
    const onScroll = () => setShow(window.scrollY > 1400);
    onScroll();
    window.addEventListener('scroll', onScroll, { passive: true });
    return () => window.removeEventListener('scroll', onScroll);
  }, []);
  return (
    <button type="button" className="ex-top" aria-label="Back to the top" title="Back to the top"
      onClick={() => window.scrollTo({ top: 0, behavior: 'smooth' })}
      style={{ opacity: show ? 1 : 0, pointerEvents: show ? 'auto' : 'none', transform: show ? 'none' : 'translateY(8px)' }}>
      <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"><path d="M12 19V5M5 12l7-7 7 7" /></svg>
    </button>
  );
}

function ExGuideStyles() {
  return (
    <style>{`
      /* group header: a big outlined numeral, the goal, one sentence and what it uses, between two hairlines */
      .ex-goal-band { background: #161412; padding: 84px 48px 30px; border-top: 1px solid rgba(242,236,228,0.16); scroll-margin-top: 70px; }
      .ex-goal-band-in { max-width: 1320px; margin: 0 auto; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 6px 34px; align-items: end; padding-bottom: 28px; border-bottom: 1px solid rgba(242,236,228,0.16); }
      .ex-goal-num { grid-row: 1 / 3; font-family: "La Villa", sans-serif; font-size: clamp(90px, 11vw, 168px); line-height: 0.78; letter-spacing: -0.03em; color: transparent; -webkit-text-stroke: 1px rgba(242,236,228,0.55); }
      .ex-goal-h { grid-column: 2; align-self: end; font-family: "La Villa", sans-serif; font-weight: 400; font-size: clamp(28px, 3.2vw, 46px); line-height: 1.12; letter-spacing: -0.01em; color: #F2ECE4; margin: 0; }
      .ex-goal-line { grid-column: 2; font-family: "La Villa", sans-serif; font-size: 15px; line-height: 1.4; color: rgba(242,236,228,0.72); margin: 0; }
      .ex-goal-uses { grid-column: 3; grid-row: 1 / 3; align-self: end; font-family: "La Villa", sans-serif; font-size: 11px; letter-spacing: 0.18em; text-transform: uppercase; color: #F2ECE4; padding: 8px 14px; border: 1px solid rgba(242,236,228,0.4); border-radius: 999px; white-space: nowrap; }

      /* group closer */
      .ex-goal-cta { background: #161412; padding: 64px 48px; }
      #film-finish, #reel, #bulk-reel, #model-swap { padding-top: 84px !important; padding-bottom: 84px !important; }
      .ex-goal-cta-in { max-width: 1320px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 28px; flex-wrap: wrap; padding: 30px 34px; border: 1px solid rgba(242,236,228,0.2); background: #1E1A17; }
      .ex-goal-cta-h { font-family: "La Villa", sans-serif; font-size: 22px; color: #F2ECE4; }
      .ex-goal-cta-sub { font-family: "La Villa", sans-serif; font-size: 13.5px; color: rgba(242,236,228,0.65); margin-top: 6px; }
      .ex-goal-cta-btns { display: flex; gap: 10px; flex-wrap: wrap; }
      .ex-btn { display: inline-flex; align-items: center; gap: 10px; padding: 14px 22px; font-family: "La Villa", sans-serif; font-size: 11px; letter-spacing: 0.2em; text-transform: uppercase; text-decoration: none; border-radius: 999px; white-space: nowrap; color: #F2ECE4; border: 1px solid rgba(242,236,228,0.4); }
      .ex-btn-solid { background: #F2ECE4; color: #161412; border-color: #F2ECE4; }

      /* less to read: in each chapter keep the heading and the pictures, drop the small print */
      .ex-chapter, .ex-kicker, .ex-eyebrow, .ex-note { display: none !important; }
      .ex-section .ex-section-head { grid-template-columns: minmax(0, 1fr) !important; }

      /* quieter chapter headings: the display font is kept for the page title only */
      .ex-section { padding-top: 84px !important; padding-bottom: 84px !important; }
      .ex-section .ex-section-head { margin-bottom: 48px !important; }
      .ex-section h2.celestial { font-family: "La Villa", sans-serif !important; text-transform: none !important; font-size: clamp(28px, 3vw, 44px) !important; line-height: 1.1 !important; letter-spacing: -0.01em !important; }

      /* the sections borrowed from the homepage follow the same rules as the chapters */
      #reel h2, #bulk-reel h2, #model-swap h2, #film-finish h2 { font-family: "La Villa", sans-serif !important; text-transform: none !important; font-size: clamp(28px, 3vw, 44px) !important; line-height: 1.1 !important; letter-spacing: -0.01em !important; }
      #reel h2 * { font-size: inherit !important; font-family: inherit !important; }
      #reel > div:first-of-type .eyebrow, #reel > div:first-of-type p, #bulk-reel .eyebrow, #model-swap .eyebrow, #film-finish .eyebrow { display: none !important; }
      #reel > div:first-of-type { margin-bottom: 40px !important; }

      /* one background for everything between the cream bands, so the bands are the only thing that changes */
      .ex-section, #reel, #bulk-reel, #model-swap, #film-finish, #sound { background: #161412 !important; }
      .ex-section + .ex-section, .ex-section + #bulk-reel, .ex-section + #model-swap, #bulk-reel + .ex-section, #model-swap + .ex-section, #reel + .ex-section { border-top: 1px solid rgba(242,236,228,0.1); }
      .ex-ing-num { visibility: hidden; }

      /* "A preset for every look" is built by hand, not from the shared chapter block: bring it into line */
      #ai-recipes { background: #161412 !important; padding-top: 84px !important; padding-bottom: 84px !important; border-top: 1px solid rgba(242,236,228,0.1); --cream: #161412; --cocoa: #F2ECE4; --fg-2: rgba(242,236,228,0.72); }
      #ai-recipes h2.celestial { font-family: "La Villa", sans-serif !important; text-transform: none !important; font-size: clamp(28px, 3vw, 44px) !important; line-height: 1.1 !important; letter-spacing: -0.01em !important; color: #F2ECE4 !important; }
      #ai-recipes > div > div:first-child > div:first-child, #ai-recipes > div > div:first-child > p { display: none !important; }

      /* back to top */
      .ex-top { position: fixed; right: 22px; bottom: 22px; z-index: 60; width: 46px; height: 46px; border-radius: 999px; display: grid; place-items: center; background: #F2ECE4; color: #161412; border: 0; cursor: pointer; box-shadow: 0 8px 24px rgba(0,0,0,0.4); transition: opacity 200ms ease, transform 200ms ease; }

      @media (max-width: 980px) {
        .ex-goal-band { padding: 52px 20px 20px; }
        .ex-goal-band-in { grid-template-columns: auto minmax(0, 1fr); gap: 8px 18px; }
        .ex-goal-num { font-size: 76px; grid-row: 1; }
        .ex-goal-line, .ex-goal-uses { grid-column: 1 / -1; grid-row: auto; justify-self: start; }
        .ex-goal-cta { padding: 40px 20px; }
        #film-finish, #reel, #bulk-reel, #model-swap { padding-top: 56px !important; padding-bottom: 56px !important; }
        .ex-goal-cta-in { padding: 24px 20px; }
        .ex-section { padding-top: 56px !important; padding-bottom: 56px !important; }
        .ex-top { right: 14px; bottom: 84px; }
      }
    `}</style>
  );
}

Object.assign(window, { ExGoalNav, ExGoal, ExGoalCTA, ExBackToTop, ExGuideStyles, EX_GOALS, exGoalHref });
