import GIS from './gis.js';
import UI from './ui.js';
import { GisState } from './state.js';
import { Application } from '@hotwired/stimulus';
import MenuController from './controllers/menu_controller.js';
import ModalController from './controllers/modal_controller.js';
import MarkerController from './controllers/marker_controller.js';
import BiblioController from './controllers/biblio_controller.js';
import TabsController from './controllers/tabs_controller.js';
import LayerController from './controllers/layer_controller.js';
import SearchController from './controllers/search_controller.js';

document.addEventListener('DOMContentLoaded', async () => {
    // Register Stimulus controllers
    initStimulus();

    let progress = document.querySelector('progress');
    const map = await GIS.initMap('map');

    // Trigger Stimulus buildMenu method...
    const menuEvent = new Event('menu-ready');
    document.dispatchEvent(menuEvent);

    progress.classList.add('is-hidden');
    map._container.setAttribute('aria-busy', false);
    
    GIS.toggleSpherical(map);

    UI.addCenterMapControl(map, GIS.CENTER_COORDS, GIS.INIT_ZOOM);
    UI.toggleBurger('navbar-burger');
});

function initStimulus() {
    window.Stimulus = Application.start();
    Stimulus.register("menu", MenuController);
    Stimulus.register("modal", ModalController);
    Stimulus.register("marker", MarkerController);
    Stimulus.register("biblio", BiblioController);
    Stimulus.register("tabs", TabsController);
    Stimulus.register("layer", LayerController);
    Stimulus.register("search", SearchController);
}