"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
var emoza = emoza || {};

/**
 * Is the DOM ready?
 *
 * This implementation is coming from https://gomakethings.com/a-native-javascript-equivalent-of-jquerys-ready-method/
 *
 * @param {Function} fn Callback function to run.
 */
emoza.helpers = {
  emozaDomReady: function emozaDomReady(fn) {
    if (typeof fn !== 'function') {
      return;
    }
    if (document.readyState === 'interactive' || document.readyState === 'complete') {
      return fn();
    }
    document.addEventListener('DOMContentLoaded', fn, false);
  },
  isInVerticalViewport: function isInVerticalViewport(el) {
    var rect = el.getBoundingClientRect();
    return rect.top >= 0 && rect.bottom <= (window.innerHeight || document.documentElement.clientHeight);
  },
  isInHorizontalViewport: function isInHorizontalViewport(el) {
    var rect = el.getBoundingClientRect();
    return rect.left >= 0 && rect.right <= document.documentElement.clientWidth;
  },
  ajax: function ajax(action, nonce, extraParams, successCallback) {
    var ajax = new XMLHttpRequest();
    ajax.open('POST', emoza.ajaxurl, true);
    ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    ajax.onload = function () {
      if (this.status >= 200 && this.status < 400) {
        successCallback.apply(this);
      }
    };
    var extraParamsStr = '';
    extraParams = Object.entries(extraParams);
    for (var i = 0; i < extraParams.length; i++) {
      extraParamsStr += '&' + extraParams[i].join('=');
    }
    ajax.send('action=' + action + '&nonce=' + nonce + extraParamsStr);
  },
  setCookie: function setCookie(cname, cvalue, exdays) {
    var d = new Date();
    d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1000);
    var expires = "expires=" + d.toUTCString();
    document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
  },
  getCookie: function getCookie(cname) {
    var name = cname + "=",
      ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
      var c = ca[i];
      while (c.charAt(0) == ' ') {
        c = c.substring(1);
      }
      if (c.indexOf(name) == 0) {
        return c.substring(name.length, c.length);
      }
    }
    return "";
  }
};

/**
 * Handles toggling the navigation menu for small screens and enables TAB key
 * navigation support for dropdown menus.
 */
