using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using C1.Silverlight.Schedule;
using C1.C1Schedule;

namespace DefaultViews
{
    public partial class MainPage : UserControl, IDisposable
    {
        public MainPage()
        {
            InitializeComponent();
            
            // initialize palette combo
            paletteBox.SelectedIndex = 0;

            Appointment app = new Appointment(DateTime.Today.AddDays(-1), TimeSpan.FromDays(1));
            app.AllDayEvent = true;
            app.Private = true;
            app.Subject = "Test All-Day Event";
            app.Label = sched1.DataStorage.LabelStorage.Labels[8];
            app.Location = "Room 15";
            sched1.DataStorage.AppointmentStorage.Appointments.Add(app);
            app = new Appointment(DateTime.Today, TimeSpan.FromDays(1));
            app.AllDayEvent = true;
            app.BusyStatus = sched1.DataStorage.StatusStorage.Statuses[StatusTypeEnum.Tentative];
            app.Subject = "Another test All-Day Event";
            app.Label = sched1.DataStorage.LabelStorage.Labels[7];
            app.Location = "Room 22";
            sched1.DataStorage.AppointmentStorage.Appointments.Add(app);
            app = new Appointment();
            app.Duration = TimeSpan.FromMinutes(60);
            app.Subject = "Test Appointment";
            app.Location = "Room 327";
            app.Label = sched1.DataStorage.LabelStorage.Labels[5];
            sched1.DataStorage.AppointmentStorage.Appointments.Add(app);
            app = new Appointment();
            app.Duration = TimeSpan.FromMinutes(20);
            app.Subject = "Another test Appointment";
            app.Location = "Room 327";
            app.BusyStatus = sched1.DataStorage.StatusStorage.Statuses[StatusTypeEnum.OutOfOffice];
            sched1.DataStorage.AppointmentStorage.Appointments.Add(app);
            app = new Appointment(DateTime.Today.AddDays(-3).AddHours(11), TimeSpan.FromMinutes(60));
            app.Subject = "Silverlight lesson";
            app.Location = "Conference room";
            app.Label = sched1.DataStorage.LabelStorage.Labels[8];
            RecurrencePattern pattern = app.GetRecurrencePattern();
            pattern.RecurrenceType = RecurrenceTypeEnum.Weekly;
            pattern.DayOfWeekMask = WeekDaysEnum.Monday;
            pattern.Occurrences = 5;
            sched1.DataStorage.AppointmentStorage.Appointments.Add(app);
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            // update toolbar buttons state
            sched1_StyleChanged(null, null);
        }
        
        private void btnToday_Click(object sender, RoutedEventArgs e)
        {
            sched1.VisibleDates.BeginUpdate();
            sched1.VisibleDates.Clear();
            sched1.VisibleDates.Add(DateTime.Today);
            sched1.VisibleDates.EndUpdate();
        }

        private void sched1_StyleChanged(object sender, RoutedEventArgs e)
        {
            // update toolbar buttons state according to the current C1Scheduler view
            if (sched1.Style == sched1.WorkingWeekStyle)
            {
                btnWorkWeek.IsChecked = true;
            }
            else if (sched1.Style == sched1.WeekStyle)
            {
                btnWeek.IsChecked = true;
            }
            else if (sched1.Style == sched1.MonthStyle)
            {
                btnMonth.IsChecked = true;
            }
            else if (sched1.Style == sched1.TimeLineStyle)
            {
                btnTimeLine.IsChecked = true;
            }
            else
            {
                btnDay.IsChecked = true;
            }
        }

        #region IDisposable Members

        public void Dispose()
        {
            sched1.Dispose();
        }

        #endregion

    }
}
