"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useLogic = void 0;
const react_1 = require("react");
const useId_1 = require("../../../useId");
const getFormatDisabledItems_1 = require("../../utils/getFormatDisabledItems");
const utils_1 = require("./utils");
const useLogic = ({ value, data, disabledItems, isObjectMode, }) => {
    const prefixId = (0, useId_1.useId)();
    const listRef = (0, react_1.useRef)(null);
    (0, react_1.useEffect)(() => {
        if (listRef.current && value) {
            const targetId = isObjectMode && typeof value === 'object' ? value.id : value;
            const targetItem = listRef.current.querySelector(`
        li[id="${prefixId}${targetId}"]`);
            if (targetItem) {
                targetItem.scrollIntoView({ block: 'center' });
            }
        }
    }, [listRef, prefixId]);
    const formattedDisabledItems = (0, react_1.useMemo)(() => (0, getFormatDisabledItems_1.getFormatDisabledItems)(disabledItems), [disabledItems]);
    const chainToSelectedItem = (0, react_1.useMemo)(() => (0, utils_1.getChainId)(data, value), [data, value]);
    return {
        listProps: {
            ref: listRef,
        },
        itemProps: {
            chainToSelectedItem,
            disabledItems: formattedDisabledItems,
            prefixId,
        },
    };
};
exports.useLogic = useLogic;
