using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using ReportServer.ReportsService;
using System.Collections.Generic;
using C1.Silverlight.Extended;
using C1.Silverlight;
using System.Windows.Data;
using System.ComponentModel;

namespace ReportServer
{
    public class ComboEditor : C1ComboBox, ITypeEditorControl
    {
        IEnumerable<ValidValue> _values;

        public ComboEditor(IEnumerable<ValidValue> values)
        {
            _values = values;
        }

        ComboEditor() { }

        public ITypeEditorControl Create()
        {
            return new ComboEditor
            {
                ItemsSource = _values,
                DisplayMemberPath = "Label",
                SelectedValuePath = "Value",
                MaxDropDownHeight = 700
            };
        }

        public bool Supports(PropertyAttribute Property)
        {
            return Property.PropertyInfo.PropertyType == typeof(DateTime);
        }

        public void Attach(PropertyAttribute property)
        {
            var binding = new Binding(property.PropertyInfo.Name)
            {
                Mode = BindingMode.TwoWay,
                Source = property.SelectedObject,
            };
            SetBinding(C1ComboBox.SelectedValueProperty, binding);
        }

        public void Detach(PropertyAttribute property)
        {
        }

        public event PropertyChangedEventHandler ValueChanged;
    }
}
