using Xamarin.Forms;

namespace Pixiview.UI.Theme
{
    public abstract class ThemeBase : ResourceDictionary
    {
        public const string FontIconUser = nameof(FontIconUser);
        public const string FontIconSparkles = nameof(FontIconSparkles);
        public const string FontIconOrder = nameof(FontIconOrder);
        public const string FontIconRefresh = nameof(FontIconRefresh);
        public const string FontIconLove = nameof(FontIconLove);
        public const string FontIconNotLove = nameof(FontIconNotLove);
        public const string FontIconOption = nameof(FontIconOption);
        public const string FontIconDownload = nameof(FontIconDownload);
        public const string FontIconFavorite = nameof(FontIconFavorite);

        public const string StatusBarStyle = nameof(StatusBarStyle);
        public const string WindowColor = nameof(WindowColor);
        public const string TintColor = nameof(TintColor);
        public const string TextColor = nameof(TextColor);
        public const string SubTextColor = nameof(SubTextColor);
        public const string CardBackgroundColor = nameof(CardBackgroundColor);
        public const string MaskColor = nameof(MaskColor);
        public const string NavColor = nameof(NavColor);
        public const string NavSelectedColor = nameof(NavSelectedColor);

        public const string IconLightFontFamily = nameof(IconLightFontFamily);
        public const string IconRegularFontFamily = nameof(IconRegularFontFamily);
        public const string IconSolidFontFamily = nameof(IconSolidFontFamily);
        public const string IconLeft = nameof(IconLeft);
        public const string FontSizeTitle = nameof(FontSizeTitle);
        public const string FontSizeTitleIcon = nameof(FontSizeTitleIcon);
        //public const string Horizon10 = nameof(Horizon10);
        public const string ScreenBottomPadding = nameof(ScreenBottomPadding);
        public const string NavigationBarHeight = nameof(NavigationBarHeight);
        public const string IconRefresh = nameof(IconRefresh);
        public const string IconOption = nameof(IconOption);
        public const string IconDownload = nameof(IconDownload);

        protected void InitResources()
        {
            Add(FontSizeTitle, StyleDefinition.FontSizeTitle);
            Add(FontSizeTitleIcon, StyleDefinition.FontSizeTitleIcon);
            //Add(Horizon10, StyleDefinition.Horizon10);
            Add(ScreenBottomPadding, StyleDefinition.ScreenBottomPadding);
            Add(IconRefresh, StyleDefinition.IconRefresh);
            Add(IconOption, StyleDefinition.IconOption);
            Add(IconDownload, StyleDefinition.IconDownload);

            if (App.ExtraResources != null)
            {
                foreach (var kv in App.ExtraResources)
                {
                    Add(kv.Key, kv.Value);
                }
            }

            var regularFontFamily = (string)this[IconRegularFontFamily];
            var solidFontFamily = (string)this[IconSolidFontFamily];

            Add(FontIconLove, GetSolidIcon(StyleDefinition.IconLove, solidFontFamily, StyleDefinition.ColorRedBackground));
            Add(FontIconUser, GetSolidIcon(StyleDefinition.IconUser, solidFontFamily));
            Add(FontIconSparkles, GetSolidIcon(StyleDefinition.IconSparkles, solidFontFamily));
            Add(FontIconOrder, GetSolidIcon(StyleDefinition.IconOrder, solidFontFamily));
            Add(FontIconRefresh, GetSolidIcon(StyleDefinition.IconRefresh, solidFontFamily));
            Add(FontIconNotLove, GetSolidIcon(StyleDefinition.IconLove, regularFontFamily));
            Add(FontIconOption, GetSolidIcon(StyleDefinition.IconOption, solidFontFamily));
            Add(FontIconDownload, GetSolidIcon(StyleDefinition.IconDownload, solidFontFamily));
            Add(FontIconFavorite, GetSolidIcon(StyleDefinition.IconFavorite, solidFontFamily));
        }

        private FontImageSource GetSolidIcon(string icon, string family, Color color = default)
        {
            return new FontImageSource
            {
                FontFamily = family,
                Glyph = icon,
                Size = StyleDefinition.FontSizeTitle,
                Color = color
            };
        }
    }
}