emoza.navigation = {
  init: function init() {
    var self = this,
      siteNavigation = document.getElementById('site-navigation') == null ? document.getElementById('site-navigation-mobile') : document.getElementById('site-navigation'),
      offCanvas = document.getElementsByClassName('emoza-offcanvas-menu')[0],
      button = document.getElementsByClassName('menu-toggle')[0];
    if (siteNavigation === null) {
      return;
    }

    // Return early if the navigation don't exist.
    if (!siteNavigation && typeof button === 'undefined') {
      return;
    }
    if (typeof offCanvas === 'undefined') {
      return;
    }
    var closeButton = document.getElementsByClassName('mobile-menu-close')[0];

    // Return early if the button don't exist.
    if ('undefined' === typeof button) {
      return;
    }
    var menu = siteNavigation.getElementsByTagName('ul')[0];
    var mobileMenuClose = siteNavigation.getElementsByClassName('mobile-menu-close')[0];

    // Hide menu toggle button if menu is empty and return early.
    if ('undefined' === typeof menu) {
      button.style.display = 'none';
      return;
    }
    if (!menu.classList.contains('nav-menu')) {
      menu.classList.add('nav-menu');
    }
    var focusableEls = offCanvas.querySelectorAll('a[href]:not([disabled]):not(.mobile-menu-close)');
    var firstFocusableEl = focusableEls[0];
    button.addEventListener('click', function (e) {
      e.preventDefault();
      button.classList.add('open');
      offCanvas.classList.add('toggled');
      document.body.classList.add('mobile-menu-visible');

      //Toggle submenus
      var submenuToggles = offCanvas.querySelectorAll('.dropdown-symbol, .menu-item-has-children > a[href="#"]');
      var _iterator = _createForOfIteratorHelper(submenuToggles),
        _step;
      try {
        for (_iterator.s(); !(_step = _iterator.n()).done;) {
          var submenuToggle = _step.value;
          submenuToggle.addEventListener('touchstart', submenuToggleHandler);
          submenuToggle.addEventListener('click', submenuToggleHandler);
          submenuToggle.addEventListener('keydown', function (e) {
            var isTabPressed = e.key === 'Enter' || e.keyCode === 13;
            if (!isTabPressed) {
              return;
            }
            e.preventDefault();
            var parent = submenuToggle.parentNode.parentNode;
            parent.getElementsByClassName('sub-menu')[0].classList.toggle('toggled');
          });
        }

        //Trap focus inside modal
      } catch (err) {
        _iterator.e(err);
      } finally {
        _iterator.f();
      }
      firstFocusableEl.focus();
    });
    function submenuToggleHandler(e) {
      e.preventDefault();
      var parent = e.target.closest('li');
      parent.querySelector('.sub-menu').classList.toggle('toggled');
    }

    // Close the offcanvas when a anchor that contains a hash is clicked
    var anchors = offCanvas.querySelectorAll('a[href*="#"]');
    if (anchors.length) {
      var _iterator2 = _createForOfIteratorHelper(anchors),
        _step2;
      try {
        for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
          var anchor = _step2.value;
          anchor.addEventListener('click', function (e) {
            if (e.target.hash && document.querySelector(e.target.hash) !== null && !e.target.classList.contains('emoza-tabs-nav-link')) {
              button.classList.remove('open');
              offCanvas.classList.remove('toggled');
              document.body.classList.remove('mobile-menu-visible');
            }
          });
        }
      } catch (err) {
        _iterator2.e(err);
      } finally {
        _iterator2.f();
      }
    }
    var focusableEls = offCanvas.querySelectorAll('a[href]:not([disabled])');
    var firstFocusableEl = focusableEls[0];
    var lastFocusableEl = focusableEls[focusableEls.length - 1];
    var KEYCODE_TAB = 9;
    lastFocusableEl.addEventListener('keydown', function (e) {
      var isTabPressed = e.key === 'Tab' || e.keyCode === KEYCODE_TAB;
      if (!isTabPressed) {
        return;
      }
      if (e.shiftKey) /* shift + tab */{} else /* tab */{
          firstFocusableEl.focus();
        }
    });
    closeButton.addEventListener('click', function (e) {
      e.preventDefault();
      var buttonRect = button.getBoundingClientRect();
      if (buttonRect.top + buttonRect.height > 0) {
        button.focus();
      }
      button.classList.remove('open');
      offCanvas.classList.remove('toggled');
      document.body.classList.remove('mobile-menu-visible');
    });
    document.addEventListener('click', function (e) {
      if (e.target.closest('.emoza-offcanvas-menu') === null && !e.target.classList.contains('menu-toggle') && e.target.closest('.menu-toggle') === null) {
        button.classList.remove('open');
        offCanvas.classList.remove('toggled');
        document.body.classList.remove('mobile-menu-visible');
      }
    });

    // Get all the link elements within the menu.
    var links = menu.getElementsByTagName('a');

    // Get all the link elements with children within the menu.
    var linksWithChildren = menu.querySelectorAll('.menu-item-has-children > a, .page_item_has_children > a');

    // Toggle focus each time a menu link is focused or blurred.
    var _iterator3 = _createForOfIteratorHelper(links),
      _step3;
    try {
      for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
        var link = _step3.value;
        link.addEventListener('focus', toggleFocus, true);
        link.addEventListener('blur', toggleFocus, true);
      }

      // Toggle focus each time a menu link with children receive a touch event.
    } catch (err) {
      _iterator3.e(err);
    } finally {
      _iterator3.f();
    }
    var _iterator4 = _createForOfIteratorHelper(linksWithChildren),
      _step4;
    try {
      for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
        var _link = _step4.value;
        _link.addEventListener('touchstart', toggleFocus, false);
      }

      /**
       * Sets or removes .focus class on an element.
       */
    } catch (err) {
      _iterator4.e(err);
    } finally {
      _iterator4.f();
    }
    function toggleFocus() {
      if (event.type === 'focus' || event.type === 'blur') {
        var _self2 = this;
        // Move up through the ancestors of the current link until we hit .nav-menu.
        while (!_self2.classList.contains('nav-menu')) {
          // On li elements toggle the class .focus.
          if ('li' === _self2.tagName.toLowerCase()) {
            _self2.classList.toggle('focus');
          }
          _self2 = _self2.parentNode;
        }
      }
      if (event.type === 'touchstart') {
        var menuItem = this.parentNode;
        event.preventDefault();
        var _iterator5 = _createForOfIteratorHelper(menuItem.parentNode.children),
          _step5;
        try {
          for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
            var link = _step5.value;
            if (menuItem !== link) {
              link.classList.remove('focus');
            }
          }
        } catch (err) {
          _iterator5.e(err);
        } finally {
          _iterator5.f();
        }
        menuItem.classList.toggle('focus');
      }
    }

    // Mobile accordion style navigation
    this.mobileAccordionNavigation();

    // Hover with delay effect
    this.initHoverClass();

    // Menu reverse
    this.checkMenuReverse();
  },
  /**
   * Initialize hover class for dropdown items.
   */
  initHoverClass: function initHoverClass() {
    var self = this;
    if (typeof emoza.settings !== 'undefined' && 'no' === emoza.settings.misc.dropdowns_hover_delay) {
      return false;
    }

    // Add hover class to dropdown items. 
    // Run it only once and after the first user interaction on the page.
    var initialized = false;
    var events = [{
      name: 'scroll',
      selector: window
    }, {
      name: 'mouseenter',
      selector: document
    }, {
      name: 'mouseover',
      selector: document
    }, {
      name: 'touchstart',
      selector: document
    }];
    for (var _i = 0, _events = events; _i < _events.length; _i++) {
      var _event = _events[_i];
      _event.selector.addEventListener(_event.name, function () {
        if (initialized) {
          return false;
        }
        initialized = true;
        self.addHoverClassToDropdownItems();
      });
    }
  },
  /**
   * Add hover class to dropdown items.
   */
  addHoverClassToDropdownItems: function addHoverClassToDropdownItems() {
    var dropdownLis = document.querySelectorAll('.emoza-dropdown-li');
    var _iterator6 = _createForOfIteratorHelper(dropdownLis),
      _step6;
    try {
      var _loop = function _loop() {
        var li = _step6.value;
        var mouseOutTimeout = void 0,
          mouseOverTimeout = void 0,
          delayTime = 300;
        var parent = li;
        li.addEventListener('mouseover', function (e) {
          var self = this;
          clearTimeout(mouseOutTimeout);
          mouseOverTimeout = setTimeout(function () {
            self.classList.add('hovered');
          }, delayTime);
        });
        var subDropdownLis = li.querySelectorAll('.emoza-dropdown-ul > .emoza-dropdown-li');
        var _iterator7 = _createForOfIteratorHelper(subDropdownLis),
          _step7;
        try {
          for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
            var subLi = _step7.value;
            subLi.addEventListener('mouseover', function (e) {
              clearTimeout(mouseOutTimeout);
              setTimeout(function () {
                parent.classList.add('hovered');
              }, delayTime);
            });
          }
        } catch (err) {
          _iterator7.e(err);
        } finally {
          _iterator7.f();
        }
        li.addEventListener('mouseout', function (e) {
          var self = this;
          clearTimeout(mouseOverTimeout);
          if (parent.contains(e.relatedTarget)) {
            return false;
          }
          mouseOutTimeout = setTimeout(function () {
            self.classList.remove('hovered');
          }, delayTime);
        });
      };
      for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
        _loop();
      }
    } catch (err) {
      _iterator6.e(err);
    } finally {
      _iterator6.f();
    }
  },
  /*
  * Mobile navigation (accordion style navigation)
  */
  mobileAccordionNavigation: function mobileAccordionNavigation() {
    var navs = document.querySelectorAll('.emoza-dropdown-mobile-accordion');
    if (!navs.length) {
      return false;
    }
    var _iterator8 = _createForOfIteratorHelper(navs),
      _step8;
    try {
      for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
        var nav = _step8.value;
        var nav_item = nav.querySelectorAll('.menu-item-has-children');
        if (!nav_item.length) {
          return false;
        }
        var _iterator9 = _createForOfIteratorHelper(nav_item),
          _step9;
        try {
          for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
            var item = _step9.value;
            var dropdownToggler = item.querySelectorAll('.dropdown-symbol');
            dropdownToggler[0].addEventListener('click', function (e) {
              e.stopPropagation();
              var parent = this.parentNode;
              if (parent.classList.contains('expand')) {
                parent.classList.remove('expand');
              } else {
                parent.classList.add('expand');
              }
            });
          }
        } catch (err) {
          _iterator9.e(err);
        } finally {
          _iterator9.f();
        }
      }
    } catch (err) {
      _iterator8.e(err);
    } finally {
      _iterator8.f();
    }
  },
  /* 
  * Check if sub-menu items are visible. If not, reverse the item position 
  */
  checkMenuReverse: function checkMenuReverse() {
    var items = document.querySelectorAll('.header-login-register, .top-bar-login-register, .emoza-dropdown .menu li');
    var _iterator10 = _createForOfIteratorHelper(items),
      _step10;
    try {
      for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
        var element = _step10.value;
        element.removeEventListener('mouseover', this.menuReverseEventHandler);
        element.addEventListener('mouseover', this.menuReverseEventHandler, {
          passive: true
        });
        element.removeEventListener('touchstart', this.menuReverseEventHandler);
        element.addEventListener('touchstart', this.menuReverseEventHandler, {
          passive: true
        });
      }
    } catch (err) {
      _iterator10.e(err);
    } finally {
      _iterator10.f();
    }
  },
  menuReverseEventHandler: function menuReverseEventHandler() {
    var is_rtl = 'rtl' === document.querySelector('html').getAttribute('dir');
    event.stopPropagation();
    var submenu = event.currentTarget.querySelector('.header-login-register>nav, .top-bar-login-register>nav, .sub-menu');
    if (submenu === null) {
      return false;
    }

    // Reverse horizontally
    submenu.classList.remove('sub-menu-reverse');
    if (is_rtl) {
      submenu.classList.add('sub-menu-reverse');
    } else {
      if (emoza.helpers.isInHorizontalViewport(submenu) == false && !submenu.closest('.menu-item').classList.contains('emoza-mega-menu')) {
        submenu.classList.add('sub-menu-reverse');
      } else {
        submenu.classList.remove('sub-menu-reverse');
      }
    }

    // Reverse vertically
    // Do not reverse vertically if the menu is in the header
    if (submenu.closest('.site-header') || submenu.closest('.bottom-header-row') || submenu.closest('.ehfb-header')) {
      return false;
    }
    submenu.classList.remove('sub-menu-reverse-vertically');
    if (emoza.helpers.isInVerticalViewport(submenu) == false && !submenu.closest('.menu-item').classList.contains('emoza-mega-menu')) {
      submenu.classList.add('sub-menu-reverse-vertically');
    } else {
      submenu.classList.remove('sub-menu-reverse-vertically');
    }
  }
};

