class SettingsMobile extends Phaser.Scene {

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

    create(data)
    {
        this.parent = data.scene;
        
        this.x = data.x;
        this.y = data.y;
    
        this.img = this.add.image(this.x, this.y, data.key);
        this.img.setScale(2);
       
        this.scene.sleep();

        this.checkMuteSound = new Checkbox({
            'scene': this,
            'key':'checkBox',
            'name':'checkMuteSound',
            'state':'checked',
            'up': 0,
            'x': 232,
            'y': 537,
            'extraval': null,
            'onClick': this.onMuteAllSounds
        });
        
        this.checkMuteSound.setChecked(this.parent.conf.allSoundMuted);
        this.checkMuteSound.setScale(2.0);
        this.checkMuteSound.input.hitArea.setTo(0, 0, 300, 40);

        this.checkBackgroundSound = new Checkbox({
            'scene': this,
            'key':'checkBox',
            'name':'checkBackgroundSound',
            'state':'checked',
            'up': 0,
            'x': 232,
            'y': 669,
            'extraval': null,
            'onClick': this.onBackgroundSoundChange
        });
        
        this.checkBackgroundSound.setChecked(this.parent.conf.bgrSoundMuted);
        this.checkBackgroundSound.setScale(2.0);
        this.checkBackgroundSound.input.hitArea.setTo(0, 0, 450, 40);

        this.checkAutoSpin5 = new Checkbox({
            'scene': this,
            'key':'checkBox',
            'name':'checkAutoSpin5',
            'state':'checked',
            'up': 0,
            'x': 232,
            'y': 948,
            'extraval': 5,
            'onClick': this.onAutoSpinLimit
        });
        
        this.checkAutoSpin5.setChecked( this.parent.conf.autoSpinLimit == 5 );
        this.checkAutoSpin5.setScale(2.0);
        this.checkAutoSpin5.input.hitArea.setTo(0, 0, 170, 40);

        this.checkAutoSpin10 = new Checkbox({
            'scene': this,
            'key':'checkBox',
            'name':'checkAutoSpin10',
            'state':'unchecked',
            'up': 0,
            'x': 232,
            'y': 1088,
            'extraval': 10,
            'onClick': this.onAutoSpinLimit
        });
        
        this.checkAutoSpin10.setChecked( this.parent.conf.autoSpinLimit == 10 );
        this.checkAutoSpin10.setScale(2.0);
        this.checkAutoSpin10.input.hitArea.setTo(0, 0, 170, 40);

        this.checkAutoSpin20 = new Checkbox({
            'scene': this,
            'key':'checkBox',
            'name':'checkAutoSpin20',
            'state':'unchecked',
            'up': 0,
            'x': 738,
            'y': 948,
            'extraval': 20,
            'onClick': this.onAutoSpinLimit
        });
        
        this.checkAutoSpin20.setChecked( this.parent.conf.autoSpinLimit == 20 );
        this.checkAutoSpin20.setScale(2.0);
        this.checkAutoSpin20.input.hitArea.setTo(0, 0, 170, 40);

        this.checkAutoSpinUnlimited = new Checkbox({
            'scene': this,
            'key':'checkBox',
            'name':'checkAutoSpinUnlimited',
            'state':'unchecked',
            'up': 0,
            'x': 738,
            'y': 1088,
            'extraval': -1,
            'onClick': this.onAutoSpinLimit
        });
        
        this.checkAutoSpinUnlimited.setChecked( this.parent.conf.autoSpinLimit == -1 );
        this.checkAutoSpinUnlimited.setScale(2.0);
        this.checkAutoSpinUnlimited.input.hitArea.setTo(0, 0, 178, 40);


        this.checkAutoSpin5.setGroup([this.checkAutoSpin10, this.checkAutoSpin20, this.checkAutoSpinUnlimited]);
        this.checkAutoSpin10.setGroup([this.checkAutoSpin5, this.checkAutoSpin20, this.checkAutoSpinUnlimited]);
        this.checkAutoSpin20.setGroup([this.checkAutoSpin5, this.checkAutoSpin10, this.checkAutoSpinUnlimited]);
        this.checkAutoSpinUnlimited.setGroup([this.checkAutoSpin5, this.checkAutoSpin10, this.checkAutoSpin20]);
    }

