using ComPDFKit.PDFDocument;
using ComPDFKitViewer.PdfViewer;
using PDF_Office.Model;
using Prism.Mvvm;
using Prism.Regions;
using Prism.Services.Dialogs;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;

namespace PDF_Office.ViewModels.BOTA
{
    public class BookmarkContentViewModel : BindableBase, INavigationAware
    {
        #region 属性

        private IRegionManager region;
        private IDialogService dialogs;
        public CPDFViewer PDFViewer;
        public ObservableCollection<CPDFBookmark> Bookmarklist { get; set; }

        private Visibility isEmptyPanelVisibility = Visibility.Collapsed;

        public Visibility IsEmptyPanelVisibility
        {
            get { return isEmptyPanelVisibility; }
            set { isEmptyPanelVisibility = value; }
        }

        #endregion 属性

        public BookmarkContentViewModel(IRegionManager regionManager, IDialogService dialogService)
        {
            region = regionManager;
            dialogs = dialogService;
        }

        public void OnNavigatedTo(NavigationContext navigationContext)
        {
            navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
            if (PDFViewer == null)
            {
                return;
            }

            Bookmarklist = new ObservableCollection<CPDFBookmark>(PDFViewer.Document.GetBookmarkList().OrderBy(d => d.Title));
            if (Bookmarklist.Count < 1)
            {
                IsEmptyPanelVisibility = Visibility.Visible;
                return;
            }
            else
            {
                isEmptyPanelVisibility = Visibility.Collapsed;
            }
        }

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

        public void OnNavigatedFrom(NavigationContext navigationContext)
        {
        }
    }
}