/**
 * Desktop off canvas toggle navigation
 */
emoza.desktopOffCanvasToggleNav = {
  init: function init() {
    var siteNavigation = document.getElementById('site-navigation'),
      offCanvas = document.getElementsByClassName('emoza-desktop-offcanvas-menu')[0];

    // Return early if the navigation don't exist.
    if (!siteNavigation || typeof offCanvas === 'undefined') {
      return;
    }

    //Toggle submenus
    var submenuToggles = offCanvas.querySelectorAll('.dropdown-symbol, .menu-item-has-children > a[href="#"]');
    var _iterator11 = _createForOfIteratorHelper(submenuToggles),
      _step11;
    try {
      for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
        var submenuToggle = _step11.value;
        submenuToggle.addEventListener('touchstart', submenuToggleHandler);
        submenuToggle.addEventListener('click', submenuToggleHandler);
        submenuToggle.addEventListener('keydown', function (e) {
          var isTabPressed = e.key === 'Enter' || e.keyCode === 13;
          if (!isTabPressed) {
            return;
          }
          e.preventDefault();
          var parent = submenuToggle.parentNode.parentNode;
          parent.getElementsByClassName('sub-menu')[0].classList.toggle('toggled');
        });
      }
    } catch (err) {
      _iterator11.e(err);
    } finally {
      _iterator11.f();
    }
    function submenuToggleHandler(e) {
      e.preventDefault();
      var parent = e.target.closest('li');
      parent.querySelector('.sub-menu').classList.toggle('toggled');
    }
  }
};

/**
 * Desktop offcanvas menu navigation
 */
emoza.desktopOffcanvasNav = {
  init: function init() {
    var buttons = document.querySelectorAll('.desktop-menu-toggle'),
      closeButton = document.getElementsByClassName('desktop-menu-close')[0],
      offcanvas = document.getElementsByClassName('emoza-desktop-offcanvas')[0];
    if (!buttons.length) {
      return false;
    }
    for (var i = 0; i < buttons.length; i++) {
      buttons[i].addEventListener('click', function (e) {
        e.preventDefault();
        if (offcanvas.classList.contains('emoza-desktop-offcanvas-show')) {
          offcanvas.classList.remove('emoza-desktop-offcanvas-show');
        } else {
          offcanvas.classList.add('emoza-desktop-offcanvas-show');
        }
      });
    }
    closeButton.addEventListener('click', function (e) {
      e.preventDefault();
      offcanvas.classList.remove('emoza-desktop-offcanvas-show');
    });

    // Close mega menu when clicking outside
    document.addEventListener('click', function (e) {
      if (e.target.closest('.emoza-desktop-offcanvas-menu') === null && offcanvas.querySelector('.emoza-mega-menu .sub-menu.toggled') !== null) {
        offcanvas.querySelector('.emoza-mega-menu .sub-menu.toggled').classList.remove('toggled');
      }
    });
  }
};

/**
 * Header search
 */
emoza.headerSearch = {
  init: function init() {
    var self = this,
      button = document.querySelectorAll('.header-search'),
      form = window.matchMedia('(max-width: 1024px)').matches ? document.querySelector('#masthead-mobile .header-search-form') : document.querySelector('#masthead .header-search-form'),
      overlay = document.getElementsByClassName('search-overlay')[0],
      searchBtn = form !== null ? form.getElementsByClassName('search-submit')[0] : undefined;
    if (button.length === 0) {
      return;
    }
    if (document.body.classList.contains('has-ehfb-builder')) {
      form = document.querySelector('.header-search-form');
    }
    if (typeof overlay !== 'undefined') {
      var _iterator12 = _createForOfIteratorHelper(button),
        _step12;
      try {
        for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
          var buttonEl = _step12.value;
          buttonEl.addEventListener('click', function (e) {
            e.preventDefault();

            // Hide other search icons 
            if (button.length > 1) {
              var _iterator13 = _createForOfIteratorHelper(button),
                _step13;
              try {
                for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) {
                  var btn = _step13.value;
                  btn.classList.toggle('hide');
                }
              } catch (err) {
                _iterator13.e(err);
              } finally {
                _iterator13.f();
              }
            }
            form.classList.toggle('active');
            overlay.classList.toggle('active');
            document.body.classList.toggle('header-search-form-active');
            e.target.closest('.header-search').getElementsByClassName('icon-search')[0].classList.toggle('active');
            e.target.closest('.header-search').getElementsByClassName('icon-cancel')[0].classList.toggle('active');
            e.target.closest('.header-search').classList.add('active');
            e.target.closest('.header-search').classList.remove('hide');
            var searchInput = '';
            if (window.matchMedia('screen and (min-width: 1024px)').matches) {
              searchInput = document.querySelectorAll('.ehfb-desktop .header-search-form .search-field')[0];
            } else {
              searchInput = document.querySelectorAll('.ehfb-mobile .header-search-form .search-field')[0];
            }
            if (e.target.closest('.header-search').parentNode.classList.contains('header-search-form-hide-input-on-mobile')) {
              searchInput = document.querySelectorAll('.ehfb-mobile .header-search-form .search-field')[1];
            }
            if (typeof searchInput !== 'undefined') {
              searchInput.focus();
            }
            if (e.target.closest('.emoza-offcanvas-menu') !== null) {
              e.target.closest('.emoza-offcanvas-menu').classList.remove('toggled');
            }
          });
        }
      } catch (err) {
        _iterator12.e(err);
      } finally {
        _iterator12.f();
      }
      overlay.addEventListener('click', function () {
        form.classList.remove('active');
        overlay.classList.remove('active');
        document.body.classList.remove('header-search-form-active');

        // Back buttons to default state
        self.backButtonsToDefaultState(button);
      });
    }
    if (typeof searchBtn !== 'undefined') {
      searchBtn.addEventListener('keydown', function (e) {
        var isTabPressed = e.key === 'Tab' || e.keyCode === KEYCODE_TAB;
        if (!isTabPressed) {
          return;
        }
        form.classList.remove('active');
        overlay.classList.remove('active');
        document.body.classList.remove('header-search-form-active');

        // Back buttons to default state
        self.backButtonsToDefaultState(button);
        button.focus();
      });
    }
    var desktop_offcanvas = document.getElementsByClassName('header-desktop-offcanvas-layout2')[0] !== null ? document.getElementsByClassName('emoza-desktop-offcanvas')[0] : false;
    if (desktop_offcanvas) {
      desktop_offcanvas.addEventListener('click', function (e) {
        if (e.target.closest('.header-search') === null) {
          form.classList.remove('active');
          overlay.classList.remove('active');
          document.body.classList.remove('header-search-form-active');

          // Back buttons to default state
          self.backButtonsToDefaultState(button);
        }
      });
    }
    return this;
  },
  backButtonsToDefaultState: function backButtonsToDefaultState(button) {
    var _iterator14 = _createForOfIteratorHelper(button),
      _step14;
    try {
      for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) {
        var btn = _step14.value;
        btn.classList.remove('hide');
        btn.querySelector('.icon-cancel').classList.remove('active');
        btn.querySelector('.icon-search').classList.add('active');
      }
    } catch (err) {
      _iterator14.e(err);
    } finally {
      _iterator14.f();
    }
  }
};

