export default () => {
    const accordionClass = '.muy-accordion'
    const accordions = $(accordionClass)

    accordions.map(function() {
        const accordion = $(this)
        const title = $(this).find('.accordion-header')
        const content = $(this).find('.accordion-content')
        const accordionGroup = accordion.data('accordion-group')
        const othersInGroup = $(`${accordionClass}[data-accordion-group="${accordionGroup}"]`).filter(function () {
            return this != accordion[0]
        })
        const othersContentsInGroup = $(`${accordionClass}[data-accordion-group="${accordionGroup}"] .accordion-content`).filter(function () {
          return this != content[0]
        })

        title.on('click', function (e) {
            e.preventDefault()

            othersContentsInGroup.slideUp()
            othersInGroup.removeClass('open')

            content.slideToggle();
            accordion.toggleClass('open')
        });
    })
}
