using System;
using CafeTerrace.Dependencies;
using CafeTerrace.ViewModels;
using CafeTerrace.Views.DialogBox;
using MD.PersianDateTime.Standard;
using Rg.Plugins.Popup.Pages;
using Rg.Plugins.Popup.Services;
using Xamarin.Forms;

namespace CafeTerrace.Views
{
    public partial class LoginPage : ContentPage
    {
        public LoginPage()
        {
            InitializeComponent();
            signUpFrame.TranslateTo(0, 380, 0);
            PopupNavigation.Instance.PushAsync(Utilities.PopUpUtilites.InfoPage("لطفا برای استفاده کامل از اپلیکیشن به وای فای کافه تراس متصل شوید"));
            
        }

        private void SignUpButton_OnClicked(object sender, EventArgs e)
        {
            signUpFrame.TranslateTo(0, 0, 380);
            loginFrame.TranslateTo(0, 380, 380);
        }

        private void LoginButton_OnClicked(object sender, EventArgs e)
        {
            signUpFrame.TranslateTo(0, 380, 380);
            loginFrame.TranslateTo(0, 0, 380);
        }

        private void BirthDayEntry_OnFocused(object sender, FocusEventArgs e)
        {
            try
            {
                var datePickerDialog = new PersianDatePicker();
                PopupNavigation.Instance.PushAsync(new PopupPage
                {
                    Content = datePickerDialog,
                    CloseWhenBackgroundIsClicked = false
                });
                datePickerDialog.DateSelected += ((date, ee) =>
                {
                    //birthDayEntry.Text = (new PersianDateTime((DateTime)date)).ToLongDateString();
                    (BindingContext as LoginPageViewModel).SignUpUser.BirthDate = (DateTime)date;
                });
            }
            catch (Exception exception)
            {
                DisplayAlert("خطا", exception.Message, "بستن");
            }
        }

        private void PhoneEntry_OnCompleted(object sender, EventArgs e)
        {
            phoneEntry.Unfocus();
            nameEntry.Focus();
        }

        private void NameEntry_OnCompleted(object sender, EventArgs e)
        {

            nameEntry.Unfocus();
            familyEntry.Focus();
        }

        private void FamilyEntry_OnCompleted(object sender, EventArgs e)
        {

            familyEntry.Unfocus();
            passwordEntry.Focus();
        }

        private void PasswordEntry_OnCompleted(object sender, EventArgs e)
        {
            passwordEntry.Unfocus();
        }

        private void PhoneLoginEntry_OnCompleted(object sender, EventArgs e)
        {
            phoneLoginEntry.Unfocus();
            passwordLoginEntry.Focus();
        }
    }
}
