using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ComPDFKit.PDFDocument;
using ComPDFKitViewer.PdfViewer;
using PDF_Office.Helper;
using PDFSettings.Settings;

namespace PDF_Office.Views.HomePanel.RecentFiles
{
    /// <summary>
    /// DocItemListViewControl.xaml 的交互逻辑
    /// </summary>
    public partial class DocItemListViewControl : UserControl
    {
        public event EventHandler<RoutedEventArgs> DeleteItemHandler;
        public event EventHandler<RoutedEventArgs> PrintItemHandler;
        public event EventHandler<RoutedEventArgs> FileInfoItemHandler;
        public event EventHandler<RoutedEventArgs> ShareItemHandler;
        public event EventHandler<RoutedEventArgs> FilePathItemHandler;

        public DocItemListViewControl()
        {
            InitializeComponent();
            SetLangText();
        }

        private void SetLangText()
        {

        }

        #region UI
        public bool IsHoverState
        {
            get { return (bool)GetValue(IsHoverStateProperty); }
            set { SetValue(IsHoverStateProperty, value); }
        }

        public static readonly DependencyProperty IsHoverStateProperty =
            DependencyProperty.Register("IsHoverState", typeof(bool), typeof(DocItemListViewControl), new PropertyMetadata(false));

        private void UserControl_MouseEnter(object sender, MouseEventArgs e)
        {
            IsHoverState = true;
        }

        private void UserControl_MouseLeave(object sender, MouseEventArgs e)
        {
            IsHoverState = false;
        }

        private void UserControl_MouseMove(object sender, MouseEventArgs e)
        {
            IsHoverState = true;
        }

        private void MoreButton_Initialized(object sender, EventArgs e)
        {
            MoreButton.ContextMenu = null;
        }

        private void MoreButton_Click(object sender, RoutedEventArgs e)
        {
            MenuMore.PlacementTarget = MoreButton;
            MenuMore.Placement = System.Windows.Controls.Primitives.PlacementMode.Bottom;
            MenuMore.IsOpen = true;
        }

        #endregion

        #region 事件
        private void MenuPrint_Click(object sender, RoutedEventArgs e)
        {
            PrintItemHandler.Invoke(sender, e);
        }

        private void MenuShare_Click(object sender, RoutedEventArgs e)
        {
            ShareItemHandler.Invoke(sender, e);
        }

        private void MenuFileInfo_Click(object sender, RoutedEventArgs e)
        {
            FileInfoItemHandler.Invoke(sender, e);
        }
        #endregion

        private void DeleteButton_Click(object sender, RoutedEventArgs e)
        {
            DeleteItemHandler.Invoke(sender, e);
        }

        private void MenuFilePath_Click(object sender, RoutedEventArgs e)
        {
            FilePathItemHandler.Invoke(sender, e);
        }

        private void MenuMore_Loaded(object sender, RoutedEventArgs e)
        {


        }

        private void Grid_Loaded(object sender, RoutedEventArgs e)
        {
            var grid = sender as Grid;
            if (grid != null)
            {
                var data = grid.DataContext as OpenFileInfo;
                if (data == null) return;


                if (File.Exists(data.ThumbImgPath))
                {
                    CoverImage.Source = ToolMethod.GetFileThumbImg(data.ThumbImgPath);
                }
                else if (data.ThumbImgPath.Equals("pack://application:,,,/Resources/FilesType/ic_propertybar_file_pdf_lock.png"))
                    CoverImage.Source = ToolMethod.GetFileThumbImg("pack://application:,,,/Resources/FilesType/ic_propertybar_file_pdf_lock.png");
                else//最近文档 但是删除了缩略图的情况
                    CoverImage.Source = ToolMethod.GetFileThumbImg("pack://application:,,,/Resources/FilesType/ic_propertybar_file_png_Large.png");
            }

        }

     
    }
}