/**
 * Sticky header
 */
emoza.stickyHeader = {
  init: function init() {
    var _this = this,
      sticky = document.getElementsByClassName('sticky-header')[0],
      ehfb_sticky = document.getElementsByClassName('ehfb-sticky-header')[0],
      body = document.getElementsByTagName('body')[0];
    if ('undefined' === typeof sticky && 'undefined' === typeof ehfb_sticky) {
      return;
    }
    var sticky_selector = 'undefined' !== typeof sticky ? '.sticky-header' : '.ehfb-sticky-header';
    if ('undefined' === typeof sticky) {
      sticky = ehfb_sticky;
    }
    this.stickyChangeLogo();
    var topOffset = window.pageYOffset || document.documentElement.scrollTop;
    if (topOffset > 10) {
      sticky.classList.add('is-sticky');
      body.classList.add('sticky-header-active');
      window.dispatchEvent(new Event('emoza.sticky.header.activated'));
    }
    var header_offset_y = document.querySelector(sticky_selector).getBoundingClientRect().y;
    if (document.body.classList.contains('admin-bar')) {
      header_offset_y = header_offset_y - 32;
    }
    if (document.body.classList.contains('emoza-site-layout-padded')) {
      header_offset_y = header_offset_y - parseInt(getComputedStyle(document.body).getPropertyValue('--emoza_padded_spacing'));
    }
    if (sticky.classList.contains('sticky-scrolltop') || document.querySelector('.ehfb.sticky-scrolltop') !== null) {
      var lastScrollTop = 0;
      window.addEventListener('scroll', function () {
        var scroll = window.pageYOffset || document.documentElement.scrollTop,
          is_sticky = scroll > lastScrollTop || scroll < 10;
        if (document.querySelector('.ehfb.sticky-scrolltop') !== null) {
          var ehfb_header_height = document.querySelector('.ehfb.sticky-scrolltop').getBoundingClientRect().height;
          is_sticky = scroll < ehfb_header_height;
        }
        if (is_sticky) {
          sticky.classList.remove('is-sticky');
          body.classList.remove('sticky-header-active');
          _this.isHBStickyDeactivated('scrolltop');
          body.classList.add('on-header-area');
          window.dispatchEvent(new Event('emoza.sticky.header.deactivated'));
        } else {
          sticky.classList.add('is-sticky');
          body.classList.add('sticky-header-active');
          _this.isHBStickyActive('scrolltop');
          body.classList.remove('on-header-area');
          window.dispatchEvent(new Event('emoza.sticky.header.activated'));
        }
        lastScrollTop = scroll <= 0 ? 0 : scroll;
      }, false);
    } else {
      window.addEventListener('scroll', function () {
        var vertDist = window.scrollY;
        if (vertDist > header_offset_y) {
          sticky.classList.add('sticky-shadow');
          body.classList.add('sticky-header-active');
          _this.isHBStickyActive();
          window.dispatchEvent(new Event('emoza.sticky.header.activated'));
        } else {
          sticky.classList.remove('sticky-shadow');
          body.classList.remove('sticky-header-active');
          _this.isHBStickyDeactivated();
          window.dispatchEvent(new Event('emoza.sticky.header.deactivated'));
        }
      }, false);
    }
  },
  isHBStickyActive: function isHBStickyActive(effect) {
    var ehfb = document.querySelector('header.ehfb'),
      has_admin_bar = document.body.classList.contains('admin-bar'),
      above_header_row = document.querySelector('.ehfb-above_header_row'),
      main_header_row = document.querySelector('.ehfb-main_header_row'),
      below_header_row = document.querySelector('.ehfb-below_header_row');
    if (ehfb === null) {
      return false;
    }
    var topVal = 0,
      convertToPositive = false;
    if (ehfb.classList.contains('sticky-row-main-header-row')) {
      if (!above_header_row.classList.contains('em-d-none')) {
        topVal = above_header_row.clientHeight;
        if (document.body.classList.contains('emoza-site-layout-padded')) {
          convertToPositive = true;
        }
      } else {
        convertToPositive = true;
      }

      // Admin Bar
      if (has_admin_bar) {
        topVal = topVal - 32;
      } else {
        if (!above_header_row.classList.contains('em-d-none') && document.body.classList.contains('emoza-site-layout-padded')) {
          convertToPositive = false;
        }
      }

      // Padded Layout
      if (document.body.classList.contains('emoza-site-layout-padded')) {
        topVal = topVal - parseFloat(getComputedStyle(document.body).getPropertyValue('--emoza_padded_spacing'));
      }

      // Conert to negative value
      topVal = convertToPositive ? +Math.abs(topVal) : -Math.abs(topVal);
      ehfb.style.top = "".concat(topVal, "px");
    }
    if (ehfb.classList.contains('sticky-row-below-header-row')) {
      if (!below_header_row.classList.contains('em-d-none')) {
        if (has_admin_bar) {
          topVal = ehfb.clientHeight - below_header_row.clientHeight - 32 - parseFloat(getComputedStyle(below_header_row).borderBottomWidth);
        } else {
          topVal = ehfb.clientHeight - below_header_row.clientHeight - parseFloat(getComputedStyle(below_header_row).borderBottomWidth);
        }
      }
      if (above_header_row.classList.contains('em-d-none') && main_header_row.classList.contains('em-d-none')) {
        convertToPositive = true;
      }

      // Padded Layout
      if (document.body.classList.contains('emoza-site-layout-padded')) {
        topVal = topVal - parseFloat(getComputedStyle(document.body).getPropertyValue('--emoza_padded_spacing'));
      }

      // Conert to negative value
      topVal = convertToPositive ? +Math.abs(topVal) : -Math.abs(topVal);
      ehfb.style.top = "".concat(topVal, "px");
    }
    if (effect === 'scrolltop' && document.body.classList.contains('on-header-area')) {
      ehfb.classList.add('ehfb-no-transition');
      setTimeout(function () {
        ehfb.classList.remove('ehfb-no-transition');
      }, 500);
    }
  },
  isHBStickyDeactivated: function isHBStickyDeactivated(effect) {
    var ehfb = document.querySelector('header.ehfb');
    if (ehfb === null) {
      return false;
    }
    if (ehfb.classList.contains('sticky-row-main-header-row')) {
      ehfb.style.top = '0px';
    }
    if (ehfb.classList.contains('sticky-row-below-header-row')) {
      if (!document.querySelector('.ehfb-below_header_row').classList.contains('em-d-none')) {
        ehfb.style.top = '0px';
      }
    }
  },
  stickyChangeLogo: function stickyChangeLogo() {
    var sticky_flag = false;
    if (window.matchMedia('screen and (min-width: 1024px)').matches) {
      if (typeof emoza_sticky_header_logo !== 'undefined') {
        var logo = document.body.classList.contains('has-ehfb-builder') ? document.querySelector('.ehfb-sticky-header .site-branding img') : document.querySelector('.sticky-header .site-branding img');
        if (logo === null) {
          return false;
        }
        var initialSrc = logo.getAttribute('src'),
          initialSrcset = logo.getAttribute('srcset'),
          initialSizes = logo.getAttribute('sizes'),
          initialHeight = logo.clientHeight;
        window.addEventListener('emoza.sticky.header.activated', function () {
          if (sticky_flag) {
            return false;
          }
          logo.setAttribute('src', emoza_sticky_header_logo[0]);
          logo.setAttribute('style', 'max-height: ' + initialHeight + 'px;');
          if (typeof emoza_sticky_header_logo['srcset'] !== 'undefined') {
            logo.setAttribute('srcset', emoza_sticky_header_logo['srcset']);
          }
          if (typeof emoza_sticky_header_logo['sizes'] !== 'undefined') {
            logo.setAttribute('sizes', emoza_sticky_header_logo['sizes']);
          }
          sticky_flag = true;
        });
        window.addEventListener('emoza.sticky.header.deactivated', function () {
          if (!sticky_flag) {
            return false;
          }
          logo.setAttribute('src', initialSrc);
          if (initialSrcset !== null) {
            logo.setAttribute('srcset', initialSrcset);
          }
          if (initialSizes !== null) {
            logo.setAttribute('sizes', initialSizes);
          }
          sticky_flag = false;
        });
      }
    }
  }
};

