using System.Collections.Generic;
using System.Linq;
using UnityEngine;

public class UIHandleIK : UIHandle
{
    public List<UIHandle> HiddenHandles = new List<UIHandle>();

    public static Transform CreateTransform(string handleName, Transform parent, Vector3 position)
    {
        var go = new GameObject(handleName);
        go.transform.SetParent(parent);
        go.transform.position = position;
        return go.transform;
    }

    public static Transform CreateTransform(string handleName, Transform parent, Vector3 position, Vector3 eulerAngles)
    {
        var go = CreateTransform(handleName, parent, position);
        go.eulerAngles = eulerAngles;
        return go;
    }

    public static UIHandleIK CreateAsChild(ObjectContainer owner, Transform parent, Color color, string name, float scale)
    {
        var handle = CreateAsChild<UIHandleIK>(parent);
        handle.Init(owner).SetName(name).SetColor(color).SetScale(scale);
        return handle;
    }

    public override UIHandle Init(ObjectContainer owner)
    {
        base.Init(owner);
        Popup.AddButton("Reset Position", () => TransformResetPosition());
        Popup.AddButton("Reset Rotation", () => TransformResetRotation());
        Popup.AddButton("Toggle Helper Lines", () =>
        {
            foreach (var c in owner.GetComponents<InverseKinematics>())
            {
                c.forceLinesInvisible = !c.forceLinesInvisible;
            }
        });
        return this;
    }

    protected override bool ShouldBeHidden()
    {
        return _forceDisplayOff || !HandleManager.Instance.EnabledHandles.Contains(SerializableBone.BoneTags.IK);
    }
}
