using C1.Xaml.Sparkline;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

namespace SparklineSamplesLib2013
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class AppearanceSample : Page
    {
        private SampleData sampleData = new SampleData();
        public AppearanceSample()
        {
            this.InitializeComponent();
            sparkline.Data = sampleData.DefaultData;
            SeriesColor.ItemsSource = sampleData.DefaultColors;
            MarksColor.ItemsSource = sampleData.DefaultColors;
            HightMarkColor.ItemsSource = sampleData.DefaultColors;
            LowMarkColor.ItemsSource = sampleData.DefaultColors;
            FirstMarkColor.ItemsSource = sampleData.DefaultColors;
            LastMarkColor.ItemsSource = sampleData.DefaultColors;
            NegativeColor.ItemsSource = sampleData.DefaultColors;
            XAxisColor.ItemsSource = sampleData.DefaultColors;
            sparklineType.ItemsSource = Enum.GetValues(typeof(SparklineType));
            
            sparklineType.SelectedItem = sparkline.SparklineType;
            SeriesColor.SelectedItem = ConvertFromColor(sparkline.SeriesColor);
            XAxisColor.SelectedItem = ConvertFromColor(sparkline.AxisColor);
            MarksColor.SelectedItem = ConvertFromColor(sparkline.MarkersColor);
            FirstMarkColor.SelectedItem = ConvertFromColor(sparkline.FirstMarkerColor);
            LastMarkColor.SelectedItem = ConvertFromColor(sparkline.LastMarkerColor);
            HightMarkColor.SelectedItem = ConvertFromColor(sparkline.HighMarkerColor);
            LowMarkColor.SelectedItem = ConvertFromColor(sparkline.LowMarkerColor);
            NegativeColor.SelectedItem = ConvertFromColor(sparkline.NegativeColor);
            NegativeColor.SelectedItem = ConvertFromColor(sparkline.NegativeColor);
        }

        public string ConvertFromColor(Color color)
        {
            if (color == Colors.Magenta)
                return "Magenta";
            if (color == Colors.Purple)
                return "Purple";
            if (color == Colors.Teal)
                return "Teal";
            if (color == Colors.Lime)
                return "Lime";
            if (color == Colors.Brown)
                return "Brown";
            if (color == Colors.Pink)
                return "Pink";
            if (color == Colors.Orange)
                return "Orange";
            if (color == Colors.Blue)
                return "Blue";
            if (color == Colors.Red)
                return "Red";
            if (color == Colors.Green)
                return "Green";
            return "White";
        }

        public Color ConvertFromString(string color)
        {
            switch (color as string)
            {
                case "Magenta":
                    return Colors.Magenta;
                case "Purple":
                    return Colors.Purple;
                case "Teal":
                    return Colors.Teal;
                case "Lime":
                    return Colors.Lime;
                case "Brown":
                    return Colors.Brown;
                case "Pink":
                    return Colors.Pink;
                case "Orange":
                    return Colors.Orange;
                case "Blue":
                    return Colors.Blue;
                case "Red":
                    return Colors.Red;
                case "Green":
                    return Colors.Green;
                default:
                    return Colors.White;
            }
        }

        private void SeriesColor_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            sparkline.SeriesColor = ConvertFromString(SeriesColor.SelectedItem as string);
        }

        private void MarksColor_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            sparkline.MarkersColor = ConvertFromString(MarksColor.SelectedItem as string);
        }

        private void FirstMarkColor_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            sparkline.FirstMarkerColor = ConvertFromString(FirstMarkColor.SelectedItem as string);
        }

        private void LastMarkColor_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            sparkline.LastMarkerColor = ConvertFromString(LastMarkColor.SelectedItem as string);
        }

        private void HightMarkColor_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            sparkline.HighMarkerColor = ConvertFromString(HightMarkColor.SelectedItem as string);
        }

        private void LowMarkColor_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            sparkline.LowMarkerColor = ConvertFromString(LowMarkColor.SelectedItem as string);
        }

        private void NegativeColor_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            sparkline.NegativeColor = ConvertFromString(NegativeColor.SelectedItem as string);
        }

        private void XAxisColor_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            sparkline.AxisColor = ConvertFromString(XAxisColor.SelectedItem as string);
        }

        private void sparklineType_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            sparkline.SparklineType = (SparklineType)sparklineType.SelectedItem;
        }
    }
}
