using Intrepid.Diagnostics;
using UnityEngine;

namespace Editor.GON.StageEditor
{
    internal static class StageEditorColors
    {
        public static readonly Color Background = new(0.13f, 0.13f, 0.13f, 1f);
        public static readonly Color GridMinor = new(1f, 1f, 1f, 0.08f);
        public static readonly Color GridMajor = new(1f, 1f, 1f, 0.18f);
        public static readonly Color GridBorder = new(1f, 1f, 1f, 0.28f);
        public static readonly Color PreviewFill = new(1f, 1f, 1f, 0.18f);
        public static readonly Color PreviewStroke = new(1f, 1f, 1f, 0.9f);
        public static readonly Color SelectionStroke = new(1f, 0.85f, 0.25f, 1f);
        public static readonly Color WorldSyncFootprint = new(1f, 0.1f, 0.95f, 0.42f);
        public static readonly Color WorldSyncAnchor = new(0.05f, 0.9f, 1f, 0.48f);
        public static readonly Color WorldSyncLift = new(1f, 0.16f, 0.14f, 0.48f);
        public static readonly Color WorldSyncSocket = new(1f, 0.9f, 0.12f, 0.9f);
        
        private static readonly Color GroundColor = FromHtml("55E0FF");
        private static readonly Color WallColor = FromHtml("668B93");
        private static readonly Color EmptyColor = new(0f, 0f, 0f, 0f);

        public static Color FromHtml(string html)
        {
            if (!html.StartsWith("#")) html = $"#{html}";
            if (ColorUtility.TryParseHtmlString(html, out var color))
            {
                return color;
            }
            DLogger.LogDebug("color not supported");
            return Color.magenta;
        }
        
        public static Color Structural(StructuralCellKind kind)
        {
            return kind switch
            {
                StructuralCellKind.Ground => GroundColor,
                StructuralCellKind.Ramp_Front => GroundColor,
                StructuralCellKind.Ramp_Left => GroundColor,
                StructuralCellKind.Ramp_Right => GroundColor,
                StructuralCellKind.Stair_Front => WallColor,
                StructuralCellKind.Stair_Left => WallColor,
                StructuralCellKind.Stair_Right => WallColor,
                StructuralCellKind.Wall => WallColor,
                _ => EmptyColor
            };
        }

        public static Color Layer(StageLogicalLayer layer)
        {
            switch (layer)
            {
                case StageLogicalLayer.Design:
                    return new Color(0.85f, 0.35f, 0.25f, 0.75f);
                case StageLogicalLayer.Camera:
                    return new Color(0.25f, 0.48f, 0.95f, 0.35f);
                case StageLogicalLayer.Markers:
                    return new Color(0.85f, 0.75f, 0.25f, 0.75f);
                case StageLogicalLayer.Structural:
                default:
                    return new Color(0.35f, 0.7f, 0.45f, 0.75f);
            }
        }
    }
}
