using System;
using Windows.Phone.UI.Input;
using Windows.System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace ControlExplorer
{
    public partial class AboutPage : Page
    {
        public AboutPage()
        {
            InitializeComponent();

            DataContext = ViewModel.Instance;
            Loaded += OnLoaded;
            Unloaded += OnUnloaded;
        }

        void OnLoaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            HardwareButtons.BackPressed += OnBackPressed;
        }

        void OnUnloaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            HardwareButtons.BackPressed -= OnBackPressed;
        }
        
        private void OnBackPressed(object sender, BackPressedEventArgs e)
        {
            if (Frame.CanGoBack)
            {
                Frame.GoBack();
                e.Handled = true;
            }
        }

        private async void HyperlinkButton_Click(object sender, RoutedEventArgs e)
        {
            var hyperlink = (HyperlinkButton)sender;
            await Launcher.LaunchUriAsync(new Uri("https://www.grapecity.com/en/componentone", UriKind.Absolute));
        }
    }
}