using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using InABox.Core;

namespace InABox.DynamicGrid
{
    public class CheckBoxEditorControl : DynamicEditorControl<bool, CheckBoxEditor>
    {
        
        static CheckBoxEditorControl()
        {
            //DynamicEditorControlFactory.Register<CheckBoxEditorControl, CheckBoxEditor>();
        }
        
        private CheckBox Editor;

        public override void Configure()
        {
        }

        protected override FrameworkElement CreateEditor()
        {
            Editor = new CheckBox
            {
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Stretch
            };
            Editor.Checked += (o, e) => CheckChanged();
            Editor.Unchecked += (o, e) => CheckChanged();
            return Editor;
        }

        public override int DesiredHeight()
        {
            return 25;
        }

        public override int DesiredWidth()
        {
            return 25;
        }

        protected override bool RetrieveValue()
        {
            return Editor.IsChecked == true;
        }

        protected override void UpdateValue(bool value)
        {
            Editor.IsChecked = value;
        }

        public override void SetFocus()
        {
            Editor.Focus();
        }

        public override void SetColor(Color color)
        {
            Editor.Background = new SolidColorBrush(color);
        }
    }
}