import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import * as React from 'react';
import 'swiper/css';
import 'swiper/css/a11y';
import 'swiper/css/pagination';
import { A11y, Autoplay, Pagination } from 'swiper/modules';
import { Swiper as SwiperReact, SwiperSlide } from 'swiper/react';
import Anchor from "../../components/Anchor/Anchor.js";
import AnimateBlock from "../../components/AnimateBlock/AnimateBlock.js";
import Title from "../../components/Title/Title.js";
import { Grid } from "../../gravity-blocks/grid/index.js";
import { SliderType } from "../../models/index.js";
import { block } from "../../utils/index.js";
import Arrow from "./Arrow/Arrow.js";
import { i18n } from "./i18n/index.js";
import { useSlider } from "./useSlider.js";
import { useSliderPagination } from "./useSliderPagination.js";
import './Slider.css';
const b = block('SliderBlock');
export const SliderBlock = ({ animated, title, description, type, anchorId, arrows = true, adaptive, autoplay: autoplayMs, dots = true, initialSlide = 0, className, dotsClassName, disclaimer, children, blockClassName, arrowSize, slidesToShow, onSlideChange, onSlideChangeTransitionStart, onSlideChangeTransitionEnd, onActiveIndexChange, onBreakpoint, }) => {
    const { autoplay, isLocked, childrenCount, breakpoints, onSwiper, onPrev, onNext, setIsLocked } = useSlider({
        slidesToShow,
        children,
        type,
        autoplayMs,
    });
    const isA11yControlHidden = Boolean(autoplay);
    const controlTabIndex = isA11yControlHidden ? -1 : 0;
    const paginationProps = useSliderPagination({
        enabled: dots,
        isA11yControlHidden,
        controlTabIndex,
        horizontalClass: b('dots'),
        bulletClass: b('dot', dotsClassName),
        bulletActiveClass: b('dot_active'),
        paginationLabel: i18n('pagination-label'),
    });
    return (_jsx(Grid, { children: _jsxs("div", { className: b({
                'one-slide': childrenCount === 1,
                'only-arrows': (!title || (typeof title !== 'string' && !title?.text)) &&
                    !description &&
                    arrows,
                'without-dots': !dots || isLocked,
                type,
            }, blockClassName), children: [anchorId && _jsx(Anchor, { id: anchorId }), _jsx(Title, { title: title, subtitle: description, className: b('header', { 'no-description': !description }) }), _jsxs(AnimateBlock, { className: b('animate-slides'), animate: animated, children: [_jsx(SwiperReact, { modules: [Autoplay, A11y, Pagination], className: b('slider', className), onSwiper: onSwiper, speed: 1000, autoplay: autoplay, autoHeight: adaptive, initialSlide: initialSlide, noSwiping: false, breakpoints: breakpoints, onSlideChange: onSlideChange, onSlideChangeTransitionStart: onSlideChangeTransitionStart, onSlideChangeTransitionEnd: onSlideChangeTransitionEnd, onActiveIndexChange: onActiveIndexChange, onBreakpoint: onBreakpoint, onLock: () => setIsLocked(true), onUnlock: () => setIsLocked(false), watchOverflow: true, watchSlidesProgress: true, touchStartPreventDefault: false, touchAngle: 45, threshold: 10, longSwipes: true, longSwipesRatio: 0.5, resistance: true, resistanceRatio: 0.5, a11y: {
                                slideLabelMessage: '',
                                paginationBulletMessage: i18n('dot-label', { index: '{{index}}' }),
                            }, ...paginationProps, children: React.Children.map(children, (elem, index) => (_jsx(SwiperSlide, { className: b('slide'), children: ({ isVisible }) => (_jsx("div", { className: b('slide-item'), "aria-hidden": !isA11yControlHidden && !isVisible, children: elem })) }, index))) }), arrows && !isLocked && (_jsx(React.Fragment, { children: _jsxs("div", { "aria-hidden": isA11yControlHidden, children: [_jsx(Arrow, { className: b('arrow', { prev: true }), type: "left", transparent: type === SliderType.HeaderCard, onClick: onPrev, size: arrowSize, extraProps: { tabIndex: controlTabIndex } }), _jsx(Arrow, { className: b('arrow', { next: true }), type: "right", transparent: type === SliderType.HeaderCard, onClick: onNext, size: arrowSize, extraProps: { tabIndex: controlTabIndex } })] }) })), _jsx("div", { className: b('footer'), children: disclaimer ? (_jsx("div", { className: b('disclaimer', { size: disclaimer?.size || 'm' }), children: disclaimer?.text })) : null })] })] }) }));
};
export default SliderBlock;
//# sourceMappingURL=Slider.js.map
