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 CalendarData
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class AppointmentPage : Page
    {
        private Appointment _appointment = null;

        public AppointmentPage()
        {
            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)
        {
            // initialize controls
            _appointment = e.Parameter as Appointment;
            if (_appointment != null)
            {
                Start.DateTime = _appointment.Start;
                End.DateTime = _appointment.End;
                Location.Text = _appointment.Location;
                Subject.Text = _appointment.Subject;
                Description.Text = _appointment.Description;
            }
        }

        private void save_Click(object sender, RoutedEventArgs e)
        {
            // save changes to appointment object
            _appointment.Start = Start.DateTime.Value;
            _appointment.End = End.DateTime.Value;
            _appointment.Location = Location.Text;
            _appointment.Subject = Subject.Text;
            _appointment.Description = Description.Text;

            // navigate to the MainPage, send appointment as parameter
            Frame.Navigate(typeof(MainPage), _appointment);
        }

        private void cancel_Click(object sender, RoutedEventArgs e)
        {
            // just go back, don't save changes
            if (Frame.CanGoBack)
            {
                Frame.GoBack();
            }
        }
    }
}
