using Billing.UI;
using Xamarin.Forms;

namespace Billing.Themes
{
    public abstract class BaseTheme : ResourceDictionary
    {
        public static Color CurrentPrimaryColor => (Color)Application.Current.Resources[PrimaryColor];
        public static Color CurrentTextColor => (Color)Application.Current.Resources[TextColor];
        public static Color CurrentSecondaryTextColor => (Color)Application.Current.Resources[SecondaryTextColor];

        public const string FontSemiBold = nameof(FontSemiBold);
        public const string FontBold = nameof(FontBold);

        public const string WindowBackgroundColor = nameof(WindowBackgroundColor);
        public const string OptionTintColor = nameof(OptionTintColor);
        public const string PromptBackgroundColor = nameof(PromptBackgroundColor);
        public const string PrimaryColor = nameof(PrimaryColor);
        public const string SecondaryColor = nameof(SecondaryColor);
        public const string TabBarBackgroundColor = nameof(TabBarBackgroundColor);
        public const string TabBarTitleColor = nameof(TabBarTitleColor);
        public const string TabBarUnselectedColor = nameof(TabBarUnselectedColor);
        public const string OutRangeDayColor = nameof(OutRangeDayColor);
        public const string TextColor = nameof(TextColor);
        public const string SecondaryTextColor = nameof(SecondaryTextColor);
        public const string RedColor = nameof(RedColor);
        public const string GreenColor = nameof(GreenColor);

        protected abstract Color PrimaryMauiColor { get; }
        protected abstract Color SecondaryMauiColor { get; }

        protected void InitResources()
        {
            var regularFontFamily = Definition.GetRegularFontFamily();
            Add(FontSemiBold, Definition.GetSemiBoldFontFamily());
            Add(FontBold, Definition.GetBoldFontFamily());

            Add(PrimaryColor, PrimaryMauiColor);
            Add(SecondaryColor, SecondaryMauiColor);
            Add(TabBarTitleColor, PrimaryMauiColor);

            Add(new Style(typeof(Label))
            {
                Setters =
                {
                    new Setter { Property = Label.FontSizeProperty, Value = Device.GetNamedSize(NamedSize.Small, typeof(Label)) },
                    new Setter { Property = Label.TextColorProperty, Value = PrimaryMauiColor },
                    new Setter { Property = Label.FontFamilyProperty, Value = regularFontFamily }
                }
            });
            Add(new Style(typeof(OptionEntry))
            {
                Setters =
                {
                    new Setter { Property = Entry.FontSizeProperty, Value = Device.GetNamedSize(NamedSize.Small, typeof(Entry)) },
                    new Setter { Property = Entry.FontFamilyProperty, Value = regularFontFamily }
                }
            });
            Add(new Style(typeof(OptionEditor))
            {
                Setters =
                {
                    new Setter { Property = Editor.FontSizeProperty, Value = Device.GetNamedSize(NamedSize.Small, typeof(Editor)) },
                    new Setter { Property = Editor.FontFamilyProperty, Value = regularFontFamily }
                }
            });
            Add(new Style(typeof(OptionDatePicker))
            {
                Setters =
                {
                    new Setter { Property = DatePicker.FontSizeProperty, Value = Device.GetNamedSize(NamedSize.Small, typeof(DatePicker)) },
                    new Setter { Property = DatePicker.FontFamilyProperty, Value = regularFontFamily }
                }
            });
            Add(new Style(typeof(OptionTimePicker))
            {
                Setters =
                {
                    new Setter { Property = TimePicker.FontSizeProperty, Value = Device.GetNamedSize(NamedSize.Small, typeof(TimePicker)) },
                    new Setter { Property = TimePicker.FontFamilyProperty, Value = regularFontFamily }
                }
            });
            Add(new Style(typeof(TintImage))
            {
                Setters =
                {
                    new Setter { Property = TintHelper.TintColorProperty, Value = PrimaryMauiColor }
                }
            });
            Add(new Style(typeof(TintImageButton))
            {
                Setters =
                {
                    new Setter { Property = TintHelper.TintColorProperty, Value = PrimaryMauiColor }
                }
            });
        }
    }
}