using ComPDFKit.PDFAnnotation;
using ComPDFKit.PDFAnnotation.Form;
using ComPDFKit.PDFDocument;
using ComPDFKit.Tool;
using ComPDFKit.Tool.Help;
using System.Windows;
using System.Windows.Controls;

namespace Compdfkit_Tools.PDFControl
{
    public partial class SignatureProperty : UserControl
    {
        private ComboBoxParam widgetParam = null;
        private CPDFComboBoxWidget cPDFAnnotation = null;
        private PDFViewControl pdfViewerControl = null;
        private CPDFDocument cPDFDocument = null;

        bool IsLoadedData = false;

        public SignatureProperty()
        {
            InitializeComponent();
        }

        public void SetProperty(AnnotParam annotParam, CPDFAnnotation annotation, CPDFDocument doc, PDFViewControl cPDFViewer)
        {
            widgetParam = (ComboBoxParam)annotParam;
            cPDFAnnotation = (CPDFComboBoxWidget)annotation;
            pdfViewerControl = cPDFViewer;
            cPDFDocument = doc;
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            FormFieldCombox.SelectedIndex = (int)ParamConverter.ConverterWidgetFormFlags(widgetParam.Flags, widgetParam.IsHidden);
            IsLoadedData = true;
        }

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

        private void FormFieldCombox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (IsLoadedData)
            {
                ParamConverter.SetFormField((ParamConverter.FormField)(sender as ComboBox).SelectedIndex, cPDFAnnotation);
                pdfViewerControl.PDFViewTool.GetCPDFViewer().UpDataAnnotFrame();
            }
        }

    }
}
