using UnityEngine;

namespace RothenburgAR.UI
{
    internal class UIColorScheme
    {
        private readonly float _transparency;
        private readonly Color _baseColor;
        private readonly string _name;
        public Color BaseColorOpaque
        {
            get { return _baseColor; }
        }

        public Color BaseColorTransparent
        {
            get { return GetTransparentColor(_baseColor); }
        }

        private readonly Color _lightColor;
        public Color LightColorOpaque
        {
            get { return _lightColor; }
        }

        public Color LightColorTransparent
        {
            get { return GetTransparentColor(_lightColor); }
        }

        private readonly Color _darkColor;
        public Color DarkColorOpaque
        {
            get { return _darkColor; }
        }

        public Color DarkColorTransparent
        {
            get { return GetTransparentColor(_darkColor); }
        }

        public string Name
        {
            get { return _name; }
        }

        //Since we are using Google's Material Design Colors, the constructor takes Html colorvalues
        public UIColorScheme(string name, string baseHtmlColor, string lightHtmlColor, string darkHtmlColor, float transparency)
        {
            _name = name;
            _baseColor = ParseHtmlColor(baseHtmlColor);
            _lightColor = ParseHtmlColor(lightHtmlColor);
            _darkColor = ParseHtmlColor(darkHtmlColor);
            _transparency = transparency;
        }

        private Color ParseHtmlColor(string htmlColor)
        {
            Color color;
            if (ColorUtility.TryParseHtmlString(htmlColor, out color) == false)
            {
                Debug.LogError("HtmlColor '" + htmlColor + "' could not be parsed. Required Format: '#RRGGBB'");
                return Color.black;
            }

            //base opacity always is 1.0f
            color.a = 1.0f;
            return color;
        }

        private Color GetTransparentColor(Color color)
        {
            return new Color(color.r, color.g, color.b, _transparency);
        }
    }
}
