﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Arugula.Animation;
using TMPro;

namespace Arugula.Games
{
    public class PoseCallout : Callout
    {
        public TextMeshPro label;
        public bool showOnStart = true;

        public Tween.Options showTween;
        public Tween.Options hideTween;

        public TransformPose showPose;
        public TransformPose hidePose;

        ITween<TransformPose> tween;

        private void Start()
        {
            if (showOnStart)
                Show();
        }

        public override void Show()
        {
            if (Visible)
                return;

            gameObject.SetActive(true);
            Visible = true;
            ClearTween();
            hidePose.Apply(transform);
            tween = transform.PoseTo(showPose, showTween);
        }

        public override void Hide()
        {
            Visible = false;
            ClearTween();
            tween = transform.PoseTo(hidePose, hideTween);
            tween.OnFinished += (x) => { if (x) gameObject.SetActive(false); };
        }

        void ClearTween()
        {
            if (tween != null && !tween.Finished)
                tween.Finish(false);
        }
    }
}