using System.Collections.Generic;
using NBC;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Utilities;

namespace NBF
{
    public class InputIconData
    {
        public string MapName;
        public Dictionary<string, string> KeyboardIcons = new Dictionary<string, string>();

        public string GetIcon(string actionName)
        {
            if (KeyboardIcons.TryGetValue(actionName, out var keyboardIcon))
            {
                return keyboardIcon;
            }

            return string.Empty;
        }


        public void CacheInputActionIcons(ReadOnlyArray<InputAction> actions)
        {
            KeyboardIcons.Clear();
            foreach (var inputAction in actions)
            {
                foreach (var binding in inputAction.bindings)
                {
                    var path = binding.effectivePath.Replace("<", "").Replace(">", "").Replace("/", "_");
                    if (path.Contains("Keyboard") || path.Contains("keyboard"))
                    {
                        path = path.Replace("Keyboard", "keyboard");
                        KeyboardIcons.TryAdd(inputAction.name, path);

                        Log.Info($"ActionIcons {inputAction.name}={path}");
                    }
                }
            }
        }
    }
}