using Cryville.Common;
using Cryville.Crtr.Ruleset;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

namespace Cryville.Crtr.Config.UI {
	public class InputConfigPanelEntry : MonoBehaviour {
		[SerializeField]
		Text m_key;

		[SerializeField]
		Text m_value;

		[SerializeField]
		Button m_button;

		public void SetKey(InputConfigPanel master, Identifier name) {
			m_key.text = (string)name.Name;
			m_value.text = "None";
			m_button.onClick.AddListener(() => {
				master.OpenDialog(name);
				EventSystem.current.SetSelectedGameObject(null);
			});
		}

		public void OnProxyChanged(ProxyChangedEventArgs e) {
			if (e.Used) {
				m_button.interactable = false;
				m_value.text = "(Not Required)";
			}
			else {
				m_button.interactable = true;
				if (e.Proxy == null) {
					m_value.text = "(Unassigned)";
					if (e.Required) m_value.text += " (Required)";
				}
				else {
					m_value.text = e.Proxy.Value.Handler.GetTypeName(e.Proxy.Value.Type);
				}
			}
			m_value.color = e.Required ? Color.yellow : Color.black;
		}
	}
}
