import { setValue, deleteByPaths } from '..';
import { getIdByPath } from '../../../utils/get-id-by-path';
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;
}, []);
const filterScenes = (scenes, templateIds) => scenes.map((scene) => (Object.assign(Object.assign({}, scene), { actors: filterActors(scene.actors, templateIds) })));
export const deleteTemplates = (paths) => (dispatch, getState) => {
    const templateIds = new Set(paths.map((path) => getIdByPath(path)));
    const scenes = getState(['scenes']);
    dispatch(setValue(['scenes'], filterScenes(scenes, templateIds)));
    dispatch(deleteByPaths(paths, true));
};
