using System;
using System.ComponentModel;

namespace RadTimePicker
{
	public class TimeViewModel : INotifyPropertyChanged
	{
		private DateTime selectedDate;
		private TimeSpan selectedTime;

		public DateTime SelectedDate
		{
			get
			{
				return this.selectedDate;
			}
			set
			{
				if (this.selectedDate != value)
				{
					this.selectedDate = value.Date.Add(value.Date.TimeOfDay.Add(this.SelectedTime));
					this.OnPropertyChanged("SelectedDate");
				}
			}
		}

		public TimeSpan SelectedTime
		{
			get
			{
				return this.selectedTime;
			}
			set
			{
				if (value != this.selectedTime)
				{
					this.selectedTime = value;
					this.SelectedDate = SelectedDate.Date.Add(this.SelectedDate.Date.TimeOfDay.Add(value));

					this.OnPropertyChanged("SelectedTime");
				}
			}
		}

		public event PropertyChangedEventHandler PropertyChanged = delegate { };

		protected virtual void OnPropertyChanged(string propertyName)
		{
			var validateProperty = this.GetType().GetProperty(propertyName);

			if (validateProperty == null) return;

			this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
		}
	}






}
