using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using CafeTerrace.Dependencies;
using CafeTerrace.Droid.Dependencies_Droid;
using Xamarin.Forms.Internals;

[assembly: Xamarin.Forms.Dependency(typeof(PersianDatePickerDependencys_Driod))]
namespace CafeTerrace.Droid.Dependencies_Droid
{

    public class PersianDatePickerDependencys_Driod : IPersianDatePickerDependencys
    {
        public event EventHandler<string> DateSelected;

        public IPersianDatePickerDependencys GetDataPicker()
        {
            return new PersianDatePickerDependencys_Driod();
        }

        public void OpenDatePicker()
        {
            var ac = Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity;
            Com.Mohamadamin.Persianmaterialdatetimepicker.Date.DatePickerDialog pickerDialog = new Com.Mohamadamin.Persianmaterialdatetimepicker.Date.DatePickerDialog();
            pickerDialog.Show(ac.FragmentManager, "تقویم");
            DateTime date;
            pickerDialog.DateSet += (sender, e) =>
            {
                Int32 m = e.P2 + 1;
                PersianCalendar pc = new PersianCalendar();
                date = new DateTime(e.P1, m, e.P3, pc);
                string pcs = pc.GetYear(date) + " " + pc.GetMonth(date) + " " + pc.GetDayOfMonth(date);

                DateSelected?.Invoke(date,pcs);
            };
        }
    }
}