using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls;
using Telerik.WinControls.Primitives;

namespace Telerik.QuickStart.WinControls
{
    public class CarouselMouseOverBehavior : PropertyChangeBehavior
    {
        private Color baseColor;

        public CarouselMouseOverBehavior( Color baseColor )
            : base( RadItem.IsMouseOverProperty )
        {
            this.baseColor = baseColor;
        }

        public void SetupInitialItemState(FillPrimitive fill)
        {            
            if (fill != null)
            {
                this.SetStyleValue(fill, FillPrimitive.BackColorProperty, 
                    Color.FromArgb(0, baseColor));
                this.SetStyleValue(fill, FillPrimitive.BackColor2Property,
                    Color.FromArgb(0, baseColor));
                this.SetStyleValue(fill, FillPrimitive.BackColor3Property,
                    Color.FromArgb(0, baseColor));
                this.SetStyleValue(fill, FillPrimitive.BackColor4Property,
                    Color.FromArgb(0, baseColor));
                
                fill.GradientStyle = GradientStyles.Radial;
                fill.GradientAngle = 90f;

                //fill.GradientPercentage = 0.1f;
                //fill.GradientPercentage2 = 0.9f;

                fill.NumberOfColors = 2;
                fill.ZIndex = 5;
            }
        }

        private void SetStyleValue(RadElement element, RadProperty property, object value)
        {
            PropertySetting setting = new PropertySetting(property, value);
            setting.ApplyValue(element);
        }

        public override void OnPropertyChange( RadElement element, RadPropertyChangedEventArgs e )
        {
            AnimatedPropertySetting setting1 = new AnimatedPropertySetting
                 (
                 FillPrimitive.BackColor2Property,
                 Color.FromArgb(70, ControlPaint.Light(baseColor)), //end value
                 10, //number of frames
                 40  //interval between frames
                 );

            AnimatedPropertySetting setting2 = new AnimatedPropertySetting
                 (
                 FillPrimitive.BackColorProperty,
                 Color.FromArgb(0, baseColor), //end value
                 10, //number of frames
                 40  //interval between frames
                 );

            if ((bool)e.NewValue != true)
            {
                setting1.EndValue = Color.FromArgb(0, this.baseColor);
                setting2.EndValue = Color.FromArgb(0, this.baseColor);
            }

            setting1.ApplyValue(element);
            //setting1.RemoveAfterApply = true;

            setting2.ApplyValue(element);
            //setting2.RemoveAfterApply = true;            
        }
    }
}



