using System.Linq;
using Telerik.XamarinForms.ChartRenderer.iOS;
using TelerikUI;
using Xamarin.Forms.Platform.iOS;
using CC = CartesianChartXF_1171097.Portable;

[assembly: Xamarin.Forms.ResolutionGroupName(CC.GradientBarEffect.YourCompanyName)]
[assembly: Xamarin.Forms.ExportEffect(typeof(CartesianChartXF_1171097.iOS.GradientBarEffect), CC.GradientBarEffect.GradientBarEffectName)]

namespace CartesianChartXF_1171097.iOS
{
    public class GradientBarEffect : PlatformEffect
    {
        protected override void OnAttached()
        {
            CC.GradientBarEffect effect = (CC.GradientBarEffect)this.Element.Effects.First(e => e is CC.GradientBarEffect);
            var chart = (TKExtendedChart)this.Control;

            foreach (TKChartSeries series in chart.Series)
            {
                TKChartColumnSeries columnSeries = series as TKChartColumnSeries;
                if (columnSeries != null)
                {
                    columnSeries.Style.Fill = this.CreateGradientBarFill();
                    columnSeries.Style.Stroke = null;
                }
            }
        }

        protected override void OnDetached()
        {
        }

        private TKLinearGradientFill CreateGradientBarFill()
        {
            return new TKLinearGradientFill(new Foundation.NSObject[] { UIKit.UIColor.Black, UIKit.UIColor.Red, }, new CoreGraphics.CGPoint(0.5, 1), new CoreGraphics.CGPoint(0.5, 0));
        }
    }
}