using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Graphics.Display;
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 SalesDashboard
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
        }

        /// <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)
        {
        }

        private void Page_Loaded_1(object sender, RoutedEventArgs e)
        {
            DisplayProperties.OrientationChanged += DisplayProperties_OrientationChanged;
        }

        void DisplayProperties_OrientationChanged(object sender)
        {
            if (DisplayProperties.CurrentOrientation == DisplayOrientations.Portrait ||
                DisplayProperties.CurrentOrientation == DisplayOrientations.PortraitFlipped)
            {
                //grid 1
                grid1.RowDefinitions.Add(new RowDefinition(){ Height = new GridLength(2, GridUnitType.Star)});
                grid1.ColumnDefinitions.RemoveAt(0);
                Grid.SetRow(salesByType, 2);
                salesByType.Margin = new Thickness(0, 20, 0, 0);

                //grid 2
                grid2.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(2, GridUnitType.Star) });
                grid2.ColumnDefinitions.RemoveAt(0);
                Grid.SetRow(salesByCategory, 2);
                salesByCategory.Margin = new Thickness(0, 20, 0, 0);

            }
            else
            {
                //grid 1
                grid1.ColumnDefinitions.Add(new ColumnDefinition());
                grid1.RowDefinitions.RemoveAt(0);
                Grid.SetRow(salesByType, 0);
                Grid.SetColumn(salesByType, 1);
                Grid.SetRowSpan(salesByType, 2);
                salesByType.Margin = new Thickness(20, 0, 0, 0);

                //grid 1
                grid2.ColumnDefinitions.Add(new ColumnDefinition());
                grid2.RowDefinitions.RemoveAt(0);
                Grid.SetRow(salesByCategory, 0);
                Grid.SetColumn(salesByCategory, 1);
                Grid.SetRowSpan(salesByCategory, 2);
                salesByCategory.Margin = new Thickness(20, 0, 0, 0);
            }
        }
    }
}
