using Microsoft.Win32;
using PDF_Master.Helper;
using PDF_Master.Model;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Linq;

namespace PDF_Master.ViewModels.HomePanel.PDFTools
{
    public class HomeFilesContentViewModel : BindableBase, INavigationAware
    {
        HomeContentViewModel homeContentViewModel = null;
        public DelegateCommand OpenFileCommand { get; set; }

        public DelegateCommand CreateBlackPDFCommand { get; set; }

        public DelegateCommand CreateFromOtherFile { get; set; }

        public DelegateCommand<string> CreateFromScanner { get; set; }

        public HomeFilesContentViewModel()
        {
            OpenFileCommand = new DelegateCommand(OpenFile);
            CreateBlackPDFCommand = new DelegateCommand(CreatBlankPDF);
            CreateFromOtherFile = new DelegateCommand(createFromOtherFile);
            CreateFromScanner = new DelegateCommand<string>(createFromScanner);
        }

        /// <summary>
        /// 从扫描仪创建
        /// </summary>
        private async void createFromScanner(string args)
        {

            if (homeContentViewModel != null)
            {
                homeContentViewModel.createFromScanner("");
            }
        }

        /// <summary>
        /// 打开文件
        /// </summary>
        public async void OpenFile()
        {
            if (homeContentViewModel != null)
            {
                homeContentViewModel.OpenFile();
            }
        }

        /// <summary>
        /// 创建空白文档
        /// </summary>
        public void CreatBlankPDF()
        {
            if (homeContentViewModel != null)
            {
                homeContentViewModel.CreatBlankPDF();
            }
        }

        /// <summary>
        /// 从其他格式文件创建PDF
        /// </summary>
        private async void createFromOtherFile()
        {
            if (homeContentViewModel != null)
            {
                homeContentViewModel.createFromOtherFile();
            }
        }

        public void OnNavigatedTo(NavigationContext navigationContext)
        {
            navigationContext.Parameters.TryGetValue<HomeContentViewModel>(ParameterNames.HomeContentViewModel, out homeContentViewModel);
        }

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

        public void OnNavigatedFrom(NavigationContext navigationContext)
        {

        }
    }
}