class SceneJackpots extends Phaser.Scene {

    constructor ()
    {
        super({ key: 'Jackpots', active: true });
    }
    
    preload()
    {
    }

    create (data)
    {
        this.bgrjackpots = this.add.image(640, 41, 'bgrjackpots');
        this.parent = data.scene;

        this.canSleep = true;
        this.canWake = true;

        this.disabled = false;
        
        this.animJackpotGrand = new AnimatedAmount(this, 640, 30, data.fontGrand, false);
        this.animJackpotGrand.setOrigin(0.5);
        this.animJackpotMaxi = new AnimatedAmount(this, 180, 20, data.fontMaxi, false);
        this.animJackpotMaxi.setOrigin(0.5);
        this.animJackpotMini = new AnimatedAmount(this, 1100, 20, data.fontMini, false);
        this.animJackpotMini.setOrigin(0.5);
        this.scene.sleep();
    }
    
    sleep()
    {
        if(this.disabled)
        {
            return;
        }

        if(this.canSleep)
        {
            this.scene.sleep();
        }            
    }

    wake()
    {
        if(this.disabled)
        {
            return;
        }

        if(this.canWake)
        {
            this.scene.wake();
            this.scene.setVisible(true);
            this.scene.bringToTop();
            if(this.scale.orientation == Phaser.Scale.LANDSCAPE)
            {
                this.sound.play("jackpotShow");
            }                
        }            
    }

    setCanSleep(v)
    {
        this.canSleep = v;
    }

    setCanWake(v)
    {
        this.canWake = v;
    }

    disableJackpots()
    {
        this.disabled = true;
    }

    update(time, delta) 
    {
        if(!this.parent.hasOwnProperty('gameSocket'))
        {
            return;
        }

        if(this.disabled)
        {
            return;
        }

        let jackpots = this.parent.gameSocket.getJackpots();
        
        if (jackpots.length == 3)
        {
            this.animJackpotGrand.update(delta, jackpots[0]);
            this.animJackpotMaxi.update(delta, jackpots[1]);
            this.animJackpotMini.update(delta, jackpots[2]);
        }            
    }
}
