// Copyright 2013-2022 AFI,Inc. All rights reserved

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

// UI_SubFunction에 속한 각 버튼들의 스크립트
public class UI_SubFunctionButton : MonoBehaviour {

    private Button       _button;
    private TMP_Text     _text; // 버튼 명 Text
    
    private string       _buttonName; // 버튼 명
    private Action       _buttonAction; // 버튼 클릭 액션
    
    public void Initialize(string buttonName, Action buttonAction) {

        _buttonName = buttonName;
        
        if (_button == null) {
            _button = GetComponent<Button>();
            // 클릭 시 우측 상단에 함수 이름 변경
            // 왼쪽 인자값 UI 리셋
            _button.onClick.AddListener(() => UIManager.Instance.SetSubFunctionName(_buttonName));
            _button.onClick.AddListener(() => UIManager.Instance.ResetRequestUI());
            _button.onClick.AddListener(() => _buttonAction());
        }

        if (_text == null) {
            _text = GetComponentInChildren<TMP_Text>();
        }
        
        _text.text = _buttonName;
        _buttonAction = buttonAction;
    }

    public void Reset() {
        _text.text = string.Empty;
        _buttonAction = null;
    }
}