using System.Collections.Generic;
using System.Windows.Controls;
using System.Windows.Media;
using C1.Silverlight;
using C1.Silverlight.Theming;
using C1.Silverlight.Chart;
using System.Windows;
using System;

using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Data;
using C1.Silverlight.FlexGrid;

namespace Themes
{
    public partial class Gallery : UserControl
    {
        public Gallery()
        {
            InitializeComponent();

            // generate sample data
            var people = Person.Generate(80);

            // bind controls
            propGrid1.SelectedObject = people[0];
            //propGrid2.SelectedObject = persons[1];
            grid.ItemsSource = people;
            flexGrid.ItemsSource = people;
            coverFlow.ItemsSource = people;
            coverFlow.SelectedIndex = 5;
            listBox.ItemsSource = people;
            //ReportViewer.LoadDocument(Application.GetResourceStream(new Uri("/Themes;component/Resources/Sales.pdf", UriKind.Relative)).Stream);

            // customize groups for the _flexCustomGrouping control
            _groupPanelCustomGrouping.PropertyGroupCreated += _groupPanel_PropertyGroupCreated;
        }
        /// <summary>
        /// Customize group descriptors created by the C1FlexGridGroupPanel.
        /// </summary>
        void _groupPanel_PropertyGroupCreated(object sender, PropertyGroupCreatedEventArgs e)
        {
            var pgd = e.PropertyGroupDescription;
            switch (pgd.PropertyName)
            {
                case "Introduced":
                    //pgd.Converter = new DateTimeGroupConverter();
                    break;
                case "Price":
                    //pgd.Converter = new AmountGroupConverter(1000);
                    break;
                case "Cost":
                    //pgd.Converter = new AmountGroupConverter(300);
                    break;
            }
        }

        // **********************************************************************
        // Won't be required in Silverlight 4
        // **********************************************************************
        public Theme CurrentTheme
        {
            get { return (Theme)GetValue(CurrentThemeProperty); }
            set { SetValue(CurrentThemeProperty, value); }
        }

        // Using a DependencyProperty as the backing store for CurrentTheme.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty CurrentThemeProperty =
            DependencyProperty.Register("CurrentTheme", typeof(Theme), typeof(Gallery), new PropertyMetadata(null));



        #region C1Chart specifics

        private void C1Chart_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {
          C1Chart chart = (C1Chart)sender;
          chart.Data.Children.Add(new DataSeries() { Label = "Series1", ValuesSource = new double[] { 3, 2, 7, 4, 8 } });

          if (chart.ChartType != ChartType.Pie)
          {
              chart.Data.Children.Add(new DataSeries() { Label = "Series2", ValuesSource = new double[] { 1, 2, 3, 4, 6 } });
              chart.Data.Children.Add(new DataSeries() { Label = "Series3", ValuesSource = new double[] { 0, 1, 6, 2, 3 } });
          }
          
          chart.Loaded -= new RoutedEventHandler(C1Chart_Loaded);
        }

        #endregion
		
		public class MailFolders
    {
        public string Name { get; set; }
        public Image Image { get; set; }
        public string Source { get; set; }
        public List<MailFolders> Children { get; set; }

        public MailFolders()
        {
            this.Name = string.Empty;
            this.Image = null;
            this.Children = new List<MailFolders>();
        }

        public static IEnumerable<MailFolders> GetData()
        {
            List<MailFolders> data = new List<MailFolders>();

            // add root item
            MailFolders inbox = new MailFolders { Name = "Inbox", Source = "/Resources/FolderOpen.png" };

            for (int i = 0; i < 2; i++)
            {
                MailFolders folder = new MailFolders { Name = string.Format("Folder{0}", i), Source = "Resources/FolderOpen.png" };

                for (int j = 0; j < 8; j++)
                {
                    folder.Children.Add(new MailFolders { Name = string.Format("{0}.{1}", folder.Name, j), Source = "Resources/FolderOpen.png" });
                }

                inbox.Children.Add(folder);
            }

            data.Add(inbox);

            return data;
        }
    }
    }
}
