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

namespace MPStudio
{
    public class ClosePanel : MonoBehaviour
    {
        public string audioName;
        
        public float animationCost = 0.22f;
        
        private Button _btn;

        private double x;
        private void Awake()
        {
            _btn = GetComponent<Button>();
            x = _btn.transform.parent.localScale.x;

        }

        // Start is called before the first frame update
        void Start()
        {
            _btn.onClick.AddListener(() =>
            {
                if(String.IsNullOrEmpty(this.audioName)==false)
                    AudioManager.Inst.EffectPlay(this.audioName);
                
                StartCoroutine(TweenManager.Inst.ToFloat(x, 0, animationCost, (f) =>
                {
                    _btn.transform.parent.localScale = Vector3.one * (float)f;
                }, () =>
                {
                    _btn.transform.parent.gameObject.SetActive(false);
                    _btn.transform.parent.localScale = Vector3.one * (float)x;
                }));
            });
        }
        
    }
}