var Wick = window.Wick || {};
Wick.Calendar = {
    el: {
        switchBtn: '.calendar__switch',
        switchBtnLatest: 'calendar__switch-latest',
        switchBtnEarlier: 'calendar__switch-earlier',
        componentDateSection: '.component-date-selection',
        dateSection: '.date-selection',
        dateSectionHidden: 'date-selection-hidden',
    },
    SwitchCalendar: function () {
        let $currentCalendar = $(this).closest(Wick.Calendar.el.dateSection);

        $currentCalendar.addClass(Wick.Calendar.el.dateSectionHidden);

        if ($(this).hasClass(Wick.Calendar.el.switchBtnEarlier)) {
            $currentCalendar = $currentCalendar.prev();
            $currentCalendar.removeClass(Wick.Calendar.el.dateSectionHidden);

        } else if ($(this).hasClass(Wick.Calendar.el.switchBtnLatest)) {
            $currentCalendar = $currentCalendar.next(Wick.Calendar.el.dateSection);
            $currentCalendar.removeClass(Wick.Calendar.el.dateSectionHidden);
        }
    },

};

$(document).ready(function () {
    function init() {

        if (Wick.checkLocalEnv) {
            $(Wick.Calendar.el.componentDateSection).on('click', Wick.Calendar.el.switchBtn, Wick.Calendar.SwitchCalendar);
        }
    }

    function unbind() {
        $(Wick.Calendar.el.componentDateSection).unbind('click');
    }

    init();

    $(window).on('resize', _.debounce(function () {
        unbind();
        init();
    }, 250));
});
