using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace ControlExplorer
{
    public class ControlViewModel
    {
        private ObservableCollection<SampleViewModel> _samples = new ObservableCollection<SampleViewModel>();
        public ControlViewModel() { }

        public ControlViewModel(string name)
        {
            ControlName = name;
            IconTemplate = Application.Current.Resources["IconC1" + ControlName] as DataTemplate;
            Categories = new List<ControlCat>();
            _samples.CollectionChanged += OnSamplesCollectionChanged;
        }

        public string ControlName { get; set; }
        public DataTemplate IconTemplate { get; set; }
        public ObservableCollection<SampleViewModel> Samples
        {
            get
            {
                return _samples;
            }
        }

        public List<ControlCat> Categories { get; set; }

        private void OnSamplesCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            foreach (SampleViewModel sample in e.NewItems)
            {
                sample.Control = this;
            }
        }
    }
}
