using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using System.ComponentModel;

namespace RadTimeBarOfficial
{
    public class SalesViewModel : FrameworkElement, INotifyPropertyChanged
    {
        private ObservableCollection<SalesDataItem> _salesData;
        public ObservableCollection<SalesDataItem> SalesData
        {
            get 
            {
                return _salesData; 
            }
            set 
            {
                if (_salesData != value)
                {
                    _salesData = value;
                    OnPropertyChanged("SalesData");
                }
            }
        }

        public SalesViewModel()
        {
            if (DesignerProperties.IsInDesignTool)
            {
                MakeData(132, 10);
            }
            else
            {
                MakeData(1320, 2);
            }
        }

        // Sample data makes the world go 'round
        private void MakeData(int numToMake, int multiplier)
        {
            SalesData = new ObservableCollection<SalesDataItem>();


            Random rnd = new Random();

            for (int i = 0; i < numToMake; i++)
            {
                int salesTotal = rnd.Next(10,40);
                int marketingTotal = Convert.ToInt32((salesTotal * (i % 3 == 0 ? 2 : .5)));
                DateTime seedDateTime = new DateTime(2011, 1, 1).AddHours(i * multiplier);

                SalesDataItem sdi = new SalesDataItem(i, seedDateTime, salesTotal, marketingTotal, (i % 2 == 0 ? "North" : "South"), (i % 5 == 0 ? true : false));

                SalesData.Add(sdi);
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        public void OnPropertyChanged(string propName)
        {
            if (string.IsNullOrEmpty(propName))
                throw new ArgumentException("propName");

            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propName));
        }
    }
}
