using Valg.EVA.Skanning.UserInterfaceElements;
using Valg.EVA.Skanning.UserInterfaceElements.LightBox;
using Valg.EVA.Skanning.UserInterfaceElements.UserSettings;

namespace Valg.EVA.Skanning.Verify.Startup.VerifyBallotPaper.VerifiableViewModelsCollection
{
    public class BallotCompleteViewModel : ViewModelBase, IBallotCompleteViewModel
    {
        private readonly IUserSettingsProvider settingManager;
        private bool dontShowTipOnBallotComplete;
        private bool? isOkButtonFocused;

        public BallotCompleteViewModel(IUserSettingsProvider settingManager)
        {
            this.settingManager = settingManager;
            SetPropertyValues();
        }

        
        
        
        
        
        
        
        public bool DontShowTipOnBallotComplete
        {
            get { return dontShowTipOnBallotComplete; }
            set
            {
                dontShowTipOnBallotComplete = value;
                OnPropertyChanged();
            }
        }

        public bool? IsOkButtonFocused
        {
            get { return isOkButtonFocused; }
            set
            {
                isOkButtonFocused = value;
                OnPropertyChanged();
            }
        }

        
        
        
        public void ShowTipIfNotHiddenByUser()
        {
            if (!DontShowTipOnBallotComplete)
            {
                DelayedFocusSetter.SetFocus(() => IsOkButtonFocused = true);
                
                var eventArgs = new LightBoxEventArgs(typeof(BallotCompleteWindow), this);
                PublishEvent<ShowLightBoxEvent, LightBoxEventArgs>(eventArgs);
            }
        }

        public void SaveSettings()
        {
            UserSettings settings = settingManager.GetUserSettings();
            settings.ShowBallotCompleteTip = !DontShowTipOnBallotComplete;
            settingManager.SaveUserSettings(settings);
        }

        private void SetPropertyValues()
        {
            UserSettings settings = settingManager.GetUserSettings();
            DontShowTipOnBallotComplete = !settings.ShowBallotCompleteTip;
        }
    }
}