/**
 * Emoza scroll direction
 */
emoza.scrollDirection = {
  init: function init() {
    var elements = document.querySelectorAll('.emoza-single-sticky-add-to-cart-wrapper.hide-when-scroll'),
      body = document.getElementsByTagName('body')[0];
    if ('null' === typeof elements) {
      return;
    }
    var lastScrollTop = 0;
    window.addEventListener('scroll', function () {
      var scroll = window.pageYOffset || document.documentElement.scrollTop;
      if (scroll > lastScrollTop) {
        body.classList.remove('emoza-scrolling-up');
        body.classList.add('emoza-scrolling-down');
      } else {
        body.classList.remove('emoza-scrolling-down');
        body.classList.add('emoza-scrolling-up');
      }
      lastScrollTop = scroll <= 0 ? 0 : scroll;
    }, false);
  }
};

/**
 * Emoza custom add to cart button
 * 
 */
emoza.customAddToCartButton = {
  init: function init() {
    var button = document.querySelectorAll('.emoza-custom-addtocart');
    if (!button.length) {
      return false;
    }
    for (var i = 0; i < button.length; i++) {
      button[i].addEventListener('click', function (e) {
        e.preventDefault();
        var button = this,
          productId = this.getAttribute('data-product-id'),
          initial_text = this.innerHTML,
          loading_text = this.getAttribute('data-loading-text'),
          added_text = this.getAttribute('data-added-text'),
          nonce = this.getAttribute('data-nonce');
        var ajax = new XMLHttpRequest();
        ajax.open('POST', emoza.ajaxurl, true);
        ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        button.innerHTML = loading_text;
        ajax.onload = function () {
          if (this.status >= 200 && this.status < 400) {
            button.innerHTML = added_text;
            setTimeout(function () {
              button.innerHTML = initial_text;
            }, 1500);
            jQuery(document.body).trigger('wc_fragment_refresh');
            jQuery(document.body).trigger('added_to_cart');
            document.body.dispatchEvent(new Event('emoza.custom_added_to_cart'));
          }
        };
        ajax.send('action=emoza_custom_addtocart&product_id=' + productId + '&nonce=' + nonce);
      });
    }
  }
};

/**
 * Back to top button
 */
emoza.backToTop = {
  init: function init() {
    this.backToTop();
    window.addEventListener('scroll', function () {
      this.backToTop();
    }.bind(this));
    this.safariDoubleClickFix();
  },
  backToTop: function backToTop() {
    var button = document.getElementsByClassName('back-to-top')[0];
    if ('undefined' !== typeof button) {
      var scrolled = window.pageYOffset;
      if (scrolled > 300) {
        button.classList.add('display');
      } else {
        button.classList.remove('display');
      }
      button.removeEventListener('click', this.scrollToTop);
      button.addEventListener('click', this.scrollToTop);
    }
  },
  scrollToTop: function scrollToTop() {
    window.scrollTo({
      top: 0,
      left: 0,
      behavior: 'smooth'
    });
  },
  // Unknown safari issue. If we add a 'touchend' event listener to the button the problem is resolved.
  // Fixes: https://wordpress.org/support/topic/double-tap-issue-on-mobile/
  safariDoubleClickFix: function safariDoubleClickFix() {
    var links = document.querySelectorAll('.product-gallery-summary .emoza-single-addtocart-wrapper .button, .single-product .content-wrapper a, .single-product .footer-widgets a, .single-product .site-footer a');
    if (!links.length) {
      return false;
    }
    var _iterator15 = _createForOfIteratorHelper(links),
      _step15;
    try {
      for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
        var link = _step15.value;
        link.addEventListener('touchend', function () {});
      }
    } catch (err) {
      _iterator15.e(err);
    } finally {
      _iterator15.f();
    }
  }
};

/**
 * Quantity button
 */