    setScale(v)
    {
        if(v == 1.0)
        {
            this.img.setPosition(this.x, 350);

            this.checkMuteSound.setPosition(435, 239);
            this.checkMuteSound.setScale(1.0);
            this.checkMuteSound.input.hitArea.setTo(0, 0, 300, 40);
    
            this.checkBackgroundSound.setPosition(435, 305);
            this.checkBackgroundSound.setScale(1.0);
            this.checkBackgroundSound.input.hitArea.setTo(0, 0, 450, 40);
    
            this.checkAutoSpin5.setPosition(435, 444);
            this.checkAutoSpin5.setScale(1.0);
            this.checkAutoSpin5.input.hitArea.setTo(0, 0, 170, 40);
    
            this.checkAutoSpin10.setPosition(435, 514);
            this.checkAutoSpin10.setScale(1.0);
            this.checkAutoSpin10.input.hitArea.setTo(0, 0, 170, 40);
    
            this.checkAutoSpin20.setPosition(688, 444);
            this.checkAutoSpin20.setScale(1.0);
            this.checkAutoSpin20.input.hitArea.setTo(0, 0, 170, 40);
    
            this.checkAutoSpinUnlimited.setPosition(688, 514);
            this.checkAutoSpinUnlimited.setScale(1.0);
            this.checkAutoSpinUnlimited.input.hitArea.setTo(0, 0, 178, 40);

        }
        else
        {
            this.img.setPosition(this.x, this.y);

            this.checkMuteSound.setPosition(232, 537);
            this.checkMuteSound.setScale(2.0);
            this.checkMuteSound.input.hitArea.setTo(0, 0, 300, 40);
    
            this.checkBackgroundSound.setPosition(232, 669);
            this.checkBackgroundSound.setScale(2.0);
            this.checkBackgroundSound.input.hitArea.setTo(0, 0, 450, 40);
    
            this.checkAutoSpin5.setPosition(232, 948);
            this.checkAutoSpin5.setScale(2.0);
            this.checkAutoSpin5.input.hitArea.setTo(0, 0, 170, 40);
    
            this.checkAutoSpin10.setPosition(232, 1088);
            this.checkAutoSpin10.setScale(2.0);
            this.checkAutoSpin10.input.hitArea.setTo(0, 0, 170, 40);
    
            this.checkAutoSpin20.setPosition(738, 948);
            this.checkAutoSpin20.setScale(2.0);
            this.checkAutoSpin20.input.hitArea.setTo(0, 0, 170, 40);
    
            this.checkAutoSpinUnlimited.setPosition(738, 1088);
            this.checkAutoSpinUnlimited.setScale(2.0);
            this.checkAutoSpinUnlimited.input.hitArea.setTo(0, 0, 178, 40);
        }

        this.img.setScale(v);
    }

    onMuteAllSounds()
    {
        if(localStorage)
        {
            localStorage.allSoundMuted = this.checkMuteSound.isChecked();
        }

        this.parent.conf.allSoundMuted = this.checkMuteSound.isChecked();
        this.parent.sound.setMute(this.checkMuteSound.isChecked());
    }

    onBackgroundSoundChange()
    {
        if(localStorage)
        {
            localStorage.bgrSoundMuted = this.checkBackgroundSound.isChecked();
        }

        this.parent.conf.bgrSoundMuted = this.checkBackgroundSound.isChecked();

        this.parent.sndBackground.setMute(this.checkBackgroundSound.isChecked());
    }
   
    onSpinSpeedChange(v)
    {
        if(localStorage)
        {
            localStorage.reelsSpeed = v;
        }

        this.parent.conf.reelsSpeed = v;//medium, 0 - slow, 1 - medium, 2 - fast

        this.parent.reelmanager.setReelsSpeed(v);

    }

    onAutoSpinLimit(v)
    {
        if(localStorage)
        {
            localStorage.autoSpinLimit = v;
        }
        
        this.parent.conf.autoSpinLimit = v;
        
        this.parent.setAutoSpinLimit(v);
    }

    wake()
    {
        this.scene.wake();
        this.scene.bringToTop();

        this.checkMuteSound.setChecked(this.parent.conf.allSoundMuted);
        this.checkBackgroundSound.setChecked(this.parent.conf.bgrSoundMuted);
        this.checkAutoSpin5.setChecked( this.parent.conf.autoSpinLimit == 5 );
        this.checkAutoSpin10.setChecked( this.parent.conf.autoSpinLimit == 10 );
        this.checkAutoSpin20.setChecked( this.parent.conf.autoSpinLimit == 20 );
        this.checkAutoSpinUnlimited.setChecked( this.parent.conf.autoSpinLimit == -1 );
    }
}

