using System;
using Xamarin.Forms.Xaml;

namespace InABox.Mobile
{

    public class DateSelectorChangedArgs : EventArgs
    {
        public DateTime Date { get; private set; }

        public DateSelectorChangedArgs(DateTime date)
        {
            Date = date;
        }
    }
    public delegate void DateSelectorChanged(object sender, DateSelectorChangedArgs args);
    
    
    
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class MobileDateSelector
    {
        
        public event DateSelectorChanged Changed;
        public event EventHandler Cancelled;
        
        public DateTime Date
        {
            get => Picker.Date;
            set => Picker.Date = value;
        }
        
        public MobileDateSelector()
        {
            InitializeComponent();
        }

        private void Clear_OnClicked(object sender, MobileButtonClickEventArgs args)
        {
            Picker.Date = DateTime.MinValue;
            Changed?.Invoke(this, new DateSelectorChangedArgs(Picker.Date));
        }

        private void Now_OnClicked(object sender, MobileButtonClickEventArgs args)
        {
            Picker.Date = DateTime.Today;
            Changed?.Invoke(this, new DateSelectorChangedArgs(Picker.Date));
        }

        private void Select_OnClicked(object sender, MobileMenuButtonClickedEventArgs args)
        {
            Changed?.Invoke(this, new DateSelectorChangedArgs(Picker.Date));
        }

        private void Cancel_OnClicked(object sender, MobileMenuButtonClickedEventArgs args)
        {
            Cancelled?.Invoke(this, EventArgs.Empty);
        }
    }
}