import { v4 as uuidv4 } from 'uuid';
import { t } from 'i18next';
import { getUniqueName } from '../../../utils/get-unique-name';
import { getTransformConfig } from '../../../utils/get-transform-config';
import { addValue, setValue } from '..';
import { getUpdatedScenes } from './utils';
export const addTemplate = (destinationPath) => (dispatch, getState) => {
    const destination = getState(destinationPath);
    const template = {
        id: uuidv4(),
        name: getUniqueName(t('explorer.templates.actionBar.template.new.title'), destination),
        components: [getTransformConfig()],
        children: [],
    };
    dispatch(addValue(destinationPath, template));
    if (destinationPath.at(-1) === 'children') {
        const parent = getState(destinationPath.slice(0, -1));
        const scenes = getState(['scenes']);
        dispatch(setValue(['scenes'], getUpdatedScenes(scenes, parent.id, [template]), true));
    }
};
