using ComPDFKitViewer.PdfViewer;
using PDF_Office.Model;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace PDF_Office.ViewModels.FillAndSign
{
    public class FillAndSignContentViewModel : BindableBase, INavigationAware
    {
        #region 
        private CPDFViewer pdfViewer;

        private ViewContentViewModel viewContentViewMode;

        private IRegionManager regions { get; set; }
        #endregion

        #region Command
        public DelegateCommand<RoutedEventArgs> CheckCommand { get; set; }

        /// <summary>
        /// 按钮名称和属性面板映射字典
        /// </summary>
        public Dictionary<string, string> btnToProperty = new Dictionary<string, string>();
        #endregion

        public FillAndSignContentViewModel(IRegionManager regionManager)
        {
            regions = regionManager;

            CheckCommand = new DelegateCommand<RoutedEventArgs>(CheckedEvent);

            InitDictionary();
        }

        private void CheckedEvent(RoutedEventArgs e)
        {
            var control = e.OriginalSource as Control;

            NavigateToProperty(control.Name);
        }

        private void NavigateToProperty(string btnName)
        {
            NavigationParameters values = new NavigationParameters();
            values.Add(ParameterNames.PDFViewer, pdfViewer);
            regions.RequestNavigate(RegionNames.PropertyRegionName,btnToProperty[btnName]);
            viewContentViewMode.IsPropertyOpen = true;
        }

        /// <summary>
        /// 初始化按钮名称-属性面板字典
        /// </summary>
        private void InitDictionary()
        {
            btnToProperty["RbtnText"] = "TextFillProperty";
            btnToProperty["RbtnTick"] = "ShapFillProperty";
            btnToProperty["RbtnFork"] = "ShapFillProperty";
            btnToProperty["RbtnRectangle"] = "ShapFillProperty";
            btnToProperty["RbtnLine"] = "ShapFillProperty";
            btnToProperty["RbtnPoint"] = "ShapFillProperty";
            btnToProperty["RbtnDate"] = "DateFillProperty";
            btnToProperty["RbtnSign"] = "";

        }

        #region Navigation

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

        public void OnNavigatedFrom(NavigationContext navigationContext)
        {

        }

        public void OnNavigatedTo(NavigationContext navigationContext)
        {
            navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewMode);
            navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out pdfViewer);
        }
        #endregion
    }
}