emoza.qtyButton = {
  init: function init(type) {
    this.events(type);
    this.wooEvents();
  },
  events: function events(type) {
    var self = this;
    var qty = document.querySelectorAll('.emoza-quantity-minus');
    if (qty.length < 1) {
      return false;
    }
    for (var i = 0; i < qty.length; i++) {
      var wrapper = qty[i].closest('.quantity');
      if (wrapper === null || wrapper.dataset.qtyInitialized) {
        continue;
      }
      if (wrapper.classList.contains('hidden')) {
        return false;
      }
      var qtyInput = wrapper.querySelector('.qty'),
        plus = wrapper.querySelector('.emoza-quantity-plus'),
        minus = wrapper.querySelector('.emoza-quantity-minus'),
        input = wrapper.querySelector('.input-text');
      plus.classList.add('show');
      minus.classList.add('show');
      qtyInput.addEventListener('change', function (e) {
        self.behaviorsBasedOnQuantityValue(this, this.value);
      });
      qtyInput.addEventListener('keyup', function (e) {
        self.behaviorsBasedOnQuantityValue(this, this.value);
      });
      plus.addEventListener('click', function (e) {
        e.preventDefault();
        var input = this.parentNode.querySelector('.qty'),
          qtyMax = Number(input.getAttribute('max')) || 99999,
          qtyMin = Number(input.getAttribute('min')),
          qtyStep = Number(input.getAttribute('step')),
          qtyValue = Number(input.value),
          changeEvent = document.createEvent('HTMLEvents');
        input.value = Math.max(qtyMin, Math.min(qtyMax, (qtyValue + qtyStep).toFixed(1)));
        changeEvent.initEvent('change', true, false);
        input.dispatchEvent(changeEvent);
        self.updateAddToCartQuantity(this, input.value);
        self.updateBuyNowButtonQuantity(this, input.value);
        self.behaviorsBasedOnQuantityValue(this, input.value);
      });
      minus.addEventListener('click', function (e) {
        e.preventDefault();
        var input = this.parentNode.querySelector('.qty'),
          qtyMax = Number(input.getAttribute('max')) || 99999,
          qtyMin = Number(input.getAttribute('min')),
          qtyStep = Number(input.getAttribute('step')),
          qtyValue = Number(input.value),
          changeEvent = document.createEvent('HTMLEvents');
        input.value = Math.max(qtyMin, Math.min(qtyMax, (qtyValue - qtyStep).toFixed(1)));
        changeEvent.initEvent('change', true, false);
        input.dispatchEvent(changeEvent);
        self.updateAddToCartQuantity(this, input.value);
        self.updateBuyNowButtonQuantity(this, input.value);
        self.behaviorsBasedOnQuantityValue(this, input.value);
      });
      input.addEventListener('change', function (e) {
        self.updateAddToCartQuantity(this, this.value);
        self.updateBuyNowButtonQuantity(this, this.value);
      });
      wrapper.dataset.qtyInitialized = true;
    }
  },
  wooEvents: function wooEvents() {
    var _self = this;
    if (typeof jQuery !== 'undefined') {
      jQuery('body').on('updated_cart_totals', function () {
        _self.events();
      });
      jQuery(document).on('wc_fragments_loaded', function () {
        _self.events();
      });
    }
  },
  updateAddToCartQuantity: function updateAddToCartQuantity(qtyItem, qtyValue) {
    if (qtyItem.closest('.woocommerce-cart-form') !== null) {
      return false;
    }
    var productSelector = qtyItem.closest('.product') ? '.product' : '.wc-block-grid__product',
      product = qtyItem.closest(productSelector),
      qtyInput = qtyItem.parentNode.querySelector('.qty');
    if (product) {
      var addToCartButton = product.querySelector('.add_to_cart_button:not(.single_add_to_cart_button)');
      if (addToCartButton) {
        addToCartButton.setAttribute('data-quantity', qtyValue);
      }
    }
    var miniCartItem = qtyItem.closest('.mini_cart_item') ? qtyItem.closest('.mini_cart_item') : qtyItem.closest('.woocommerce-cart-form__cart-item');
    if (miniCartItem) {
      var $cart = jQuery(qtyItem.closest('.widget_shopping_cart'));
      $cart.block({
        message: null,
        overlayCSS: {
          background: '#fff',
          opacity: 0.6
        }
      });
      jQuery.post({
        url: emoza.ajaxurl,
        data: {
          action: 'emoza_update_mini_cart_quantity',
          quantity: qtyInput.value,
          cart_item_key: qtyInput.name,
          nonce: jQuery('#mini_cart_qty_nonce').val()
        },
        success: function success(response) {
          jQuery(document.body).trigger('added_to_cart', [response.fragments, response.cart_hash]);
          setTimeout(function () {
            $cart.unblock();
          }, 100);
        }
      });
    }
  },
  updateBuyNowButtonQuantity: function updateBuyNowButtonQuantity(qtyItem, qtyValue) {
    var is_checkout_quantity = qtyItem.parentNode.parentNode.classList.contains('emoza-sc-product-name') || qtyItem.parentNode.parentNode.classList.contains('product-name') ? true : false,
      is_mini_cart_quantity = qtyItem.closest('.woocommerce-mini-cart-item') !== null ? true : false;
    if (is_checkout_quantity || is_mini_cart_quantity) {
      return false;
    }
    var productSelector = qtyItem.closest('.product') ? '.product' : '.wc-block-grid__product',
      product = qtyItem.closest(productSelector),
      qtyInput = qtyItem.parentNode.querySelector('.qty'),
      buyNowButton = product ? product.querySelector('.emoza-buy-now-button') : null;
    if (buyNowButton === null) {
      return false;
    }
    var url = new URL(buyNowButton.getAttribute('href'));
    url.searchParams.set('quantity', qtyValue);
    buyNowButton.setAttribute('href', url);
  },
  behaviorsBasedOnQuantityValue: function behaviorsBasedOnQuantityValue(qtyItem, qtyValue) {
    var productSelector = qtyItem.closest('.product') ? '.product' : '.wc-block-grid__product',
      product = qtyItem.closest(productSelector);
    if (product) {
      var addToCartButton = product.querySelector('.add_to_cart_button:not(.single_add_to_cart_button)');
      if (addToCartButton) {
        if (qtyValue == 0) {
          addToCartButton.classList.add('disabled');
        } else {
          addToCartButton.classList.remove('disabled');
        }
      }
    }
  }
};

/**
 * Carousel 
 */
emoza.carousel = {
  init: function init() {
    this.build();
    this.events();
  },
  build: function build() {
    if (document.querySelector('.emoza-carousel') === null && document.querySelector('.has-cross-sells-carousel') === null && document.querySelector('.emoza-woocommerce-mini-cart__cross-sell') === null) {
      return false;
    }
    var carouselEls = document.querySelectorAll('.emoza-carousel, #masthead .cross-sells, .emoza-side-mini-cart .cross-sells, .cart-collaterals .cross-sells');
    var _iterator16 = _createForOfIteratorHelper(carouselEls),
      _step16;
    try {
      for (_iterator16.s(); !(_step16 = _iterator16.n()).done;) {
        var carouselEl = _step16.value;
        if (carouselEl.querySelector('.emoza-carousel-stage') === null) {
          carouselEl.querySelector('.products').classList.add('emoza-carousel-stage');
        }
        if (carouselEl.getAttribute('data-initialized') !== 'true') {
          var perPage = carouselEl.getAttribute('data-per-page');
          if (perPage === null) {
            var stageClassList = carouselEl.querySelector('.products').classList.value;
            [1, 2, 3, 4, 5].forEach(function (columns) {
              if (stageClassList.indexOf('columns-' + columns) > 0) {
                perPage = columns;
              }
            });
          }

          // Mount carousel wrapper
          var wrapper = document.createElement('div'),
            stage = carouselEl.querySelector('.emoza-carousel-stage');
          wrapper.className = 'emoza-carousel-wrapper';
          wrapper.innerHTML = stage.outerHTML;
          stage.remove();
          carouselEl.append(wrapper);

          // Margin
          var margin = 30;
          if (typeof emoza_carousel !== 'undefined') {
            margin = parseInt(emoza_carousel.margin_desktop);
          } else if (carouselEl.closest('.emoza-woocommerce-mini-cart__cross-sell') !== null) {
            margin = 15;
          }
          var itemsQty = carouselEl.querySelectorAll('li.product').length;
          if (itemsQty <= parseInt(perPage)) {
            carouselEl.classList.add('emoza-carousel-not-initialized');
            return false;
          }

          // Initialize
          var carousel = new Siema({
            parentSelector: carouselEl,
            selector: '.emoza-carousel-stage',
            duration: 200,
            easing: 'ease-out',
            perPage: perPage !== null ? {
              0: 1,
              768: 2,
              1025: parseInt(perPage)
            } : 2,
            startIndex: 0,
            draggable: true,
            multipleDrag: false,
            threshold: 20,
            loop: true,
            rtl: false,
            // autoplay: true, TO DO
            margin: margin,
            onInit: function onInit() {
              window.dispatchEvent(new Event('emoza.carousel.initialized'));
            }
          });
        }
      }
    } catch (err) {
      _iterator16.e(err);
    } finally {
      _iterator16.f();
    }
  },
  events: function events() {
    var _this = this;
    if (typeof jQuery !== 'undefined') {
      var onpageload = true;
      jQuery(document.body).on('wc_fragment_refresh added_to_cart removed_from_cart', function () {
        setTimeout(function () {
          var mini_cart = document.getElementById('site-header-cart'),
            mini_cart_list = mini_cart.querySelector('.cart_list');
          if (mini_cart_list !== null) {
            if (mini_cart_list.children.length > 2) {
              mini_cart.classList.remove('mini-cart-has-no-scroll');
              mini_cart.classList.add('mini-cart-has-scroll');
            } else {
              mini_cart.classList.remove('mini-cart-has-scroll');
              mini_cart.classList.add('mini-cart-has-no-scroll');
            }
          }
          _this.build();
          onpageload = false;
        }, onpageload ? 1000 : 0);
      });
    }
  }
};

