import { EViewType, IView, ViewManager } from "./index.ts";

export class ViewMenu implements IView {
    private _div: string;
    private _buttonLevels: HTMLButtonElement | null = null;
    private _viewManager: ViewManager;

    constructor(div: string, viewManager: ViewManager) {
        this._div = div;
        this._viewManager = viewManager;
        this.buttonLevelsClicked = this.buttonLevelsClicked.bind(this);
    }

    public get div(): string {
        return this._div;
    }

    public activate() {
        this._buttonLevels = document.getElementById("btn-levels") as HTMLButtonElement;
        if (!!this._buttonLevels) {
            this._buttonLevels.addEventListener("click", this.buttonLevelsClicked);
        }
    }

    public deactivate() {
        this._buttonLevels?.removeEventListener("click", this.buttonLevelsClicked);
    }

    private buttonLevelsClicked() {
        this._viewManager.showView(EViewType.Levels);
    }
}