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;

namespace C1Extended_Demo
{
    public partial class CalendarBookTop : UserControl
    {
        public CalendarBookTop()
        {
            InitializeComponent();

            Loaded += new RoutedEventHandler(CalendarBookTop_Loaded);
        }

        void CalendarBookTop_Loaded(object sender, RoutedEventArgs e)
        {
            months.Items.Clear();
            foreach (var month in MonthData.Months)
            {
                months.Items.Add(new CalendarItem()
                {
                    Month = month,
                    Current = !(DataContext == month)
                });
            }
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var btn = (Button) sender;
            var item = btn.DataContext as CalendarItem;
            if (MonthRequested != null)
            {
                MonthRequested(this, new MonthEventArgs() { Month = item.Month });
            }
        }

        public event EventHandler<MonthEventArgs> MonthRequested;
    }

    public class MonthEventArgs 
        : EventArgs
    {
        public MonthData Month { get; set; }
    }

    public class CalendarItem 
    {
        public bool Current { get; set; }
        public MonthData Month { get; set; }
    }
}
