using System.Windows;
using System.Collections.ObjectModel;
using Telerik.Windows.Controls.ScheduleView;
using System;
using System.Linq;
using Telerik.Windows.Controls;

namespace NBCdemo
{
	public partial class MainWindow : Window
	{	private Random random = new Random();

		public MainWindow()
		{
			InitializeComponent();

			this.DataContext = this;
			this.Appointments = this.CreateRandomSource();
			this.ResourceTypes = new ObservableCollection<ResourceType>();
			var resourceType =new ResourceType("Rooms");
			resourceType.Resources.Add(new Resource("Room1"));
			resourceType.Resources.Add(new Resource("Room2"));
			this.ResourceTypes.Add(resourceType);
		}

		private void RadButton_Click(object sender, RoutedEventArgs e)
		{
			var oldItems =this.Appointments.ToList();
			this.Appointments.Add(new Appointment()
				{
					Subject = "new",
					Start = DateTime.Now,
					End = DateTime.Now.AddHours(2)
				});
			oldItems.All(item => this.Appointments.Remove(item));
		}

		public ObservableCollection<Appointment> Appointments { get; private set; }
		public ObservableCollection<ResourceType> ResourceTypes { get; private set; }
		private ObservableCollection<Appointment> CreateRandomSource()
		{
			var appointments = new ObservableCollection<Appointment>();
			var yesterday = DateTime.Today.AddDays(-1);

			for (var i = 0; i < 130; i++)
			{
				var start = yesterday.AddHours(random.Next(i % 4));
				var end = start.AddHours(random.Next(1, 1 + i % 4));
				var appointment = new Appointment()
				{
					Subject = string.Format("Item {0}", i),
					Start = start,
					End = end
				};
				appointment.Resources.Add(new Resource("Room1", "Rooms"));
				appointments.Add(appointment);
				yesterday = end;
			}

			return appointments;
		}
	}
}