using C1.Xaml.Document;
using C1.Xaml.SsrsViewer;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Graphics.Printing;
using Windows.UI.ApplicationSettings;
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;

namespace SsrsViewerSamples.Samples
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class DefaultView : Page
    {

        public DefaultView()
        {
            this.InitializeComponent();
            ssrsViewer.Credential = new System.Net.NetworkCredential("ssrs_demo", "bjqveS5gh89BH1Q");

            Loaded += DefaultView_Loaded;
            Unloaded += DefaultView_Unloaded;
        }

        void DefaultView_Unloaded(object sender, RoutedEventArgs e)
        {
            // register for printing and app commands
            PrintManager.GetForCurrentView().PrintTaskRequested -= DefaultView_PrintTaskRequested;
            SettingsPane.GetForCurrentView().CommandsRequested -= DefaultView_CommandsRequested;
        }

        void DefaultView_Loaded(object sender, RoutedEventArgs e)
        {
            // un-register for printing and app commands
            PrintManager.GetForCurrentView().PrintTaskRequested += DefaultView_PrintTaskRequested;
            SettingsPane.GetForCurrentView().CommandsRequested += DefaultView_CommandsRequested;
        }

        async void DefaultView_PrintTaskRequested(PrintManager sender, PrintTaskRequestedEventArgs args)
        {
            await ssrsViewer.CreatePrintTaskAsync(args);
        }

        void DefaultView_CommandsRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs args)
        {
            var pageSettingsCommand = new SettingsCommand(Guid.Empty, "Page Settings",
                (command) =>
                {
                    ssrsViewer.PageSettingsFlyout.Show();
                });
            args.Request.ApplicationCommands.Add(pageSettingsCommand);
        }
    }
}
