const $ = global.$;
import 'jquery.easing';
import Slider from "../slider/slider";

class IHKMHSlider {
    constructor(section) {
        this.section = section.addClass('initiated');
        this.slider = new Slider(section);
        this.slider.settings = {
            loop: true,
            autoplay: true,
            infinite: true,
            autoplaySpeed: 700000,
            animationSpeed: 600,
            startSlide: 1,
        };

        this.section.on('slide-change', () => this.syncHeights());
        requestAnimationFrame(() => this.syncHeights());

        $(window).on('resize', () => this.syncHeights());
    }

    syncHeights() {
        if (!this.section.closest('.hero-fullwidth').length) return;

        this.section.find('.slide').each(function () {
            const textBox = $(this).find('.text-box');
            const textInImageBox = $(this).find('.text-in-image-box');

            if ($(window).width() > 999) {
                textInImageBox.height(textBox.innerHeight() - 36);
            } else {
                textInImageBox.css('height', '');
            }
        });
    }
}

export default IHKMHSlider;

$('body').on('ihk-init dynamic-component-loaded gfi-dynamic-init', function () {
    $('.slider:not(.initiated)').each(function () {
        new IHKMHSlider($(this));
    });
});


