"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useLogic = void 0;
const react_1 = require("react");
const useViewportType_1 = require("../../useViewportType");
const constants_1 = require("../constants");
const utils_1 = require("./utils");
const useLogic = ({ orientation = 'horizontal', connector = 'line', alternativeLabel = false, activeStep = 0, onClickPrevStep, onClickStep, className, children, }) => {
    (0, react_1.useEffect)(() => {
        (0, utils_1.validateStepperProps)({ orientation, connector, alternativeLabel });
    }, []);
    const { isMobile } = (0, useViewportType_1.useViewportType)();
    // На разрешении sm и ниже connector line + alternativeLabel выглядит как connector arrow без alternativeLabel
    const isMobileDisplayStepper = isMobile && orientation === 'horizontal' && connector === 'line';
    const stepperConnector = isMobileDisplayStepper ? 'arrow' : connector;
    const stepperAlternativeLabel = isMobileDisplayStepper
        ? false
        : alternativeLabel;
    const containerRef = (0, react_1.useRef)(null);
    (0, react_1.useEffect)(() => {
        if (!isMobile || !containerRef.current) {
            return;
        }
        const container = containerRef.current;
        const runScroll = () => {
            const activeStepElement = container.querySelector('[data-active-step="true"]');
            if (activeStepElement) {
                activeStepElement.scrollIntoView({
                    behavior: 'smooth',
                    block: 'nearest',
                    inline: 'center',
                });
            }
        };
        setTimeout(() => {
            runScroll();
        }, constants_1.MOBILE_ACTIVE_STEP_SCROLL_DEFER_MS);
    }, [activeStep, isMobile, orientation]);
    return {
        containerRef,
        stepperConnector,
        stepperAlternativeLabel,
        activeStep,
        onClickPrevStep,
        orientation,
        onClickStep,
        className,
        children,
    };
};
exports.useLogic = useLogic;
