using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Syncfusion.XForms.Pickers;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace InABox.Mobile
{

    public class TimeSelectorChangedEventArgs : EventArgs
    {
        public TimeSpan Time { get; private set; }

        public TimeSelectorChangedEventArgs(TimeSpan time)
        {
            Time = time;
        }
    }
    public delegate void TimeSelectorChangedEvent(object sender, TimeSelectorChangedEventArgs args);
    
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class MobileTimeSelector
    {
        
        public event TimeSelectorChangedEvent Changed;
        public event EventHandler Cancelled;
        
        public TimeSpan Time
        {
            get => Picker.Time;
            set => Picker.Time = value;
        }
        
        public MobileTimeSelector()
        {
            InitializeComponent();
        }

        private void Clear_OnClicked(object sender, MobileButtonClickEventArgs args)
        {
            Picker.Time = TimeSpan.Zero;
        }

        private void Now_OnClicked(object sender, MobileButtonClickEventArgs args)
        {
            Picker.Time = DateTime.Now.TimeOfDay;
        }

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

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