using GMCabsDriverAssistant.Models;
using GMCabsDriverAssistant.Services;
using GMCabsDriverAssistant.Utils;
using System.Diagnostics;

namespace GMCabsDriverAssistantSolution.Views;

public partial class SettingsPage : ContentPage
{


    public SettingsPage()
    {
        InitializeComponent();

        //if (!Preferences.ContainsKey(Constants.VoucherScanUseFrontCamera))
        //{
        //    Preferences.Set(Constants.VoucherScanUseFrontCamera, true);
        //}
        IsHideVoucherScanSettings();
        SwitchVoucherScanUseFrontCamera.On = Preferences.Get("VoucherScanUseFrontCamera", true);
        SwitchSilentMode.On = Preferences.Get("IsSilentMode", false);
    }

    private void SwitchVoucherScanUseFrontCamera_OnChanged(object sender, ToggledEventArgs e)
    {
        Preferences.Set("VoucherScanUseFrontCamera", e.Value);
    }

    private async void IsHideVoucherScanSettings()
    {
        var isVisibleVoucherScan = Preferences.Get(SecureStorageData.CanScanVouchers, false);
        if (Convert.ToBoolean(isVisibleVoucherScan) == false)
        {
            Settings.Root.Remove(VoucherScanSettings);
        }

    }

    private async void SilentModeSwitch_OnChanged(object sender, ToggledEventArgs e)
    {
        var token = Preferences.Get(SecureStorageData.Token, "");
        Debug.WriteLine(e.Value);
        Preferences.Set("IsSilentMode", e.Value);
        GMCabsDriverService gmCabsDriverService = new GMCabsDriverService();
        SilentModeSettingRequest silentModeSettingRequest = new SilentModeSettingRequest
        {
            IsSilentModeEnabled = e.Value
        };
        await gmCabsDriverService.UpdateSilentModeSetting(token, silentModeSettingRequest);
    }

    private void CloseButton_Clicked(object sender, EventArgs e)
    {
        //Navigation.ShowPopup(new CloseAccountDialogPage(this));
    }
}
