using Xamarin.Forms;

namespace Pixiview.Utils
{
    public static class Extensions
    {
        public static T Binding<T>(this T view, BindableProperty property, string name) where T : BindableObject
        {
            view.SetBinding(property, name);
            return view;
        }

        public static T DynamicResource<T>(this T view, BindableProperty property, string key) where T : Element
        {
            view.SetDynamicResource(property, key);
            return view;
        }

        public static T GridRow<T>(this T view, int row) where T : BindableObject
        {
            Grid.SetRow(view, row);
            return view;
        }
    }

    public static class Screen
    {
        private const string StatusBarStyle = nameof(StatusBarStyle);
        private const string HomeIndicatorAutoHidden = nameof(HomeIndicatorAutoHidden);

        public static readonly BindableProperty StatusBarStyleProperty = BindableProperty.CreateAttached(
            StatusBarStyle,
            typeof(StatusBarStyles),
            typeof(Page),
            StatusBarStyles.WhiteText);
        public static StatusBarStyles GetStatusBarStyle(VisualElement page) => (StatusBarStyles)page.GetValue(StatusBarStyleProperty);
        public static void SetStatusBarStyle(VisualElement page, StatusBarStyles value) => page.SetValue(StatusBarStyleProperty, value);

        public static readonly BindableProperty HomeIndicatorAutoHiddenProperty = BindableProperty.CreateAttached(
            HomeIndicatorAutoHidden,
            typeof(bool),
            typeof(Shell),
            false);
        public static bool GetHomeIndicatorAutoHidden(VisualElement page) => (bool)page.GetValue(HomeIndicatorAutoHiddenProperty);
        public static void SetHomeIndicatorAutoHidden(VisualElement page, bool value) => page.SetValue(HomeIndicatorAutoHiddenProperty, value);
    }

    public enum StatusBarStyles
    {
        Default,
        // Will behave as normal. 
        // White text on black NavigationBar/in iOS Dark mode and 
        // Black text on white NavigationBar/in iOS Light mode
        DarkText,
        // Will switch the color of content of StatusBar to black. 
        WhiteText,
        // Will switch the color of content of StatusBar to white. 
        Hidden
        // Will hide the StatusBar
    }
}
