import "./components/form/form_manager";// declare ASAP for AAForm availability for other scripts

import {entityList} from "./components/entity-list";
import {entityForm} from "./components/entity-form";
import {entityExport} from "./components/entity-export";
import {sidebar} from "./components/sidebar";

require('../scss/app.scss');

import {prevent} from "./components/prevent";
import {flashbagNotification} from "./components/flashbag-notification";
import $ from 'jquery'
import "bootstrap";
import "startbootstrap-sb-admin-2/js/sb-admin-2";
import "url-search-params-polyfill";

import AAUtils from "./components/util/util";
global.AAUtils = AAUtils;

// import form && tools
import "./components/form/form_config";
// import form type handlers
import "./components/form/handler/collection";
import "./components/form/handler/date_picker";
import "./components/form/handler/rich_select";
import "./components/form/handler/rich_text";
import "./components/form/handler/content_reference";

global.$ = window.$ = window.jQuery = $;// still required?

$(function () {
    prevent($);
    flashbagNotification($);
    entityList();
    entityForm($);
    entityExport();
    sidebar($);

    // console.log('Registering mutation observer');
    var dom_observer = new MutationObserver(function (mutation) {
        // console.log('function called');
    });
    var container = document.documentElement || document.body;
    // console.log('container');
    // console.log(container);
    var config = {
        childList: true,
        attributes: true,
        characterData: true,
        subtree: true,
    };
    dom_observer.observe(container, config);

    // initialize form fields
    AAForm.initialize();
});

document.querySelectorAll('.search-empty-input').forEach(elt => {
    elt.parentNode.querySelector('.search-empty-label').style.color = elt.checked ? '#4e73df' : '';
    elt.addEventListener('click', function(e) {
        e.target.parentNode.querySelector('.search-empty-label').style.color = e.target.checked ? '#4e73df' : '';
    })
})