/**
 * Copy link to clipboard
 */
emoza.copyLinkToClipboard = {
  init: function init(event, el) {
    event.preventDefault();
    navigator.clipboard.writeText(window.location.href);
    el.classList.add('copied');
    el.setAttribute('data-emoza-tooltip', emoza.i18n.emoza_sharebox_copy_link_copied);
    setTimeout(function () {
      el.setAttribute('data-emoza-tooltip', emoza.i18n.emoza_sharebox_copy_link);
      el.classList.remove('copied');
    }, 1000);
  }
};

/**
 * Toggle class
 */
emoza.toggleClass = {
  init: function init(event, el, triggerEvent) {
    event.preventDefault();
    event.stopPropagation();
    var selector = document.querySelector(el.getAttribute('data-emoza-selector')),
      removeClass = el.getAttribute('data-emoza-toggle-class-remove'),
      classname = el.getAttribute('data-emoza-toggle-class'),
      classes = selector.classList;
    if (typeof removeClass === 'string') {
      classes.remove(removeClass);
    }
    classes.toggle(classname);
    if (triggerEvent) {
      var ev = document.createEvent('HTMLEvents');
      ev.initEvent(triggerEvent, true, false);
      window.dispatchEvent(ev);
    }
  }
};

/**
 * Collapse
 */
