import { ViewMenu, ViewLevels, ViewGame } from "./index.js";
export var EViewType;
(function (EViewType) {
    EViewType[EViewType["None"] = 0] = "None";
    EViewType[EViewType["Menu"] = 1] = "Menu";
    EViewType[EViewType["Levels"] = 2] = "Levels";
    EViewType[EViewType["Game"] = 3] = "Game";
})(EViewType || (EViewType = {}));
export class ViewManager {
    _viewMap;
    _currentViewType;
    _app;
    constructor() {
        this._viewMap = new Map();
        this._currentViewType = EViewType.None;
        this._app = document.getElementById("app");
    }
    async loadAsync(gdRoot) {
        const viewManager = this;
        this._viewMap.set(EViewType.Menu, new ViewMenu(await this.loadView("menu"), viewManager));
        this._viewMap.set(EViewType.Levels, new ViewLevels(await this.loadView("levels"), viewManager));
        this._viewMap.set(EViewType.Game, new ViewGame(await this.loadView("game"), gdRoot, viewManager));
    }
    showView(viewType) {
        const oldView = this._viewMap.get(this._currentViewType);
        if (!!oldView) {
            oldView.deactivate();
            this._currentViewType = EViewType.None;
        }
        const newView = this._viewMap.get(viewType);
        if (!!newView) {
            this._app.innerHTML = newView.div;
            this._currentViewType = viewType;
            newView.activate();
        }
    }
    async loadView(viewName) {
        const response = await fetch(`views/${viewName}.html`);
        if (!response.ok) {
            throw new Error(`Failed to load view: ${viewName}`);
        }
        const html = await response.text();
        return html;
    }
}
//# sourceMappingURL=ViewManager.js.map