using UnityEngine.UI;

namespace TFramework
{
    public class BindIntData : BindDataBase<int>
    {
        public static implicit operator int(BindIntData data) => data.Data;
        public static explicit operator float(BindIntData data) => data.Data;

        protected override void BindEvent(UIBehaviour uI)
        {
            uI.GetComponent<Slider>()?.onValueChanged.AddListener((value) => Data = (int)value);
            uI.GetComponent<Scrollbar>()?.onValueChanged.AddListener(value => Data = (int)value);
        }

        protected override void DataValueChangeEvent()
        {
            foreach (var item in m_UIs)
            {
                if (item.GetComponent<Text>())
                    item.GetComponent<Text>().text = Data.ToString();
            }
        }
    }
}