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 a <b>note is acknowledged</b>.",
        prettyName = "Note Acknowledged")]
    public class OnNoteAcknowledged : Initiator
    {

        public simpleARInstructionFeatures instructionPanel;
        InstructionNote instructionNote;


        public bool listenForNoteId;

        [Conditional("listenForNoteId", true, ComparisonType.Equals)]
        public string noteId;


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

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

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

            instructionPanel =
                instructionPanel == null ?
                Object.FindObjectOfType<simpleARInstructionFeatures>() :
                instructionPanel;

            instructionNote = instructionPanel?.GetComponentInChildren<InstructionNote>();

            instructionNote?.OnNoteAcknowledged
                .AddListener(HandleNoteAcknowledged);
        }

        public new void OnDestroy()
        {
            base.OnDestroy();
            instructionNote?.OnNoteAcknowledged
                .RemoveListener(HandleNoteAcknowledged);
        }



        public void HandleNoteAcknowledged(string id)
        {
            if (listenForNoteId)
            {
                if (id == noteId) base.Initiate();
            }
            else
            {
                base.Initiate();
            }
            
        }
    }
}