using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
using Windows.UI.Xaml.Media.Imaging;


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

namespace Zebra_RFID_Mobile
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class PageBattery : Page
    {        
        public PageBattery()
        {
            this.InitializeComponent();
            TextBlockPercentage.DataContext = ReaderConfig.batteryLevel;
            ImageBattery.DataContext = ReaderConfig.batteryLevel;
            if(ReaderConfig.isReaderConnected==false)
            {
                showBatteryImage(0);
            }
            TextBlockChargingStatus.DataContext = ReaderConfig.batteryLevel;
            if (ReaderConfig.isReaderConnected)
                TextBlockPercentage.Visibility = Windows.UI.Xaml.Visibility.Visible;
            else
                TextBlockPercentage.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
        }

        public void showBatteryImage(int batterylevl)
        {
            batterylevl = batterylevl / 10;
            Uri imageURI = new Uri("ms-appx:///Assets/battery_" + batterylevl.ToString() + ".png", UriKind.Absolute);
            BitmapImage batterySource = new BitmapImage(imageURI);
            ImageBattery.Source = batterySource;
        }
       
        /// <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.
        /// This parameter is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }

        protected override void OnNavigatedFrom(NavigationEventArgs e)
        {
            base.OnNavigatedFrom(e);
        }      

        private void AppBarButtonSettings_Click(object sender, RoutedEventArgs e)
        {
            //this.Frame.Navigate(typeof(PageSettings));
            Frame rootFrame = Window.Current.Content as Frame;
            if (rootFrame == null)
            	this.Frame.Navigate(typeof(PageSettings));
            else
        	{
                // If we can go back and the event has not already been handled, do so.
                if (rootFrame.CanGoBack)
                {
                    rootFrame.GoBack();
                }
            }
        }
    }
}
