(function (global, factory) {
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('nice-select2')) :
  typeof define === 'function' && define.amd ? define(['nice-select2'], factory) :
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.NiceSelect));
})(this, (function (NiceSelect) { 'use strict';

  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

  var NiceSelect__default = /*#__PURE__*/_interopDefaultLegacy(NiceSelect);

  /* global jQuery, wp */
  var sections = document.querySelectorAll('.MSettingSection');
  console.log(sections);
  if (sections.length) {
    var tabs = document.querySelectorAll('.nav-tab');

    /* Active tab */
    var activeTabDitsCompare;
    activeTabDitsCompare = localStorage.getItem('activeTabDitsCompare');
    if (window.location.hash) {
      activeTabDitsCompare = window.location.hash;
      localStorage.setItem('activeTabDitsCompare', activeTabDitsCompare);
    }

    /* Initialize active section */
    if (activeTabDitsCompare) {
      tabs.forEach(function (tab) {
        tab.getAttribute('href') === activeTabDitsCompare && tab.classList.add('nav-tab-active');
      });
      sections.forEach(function (section) {
        "#".concat(section.id) === activeTabDitsCompare && (section.style.display = 'block');
      });
    } else {
      sections[0] && (sections[0].style.display = 'block');
      tabs[0] && tabs[0].classList.add('nav-tab-active');
    }

    /* Change active tab and section */
    tabs.forEach(function (tab) {
      tab.addEventListener('click', function (evt) {
        evt.preventDefault();
        localStorage.setItem('activeTabDitsCompare', tab.getAttribute('href'));
        tabs.forEach(function (tab) {
          return tab.classList.remove('nav-tab-active');
        });
        tab.classList.add('nav-tab-active');
        sections.forEach(function (section) {
          section.style.display = 'none';
          if ("#".concat(section.id) === tab.getAttribute('href')) {
            section.style.display = 'block';
          }
        });
      });
    });
  }
  jQuery(document).ready(function ($) {
    /***** Colour picker *****/
    $('.MColorPickerInput').wpColorPicker();

    /* File input */
    $('.MFileInputBrowse').on('click', function (event) {
      event.preventDefault();
      var self = $(this);
      var attachment;

      // Create the media frame.
      // eslint-disable-next-line camelcase
      var file_frame = wp.media.frames.file_frame = wp.media({
        title: self.data('uploader_title'),
        button: {
          text: self.data('uploader_button_text')
        },
        multiple: false
      });

      // eslint-disable-next-line camelcase
      file_frame.on('select', function () {
        // eslint-disable-next-line camelcase
        attachment = file_frame.state().get('selection').first().toJSON();
        self.prev('.MFileInput').val(attachment.url).change();
      });

      // Finally, open the modal
      // eslint-disable-next-line camelcase
      file_frame.open();
    });
  });
  document.querySelectorAll('.dits-select').forEach(function (selectElement) {
    NiceSelect__default["default"] === null || NiceSelect__default["default"] === void 0 || NiceSelect__default["default"].bind(selectElement, {
      searchable: true
    });
  });

}));
//# sourceMappingURL=admin.js.map
