/* ============================================================================
   MyNextOpp — frontend entry (Vite)
   ----------------------------------------------------------------------------
   This is the module Vite bundles. It:
     1. Imports the Career Intelligence enhancement layer (ESM) so it is
        included in the production build and tree-shaken.
     2. Boots the layer (UI panel + local-first notice) and attaches the public
        window.MNO_* globals for host/console compatibility.
     3. Logs the resolved API configuration so operators can confirm at a glance
        whether the build is wired to a backend or running standalone.

   The host React SPA is a separate, pre-built bundle loaded from /assets; this
   entry never imports it (it is not source). The two coexist: the host renders
   the app, the enhancement layer overlays Career Intelligence on top.
   ========================================================================== */

import { install } from './enhancement/index.js';
import { API_URL, HAS_API, MODE } from './env';
// Enhancement layer styles (hover/focus states, entrance animation, responsive
// + print rules). Imported here so Vite bundles and hashes it into dist/.
import './enhancement/enhancement.css';

function boot() {
  try {
    install();
  } catch (err) {
    // Never let the enhancement layer break the host app.
    // eslint-disable-next-line no-console
    console.warn('[MyNextOpp] enhancement layer failed to boot:', err);
  }

  if (!HAS_API) {
    // eslint-disable-next-line no-console
    console.info(
      `[MyNextOpp] Running in standalone mode (VITE_API_URL unset, mode=${MODE}). ` +
        'Data is stored per-browser. Set VITE_API_URL to connect the backend.'
    );
  } else {
    // eslint-disable-next-line no-console
    console.info(`[MyNextOpp] API base: ${API_URL} (mode=${MODE})`);
  }
}

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