using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Globalization;
using C1.Silverlight;

namespace SamplesCommon
{
    public partial class CustomColorPicker
        : UserControl
    {
        public event EventHandler<PropertyChangedEventArgs<object>> SelectedItemChanged;

        #region Exposed Properties

        public Brush BorderBrush
        {
            get
            {
                return combo.BorderBrush;
            }
            set
            {
                combo.BorderBrush = value;
            }
        }

        public bool AutoComplete
        {
            get
            {
                return combo.AutoComplete;
            }
            set
            {
                combo.AutoComplete = value;
            }
        }

        public bool IsEnabled
        {
            get
            {
                return combo.IsEnabled;
            }
            set
            {
                combo.IsEnabled = value;
            }
        }

        public bool IsEditable
        {
            get
            {
                return combo.IsEditable;
            }
            set
            {
                combo.IsEditable = value;
            }
        }

        public int MaxDropDownItems
        {
            get
            {
                return combo.MaxDropDownItems;
            }
            set
            {
                combo.MaxDropDownItems = value;
            }
        }


        public double DropDownWidth
        {
            get
            {
                return combo.DropDownWidth;
            }
            set
            {
                combo.DropDownWidth = value;
            }
        }

        public double DropDownHeight
        {
            get
            {
                return combo.DropDownHeight;
            }
            set
            {
                combo.DropDownHeight = value;
            }
        }

        public TextAlignment TextAlignment
        {
            get
            {
                return combo.TextAlignment;
            }
            set
            {
                combo.TextAlignment = value;
            }
        }

        public Brush Background
        {
            get
            {
                return combo.Background;
            }
            set
            {
                combo.Background = value;
            }
        }

        public ColorWrapper SelectedItem
        {
            get
            {
                return (combo.SelectedItem as ColorWrapper);
            }
            set
            {
                combo.SelectedItem = value;
            }
        }

        #endregion

        #region Constructor

        public CustomColorPicker()
        {
            InitializeComponent();

            // fill the color picker
            List<ColorWrapper> colors = new List<ColorWrapper>();
            colors.Add(new ColorWrapper("#ffffff"));
            colors.Add(new ColorWrapper("#000000"));
            colors.Add(new ColorWrapper("#efece3"));
            colors.Add(new ColorWrapper("#184e8c"));
            colors.Add(new ColorWrapper("#4982c7"));
            colors.Add(new ColorWrapper("#d34a42"));
            colors.Add(new ColorWrapper("#a3b46e"));
            colors.Add(new ColorWrapper("#8d589e"));
            colors.Add(new ColorWrapper("#4ca9ca"));

            colors.Add(new ColorWrapper("#f2f2f2"));
            colors.Add(new ColorWrapper("#7f7f7f"));
            colors.Add(new ColorWrapper("#dcdbbd"));
            colors.Add(new ColorWrapper("#c5d8f6"));
            colors.Add(new ColorWrapper("#d8e6f1"));
            colors.Add(new ColorWrapper("#f6d7d4"));
            colors.Add(new ColorWrapper("#eff4e0"));
            colors.Add(new ColorWrapper("#e7dfec"));
            colors.Add(new ColorWrapper("#d7f1f2"));

            colors.Add(new ColorWrapper("#d8d8d8"));
            colors.Add(new ColorWrapper("#595959"));
            colors.Add(new ColorWrapper("#c5bd96"));
            colors.Add(new ColorWrapper("#8ab3eb"));
            colors.Add(new ColorWrapper("#bcccdc"));
            colors.Add(new ColorWrapper("#e4b8b5"));
            colors.Add(new ColorWrapper("#d6e4c0"));
            colors.Add(new ColorWrapper("#cbc1da"));
            colors.Add(new ColorWrapper("#badce8"));

            colors.Add(new ColorWrapper("#bfbfbf"));
            colors.Add(new ColorWrapper("#3f3f3f"));
            colors.Add(new ColorWrapper("#978754"));
            colors.Add(new ColorWrapper("#5893d9"));
            colors.Add(new ColorWrapper("#89b8d4"));
            colors.Add(new ColorWrapper("#d69694"));
            colors.Add(new ColorWrapper("#c2d59d"));
            colors.Add(new ColorWrapper("#ba9cce"));
            colors.Add(new ColorWrapper("#90cedb"));

            colors.Add(new ColorWrapper("#a4a4a4"));
            colors.Add(new ColorWrapper("#252525"));
            colors.Add(new ColorWrapper("#494627"));
            colors.Add(new ColorWrapper("#0f3461"));
            colors.Add(new ColorWrapper("#376596"));
            colors.Add(new ColorWrapper("#913c35"));
            colors.Add(new ColorWrapper("#76923d"));
            colors.Add(new ColorWrapper("#584980"));
            colors.Add(new ColorWrapper("#2989a1"));

            colors.Add(new ColorWrapper("#7f7f7f"));
            colors.Add(new ColorWrapper("#0c0c0c"));
            colors.Add(new ColorWrapper("#1d1a13"));
            colors.Add(new ColorWrapper("#0d253f"));
            colors.Add(new ColorWrapper("#1f415c"));
            colors.Add(new ColorWrapper("#2b3c67"));
            colors.Add(new ColorWrapper("#63221e"));
            colors.Add(new ColorWrapper("#4f6123"));
            colors.Add(new ColorWrapper("#3c315b"));
            //colors.Add(new ColorWrapper("#145c72"));

            colors.Add(new ColorWrapper("#d20000"));
            colors.Add(new ColorWrapper("#fe0005"));
            colors.Add(new ColorWrapper("#fbc300"));
            colors.Add(new ColorWrapper("#fffc0d"));
            colors.Add(new ColorWrapper("#94d442"));
            colors.Add(new ColorWrapper("#18a73e"));
            colors.Add(new ColorWrapper("#00adf6"));
            colors.Add(new ColorWrapper("#0072cb"));
            colors.Add(new ColorWrapper("#002063"));

            combo.ItemsSource = colors;

            // converters
            combo.ItemConverter = new ColorWrapperConverter();

            // selected item
            combo.SelectedItemChanged += new EventHandler<PropertyChangedEventArgs<object>>(combo_SelectedItemChanged);

        }

        void combo_SelectedItemChanged(object sender, PropertyChangedEventArgs<object> e)
        {
            if (SelectedItemChanged != null)
                SelectedItemChanged(this, e);
        }

        #endregion

    }
}
