/* Sitepro Landing — bootstrap.
 *
 * Each section has its own React root. Components register themselves on `window`
 * via `window.X = X;` at the bottom of each .jsx file, so we look them up here.
 *
 * This script runs as type="text/babel" (see functions.php script_loader_tag filter).
 */

(function () {
  function mount(id, Component, label) {
    var el = document.getElementById(id);
    if (!el) return;
    if (typeof Component !== 'function') {
      console.warn('[sitepro] missing component for', label || id);
      return;
    }
    try {
      ReactDOM.createRoot(el).render(<Component />);
    } catch (err) {
      console.error('[sitepro] failed to mount', label || id, err);
    }
  }

  function bootstrap() {
    if (typeof React === 'undefined' || typeof ReactDOM === 'undefined') {
      console.error('[sitepro] React/ReactDOM not loaded');
      return;
    }

    mount('sp-cursor-root',   window.Cursor,        'Cursor');
    mount('sp-thread-root',   window.Thread,        'Thread');
    mount('sp-topbar-root',   window.Topbar,        'Topbar');
    mount('sp-hero-root',     window.Hero,          'Hero');
    mount('sp-marquee-root',  window.Marquee,       'Marquee');
    mount('sp-partners-root', window.Partners,      'Partners');
    mount('sp-aistack-root',  window.AIStack,       'AIStack');
    mount('sp-clients-root',  window.Clients,       'Clients');
    mount('sp-footer-root',   window.FooterLanding, 'FooterLanding');
  }

  if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', bootstrap);
  } else {
    bootstrap();
  }
})();
