using UnityEngine;
using System.Collections;
using Framework.Entities;
using Framework.Extensions;
using UnityEngine.UI;

public class Responsive : CoreBehaviour
{
    public string displayName;
    private GameObject label;

    public class RespondAction : CoreAction
    {
        public RespondAction(CoreBehaviour sender)
            : base(sender)
        {
        }
    }

    public class ShowNameAction : CoreAction
    {
    }

    public class HideNameAction : CoreAction
    {
    }

    protected override void InnerAwake()
    {
        AddActionHandler<RespondAction>(Respond);
        AddActionHandler<ShowNameAction>(ShowName);
        AddActionHandler<HideNameAction>(HideName);
        label = (GameObject)Instantiate(Resources.Load("LabelUI"), this.transform.position + Vector3.up * 1.5f, Quaternion.Euler(0, -45, 0));
    }

    protected override void InnerStart()
    {
        label.transform.SetParent(this.transform);
        Text labelText = label.transform.RecursivelyFindChild("Text").GetComponent<Text>();
        labelText.text = displayName;
        label.SetActive(false);
    }

    protected override void InnerUpdate()
    {

    }

    protected virtual void Respond(RespondAction action)
    {
        //Debug.Log(displayName + " responds.");
    }

    protected void ShowName(ShowNameAction action)
    {
        label.SetActive(true);
        //Debug.Log("Showing: " + displayName);
    }

    protected void HideName(HideNameAction action)
    {
        label.SetActive(false);
        //Debug.Log("Hiding: " + displayName);
    }
}
