using InABox.Wpf;
using System.Drawing;
using System.Windows;

namespace InABox.WPF
{
    /// <summary>
    ///     Interaction logic for ColorSelector.xaml
    /// </summary>
    public partial class ColorEdit : ThemableWindow
    {
        public ColorEdit(string title, Color value)
        {
            InitializeComponent();
            Title = title;
            Value = value;
        }

        public Color Value
        {
            get => Color.FromArgb(Editor.SelectedColor.Value.A, Editor.SelectedColor.Value.R, Editor.SelectedColor.Value.G,
                Editor.SelectedColor.Value.B);
            set => Editor.SelectedColor = System.Windows.Media.Color.FromArgb(value.A, value.R, value.G, value.B);
        }

        private void OK_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = true;
            Close();
        }

        private void Cancel_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
            Close();
        }

        public static bool Execute(string title, ref Color value)
        {
            var edit = new ColorEdit(title, value);
            if (edit.ShowDialog() == true)
            {
                value = edit.Value;
                return true;
            }

            return false;
        }
    }
}