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

public class UIHandleBone : UIHandle
{
    public Transform Bone => Target;

    public List<BoneTags> Tags;

    public static UIHandleBone CreateAsChild(ObjectContainer owner, Transform parent, List<BoneTags> boneTags)
    {
        var handle = CreateAsChild<UIHandleBone>(parent);
        handle.Init(owner, boneTags);
        return handle;
    }

    public override UIHandle Init(ObjectContainer owner)
    {
        throw new System.Exception("Use ObjectContainer, List<BoneTags> constructor!");
    }

    public UIHandleBone Init(ObjectContainer owner, List<BoneTags> boneTags)
    {
        if (boneTags == null || !boneTags.Any())
        {
            boneTags = new List<BoneTags>() { BoneTags.Untagged };
        }

        Tags = boneTags.ToList();
        base.Init(owner);

        SetScale(0.5f);
        if (Tags.Contains(BoneTags.Left)) SetColor(Color.green);
        else if (Tags.Contains(BoneTags.Right)) SetColor(Color.blue);
        else SetColor(Color.white);
        
        Popup.AddButton("Reset All",        TransformResetAll);
        Popup.AddButton("Reset Position",   TransformResetPosition);
        Popup.AddButton("Reset Rotation",   TransformResetRotation);
        Popup.AddButton("Reset Scale",      TransformResetScale);

        return this;
    }

    protected override bool ShouldBeHidden()
    {
        return _forceDisplayOff || !HandleManager.Instance.EnabledHandles.Intersect(Tags).Any();
    }
}