using UnityEngine;
using UnityEngine.UI;

namespace Cryville.Crtr.Config.UI {
	public class PropertyPanel : MonoBehaviour {
		[SerializeField]
		GameObject m_bool;
		[SerializeField]
		GameObject m_number;
		[SerializeField]
		GameObject m_numberStepped;
		[SerializeField]
		GameObject m_string;

		Text _key;
		Transform _valueContainer;
		PropertyValuePanel _value;

#pragma warning disable IDE0051
		void Awake() {
			_key = transform.Find("Key").GetComponent<Text>();
			_valueContainer = transform.Find("Value");
		}
#pragma warning restore IDE0051
		public void Load(IPropertyAdapter prop) {
			_key.text = prop.Name;

			GameObject vp;
			switch (prop.Type) {
				case PropertyType.Number: vp = m_number; break;
				case PropertyType.NumberStepped: vp = m_numberStepped; break;
				case PropertyType.Boolean: vp = m_bool; break;
				case PropertyType.String: vp = m_string; break;
				default: return;
			}
			_value = Instantiate(vp, _valueContainer, false).GetComponent<PropertyValuePanel>();
			_value.Init(prop);
		}
	}
}
