using System.ComponentModel;
using Billing.iOS.Renderers;
using Billing.UI;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;

[assembly: ExportRenderer(typeof(OptionPicker), typeof(OptionPickerRenderer))]
namespace Billing.iOS.Renderers
{
    public class OptionPickerRenderer : PickerRenderer
    {
        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);

            if (e.PropertyName == nameof(OptionPicker.BorderStyle))
            {
                var control = Control;
                if (control != null && Element is OptionPicker picker)
                {
                    control.BorderStyle = picker.BorderStyle switch
                    {
                        BorderStyle.RoundedRect => UITextBorderStyle.RoundedRect,
                        _ => UITextBorderStyle.None
                    };
                }
            }
        }

        protected override void OnElementChanged(ElementChangedEventArgs<Picker> e)
        {
            base.OnElementChanged(e);

            var control = Control;
            if (control != null && e.NewElement is OptionPicker picker)
            {
                control.BorderStyle = picker.BorderStyle switch
                {
                    BorderStyle.RoundedRect => UITextBorderStyle.RoundedRect,
                    _ => UITextBorderStyle.None
                };
            }
        }
    }
}
