import { Action } from "../../../src/core/process/undo/Action.js";

class ComponentRemoveAction extends Action {
    constructor(entity, componentType) {
        super();

        this.entity = entity;
        this.componentType = componentType;
        this.component = null;
    }

    async apply(editor) {
        /**
         * @type {Engine}
         */
        const engine = editor.engine;

        const em = engine.entityManager;

        /**
         * @type {EntityComponentDataset}
         */
        const ecd = em.dataset;

        this.component = ecd.removeComponentFromEntity(this.entity, this.componentType);
    }

    async revert(editor) {
        const em = editor.engine.entityManager;
        em.addComponentToEntity(this.entity, this.component);
    }
}

export default ComponentRemoveAction;
