"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: Object.getOwnPropertyDescriptor(all, name).get
    });
}
_export(exports, {
    get useNavigationMaps () {
        return useNavigationMaps;
    },
    get useSelectionMaps () {
        return useSelectionMaps;
    }
});
const _react = require("react");
const _utils = require("../../../utils");
const createNavigationMaps = (items = [])=>{
    const pathMap = new Map();
    const focusedToValueMap = new Map();
    const valueToPathMap = new Map();
    pathMap.set('root', items?.length || 0);
    const rec = (itemsToMap, prevIndex = '', path = [])=>{
        itemsToMap?.forEach((item, index)=>{
            const { value, items: innerItems } = item;
            const currIndex = `${prevIndex}/${index}`.replace(/^(\/)/, '');
            focusedToValueMap.set(currIndex, item);
            valueToPathMap.set(value.toString(), [
                ...path,
                value.toString()
            ]);
            if (innerItems && !(0, _utils.isEmpty)(innerItems)) {
                pathMap.set(value, innerItems.length);
                rec(innerItems, currIndex, [
                    ...path,
                    value.toString()
                ]);
            }
        });
    };
    rec(items);
    return [
        pathMap,
        focusedToValueMap,
        valueToPathMap
    ];
};
const createSelectionMaps = (items = [])=>{
    const valueToCheckedMap = new Map();
    const valueToItemMap = new Map();
    const valueToPathMap = new Map();
    const rec = (itemsToMap, path = [])=>{
        itemsToMap?.forEach((item)=>{
            const { value, items: innerItems } = item;
            valueToCheckedMap.set(value, false);
            valueToPathMap.set(value.toString(), [
                ...path,
                value.toString()
            ]);
            if (!innerItems || (0, _utils.isEmpty)(innerItems)) {
                valueToItemMap.set(value, item);
            } else {
                rec(innerItems, [
                    ...path,
                    value.toString()
                ]);
            }
        });
    };
    rec(items);
    return [
        valueToCheckedMap,
        valueToItemMap,
        valueToPathMap
    ];
};
const useNavigationMaps = (items = [])=>{
    return (0, _react.useMemo)(()=>createNavigationMaps(items), [
        items
    ]);
};
const useSelectionMaps = (items = [])=>{
    return (0, _react.useMemo)(()=>createSelectionMaps(items), [
        items
    ]);
};
