class Finish extends Phaser.Scene {
    constructor(father, game) {
        super('Finish');
        this.father = father;
        this.game = game;
    }

    create() {
        this.add.rectangle(0, 0, WIDTH_WINDOW, HEIGHT_WINDOW, 0x000000).setOrigin(0, 0).setAlpha(0.5);
        this.add.rectangle(0, HEIGHT_WINDOW / 2, WIDTH_WINDOW, HEIGHT_WINDOW / 2, 0x35363A).setOrigin(0, 0.5);
    }

    addTitle(title) {
        let sizeText = HEIGHT_WINDOW / 6;
        let style = {font: sizeText.toString() + 'px stencil', fill: "#e2e2e2"};
        this.add.text(WIDTH_WINDOW / 2, HEIGHT_WINDOW / 2, title, style).setOrigin(0.5, 0.5);
    }

    createButton(x, texture) {
        let btn = this.add.image(x, HEIGHT_WINDOW / 8 * 7, texture).setOrigin(0.5, 0.5).setInteractive();
        btn.on('pointerover', () => btn.setFrame(1));
        btn.on('pointerout', () => btn.setFrame(0));

        btn.displayHeight = HEIGHT_WINDOW / 9;
        btn.scaleX = btn.scaleY;

        return btn;
    }

    btnRetry(btn) {
        btn.on('pointerdown', () => this.retry());
    }

    retry() {
        this.close();
        console.log("RETRY");
        if (this.father.scene.getIndex('Game') === -1) {
            newGame(this.father);
        }
        this.father.scene.start('Game');
    }

    btnHome(btn) {
        btn.on('pointerdown', () => this.home());
    }

    home() {
        console.log("HOME");
        this.close();
        this.father.scene.remove('Game');
        this.father.scene.start('Type');
    }

    btnNext(btn) {
        btn.on('pointerdown', () => this.next());
    }

    next() {
        console.log("NEXT");
    }

    close() {
        this.sound.stopAll();
        this.father.scene.remove('GamingBoard');
        this.father.scene.remove('Finish');
    }
}