emoza.collapse = {
  init: function init() {
    var elements = document.querySelectorAll('[data-emoza-collapse]');
    if (!elements.length) {
      return false;
    }
    var _this = this;
    var _loop2 = function _loop2(i) {
      var opts = elements[i].getAttribute('data-emoza-collapse'),
        options = JSON.parse(opts.replace(/'/g, '"').replace(';', ''));
      if (!options.enable) {
        return {
          v: false
        };
      }
      _this.expand(elements[i], options, true);
      elements[i].addEventListener('click', function (e) {
        e.preventDefault();
        this.dispatchEvent(new Event('emoza.collapse.before.expand'));
        if (!elements[i].classList.contains('active')) {
          _this.expand(elements[i], options);
        } else {
          _this.collapse(elements[i], options);
        }
        this.dispatchEvent(new Event('emoza.collapse.after.collapse'));
      });
      if (options.options.oneAtTime) {
        elements[i].addEventListener('emoza.collapse.before.expand', function () {
          var emoza_collapse = document.querySelectorAll(options.options.oneAtTimeParentSelector + ' [data-emoza-collapse]');
          for (var u = 0; u < emoza_collapse.length; u++) {
            _this.collapseAll(emoza_collapse[u], options);
          }
        });
      }
    };
    for (var i = 0; i < elements.length; i++) {
      var _ret = _loop2(i);
      if (_typeof(_ret) === "object") return _ret.v;
    }
  },
  expand: function expand(el, options, first_load) {
    if (first_load && !el.classList.contains('active')) {
      return false;
    }
    var targetSelectorId = options.id,
      target = document.getElementById(targetSelectorId),
      targetContent = target.querySelector('.emoza-collapse__content');
    target.addEventListener('transitionend', this.expandTransitionEnd.bind(this, el));
    target.style = 'max-height: ' + targetContent.clientHeight + 'px;';
    el.classList.add('active');
    target.classList.add('active');
  },
  expandTransitionEnd: function expandTransitionEnd(el) {
    if (!el.classList.contains('active')) {
      return false;
    }
    el.dispatchEvent(new Event('emoza.collapse.expanded'));
  },
  collapse: function collapse(el, options, a) {
    var targetSelectorId = options.id,
      target = document.getElementById(targetSelectorId);
    target.style = 'max-height: 0px;';
    el.classList.remove('active');
    target.classList.remove('active');
    el.dispatchEvent(new Event('emoza.collapse.collapsed'));
  },
  collapseAll: function collapseAll(el, options) {
    el.classList.remove('active');
    el.nextElementSibling.classList.remove('active');
    el.nextElementSibling.style = 'max-height: 0px;';
  }
};
emoza.tabsNav = {
  init: function init() {
    var tabsNav = document.querySelectorAll('.emoza-tabs-nav');
    if (!tabsNav.length) {
      return false;
    }
    this.events();
  },
  events: function events() {
    var tabsNavItems = document.querySelectorAll('.emoza-tabs-nav-item');
    var _iterator17 = _createForOfIteratorHelper(tabsNavItems),
      _step17;
    try {
      for (_iterator17.s(); !(_step17 = _iterator17.n()).done;) {
        var tabItem = _step17.value;
        var hasClickOnMouseOver = tabItem.closest('.emoza-tabs-nav').classList.contains('emoza-tabs-nav-click-on-mouseover');
        if (hasClickOnMouseOver) {
          (function () {
            var st = void 0;
            tabItem.addEventListener('mouseover', function (e) {
              e.preventDefault();
              var self = this;
              st = setTimeout(function () {
                self.dispatchEvent(new Event('click'));
              }, 500);
            });
            tabItem.addEventListener('mouseout', function (e) {
              clearTimeout(st);
            });
          })();
        }
        tabItem.addEventListener('click', function (e) {
          e.preventDefault();
          var _this = this,
            tabId = this.querySelector('.emoza-tabs-nav-link').getAttribute('href'),
            previousTabId = this.closest('.emoza-tabs-nav').querySelector('.emoza-tabs-nav-item.is-active .emoza-tabs-nav-link').getAttribute('href'),
            previousActiveTab = document.querySelector(previousTabId),
            tabContentTo = document.querySelector(tabId),
            activeTabsCount = tabContentTo.parentNode.querySelectorAll('.emoza-tab-content.is-active').length;
          if (tabContentTo === null) {
            return false;
          }
          if (activeTabsCount === 0 || activeTabsCount > 1) {
            return false;
          }
          if (tabContentTo.classList.contains('is-active')) {
            return false;
          }
          tabsNavItems = this.closest('.emoza-tabs-nav').querySelectorAll('.emoza-tabs-nav-item');
          var _iterator18 = _createForOfIteratorHelper(tabsNavItems),
            _step18;
          try {
            for (_iterator18.s(); !(_step18 = _iterator18.n()).done;) {
              var _tabItem = _step18.value;
              var _tabContentTo = document.querySelector(_tabItem.querySelector('.emoza-tabs-nav-link').getAttribute('href'));
              if (_tabContentTo === null) {
                continue;
              }
              _tabItem.classList.remove('is-active');
              _tabContentTo.classList.remove('is-active');
            }
          } catch (err) {
            _iterator18.e(err);
          } finally {
            _iterator18.f();
          }
          previousActiveTab.classList.add('removing');
          setTimeout(function () {
            _this.classList.add('is-active');
            tabContentTo.classList.add('activating');
            setTimeout(function () {
              tabContentTo.classList.add('is-active');
              tabContentTo.classList.remove('activating');
            }, 300);
            previousActiveTab.classList.remove('removing');
          }, 300);
        });
      }
    } catch (err) {
      _iterator17.e(err);
    } finally {
      _iterator17.f();
    }
  }
};

/**
 * Misc
 */
emoza.misc = {
  init: function init() {
    this.wcExpressPayButtons();
    this.singleProduct();
    this.cart();
    this.checkout();
    this.customizer();
  },
  wcExpressPayButtons: function wcExpressPayButtons() {
    var is_checkout_page = document.querySelector('body.woocommerce-checkout'),
      is_cart_page = document.querySelector('body.woocommerce-cart'),
      is_single_product = document.querySelector('body.single-product');
    if (is_single_product === null && is_checkout_page === null && is_cart_page === null) {
      return false;
    }
    if (typeof jQuery === 'function') {
      (function ($) {
        if (typeof $('#wc-stripe-payment-request-button-separator, #wcpay-payment-request-wrapper').get(0) === 'undefined') {
          return false;
        }
        if (is_checkout_page === null) {
          $('#wc-stripe-payment-request-button-separator, #wcpay-payment-request-button-separator').appendTo('form.cart');
          $('#wc-stripe-payment-request-wrapper, #wcpay-payment-request-wrapper').appendTo('form.cart');
          $(window).trigger('emoza.wcexpresspaybtns.appended');
        }
      })(jQuery);
    }
  },
  singleProduct: function singleProduct() {
    var _this = this,
      is_product_page = document.querySelector('body.single-product');
    if (is_product_page === null) {
      return false;
    }

    // Move reset variations button for better styling
    if (typeof jQuery === 'function') {
      (function ($) {
        $('.variations_form').each(function () {
          if ($(this).data('misc-variations') === true) {
            return false;
          }

          // Move reset button
          _this.moveResetVariationButton($(this));

          // First load
          _this.checkIfHasVariationSelected($(this));

          // on change variation select
          $(this).on('woocommerce_variation_select_change', function () {
            _this.checkIfHasVariationSelected($(this));
          });
          $(this).data('misc-variations', true);
        });

        // Single Product - In Cart Flag.
        if ($('.emoza-in-cart-flag').length) {
          var $form = $('body.single-product .entry-summary .variations_form, .emoza-tb-sp-add-to-cart'),
            addToCartButton = $form.find('.single_add_to_cart_button'),
            defaultAddToCartButtonText = addToCartButton.text();
          $form.each(function () {
            $(this).on('found_variation', function (event, variation) {
              var variationInCart = emozaInCartFlag.variations_in_cart.filter(function (a) {
                return a.variation_id === variation.variation_id;
              });
              var addToCartButtonText = variationInCart.length ? variationInCart[0].addtocart_button_text : addToCartButton.text();
              addToCartButton.html(addToCartButtonText);
            });
            $(this).on('reset_data', function () {
              addToCartButton.text(defaultAddToCartButtonText);
            });
          });
        }
      })(jQuery);
    }
  },
  moveResetVariationButton: function moveResetVariationButton($this) {
    var clone = $this.find('.reset_variations');
    clone.remove();
    $this.find('table').after(clone);
  },
  checkIfHasVariationSelected: function checkIfHasVariationSelected($this) {
    var all_empty = true;
    $this.find('td.value select').each(function () {
      if (jQuery(this).val() !== '') {
        all_empty = false;
        jQuery(this).closest('table').addClass('has-variation-selected');
        return false;
      } else {
        jQuery(this).closest('table').removeClass('has-variation-selected');
      }
    });
    if (all_empty) {
      $this.closest('.variations_form').find('.reset_variations').css('display', 'none');
    } else {
      $this.closest('.variations_form').find('.reset_variations').css('display', 'inline-block');
    }
  },
  cart: function cart() {
    var is_cart_page = document.querySelector('body.woocommerce-cart');
    if (is_cart_page === null) {
      return false;
    }
    if (typeof jQuery === 'function') {
      (function ($) {
        if ($('header.has-sticky-header').length) {
          $(document).on('updated_cart_totals', function () {
            $(window).on('scroll', function (e) {
              $('html, body').stop(true, false);
              $(this).off(e);
              $('html, body').animate({
                scrollTop: $('[role="alert"]').offset().top - $('header.has-sticky-header').height()
              }, 1000);
            });
          });
        }
      })(jQuery);
    }
  },
  checkout: function checkout() {
    var is_checkout_page = document.querySelector('body.woocommerce-checkout');
    if (is_checkout_page === null) {
      return false;
    }

    // There's no woo hook for that, so we need do that with js
    if (typeof jQuery === 'function') {
      jQuery(document).on('updated_checkout', function () {
        var shipping_totals_table_column = document.querySelector('#order_review .woocommerce-shipping-totals > td');
        if (shipping_totals_table_column !== null) {
          document.querySelector('#order_review .woocommerce-shipping-totals > td').setAttribute('colspan', 2);
        }
      });
    }
  },
  customizer: function customizer() {
    if (!window.parent.document.body.classList.contains('wp-customizer')) {
      return false;
    }
    window.onload = function () {
      var cart_count = document.querySelectorAll('.cart-count');
      if (cart_count.length) {
        jQuery(document.body).trigger('wc_fragment_refresh');
      }
    };
  }
};
emoza.helpers.emozaDomReady(function () {
  emoza.navigation.init();
  emoza.desktopOffcanvasNav.init();
  emoza.desktopOffCanvasToggleNav.init();
  emoza.headerSearch.init();
  emoza.customAddToCartButton.init();
  emoza.stickyHeader.init();
  emoza.scrollDirection.init();
  emoza.backToTop.init();
  emoza.qtyButton.init();
  emoza.carousel.init();
  emoza.collapse.init();
  emoza.tabsNav.init();
  emoza.misc.init();
});