"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useLogic = void 0;
const react_1 = require("react");
const StepperContext_1 = require("../../StepperContext");
const useLogic = ({ stepId, isCompleted, onClick, children, isError, isWarning, icon, label, isDisabled, className, }) => {
    const { connector, activeStep, orientation, alternativeLabel, onClickPrevStep, onClickStep, } = (0, react_1.useContext)(StepperContext_1.StepperContext);
    (0, react_1.useEffect)(() => {
        const hasDescription = Boolean(children);
        const isValidForDescription = orientation === 'vertical' &&
            connector === 'line' &&
            alternativeLabel === false;
        if (hasDescription && !isValidForDescription) {
            // biome-ignore lint/suspicious/noConsole: Сообщение для интеграторов
            console.error('Stepper: description можно использовать только с комбинацией:\n' +
                'orientation="vertical", connector="line", alternativeLabel=false');
        }
    }, []);
    const isCompletedStep = isCompleted !== undefined ? isCompleted : activeStep > stepId;
    const isClickableStep = Boolean(onClick) ||
        Boolean(onClickStep) ||
        (Boolean(onClickPrevStep) && isCompletedStep);
    const isDisabledFromPrevOnlyMode = Boolean(onClickPrevStep) && !isClickableStep;
    const isDisabledStep = Boolean(isDisabled) || isDisabledFromPrevOnlyMode;
    const isRenderButton = Boolean(onClick) || Boolean(onClickPrevStep) || Boolean(onClickStep);
    const handleClick = () => {
        if (isDisabledStep) {
            return;
        }
        if (isCompletedStep && onClickPrevStep) {
            onClickPrevStep(stepId);
        }
        onClickStep?.(stepId);
        onClick?.(stepId);
    };
    const isRenderVerticalLineConnector = connector === 'line' && orientation === 'vertical' && !children;
    const isRenderHorizontalLineConnector = connector === 'line' && orientation === 'horizontal' && alternativeLabel;
    const isActiveStep = activeStep === stepId;
    return {
        isCompletedStep,
        isRenderButton,
        handleClick,
        connectorVariant: connector,
        alternativeLabel,
        orientation,
        stepId,
        children,
        isError,
        isWarning,
        icon,
        className,
        label,
        isRenderVerticalLineConnector,
        isRenderHorizontalLineConnector,
        isDisabled: isDisabledStep,
        isActiveStep,
    };
};
exports.useLogic = useLogic;
