using ComPDFKit.PDFDocument;
using Compdfkit_Tools.Helper;
using ComPDFKitViewer;
using System.Windows.Controls;

namespace Compdfkit_Tools.PDFControl
{
    public partial class CPDFAbstractInfoControl : UserControl
    {
        public PDFViewControl ViewControl;
        public void InitWithPDFViewer(PDFViewControl viewControl)
        {
            this.ViewControl = viewControl;
            if(viewControl!=null && viewControl.PDFViewTool != null)
            {
                CPDFViewer pdfViewer=viewControl.PDFViewTool.GetCPDFViewer();
                CPDFDocument pdfDoc=pdfViewer?.GetDocument();
                if(pdfDoc!=null)
                {
                    InitializeAbstractInfo(pdfDoc);
                }
            }
        }

        public CPDFAbstractInfoControl()
        {
            InitializeComponent();
        }

        private void InitializeAbstractInfo(CPDFDocument cpdfDocument)
        {
            FileNameTextBlock.Text = cpdfDocument.FileName;
            FileSizeTextBlock.Text = CommonHelper.GetFileSize(cpdfDocument.FilePath);
            TitleTextBlock.Text = cpdfDocument.GetInfo().Title;
            AuthorTextBlock.Text = cpdfDocument.GetInfo().Author;
            SubjectTextBlock.Text = cpdfDocument.GetInfo().Subject;
            KeywordTextBlock.Text = cpdfDocument.GetInfo().Keywords;
        }
    }
}
