"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useCarousel = void 0;
var useLayoutChange_1 = require("../layout/useLayoutChange");
var useScrolledToEdge_1 = require("../layout/useScrolledToEdge");
var useTargetZone_1 = require("../layout/useTargetZone");
var strategies_1 = require("../paging/strategies");
var usePageWithArrowKeys_1 = require("../paging/usePageWithArrowKeys");
var usePaging_1 = require("../paging/usePaging");
var useScrollSelectedIntoView_1 = require("../scroll/useScrollSelectedIntoView");
var useScrollSnapLoadingFix_1 = require("../scroll/useScrollSnapLoadingFix");
var useSelectWithArrowKeys_1 = require("../select/useSelectWithArrowKeys");
var usePages_1 = require("../paging/usePages");
var useCarouselTile_1 = require("./useCarouselTile");
exports.useCarousel = function (containerRef, _a, layoutDeps) {
    var selected = _a.selected, onSelect = _a.onSelect, numTiles = _a.numTiles;
    var _b = usePages_1.usePages(containerRef), pages = _b[0], pagesDomProps = _b[1];
    var paging = usePaging_1.usePaging(containerRef, strategies_1.pageByVisibility);
    var pageArrowKeys = usePageWithArrowKeys_1.usePageWithArrowKeys(containerRef, strategies_1.pageByVisibility);
    useScrollSelectedIntoView_1.useScrollSelectedIntoView(containerRef, selected);
    var ssFix = useScrollSnapLoadingFix_1.useScrollSnapLoadingFix(containerRef, selected);
    var arrowKeys = useSelectWithArrowKeys_1.useSelectWithArrowKeys(containerRef, { selected: selected, onSelect: onSelect, numTiles: numTiles });
    var onEdge = useScrolledToEdge_1.useScrolledToEdge(containerRef);
    var _c = useTargetZone_1.useTargetZone(containerRef), targetOffset = _c[0], targetZone = _c[1];
    var layout = useLayoutChange_1.useLayoutChange(containerRef, function () {
        pagesDomProps.onLayoutChange();
        targetZone.onLayoutChange();
    }, layoutDeps);
    var onLoad = function () {
        layout.onLoad();
        ssFix.onLoad();
    };
    var onScroll = function () {
        pagesDomProps.onScroll();
    };
    var tileProps = useCarouselTile_1.useCarouselTile(containerRef, { selected: selected, onSelect: onSelect });
    return {
        props: {
            arrow: {
                left: {
                    left: true,
                    hide: onEdge.both,
                    disabled: onEdge.left,
                    onClick: paging.pageLeft,
                    onKeyDown: pageArrowKeys.onKeyDown
                },
                right: {
                    right: true,
                    hide: onEdge.both,
                    disabled: onEdge.right,
                    onClick: paging.pageRight,
                    onKeyDown: pageArrowKeys.onKeyDown
                }
            },
            list: {
                onKeyDown: arrowKeys.onKeyDown,
                onScroll: onScroll,
                onLoad: onLoad,
                targetZoneOffset: targetOffset
            },
            tile: tileProps,
        },
        pages: pages
    };
};
