var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
import { useMemo, useCallback, useContext, } from 'react';
import { HotkeysSectionContext } from '../../../providers';
import { getIdByPath } from '../../../../utils/get-id-by-path';
export const useTreeData = (treeData) => {
    const { clipboard, isCut } = useContext(HotkeysSectionContext);
    const cutKeys = useMemo(() => {
        const keysSet = new Set();
        if (!(clipboard === null || clipboard === void 0 ? void 0 : clipboard.length) || !isCut) {
            return keysSet;
        }
        clipboard.forEach((path) => {
            keysSet.add(getIdByPath(path));
        });
        return keysSet;
    }, [clipboard, isCut]);
    const parseTreeData = useCallback((nodes) => nodes.map((_a) => {
        var { children, className } = _a, node = __rest(_a, ["children", "className"]);
        return (Object.assign(Object.assign({}, node), { children: children ? parseTreeData(children) : undefined, className: `${className !== null && className !== void 0 ? className : ''} ${cutKeys.has(String(node.key)) ? 'tree-node_cut' : ''}` }));
    }), [cutKeys]);
    const parsedTreeData = useMemo(() => parseTreeData(treeData), [treeData, parseTreeData]);
    return { treeData: parsedTreeData };
};
