using ComPDFKit.PDFDocument;
using ComPDFKitViewer.PdfViewer;
using PDF_Office.CustomControl;
using PDF_Office.Model;
using PDF_Office.Model.PDFTool;
using PDF_Office.Views.HomePanel.PDFTools;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;

namespace PDF_Office.ViewModels.HomePanel
{
    public class HomeGuidContentViewModel : BindableBase
    {
        public IDialogService dialogs;
        public DelegateCommand<ToolItem> QuickToolsCommand { get; set; }
        public HomeGuidContentViewModel(IDialogService dialogService)
        {
            QuickToolsCommand = new DelegateCommand<ToolItem>(QuickTools_Click);
            dialogs = dialogService;
        }

        public void QuickTools_Click(ToolItem toolItem)
        {
            /*
             *设置这个对话框的起始保存路径
             */
            System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog();
            dlg.Multiselect = false;
            dlg.Filter = "PDF|*.pdf;*.PDF;";
            if (toolItem.Tag == PDFToolType.Merge)
            {
                dlg.Multiselect = true;
                dlg.Filter = "Picture|*.png;*.PNG;*.jpg;*.JPG;*bmp;*jpeg;*gif;*tiff;*webp;";
            }
            if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                CPDFViewer viewer = new CPDFViewer();
                viewer.InitDocument(dlg.FileName);
                switch (toolItem.Tag)
                {
                    case PDFToolType.Split:
                        DialogParameters splitvalue = new DialogParameters();
                        splitvalue.Add(ParameterNames.PDFViewer, viewer);
                        splitvalue.Add(ParameterNames.FilePath, dlg.FileName);
                        dialogs.ShowDialog(DialogNames.HomePageSplitDialog, splitvalue, e => { });
                        break;

                    case PDFToolType.Extract:
                        DialogParameters extractvalue = new DialogParameters();
                        extractvalue.Add(ParameterNames.PDFViewer, viewer);
                        extractvalue.Add(ParameterNames.FilePath, dlg.FileName);
                        dialogs.ShowDialog(DialogNames.HomePageExtractDialog, extractvalue, e => { });
                        break;

                    case PDFToolType.Insert:
                        DialogParameters insertvalue = new DialogParameters();
                        insertvalue.Add(ParameterNames.PDFViewer, viewer);
                        insertvalue.Add(ParameterNames.FilePath, dlg.FileName);
                        dialogs.ShowDialog(DialogNames.HomePageInsertDialog, insertvalue, e => { });
                        break;

                    case PDFToolType.Compress:
                        break;

                    case PDFToolType.Merge:
                        DialogParameters picturetopdf = new DialogParameters();
                        picturetopdf.Add(ParameterNames.FilePath, dlg.FileNames);
                        dialogs.ShowDialog(DialogNames.HomePagePictureToPDFDialog, picturetopdf, e => { });
                        break;

                    case PDFToolType.Print:
                        DialogParameters printvalue = new DialogParameters();
                        printvalue.Add(ParameterNames.PDFViewer, viewer); ;
                        printvalue.Add(ParameterNames.FilePath, dlg.FileName);
                        dialogs.ShowDialog(DialogNames.HomePagePrinterDialog, printvalue, e => { });
                        break;

                    case PDFToolType.Security:
                        break;
                }

            }
        }

    }
}
