/* eslint-disable */

/**
 * Creating an options object with data attributes, classes and event names necessary for
 * initializing tabs, accordion and accordion-autoplay plugins.
 *
 * Tabs, accordion and accordion-autoplay plugins gets initialized on vcv 'ready' global event.
 *
 * Minified version of this file is compiled via webpack:
 * 1. Enter the public folder where webpack file is located
 * cd tabsWithSlide/public
 * 2. To compile run following command
 * ../../../../node_modules/.bin/webpack --config=webpack.config.js -p
 */

(function () {
  var tabs
  var accordion
  var accordionAutoplay

  var options = {
    isSlider: true,
    isDropdown: true,
    sliderWidth: 'outer',
    tabsAndAccordion: true,
    dataAttr: '[data-vce-toggle-container]',
    clickEventSelector: 'click.vce.toggleContainer.data-api',
    changeEventSelector: 'change.vce.toggleContainer.data-api',
    showEventSelector: 'show.vce.toggleContainerAccordion hide.vce.toggleContainerAccordion',
    accordionDropdownEventSelector: 'click.vce.toggleContainerAccordion.data-api.dropdown',
    accordionHashChangeEvent: 'hashchange.vce.toggleContainerAccordion',
    accordionClickEventSelector: 'click.vce.toggleContainerAccordion.data-api',
    accordionReadyEventSelector: 'ready.vce.toggleContainerAccordion',
    accordionAfterShowEventSelector: 'afterShow.vce.toggleContainerAccordion',
    activeAttribute: 'data-vcv-active',
    activeTabAttribute: 'data-active-tab',
    openedAttribute: 'data-vcv-tabs-opened',
    animatingAttribute: 'data-vcv-animating',
    positionToActive: 'data-vcv-position-to-active',
    tabDataSelector: '[data-vce-toggle-container-tab]',
    accordionDataSelector: '[data-vce-toggle-container-accordion]',
    accordionContainer: 'vce.toggleContainerAccordion',
    accordionPropertyName: 'vceToggleContainerAccordion',
    showTabSelector: 'show.vce.toggleContainerTab',
    hideTabSelector: 'hide.vce.toggleContainerTab',
    showAccordionSelector: 'show.vce.toggleContainerAccordion',
    hideAccordionSelector: 'hide.vce.toggleContainerAccordion',
    beforeShowAccordionSelector: 'beforeShow.vce.toggleContainerAccordion',
    afterShowAccordionSelector: 'afterShow.vce.toggleContainerAccordion',
    beforeHideAccordionSelector: 'beforeHide.vce.toggleContainerAccordion',
    afterHideAccordionSelector: 'afterHide.vce.toggleContainerAccordion',
    tabsDataSelector: 'vce.toggleContainer',
    dropdownSelector: '.vce-toggle-container-dropdown',
    tabsSelector: '.vce-toggle-container',
    tabsPropertyName: 'vceToggleContainer',
    tabContainerSelector: '.vce-toggle-container-list',
    resizeSelector: '.vce-toggle-container-resize-helper',
    sliderSelector: '.vce-toggle-container-slider',
    slidePanelsSelector: '.vce-toggle-container-panels',
    slidePanelSelector: '.vce-toggle-container-panel',
    slidePanelTitleSelector: '.vce-toggle-container-panel-title',
    slideInnerSelector: '.vce-toggle-container-inner',
    slidePanelHeadingSelector: '> .vce-toggle-container-panel > .vce-toggle-container-tab-inner > .vce-toggle-container-panel-heading [data-vce-toggle-container-accordion]',
    tabPanelBodySelector: '> .vce-toggle-container-tab-inner > .vce-toggle-container-panel-body',
    autoplayDataSelector: 'vce.toggleContainer.tta.autoplay',
    autoplayTimerSelector: 'vce.toggleContainer.tta.autoplay.timer',
    autoplayPropertyName: 'vceToggleContainerTtaAutoPlay',
    autoplaySelector: '[data-vce-toggle-container-tta-autoplay]',
    autoplayOnEventSelector: 'click.vce.toggleContainer.tta.autoplay.data-api',
    getAccordionHashSelector: function (hash) {
      return '[data-vce-toggle-container-accordion][href="' + hash + '"],[data-vce-toggle-container-accordion][data-vce-target="' + hash + '"]'
    }
  }

  function initiatePlugins () {
    if (!window.vcvIsToggleContainerInitialized) {
      window.vcvIsToggleContainerInitialized = true
      tabs = new window.VcvTabs(options)
      tabs.init()
      accordion = new window.VcvAccordion(options)
      accordion.init()
      if (window.VcvAccordionAutoplay) {
        accordionAutoplay = new window.VcvAccordionAutoplay(options)
        accordionAutoplay.init()
      }
    } else if (window.vcvIsToggleContainerInitialized && tabs && accordion) {
      tabs.setActiveTab()
      accordion.setActiveTab('add')
      if (accordionAutoplay) {
        accordionAutoplay.startAutoPlay()
      }
    }
  }

  if (window.vcv) {
    window.vcv.on('ready', function (action, id, options) {
      var element = document.getElementById(`el-${id}`)
      if (element && element.dataset && element.dataset.vcvTtaTypeElement) {
        initiatePlugins()
      } else if (!action && !id && !options) {
        initiatePlugins()
      }
    })
  }
})()
