using PdfViewerSamples.DataModel;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

namespace PdfViewerSamples
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class PdfFlipView : Page
    {
        PdfDocumentSource source = null;
         
        public PdfFlipView()
        {
            this.InitializeComponent();
           
            Unloaded += PdfFlipView_Unloaded;
            Loaded += PdfFlipView_Loaded;
        }

        void PdfFlipView_Loaded(object sender, RoutedEventArgs e)
        {

            source = this.Resources["pdfDocumentSource"] as PdfDocumentSource;
            source.LoadDocument("C1XapOptimizer.pdf");
            flipView1.DataContext = source;
        }

        void PdfFlipView_Unloaded(object sender, RoutedEventArgs e)
        {
            source.Close();
        }

        private void btnZoomIn_Click(object sender, RoutedEventArgs e)
        {
            PdfDocumentSource source = this.Resources["pdfDocumentSource"] as PdfDocumentSource;
            source.ZoomIn();
        }

        private void btnZoomOut_Click(object sender, RoutedEventArgs e)
        {
            PdfDocumentSource source = this.Resources["pdfDocumentSource"] as PdfDocumentSource;
            source.ZoomOut();
        }

        private void btnNext_Click(object sender, RoutedEventArgs e)
        {
            if (flipView1.SelectedIndex < flipView1.Items.Count - 1)
                flipView1.SelectedIndex += 1;
        }

        private void btnPrevious_Click(object sender, RoutedEventArgs e)
        {
            if (flipView1.SelectedIndex > 0)
                flipView1.SelectedIndex -= 1;
        }

        private void flipView1_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
        {
            txtPage.Text = (flipView1.SelectedIndex + 1).ToString();
            txtPageCount.Text = flipView1.Items.Count.ToString();
        }

        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }
    }
}
