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


namespace SimplifyXR
{
    /// <summary>
    /// Initiates a sequence based on an interactable event trigger
    /// </summary>
    [DirectiveCategory(DirectiveCategories.Initiator,
        DirectiveSubCategory.UI, prettyName = "Image Panel Updated",
        directiveInfo = "This initiator starts a sequence when a <b>Image is changed in the Standard Image Panel</b>.")]

    public class ImageChanged : ToggleInitiator
    {
        public ImagePanelFeatures imagePanel;

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

        public override List<KnobKeywords> SendKeywords()
        {
            return new List<KnobKeywords>() {
            new KnobKeywords("Image", typeof(Sprite)),
            new KnobKeywords("Image Name", typeof(string)),
            new KnobKeywords("Image Description", typeof(string))
            };
        }

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

            imagePanel =
               imagePanel == null ?
               Object.FindObjectOfType<ImagePanelFeatures>() :
               imagePanel;
            imagePanel?.OnImageChanged.AddListener(HandleImageChanged);
        }

        protected new void OnDestroy()
        {
            base.OnDestroy();
            imagePanel?.OnImageChanged.RemoveListener(HandleImageChanged);
        }

        void HandleImageChanged(ImagePanelContent content)
        {
            SendData(content);
            base.Initiate();
        }

        void SendData(ImagePanelContent content)
        {
            AddPassableData(new List<string> {
                "Image", 
                "Image Name", 
                "Image Description" }, 
                new List<object> {
                content.image, 
                content.imageName,
                content.imageDescription
                });
        }
    }

    }
