import * as React from 'react';
import { SliderType } from "../../models/index.js";
import { getSliderResponsiveParams, useMemoized } from "./utils.js";
export const useSlider = ({ children, autoplayMs, type, ...props }) => {
    const [slider, setSlider] = React.useState();
    const [isLocked, setIsLocked] = React.useState(false);
    const slidesToShow = useMemoized(props.slidesToShow);
    const childrenCount = React.Children.count(children);
    const autoplayEnabled = autoplayMs !== undefined && autoplayMs > 0;
    const breakpoints = React.useMemo(() => {
        return getSliderResponsiveParams({
            contentLength: childrenCount,
            slidesToShow,
            mobileFullscreen: Boolean(type && Object.values(SliderType).includes(type)),
        });
    }, [slidesToShow, type, childrenCount]);
    const handleNext = () => {
        if (!slider) {
            return;
        }
        if (slider.isEnd) {
            slider.slideTo(0);
            return;
        }
        slider.slideNext();
    };
    const handlePrev = () => {
        if (!slider) {
            return;
        }
        if (slider.isBeginning) {
            slider.slideTo(childrenCount - 1);
            return;
        }
        slider.slidePrev();
    };
    React.useEffect(() => {
        if (!slider) {
            return;
        }
        if (autoplayEnabled) {
            slider.autoplay.start();
        }
        else {
            slider.autoplay.stop();
        }
    }, [slider, autoplayEnabled]);
    return {
        slider,
        onSwiper: setSlider,
        onNext: handleNext,
        onPrev: handlePrev,
        breakpoints,
        childrenCount,
        isLocked,
        setIsLocked,
        autoplay: autoplayEnabled && {
            delay: autoplayMs,
            disableOnInteraction: false,
        },
    };
};
//# sourceMappingURL=useSlider.js.map
