import { buildActorConfig } from '../../../utils/build-actor-config';
const getUpdatedActors = (actors, parentId, templates) => actors.map((actor) => {
    if (actor.templateId === parentId) {
        return Object.assign(Object.assign({}, actor), { children: [
                ...(actor.children ? getUpdatedActors(actor.children, parentId, templates) : []),
                ...templates.map((template) => buildActorConfig(template)),
            ] });
    }
    if (actor.children) {
        return Object.assign(Object.assign({}, actor), { children: getUpdatedActors(actor.children, parentId, templates) });
    }
    return actor;
});
export const getUpdatedScenes = (scenes, parentId, templates) => scenes.map((scene) => (Object.assign(Object.assign({}, scene), { actors: getUpdatedActors(scene.actors, parentId, templates) })));
const filterActors = (actors, templateIds) => actors.reduce((acc, actor) => {
    if (actor.templateId && templateIds.has(actor.templateId)) {
        return acc;
    }
    acc.push(Object.assign(Object.assign({}, actor), { children: actor.children && filterActors(actor.children, templateIds) }));
    return acc;
}, []);
export const filterScenes = (scenes, templateIds) => scenes.map((scene) => (Object.assign(Object.assign({}, scene), { actors: filterActors(scene.actors, templateIds) })));
