using ComPDFKitViewer.PdfViewer;
using Microsoft.Office.Interop.Word;
using PDF_Office.Model;
using PDF_Office.Model.Dialog.HomePageToolsDialogs.HomePageBatchProcessing;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Regions;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows;
using System.Windows.Controls;

namespace PDF_Office.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcessing
{
    public class HomePageBatchProcessingDialogViewModel : BindableBase, IDialogAware, INavigationAware
    {
        #region 参数和属性
        private List<string> fileNames;

        public IRegionManager BatchProcessingRegion;

        private string batchProcessingRegionName;
        public string BatchProcessingRegionName
        {
            get
            {
                return batchProcessingRegionName;
            }
            set
            {
                SetProperty(ref batchProcessingRegionName, value);
            }
        }

        private Visibility batchProcessingVisible = Visibility.Collapsed;
        public Visibility BatchProcessingVisible
        {
            get { return batchProcessingVisible; }
            set { SetProperty(ref batchProcessingVisible, value); }
        }
        #endregion

        #region 委托声明
        public DelegateCommand<string> DelegateChangeBatchProcessingCommand { get; set; }
        #endregion
        public HomePageBatchProcessingDialogViewModel(IRegionManager regionManager)
        {
            BatchProcessingRegion = regionManager;
            BatchProcessingRegionName = Guid.NewGuid().ToString();
            DelegateChangeBatchProcessingCommand= new DelegateCommand<string>(ChangeBatchProcessing);
        }
        #region 逻辑函数
        public void ChangeBatchProcessing(string index) {
            if (index=="0"||index =="1"||index=="2") { 
            NavigationParameters param = new NavigationParameters();
            param.Add(ParameterNames.FilePath, HomePageBatchProcessingDialogModel.FilePaths);
            BatchProcessingVisible = Visibility.Collapsed;
            BatchProcessingRegion.RequestNavigate(BatchProcessingRegionName, HomePageBatchProcessingDialogModel.GetBatchProcessing[int.Parse(index)], param);
            BatchProcessingVisible = Visibility.Visible;
            }
        }
        #endregion

        public string Title => "PDF批量工具";

        public event Action<IDialogResult> RequestClose;

        #region 构架行为

        public bool CanCloseDialog()
        {
            return true;
        }

        public void OnDialogClosed()
        {

        }

        public void OnDialogOpened(IDialogParameters parameters)
        {
            string batchprocessingname = "";
            string[] filepath = null;
            parameters.TryGetValue<string>(ParameterNames.BatchProcessing_Name, out batchprocessingname);
            parameters.TryGetValue<string[]>(ParameterNames.FilePath, out filepath);
            if (batchprocessingname != null || filepath != null) {
                fileNames = filepath.ToList();
                ChangeBatchProcessing(batchprocessingname);
            }
        }

        public void OnNavigatedTo(NavigationContext navigationContext)
        {
            
        }

        public bool IsNavigationTarget(NavigationContext navigationContext)
        {
            return true;
        }

        public void OnNavigatedFrom(NavigationContext navigationContext)
        {
        }
        #endregion
    }
}
