using compdfkit_tools.Common;
using ComPDFKitViewer;
using ComPDFKitViewer.AnnotEvent;
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 compdfkit_tools.Form.Property
{
    /// <summary>
    /// CheckBoxProperty.xaml 的交互逻辑
    /// </summary>
    public partial class CheckBoxProperty : UserControl
    {
        private WidgetCheckBoxArgs widgetArgs = null;
        private AnnotAttribEvent annotAttribEvent = null;

        bool IsLoadedData = false;
        public CheckBoxProperty()
        {
            InitializeComponent();
        }


        #region Loaded

        public void SetProperty(WidgetArgs Args, AnnotAttribEvent e)
        {
            widgetArgs = (WidgetCheckBoxArgs)Args;
            annotAttribEvent = e;
        }
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            FieldNameText.Text = widgetArgs.FieldName;
            FormFieldCombox.SelectedIndex = (int)widgetArgs.FormField;
            BorderColorPickerControl.SetCheckedForColor(widgetArgs.LineColor);
            BackgroundColorPickerControl.SetCheckedForColor(widgetArgs.BgColor);
            CheckButtonStyleCombox.SelectedIndex = (int)widgetArgs.CheckStyle;
            chkSelected.IsChecked = widgetArgs.IsChecked;
            IsLoadedData = true;

        }

        private void UserControl_Unloaded(object sender, RoutedEventArgs e)
        {
            IsLoadedData = false;
        }

        #endregion

        private void FieldNameText_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (IsLoadedData)
            {
                annotAttribEvent.UpdateAttrib(AnnotAttrib.FieldName, (sender as TextBox).Text);
                annotAttribEvent.UpdateAnnot();
            }
        }

        private void FormFieldCombox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (IsLoadedData)
            {
                annotAttribEvent.UpdateAttrib(AnnotAttrib.FormField, (sender as ComboBox).SelectedIndex);
                annotAttribEvent.UpdateAnnot();
            }
        }

        private void BorderColorPickerControl_ColorChanged(object sender, EventArgs e)
        {
            if (IsLoadedData)
            {
                annotAttribEvent.UpdateAttrib(AnnotAttrib.Color, ((SolidColorBrush)BorderColorPickerControl.Brush).Color);
                annotAttribEvent.UpdateAnnot();
            }
        }

        private void BackgroundColorPickerControl_ColorChanged(object sender, EventArgs e)
        {
            if (IsLoadedData)
            {
                annotAttribEvent.UpdateAttrib(AnnotAttrib.FillColor, ((SolidColorBrush)BackgroundColorPickerControl.Brush).Color);
                annotAttribEvent.UpdateAnnot();
            }
        }

        private void CheckButtonStyleCombox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (IsLoadedData)
            {
                annotAttribEvent.UpdateAttrib(AnnotAttrib.CheckStyle, (sender as ComboBox).SelectedIndex);
                annotAttribEvent.UpdateAnnot();
            }
        }

        private void chkSelected_Checked(object sender, RoutedEventArgs e)
        {
            if (IsLoadedData)
            {
                annotAttribEvent.UpdateAttrib(AnnotAttrib.IsChecked, true);
                annotAttribEvent.UpdateAnnot();
            }
        }

        private void chkSelected_Unchecked(object sender, RoutedEventArgs e)
        {
            if (IsLoadedData)
            {
                annotAttribEvent.UpdateAttrib(AnnotAttrib.IsChecked, false);
                annotAttribEvent.UpdateAnnot();
            }
        }
    }
}