"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SliderNewBlock = void 0;
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const React = tslib_1.__importStar(require("react"));
const swiper_1 = tslib_1.__importStar(require("swiper"));
const react_1 = require("swiper/swiper-react.cjs.js");
const Anchor_1 = tslib_1.__importDefault(require("../../components/Anchor/Anchor.js"));
const AnimateBlock_1 = tslib_1.__importDefault(require("../../components/AnimateBlock/AnimateBlock.js"));
const Title_1 = tslib_1.__importDefault(require("../../components/Title/Title.js"));
const utils_1 = require("../../utils/index.js");
const Arrow_1 = tslib_1.__importDefault(require("./Arrow/Arrow.js"));
const i18n_1 = require("./i18n/index.js");
const useSlider_1 = require("./useSlider.js");
const useSliderPagination_1 = require("./useSliderPagination.js");
require("swiper/swiper-bundle.css");
const b = (0, utils_1.block)('SliderNewBlock');
swiper_1.default.use([swiper_1.Autoplay, swiper_1.A11y, swiper_1.Pagination]);
function getDisclaimerSize(size) {
    if (!size) {
        return 'm';
    }
    if (size === 'sm') {
        return 'm';
    }
    return size;
}
const SliderNewBlock = ({ animated, title, description, type, anchorId, arrows = true, adaptive, autoplay: autoplayMs, dots = true, className, dotsClassName, disclaimer, children, blockClassName, arrowSize, slidesToShow, onSlideChange, onSlideChangeTransitionStart, onSlideChangeTransitionEnd, onActiveIndexChange, onBreakpoint, }) => {
    const { autoplay, isLocked, childrenCount, breakpoints, onSwiper, onPrev, onNext, setIsLocked } = (0, useSlider_1.useSlider)({
        slidesToShow,
        children,
        type,
        autoplayMs,
    });
    const isA11yControlHidden = Boolean(autoplay);
    const controlTabIndex = isA11yControlHidden ? -1 : 0;
    const paginationProps = (0, useSliderPagination_1.useSliderPagination)({
        enabled: dots,
        isA11yControlHidden,
        controlTabIndex,
        bulletClass: b('dot', dotsClassName),
        bulletActiveClass: b('dot_active'),
        paginationLabel: (0, i18n_1.i18n)('pagination-label'),
    });
    return ((0, jsx_runtime_1.jsxs)("div", { className: b({
            'one-slide': childrenCount === 1,
            'only-arrows': !title?.text && !description && arrows,
            'without-dots': !dots || isLocked,
            type,
        }, blockClassName), children: [anchorId && (0, jsx_runtime_1.jsx)(Anchor_1.default, { id: anchorId }), (0, jsx_runtime_1.jsx)(Title_1.default, { title: title, subtitle: description, className: b('header', { 'no-description': !description }) }), (0, jsx_runtime_1.jsxs)(AnimateBlock_1.default, { className: b('animate-slides'), animate: animated, children: [(0, jsx_runtime_1.jsx)(react_1.Swiper, { className: b('slider', className), onSwiper: onSwiper, speed: 1000, autoplay: autoplay, autoHeight: adaptive, initialSlide: 0, noSwiping: false, breakpoints: breakpoints, onSlideChange: onSlideChange, onSlideChangeTransitionStart: onSlideChangeTransitionStart, onSlideChangeTransitionEnd: onSlideChangeTransitionEnd, onActiveIndexChange: onActiveIndexChange, onBreakpoint: onBreakpoint, onLock: () => setIsLocked(true), onUnlock: () => setIsLocked(false), watchSlidesVisibility: true, watchOverflow: true, a11y: {
                            slideLabelMessage: '',
                            paginationBulletMessage: (0, i18n_1.i18n)('dot-label', { index: '{{index}}' }),
                        }, ...paginationProps, children: React.Children.map(children, (elem, index) => ((0, jsx_runtime_1.jsx)(react_1.SwiperSlide, { className: b('slide'), children: ({ isVisible }) => ((0, jsx_runtime_1.jsx)("div", { className: b('slide-item'), "aria-hidden": !isA11yControlHidden && !isVisible, children: elem })) }, index))) }), arrows && !isLocked && ((0, jsx_runtime_1.jsx)(React.Fragment, { children: (0, jsx_runtime_1.jsxs)("div", { "aria-hidden": isA11yControlHidden, children: [(0, jsx_runtime_1.jsx)(Arrow_1.default, { className: b('arrow', { prev: true }), type: "left", onClick: onPrev, size: arrowSize, extraProps: { tabIndex: controlTabIndex } }), (0, jsx_runtime_1.jsx)(Arrow_1.default, { className: b('arrow', { next: true }), type: "right", onClick: onNext, size: arrowSize, extraProps: { tabIndex: controlTabIndex } })] }) })), (0, jsx_runtime_1.jsx)("div", { className: b('footer'), children: disclaimer ? ((0, jsx_runtime_1.jsx)("div", { className: b('disclaimer', {
                                size: getDisclaimerSize(disclaimer?.size),
                            }), children: disclaimer?.text })) : null })] })] }));
};
exports.SliderNewBlock = SliderNewBlock;
exports.default = exports.SliderNewBlock;
//# sourceMappingURL=Slider.js.map
