using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using iElection.Services;
using iElection.Utilities;
using Refit;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace iElection.Views.PopUps
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class ForegetPassPopUp : ContentView
    {
        private RestWrapper RestWrapper = new RestWrapper();
        public ForegetPassPopUp()
        {
            
            InitializeComponent();
        }

        private async void AcceptButton_OnClicked(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(phoneEntry.Text))
                    throw new Exception("شماره تلفن را وارد کنید");
                UtilitiesWrapper.Instance.PopUpUtilities.PushIndicator(false);
                var rest = await RestWrapper.AccountApiRest.ForgetPassUser(phoneEntry.Text);
                UtilitiesWrapper.Instance.PopUpUtilities.PopAsync();
                if (rest.IsSuccess)
                    UtilitiesWrapper.Instance.PopUpUtilities.PushSuccess("فراموشی رمز  در صورت صحت شماره تلفن برای شما پیامک  خواهد شد");
            }
            catch (ApiException ex)
            {
                RestWrapper.UnhandledExceptionRaiser(ex);
            }
            catch (Exception ex)
            {
                UtilitiesWrapper.Instance.PopUpUtilities.PushError(ex.Message);
            }
        }

        private void CancelButton_OnClicked(object sender, EventArgs e)
        {
            Utilities.UtilitiesWrapper.Instance.PopUpUtilities.PopAsync();
        }
    }
}