using UnityEngine;

namespace IStalk.EditorTools.MapGen
{
    public enum SpawnSlotType { LootItem, Shrine, PropStatic, PropDynamic, PropIncarnation, RunnerSpawn, AltarLocation }

    public class SpawnSlot : MonoBehaviour
    {
        public SpawnSlotType slotType;
        [Range(0f, 1f)]
        public float spawnProbability = 1f;
        public float radius = 0.5f;

        private void OnDrawGizmos()
        {
            Gizmos.color = GetSlotColor();
            Gizmos.DrawWireSphere(transform.position, radius);

            Vector3 labelPos = transform.position + Vector3.up * (radius + 0.3f);
#if UNITY_EDITOR
            UnityEditor.Handles.Label(labelPos, $"{slotType} ({spawnProbability:P0})");
#endif
        }

        private void OnDrawGizmosSelected()
        {
            Gizmos.color = GetSlotColor() * 0.3f;
            Gizmos.DrawSphere(transform.position, radius);
        }

        private Color GetSlotColor() => slotType switch
        {
            SpawnSlotType.LootItem => new Color(1f, 0.84f, 0f),
            SpawnSlotType.Shrine => Color.magenta,
            SpawnSlotType.PropStatic => Color.gray,
            SpawnSlotType.PropDynamic => Color.cyan,
            SpawnSlotType.PropIncarnation => new Color(0.6f, 0f, 0.8f),
            SpawnSlotType.RunnerSpawn => Color.green,
            SpawnSlotType.AltarLocation => new Color(1f, 0.5f, 0f),
            _ => Color.white
        };
    }
}
