using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace C1.Win.Chart.RangeSelector
{
    [TypeDescriptionProvider(typeof(AbstractControlDescriptionProvider<BaseSelector, UserControl>))]
    public abstract class BaseSelector: UserControl
    {
        protected Axis _chart;

        /// <summary>
        /// Thrown when range of the selection changes
        /// </summary>
        public event EventHandler RangeChanged;

        /// <summary>
        /// Lower border of selection
        /// </summary>
        public abstract double Min { get; set; }
        /// <summary>
        /// Upper border of selection
        /// </summary>
        public abstract double Max { get; set; }

        /// <summary>
        /// Vertical of Horizontal position of selector
        /// </summary>
        public abstract Orientation Orientation { get; set; }

        public BaseSelector()
        { }

        public BaseSelector(Axis axis)
        {
            if (axis == null) throw new ArgumentNullException();

            _chart = axis;
            Min = _chart.ActualMin;
            Max = _chart.ActualMax;
        }

        public BaseSelector(Axis axis, int min, int max)
            : this(axis)
        {
            Min = min;
            Max = max;
        }

        protected void OnRangeChanged()
        {
            if (RangeChanged != null)
                RangeChanged(this, new EventArgs());
        }

        /// <summary>
        /// Removes itself from parent control
        /// </summary>
        public virtual void Remove()
        {
            _chart.Min = _chart.Max = Double.NaN;
            if (this.Parent != null)
                this.Parent.Controls.Remove(this);
        }
    }
}
