using System;
using System.Globalization;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace InABox.Mobile
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class MobileCheckBox
    {
        
        public static readonly BindableProperty IsCheckedProperty = BindableProperty.Create(
            nameof(IsChecked), 
            typeof(bool), 
            typeof(MobileCheckBox),
            false,
            BindingMode.TwoWay,
            propertyChanged: (sender,oldvalue,newvalue) => CheckChanged(sender as MobileCheckBox, (bool)oldvalue, (bool)newvalue));

        private static void CheckChanged(MobileCheckBox bindable, bool oldValue, bool newValue)
        {

        }

        public bool IsChecked
        {
            get => (bool)GetValue(IsCheckedProperty);
            set
            {
                SetValue(IsCheckedProperty, value);
                OnPropertyChanged(nameof(IsChecked));
            }
        }

        public event EventHandler Changed;
        
        public MobileCheckBox()
        {
            InitializeComponent();
        }

        private void ToggleCheck(object sender, EventArgs e)
        {
            IsChecked = !IsChecked;
            Changed?.Invoke(this,EventArgs.Empty);
        }
        
    }
}