using PDF_Office.ViewModels.Form;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace PDF_Office.Views.Form
{
    /// <summary>
    /// EditPresetColorsDialog.xaml 的交互逻辑
    /// </summary>
    public partial class EditPresetColorsDialog : UserControl
    {
        public EditPresetColorsDialogViewModel ViewModel =>DataContext as EditPresetColorsDialogViewModel;
        public EditPresetColorsDialog()
        {
            InitializeComponent();
            this.Loaded += userControl_Loaded;
        }

        private void userControl_Loaded(object sender, RoutedEventArgs e)
        {
            if (ViewModel != null)
            {
                BorderColorBox.SelectedColorHandler -= BorderColorBox_SelectedColorHandler;
                BorderColorBox.SelectedColorHandler += BorderColorBox_SelectedColorHandler;

                BgColorBox.SelectedColorHandler -= BgColorBox_SelectedColorHandler;
                BgColorBox.SelectedColorHandler += BgColorBox_SelectedColorHandler;

                TextColorBox.SelectedColorHandler -= TextColorBox_SelectedColorHandler;
                TextColorBox.SelectedColorHandler += TextColorBox_SelectedColorHandler;
            }
        }

        private void TextColorBox_SelectedColorHandler(object sender, Color e)
        {
            if (ViewModel != null)
            {
                ViewModel.FontColor = new SolidColorBrush(e);
            }
        }

        private void BgColorBox_SelectedColorHandler(object sender, Color e)
        {
            if (ViewModel != null)
            {
                ViewModel.FillColor = new SolidColorBrush(e);
            }
        }

        private void BorderColorBox_SelectedColorHandler(object sender, Color e)
        {
            if (ViewModel != null)
            {
                ViewModel.BorderColor = new SolidColorBrush(e);
            }
        }
    }
}
