/* App entry point — composes sections into the full page. */

const DEFAULTS = /*EDITMODE-BEGIN*/{
  "headlineVariation": "primary",
  "billingDefault": "monthly",
  "accentHue": 244,
  "showRolesMarquee": true,
  "showCalcDeepDive": true,
  "heroFragmentsRotation": "default"
}/*EDITMODE-END*/;

const HEADLINES = {
  primary:    "Stop chasing\nyour money.",
  secondary:  "The set companion\nfor film freelancers.",
  payroll:    "Wrap the day.\nNot the math.",
};

function App() {
  const [tweaks, setTweak] = useTweaks(DEFAULTS);

  // Apply accent hue to CSS vars, live
  React.useEffect(() => {
    const h = tweaks.accentHue;
    document.documentElement.style.setProperty('--sa-accent',    `hsl(${h}, 76%, 64%)`);
    document.documentElement.style.setProperty('--sa-accent-hi', `hsl(${h}, 86%, 72%)`);
    document.documentElement.style.setProperty('--sa-accent-2',  `hsl(${h}, 96%, 82%)`);
    document.documentElement.style.setProperty('--sa-accent-dim', `hsla(${h}, 76%, 64%, 0.16)`);
    document.documentElement.style.setProperty('--sa-accent-bd',  `hsla(${h}, 86%, 72%, 0.38)`);
  }, [tweaks.accentHue]);

  // Reveal-on-scroll
  React.useEffect(() => {
    const els = document.querySelectorAll('.reveal');
    const io = new IntersectionObserver((entries) => {
      entries.forEach(e => { if (e.isIntersecting) e.target.classList.add('in'); });
    }, {threshold: 0.15});
    els.forEach(el => io.observe(el));
    return () => io.disconnect();
  });

  // Page-load fade-in: trigger once React has mounted and painted
  React.useEffect(() => {
    const id = requestAnimationFrame(() => {
      document.body.classList.add('page-ready');
    });
    return () => cancelAnimationFrame(id);
  }, []);

  const headline = HEADLINES[tweaks.headlineVariation] || HEADLINES.primary;

  return (
    <>
      <Nav/>

      <Hero headline={headline}/>

      {tweaks.showRolesMarquee && <RolesMarquee/>}

      {/* ── Section title (Apple intro pattern) ── */}
      <section className="section" id="features" style={{paddingTop: 60, paddingBottom: 20, textAlign:'center'}}>
        <div className="container-narrow">
          <div className="section-eyebrow">What's inside</div>
          <h2 className="display" style={{fontSize:'clamp(36px, 5.6vw, 72px)', margin:'0 0 22px', letterSpacing:'-0.035em'}}>
            Built for the <span className="serif grad-pearl" style={{fontWeight:500}}>call sheet</span>.<br/>
            <span style={{color:'var(--sa-text3)'}}>Not the boardroom.</span>
          </h2>
          <p style={{fontSize:17, color:'var(--sa-text3)', maxWidth:640, margin:'0 auto', lineHeight:1.55}}>
            Every screen, every calculation, every invoice template — designed by people
            who have been on a 14-hour day and still had to do their own bookkeeping.
            Here's what you get.
          </p>
        </div>
      </section>

      {/* ── Calculator deep-dive ── */}
      <FeatureBlock
        eyebrow="Calculator"
        title={<>ACCP rates.<br/>Down to the meal penalty.</>}
        body={
          <>
            Pick your role. Punch in your hours. Set Assist runs the ACCP scale —
            base rate, OT 1.5× hours 1–2, OT 2× hours 3–4, OT 3× hour 5+, meal
            penalties, kit fees, weekend bumps, multipliers — and tells you what
            your day is worth before you've even unwrapped the slate.
            <br/><br/>
            Custom roles and flat day rates work the same way. Save the calc to a
            job. Email it to a PM. Paste it into an invoice.
          </>
        }
      >
        <FragCalcResult style={{position:'static', transform:'rotate(-2deg)'}}/>
      </FeatureBlock>

      {/* ── Invoicing deep-dive ── */}
      <FeatureBlock
        eyebrow="Invoicing"
        title={<>Get paid.<br/>Without the spreadsheet.</>}
        body={
          <>
            Gear-only, labour-only, or both at once. Auto-numbered. Net 15, 30,
            or 60. Tax applied per line. Production company address book remembers
            who you bill and what they owe.
            <br/><br/>
            On Pro, your logo lands on every PDF, and the Finances tab tells you
            who's late, who paid, and what your HST quarter looks like.
          </>
        }
        accent="var(--sa-green)"
        reverse
      >
        <FragInvoiceList style={{position:'static', transform:'rotate(2deg)'}}/>
      </FeatureBlock>

      {/* ── Crew deep-dive ── */}
      <FeatureBlock
        eyebrow="Crew & Calendar"
        title={<>Get found.<br/>Get booked.</>}
        body={
          <>
            Build a crew profile — role, location, kit, availability. PMs in the
            directory can find you and reach out. Block your shoot days on the
            calendar so you stop double-booking by accident.
            <br/><br/>
            Teams lets you split a rental three ways with a tap, and the sun
            tracker pulls accurate sunrise/sunset for any location on your call sheet.
          </>
        }
        accent="var(--sa-pink)"
      >
        <div style={{position:'relative', width:'100%', maxWidth:380, height:520}}>
          <FragCrewCard style={{top:0, left:0, transform:'rotate(-2deg)'}}/>
          <FragCalendarStrip style={{bottom:0, right:0, transform:'rotate(2deg)'}}/>
        </div>
      </FeatureBlock>

      {/* ── Finances deep-dive ── */}
      <FeatureBlock
        eyebrow="Finances"
        title={<>Tax time<br/>without the panic.</>}
        body={
          <>
            Every invoice you send and every kilometre you drive lands in one
            dashboard. CRA mileage at $0.70/km for the first 5,000 — automatic.
            HST tracked by quarter so you stop being surprised in July.
            <br/><br/>
            Expenses by category. Year-to-date totals. Export when your
            accountant asks.
          </>
        }
        accent="var(--sa-amber)"
        reverse
      >
        <FragFinances style={{position:'static', transform:'rotate(-1.5deg)'}}/>
      </FeatureBlock>

      {/* ── Payroll Wrap deep-dive ── */}
      <FeatureBlock
        eyebrow="Payroll Wrap · PRO"
        title={<>Wrap the show.<br/>Pay the crew.</>}
        body={
          <>
            For Production Managers and key creatives running their own payroll.
            Add the crew, pull in their timesheets, assign ACCP line numbers, and
            export a payroll-ready bundle in one screen.
            <br/><br/>
            Common-line presets handle 80% of jobs. Edit per-crew rates without
            breaking the totals. Export to PDF or your favourite payroll service.
          </>
        }
        accent="var(--sa-purple)"
      >
        <FragPayrollWrap style={{position:'static', transform:'rotate(-1deg)'}}/>
      </FeatureBlock>

      {/* ── Kit deep-dive ── */}
      <FeatureBlock
        eyebrow="Kit Inventory · PRO"
        title={<>Your gear is<br/>a second income.</>}
        body={
          <>
            Track every body, lens, monitor, and stand. Set daily rates per item.
            Total kit value at a glance. When a job calls for kit, drop the items
            into the calculator or invoice — rates auto-fill.
            <br/><br/>
            Insurance? Export a manifest. Retired a piece? Mark it sold. Your kit
            is your business. Treat it like one.
          </>
        }
        accent="var(--sa-teal)"
        reverse
      >
        <FragKit style={{position:'static', transform:'rotate(2deg)'}}/>
      </FeatureBlock>

      {/* ── Pricing ── */}
      <Pricing initialBilling={tweaks.billingDefault}/>

      {/* ── Compare ── */}
      <Compare/>

      {/* ── FAQ ── */}
      <FAQ/>

      {/* ── Final CTA ── */}
      <section className="section ambient final-cta" style={{paddingTop:60, paddingBottom: 100, textAlign:'center', overflow:'hidden'}}>
        <div className="container-narrow">
          <h2 className="display" style={{fontSize:'clamp(40px, 6.5vw, 88px)', margin:'0 0 22px', letterSpacing:'-0.035em'}}>
            That's a <span className="serif grad-champagne" style={{fontWeight:500}}>wrap</span>.
          </h2>
          <div className="rule" style={{margin:'0 auto 22px'}}/>
          <p style={{fontSize:18, color:'var(--sa-text3)', maxWidth:540, margin:'0 auto 32px', lineHeight:1.55}}>
            Free to start. Five minutes to set up. One less spreadsheet on your laptop.
          </p>
          <div className="hero-ctas" style={{display:'flex', justifyContent:'center', gap:12, flexWrap:'wrap'}}>
            <a href="https://apps.apple.com/ca/app/set-assist/id6762023708" target="_blank" rel="noopener" className="store-badge">
              <Apple size={26}/>
              <div style={{textAlign:'left'}}>
                <div className="sb-small">Download on the</div>
                <div className="sb-big">App Store</div>
              </div>
            </a>
            <GooglePlayBadge/>
          </div>
        </div>
      </section>

      <Footer/>

      {/* Tweaks panel */}
      <TweaksPanel>
        <TweakSection title="Hero">
          <TweakSelect
            label="Headline"
            value={tweaks.headlineVariation}
            onChange={v => setTweak('headlineVariation', v)}
            options={[
              {value:'primary',   label:'Stop chasing your money.'},
              {value:'secondary', label:'The set companion…'},
              {value:'payroll',   label:'Wrap the day. Not the math.'},
            ]}
          />
          <TweakToggle
            label="Show roles marquee"
            value={tweaks.showRolesMarquee}
            onChange={v => setTweak('showRolesMarquee', v)}
          />
        </TweakSection>
        <TweakSection title="Theme">
          <TweakSlider
            label="Accent hue"
            min={0} max={360} step={1}
            value={tweaks.accentHue}
            onChange={v => setTweak('accentHue', v)}
            format={v => `${v}°`}
          />
        </TweakSection>
        <TweakSection title="Pricing">
          <TweakRadio
            label="Default billing"
            value={tweaks.billingDefault}
            onChange={v => setTweak('billingDefault', v)}
            options={[
              {value:'monthly', label:'Monthly'},
              {value:'yearly',  label:'Yearly'},
            ]}
          />
        </TweakSection>
      </TweaksPanel>
    </>
  );
}

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<App/>);
