/* ==========================================================================
   App.jsx
   Composes the page and holds the shared state that links sections:
   - intent: "quote" or "book" (set by any CTA, shown in the form)
   - quoteService: service pre-selected in the form
   - detailService: active tab in Service Details
   Load this file last.
   ========================================================================== */

function MCApp() {
  const [appIntent, setAppIntent] = React.useState('quote');
  const [appQuoteService, setAppQuoteService] = React.useState('');
  const [appDetailService, setAppDetailService] = React.useState(MC_SERVICES[0].id);

  React.useEffect(() => mcInitReveal(), []);

  const handleIntent = React.useCallback((intent, serviceId) => {
    if (intent) setAppIntent(intent);
    if (serviceId) setAppQuoteService(serviceId);
    mcScrollToId('quote', 'mc-f-name');
  }, []);

  const handleQuoteService = React.useCallback((serviceId) => handleIntent('quote', serviceId), [handleIntent]);
  const handleDetails = React.useCallback((serviceId) => setAppDetailService(serviceId), []);

  return (
    <React.Fragment>
      <a className="mc-skip" href="#main">
        Skip to content
      </a>
      <MCNav onIntent={handleIntent} />
      <main id="main" tabIndex={-1}>
        <MCHero onIntent={handleIntent} onDetails={handleDetails} />
        <MCMarquee />
        <MCServices selectedService={appQuoteService} onQuote={handleQuoteService} onDetails={handleDetails} />
        <MCBrandStory />
        <MCWhyDusty />
        <MCBeforeAfter />
        <MCDustySection />
        <MCProcess onIntent={handleIntent} />
        <MCServiceDetails active={appDetailService} onChange={setAppDetailService} onQuote={handleQuoteService} />
        <MCFAQ onIntent={handleIntent} />
        <MCFinalCTA
          intent={appIntent}
          onIntent={handleIntent}
          onIntentChange={setAppIntent}
          service={appQuoteService}
          onServiceChange={setAppQuoteService}
        />
      </main>
      <MCFooter onDetails={handleDetails} />
      <MCPrivacyDialog />
      {MC_CONFIG.showTweaks ? <MCTweaks /> : null}
    </React.Fragment>
  );
}

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

Object.assign(window, { MCApp });
