class Description extends ManageLang {
    constructor(father) {
        super('Description', father);
    }

    create() {
        super.create();
        let x = WIDTH_WINDOW / 2;
        let y = HEIGHT_WINDOW - 100;
        let returnBtn = this.add.image(x, y, 'cancel').setOrigin(0.5, 0.5).setInteractive();
        returnBtn.on('pointerover', () => returnBtn.setFrame(1));
        returnBtn.on('pointerout', () => returnBtn.setFrame(0));
        returnBtn.on('pointerdown', () => this.return());
        returnBtn.displayHeight = HEIGHT_WINDOW / 10;
        returnBtn.scaleX = returnBtn.scaleY;

        this.loadBonus();
    }

    loadBonus() {
        this.width = WIDTH_WINDOW / 3 - 20;
        this.height = HEIGHT_WINDOW / 4;
        let x = 0;
        this.createList(lShieldBonus, x, true);
        x = WIDTH_WINDOW / 3;
        this.createList(lSpeedBonus, x, false);
        x = WIDTH_WINDOW / 1.5;
        this.createList(lAttackBonus, x, false);
    }

    createList(listBonus, x, add = true) {
        let y = 50;
        this.createCategoryBonus(x, y, this.width, this.height * listBonus.length);
        listBonus.forEach(bonus => {
            let time = "";
            if (bonus.time !== undefined) {
                time = '  -  ' + selectWord("TIME", "TEMPS") + ' : ' + (bonus.time / 1000);
            }
            let value = "";
            if (bonus.value !== undefined) {
                let sign = 'x';
                if (add) {
                    sign = '+';
                }
                value = 'BONUS : ' + sign + bonus.value;
            }
            this.createBonusDescription(x, y, this.width, this.height, bonus.texture, bonus.name, value + time);
            y += this.height;
        });
    }

    createCategoryBonus(x, y, width, height) {
        x += 10;
        y += 10;
        this.add.rectangle(x, y, width, height, 0x868686).setOrigin(0, 0);
    }

    createBonusDescription(x, y, width, height, texture, name, text) {
        x += 20;
        y += 20;
        width -= 20;
        height -= 20;
        this.add.rectangle(x, y, width, height, 0xFFFFFF).setOrigin(0, 0);
        let image = this.add.image(x + 5, y + 5, texture).setOrigin(0, 0);
        image.displayHeight = 100;
        image.scaleX = image.scaleY;
        let style = {font: (image.displayHeight / 2 - name.length) + 'px stencil', fill: "#000000"};
        this.add.text(x + image.displayWidth + 10, y + 5 + image.displayHeight / 2, name.toString(), style).setOrigin(0, 0.5);
        style.font = (height / 6) + 'px stencil';
        this.add.text(x + 5, y + image.displayHeight + (height - image.displayHeight) / 2, text.toString(), style).setOrigin(0, 0.5);
    }

    return() {
        this.father.scene.start('Game');
        this.father.scene.remove('Description');
    }
}