import { jsx as _jsx } from "@emotion/react/jsx-runtime";
import { FileOutlined } from '@ant-design/icons';
import { getIdByPath } from '../../../../../utils/get-id-by-path';
const parseTemplate = (template, path, parent) => {
    var _a, _b;
    const isLeaf = !((_a = template === null || template === void 0 ? void 0 : template.children) === null || _a === void 0 ? void 0 : _a.length);
    const templatePath = path.concat(`id:${template.id}`);
    const node = {
        key: template.id,
        title: template.name,
        path: templatePath,
        parent,
        icon: _jsx(FileOutlined, {}),
        isLeaf,
    };
    if (!isLeaf) {
        const childPath = templatePath.concat('children');
        node.children = (_b = template.children) === null || _b === void 0 ? void 0 : _b.map((child) => parseTemplate(child, childPath, node));
    }
    return node;
};
export const parseTemplates = (templates) => templates.map((template) => parseTemplate(template, ['templates']));
export const getInspectedKey = (path) => {
    if (!path || path[0] !== 'templates') {
        return void '';
    }
    return getIdByPath(path);
};
export const getSelectedPaths = (paths) => paths
    .filter((path) => path[0] === 'templates');
export const filterActors = (actors, templateId) => actors.reduce((acc, actor) => {
    if (actor.templateId !== templateId) {
        acc.push(actor);
    }
    if (actor.children !== undefined) {
        actor.children = filterActors(actor.children, templateId);
    }
    return acc;
}, []);
export const filterScenes = (scenes, templateId) => scenes.map((scene) => (Object.assign(Object.assign({}, scene), { actors: filterActors(scene.actors, templateId) })));
