import "systemjs/dist/system.js";
import {UiUtils} from "./utils/UiUtils";

import IHK from './ihk';
import 'focus-visible';

const $ = global.$;


// import './modules/a-z';
// import './modules/accordion';
// import './modules/ad-teaser';
// import './modules/anchors';
// import './modules/bookmarks';
// import './modules/breadcrumb';
// import './modules/caruso';
// import './modules/contact';
// import './modules/events';
// import './modules/gallery';
import './modules/header';
// import './modules/magazine-header';
// import './modules/masonry';
// import './modules/quick-facts';
// import './modules/registration';
import './modules/search';
import './modules/sidebar';
// import './modules/slider';
// import './modules/social';
// import './modules/survey';
// import './modules/table';
// import './modules/topics';
import './modules/webforms'; // todo captcha und webforms trennen
import './utils/ie';
import Masonry from "./modules/masonry";


IHK.realVH();
$(window).on('resize', function () {
  IHK.realVH();
});

$(document).ready(function () {
  IHK.init();
  $('body').addClass('ready');
  // trigger das init event auf der globale jquery instanz so dass es alle modulle mitkriegen (z.B. cookie.js)
  $("body").trigger('ihk-init');
  UiUtils.initUI();

  // systemjs for dynamic loading of js modules
  // Load the modules if needed

  if ($("dynamic-content").length || $("dynamic-video-content").length) {
    global.System.import(window.ihk.resources.webComponentsJSLink);
  }

  if ($(".vst-registration,#confirmation, #captcha-wrapper ").length) {
    global.System.import(window.ihk.resources.gfiRegistrationJSLink).then(() => {
      global.$('body').trigger('dynamic-component-loaded');
    });
  }

  if ($(".print-share-list").length || $(".document-number").length) {
    global.System.import(window.ihk.resources.gfiBookmarksJSLink).then(() => {
    });
  }
  if ($(".breadcrumb-item.noClick").length) {
    global.System.import(window.ihk.resources.gfiBreadcrumbJSLink).then(() => {
    });
  }

  if ($(".caruso-basket").length) {
    global.System.import(window.ihk.resources.gfiCarusoJSLink).then(() => {
    });
  }

  if ($("#search-form, #search-submit, #search-submit-button, #query").length) {
    global.System.import(window.ihk.resources.gfiSearchUtilsJSLink).then(() => {
    });
  }
  if($("[data-mwf-form]").length){
    global.System.import( window.ihk.resources.gfiWebformsJSLink);
  }

  $("body").on("dynamic-component-loaded", function () {

    if ($(".highchart-container:not(.initiated)").length) {

      $(".highchart-container:not(.initiated)").each((i, el) => {
        $(el).addClass("initiated")
      });
      global.System.import(window.ihk.resources.highchartsJSLink);
    }


    if ($(".a-z:not(.initiated)").length) {
      global.System.import(window.ihk.resources.gfiAZJSLink).then(() => {
        global.$('body').trigger('gfi-dynamic-init');
      });
    }

    if ($(".accordion:not(.initiated)").length) {
      global.System.import(window.ihk.resources.gfiAccordionJSLink).then(() => {
        global.$('body').trigger('gfi-dynamic-init');
      });
    }

    if ($(".ad-box:not(.initiated)").length) {
      global.System.import(window.ihk.resources.gfiAdTeaserJSLink).then(() => {
        global.$('body').trigger('gfi-dynamic-init');
      });
    }

    if ($(".anchorlinks:not(.initiated)").length) {
      global.System.import(window.ihk.resources.gfiAnchorsJSLink).then(() => {
        global.$('body').trigger('gfi-dynamic-init');
      });
    }

    if ($(".contact-wrapper:not(.initiated)").length) {
      global.System.import(window.ihk.resources.gfiContactJSLink).then(() => {
        global.$('body').trigger('gfi-dynamic-init');
      });
    }
    if ($(".events-list[data-pagination='true']:not(.initiated)").length) {
      global.System.import(window.ihk.resources.gfiEventsJSLink).then(() => {
        global.$('body').trigger('gfi-dynamic-init');
      });
    }
    if ($(".gallery:not(.initiated)").length) {
      global.System.import(window.ihk.resources.gfiGalleryJSLink).then(() => {
        global.$('body').trigger('gfi-dynamic-init');
      });
    }
    if ($(".magazine-header:not(.initiated)").length) {
      global.System.import(window.ihk.resources.gfiMagazineHeaderJSLink).then(() => {
        global.$('body').trigger('gfi-dynamic-init');
      });
    }
    if ($(".teasers[data-type='masonry'] .row:not(.initiated)").length) {
      global.System.import(window.ihk.resources.gfiMasonryJSLink).then(() => {
        global.$('body').trigger('gfi-dynamic-init');
      });
    }
    if ($(".quick-facts:not(.initiated)").length) {
      global.System.import(window.ihk.resources.gfiQuickFactsJSLink).then(() => {
        global.$('body').trigger('gfi-dynamic-init');
      });
    }


    if ($(".slider:not(.initiated)").length) {
      global.System.import(window.ihk.resources.gfiSliderJSLink).then(() => {
        global.$('body').trigger('gfi-dynamic-init');
      });
    }
    if ($(".social-box:not(.initiated)").length) {
      global.System.import(window.ihk.resources.gfiSocialJSLink).then(() => {
        global.$('body').trigger('gfi-dynamic-init');
      });
    }
    if ($(".survey:not(.initiated)").length) {
      global.System.import(window.ihk.resources.gfiSurveyJSLink).then(() => {
        global.$('body').trigger('gfi-dynamic-init');
      });
    }
    if ($(".richtext table:not(.initiated)").length) {
      global.System.import(window.ihk.resources.gfiTableJSLink).then(() => {
        global.$('body').trigger('gfi-dynamic-init');
      });
    }
    if ($(".topics:not(.initiated)").length) {
      global.System.import(window.ihk.resources.gfiTopicsJSLink).then(() => {
        global.$('body').trigger('gfi-dynamic-init');
      });
    }
    if ($(".ihk-popper-tooltip:not(.initiated)").length) {
      global.System.import(window.ihk.resources.gfiTooltipJSLink).then(() => {
        global.$('body').trigger('gfi-dynamic-init');
      });
    }
    if ($(".tooltip, [data-toggle='dropdown'], .modal-dialog ").length) {
      global.System.import(window.ihk.resources.gfiBootstrapCustomJSLink).then(() => {
      });
    }


  });

  global.$('body').trigger('dynamic-component-loaded');

});
