import { ModalStack } from "../modal/ModalStack.js";
import LinearModifier from "../../../core/model/stat/LinearModifier.js";
import { NotificationManager } from "../notification/NotificationManager.js";
import { initializeNotifications } from "./initializeNotifications.js";

export class SceneGUIContext {
    constructor() {
        /**
         *
         * @type {Scene}
         */
        this.scene = null;

        /**
         *
         * @type {ModalStack}
         */
        this.modals = new ModalStack();

        /**
         *
         * @type {NotificationManager}
         */
        this.notifications = new NotificationManager();

        /**
         *
         * @type {LinearModifier}
         */
        this.clockModifierZero = new LinearModifier(0, 0);
    }

    /**
     *
     * @param {Scene} scene
     */
    initialize(scene) {
        this.scene = scene;

        initializeNotifications(this.notifications);

        this.notifications.ecd = scene.dataset;
    }

    /**
     *
     * @param {number} timeDelta
     */
    tick(timeDelta) {
        this.notifications.tick(timeDelta);
    }

    /**
     * @private
     */
    stopTime() {
        this.scene.speedModifiers.add(this.clockModifierZero);
    }

    /**
     * @private
     */
    resumeTime() {
        this.scene.speedModifiers.removeOneOf(this.clockModifierZero);
    }

    startup() {
        this.modals.on.firstAdded.add(this.stopTime, this);
        this.modals.on.lastRemoved.add(this.resumeTime, this);
    }

    shutdown() {
        this.modals.on.firstAdded.remove(this.stopTime, this);
        this.modals.on.lastRemoved.remove(this.resumeTime, this);
    }
}
