using Android.Graphics;
using Billing.Droid.Effects;
using Billing.UI;
using System;
using System.Linq;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;

[assembly: ResolutionGroupName("Org.Tsanie")]
[assembly: ExportEffect(typeof(ShadowEffectPlatform), nameof(ShadowEffect))]
namespace Billing.Droid.Effects
{
    public class ShadowEffectPlatform : PlatformEffect
    {
        protected override void OnAttached()
        {
            try
            {
                var effect = (ShadowEffect)Element.Effects.FirstOrDefault(e => e is ShadowEffect);
                var paint = new Paint(PaintFlags.AntiAlias);
                paint.SetShadowLayer(effect.Radius, (float)effect.Offect.Width, (float)effect.Offect.Height, effect.Color.ToAndroid());
                Control.SetLayerPaint(paint);
            }
            catch (Exception ex)
            {
                Helper.Error("shadow.effect.attached", $"Cannot set property on attached control, error: {ex.Message}");
            }
        }

        protected override void OnDetached()
        {
        }
    }
}