using Pixiview.iOS.Renderers;
using Pixiview.UI;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;

[assembly: ExportRenderer(typeof(CardView), typeof(CardViewRenderer))]
namespace Pixiview.iOS.Renderers
{
    public class CardViewRenderer : VisualElementRenderer<CardView>
    {
        protected override void OnElementChanged(ElementChangedEventArgs<CardView> e)
        {
            base.OnElementChanged(e);

            var layer = Layer;
            var element = e.NewElement;
            if (layer != null && element != null)
            {
                var cornerRadius = element.CornerRadius;
                if (cornerRadius > 0)
                {
                    layer.CornerRadius = cornerRadius;
                }

                //if (element.BackgroundColor != default)
                //{
                //    layer.BackgroundColor = element.BackgroundColor.ToCGColor();
                //}

                var shadowColor = element.ShadowColor;
                if (shadowColor != default)
                {
                    layer.ShadowColor = shadowColor.ToCGColor();
                    layer.ShadowOpacity = 1f;

                    var radius = element.ShadowRadius;
                    if (radius > 0)
                    {
                        layer.ShadowRadius = radius;
                    }

                    layer.ShadowOffset = element.ShadowOffset.ToSizeF();
                }
                else
                {
                    layer.ShadowOpacity = 0f;
                }
            }
        }
    }
}
