/** Mounts the app. Kept last in load order so every global it needs exists. */

(function () {
  'use strict';

  const required = [
    'TCIA',
    'DicomSeg',
    'Windowing',
    'Anatomy',
    'StudyLoader',
    'Cloud',
    'Progress',
    'Catalog',
    'ComparisonPairs',
    'USCases',
    'UltrasoundCase',
    'Curriculum',
    'DicomViewer',
    'CompareViewer',
    'ComparisonWorkspace',
    'CoveragePage',
    'LessonPlayer',
    'AuthScreen',
    'BootScreen',
    'AdminReport',
    'App'
  ];

  const missing = required.filter((name) => !window[name]);
  const root = document.getElementById('root');

  if (missing.length) {
    const box = document.createElement('div');
    box.style.cssText = 'padding:40px;font-family:Heebo,sans-serif;color:#b91c1c';

    const title = document.createElement('strong');
    title.textContent = 'האפליקציה לא נטענה במלואה.';
    box.append(title, document.createElement('br'));
    box.append(document.createTextNode(`מודולים חסרים: ${missing.join(', ')}`));

    root.replaceChildren(box);
    console.error('[main] missing globals', missing);
    return;
  }

  ReactDOM.createRoot(root).render(React.createElement(window.App));
})();
