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

public class ButtonEndings : MonoBehaviour
{
    public Action DelClick;

    [SerializeField] GameObject mGobIncomplete;
    [SerializeField] GameObject mGobComplete;

    [SerializeField] Text mTxtUnlocked;
    [SerializeField] Text mTxtTotal;

    [SerializeField] Image mImgIcon;

    [SerializeField] GameObject mGobTips;
    [SerializeField] GameObject mGobNew;

    private bool mIsCompleted;

    private void Awake()
    {
        Button tBtn = GetComponent<Button>();
        UIUtils.BindBtn(tBtn, OnClick);
    }

    public void Init(int pLevelID, int pUnlockCount, int pTotalCount)
    {
        mIsCompleted = pUnlockCount == pTotalCount;

        mGobIncomplete.SetActive(!mIsCompleted);
        mGobComplete.SetActive(mIsCompleted);

        if (!mIsCompleted)
        {
            mTxtUnlocked.text = pUnlockCount.ToString();
            mTxtTotal.text = pTotalCount.ToString();
        }
        else
        {
            mImgIcon.sprite = ResourceManager.Instance.LoadRes<Sprite>(Const.Path.GetLevelIconSmall(pLevelID));
        }

        ShowTip(false);
    }

    public void ShowTip(bool pShow)
    {
        if (mGobTips != null)
        {
            mGobTips.SetActive(pShow);
        }
    }

    public void ShowNew(bool pShow)
    {
        if (mGobNew != null)
        {
            mGobNew.SetActive(pShow);
            if (pShow)
            {
                mGobNew.GetComponent<DOTweenAnimation>().DOPlay();
            }
        }
    }

    private void OnClick()
    {
        DelClick?.Invoke();
    }
}