using System;
using Xamarin.Essentials;
using Xamarin.Forms;

namespace Pixiview.Login
{
    public class HybridWebView : WebView
    {
        public static readonly BindableProperty UriProperty = BindableProperty.Create(
            nameof(Uri),
            typeof(string),
            typeof(HybridWebView));
        public static readonly BindableProperty UserAgentProperty = BindableProperty.Create(
            nameof(UserAgent),
            typeof(string),
            typeof(HybridWebView));

        public event EventHandler LoginHandle;

        public string Uri
        {
            get => (string)GetValue(UriProperty);
            set => SetValue(UriProperty, value);
        }
        public string UserAgent
        {
            get => (string)GetValue(UserAgentProperty);
            set => SetValue(UserAgentProperty, value);
        }

        public void OnLoginHandle()
        {
            if (LoginHandle != null)
            {
                MainThread.BeginInvokeOnMainThread(() => LoginHandle(this, EventArgs.Empty));
            }
        }
    }
}
