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

namespace SimplifyXR
{

    [DirectiveCategory(DirectiveCategories.Initiator,
        subCategory = DirectiveSubCategory.UI,
        directiveInfo = "This <i>initiator</i> starts a sequence when an <b>object anchor has been placed</b>.",
        prettyName = "Object Anchor Placed")]
    public class OnObjectAnchorPlaced: Initiator
    {

        public ObjectAnchorPanelFeatures objectAnchorPanel;
        ObjectAnchorPanelFeatures objectAnchor;

        public override List<KnobKeywords> ReceiveKeywords()
        {
            return new List<KnobKeywords>();
        }

        public override List<KnobKeywords> SendKeywords()
        {
            return new List<KnobKeywords>();
        }

        public new void Awake()
        {
            base.Awake();

            objectAnchorPanel =
                objectAnchorPanel == null ?
                Object.FindObjectOfType<ObjectAnchorPanelFeatures>() :
                objectAnchorPanel;


            objectAnchor = objectAnchorPanel.GetComponentInChildren<ObjectAnchorPanelFeatures>();

            objectAnchor?.ObjectAnchorPlaced
                .AddListener(HandleObjectAnchorPlaced);
        }

        public new void OnDestroy()
        {
            base.OnDestroy();
            objectAnchor?.ObjectAnchorPlaced
                .RemoveListener(HandleObjectAnchorPlaced);
        }

        public void HandleObjectAnchorPlaced()
        {
                base.Initiate();
        }
    }
}