using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

namespace UI.Employee
{
    public class EmployeeDetails : MonoBehaviour
    {
        [SerializeField] protected GameObject panel;
        [SerializeField] protected Image icon;
        [SerializeField] protected TextMeshProUGUI nameText;
        [SerializeField] protected Button releaseButton;
        [SerializeField] protected WorkerDetails workerDetails;

        public void Show(bool v = true) => panel.SetActive(v);

        public virtual void Init(Employees.EmployeeData data, Sprite sp)
        {
            icon.sprite = sp;
            nameText.text = data.fullname;

            workerDetails.Init(data);
        }

        public virtual void Init(Employees.EmployeeData data, Sprite sp, UnityAction onReleaseCallback)
        {
            icon.sprite = sp;
            nameText.text = data.fullname;

            releaseButton.onClick.RemoveAllListeners();
            releaseButton.onClick.AddListener(() => onReleaseCallback?.Invoke());

            workerDetails.Init(data);
        }

        public virtual void UpdateData(Employees.EmployeeData data)
        {
            nameText.text = data.fullname;

            workerDetails.Init(data);
        }

        public virtual void UpdateData(Employees.EmployeeData data, Sprite sp)
        {
            Init(data, sp);
        }
    }
}