"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useLogic = void 0;
const react_1 = require("react");
const utils_1 = require("../../Tree/utils");
const useId_1 = require("../../useId");
const utils_2 = require("./utils");
const useLogic = ({ data, value, disabledItems, }) => {
    const prefixId = (0, useId_1.useId)();
    const listRef = (0, react_1.useRef)(null);
    (0, react_1.useEffect)(() => {
        if (listRef.current && value?.length) {
            // Выбираем первый элемент из списка value
            const firstItemId = typeof value[0] === 'string' ? value[0] : value[0].id;
            const targetItem = listRef.current.querySelector(`
        li[id="${prefixId}${firstItemId}"]`);
            if (targetItem) {
                targetItem.scrollIntoView({ block: 'center' });
            }
        }
    }, [listRef, prefixId]);
    const formattedDisabledItems = (0, react_1.useMemo)(() => (0, utils_1.getFormatDisabledItems)(disabledItems), [disabledItems]);
    const chainsToSelectedItem = (0, react_1.useMemo)(() => (0, utils_2.getChainsId)(data, value), [data, value]);
    return {
        listProps: {
            ref: listRef,
        },
        itemProps: {
            chainsToSelectedItem,
            disabledItems: formattedDisabledItems,
            prefixId,
        },
    };
};
exports.useLogic = useLogic;
