using C1.Xaml.Chart;
using System;
using System.Collections.Generic;
using System.Linq;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;


namespace ControlExplorer.Controls.Chart
{
    public partial class Gallery
        : UserControl, IExposeApplicationBarItems
    {
        List<AppBarButton> _menuItems = new List<AppBarButton>();
        SampleData sampleData;

        public Gallery()
        {
            InitializeComponent();

            sampleData = new SampleData();
            c1chart.BeginUpdate();
            c1chart.Data = sampleData.DefaultData;
            //c1chart.Data.LoadAnimation = AnimationHelper.CreateAnimation(AnimationTransform.Scale, AnimationOrigin.Center, Easing.CubicEase, true);
            c1chart.EndUpdate();

            foreach (var value in C1.Xaml.TypeEx.GetEnumValues<ChartType>(typeof(ChartType)))
            {
                var mitem = new AppBarButton()
                {
                    Label = Utils.SeparateWords(value.ToString())
                };
                mitem.Click += mitem_Click;
                _menuItems.Add(mitem);
            }
  
        }


        void mitem_Click(object sender, RoutedEventArgs e)
        {
            var menuItem = (AppBarButton)sender;
            var chartType = (ChartType)_menuItems.IndexOf(menuItem);
            if (chartType == ChartType.HighLowOpenClose || chartType == ChartType.Candle)
                c1chart.Data = sampleData.FinancialData;
            else if (chartType == ChartType.Bubble)
                c1chart.Data = sampleData.BubbleData;
            else if (chartType == ChartType.Gantt)
                c1chart.Data = sampleData.GanttData;
            else
                c1chart.Data = sampleData.DefaultData;
            c1chart.ChartType = chartType;
        }


        #region IExposeApplicationBarItems Members

        public IEnumerable<ICommandBarElement> ApplicationBarItems
        {
            get 
            {
                return _menuItems;
            }
        }

        #endregion
    }
}