function _array_like_to_array(arr, len) {
    if (len == null || len > arr.length) len = arr.length;
    for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
    return arr2;
}
function _array_without_holes(arr) {
    if (Array.isArray(arr)) return _array_like_to_array(arr);
}
function _iterable_to_array(iter) {
    if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
function _non_iterable_spread() {
    throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _to_consumable_array(arr) {
    return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
}
function _unsupported_iterable_to_array(o, minLen) {
    if (!o) return;
    if (typeof o === "string") return _array_like_to_array(o, minLen);
    var n = Object.prototype.toString.call(o).slice(8, -1);
    if (n === "Object" && o.constructor) n = o.constructor.name;
    if (n === "Map" || n === "Set") return Array.from(n);
    if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
}
import { isEmpty } from "../../../utils";
// Рекурсивно проходим по дереву items и создаем мапы для быстрой работы с деревом.
export var usePathMaps = function usePathMaps(items) {
    var pathMap = new Map();
    var focusedToValueMap = new Map();
    var valueToCheckedMap = new Map();
    var valueToItemMap = new Map();
    var valueToPathMap = new Map();
    pathMap.set('root', (items === null || items === void 0 ? void 0 : items.length) || 0);
    var rec = function rec1(items) {
        var prevIndex = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : '', path = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : [];
        items === null || items === void 0 ? void 0 : items.forEach(function(item, index) {
            var value = item.value, innerItems = item.items;
            var currIndex = "".concat(prevIndex, "/").concat(index).replace(/^(\/)/, '');
            focusedToValueMap.set(currIndex, item);
            valueToCheckedMap.set(value, false);
            valueToPathMap.set(value.toString(), _to_consumable_array(path).concat([
                value.toString()
            ]));
            if (isEmpty(innerItems) || !innerItems) {
                valueToItemMap.set(value, item);
            } else {
                pathMap.set(value, innerItems.length);
                rec(innerItems, currIndex, _to_consumable_array(path).concat([
                    value.toString()
                ]));
            }
        });
    };
    rec(items);
    return [
        pathMap,
        focusedToValueMap,
        valueToCheckedMap,
        valueToItemMap,
        valueToPathMap
    ];
};
