using System;
using Cute;
using UnityEngine;

namespace Wizard;

public class TypeFilterSingle : MonoBehaviour
{
	[SerializeField]
	private UILabel _label;

	[SerializeField]
	private UIToggle _toggle;

	private bool _cacheSelected;

	public bool IsSelected => _toggle.value;

	public CardBasePrm.TribeType Type { get; private set; }

	private bool Value
	{
		set
		{
			_toggle.value = value;
			_cacheSelected = value;
		}
	}

	public string TribeText => DataMgr.GetTribeNameByKey((int)Type);

	public Action OnValueChange { get; set; }

	public void SetSelected()
	{
		Value = true;
	}

	public void Reset()
	{
		Value = false;
	}

	private void Start()
	{
		EventDelegate.Add(_toggle.onChange, delegate
		{
			if (_toggle.value != _cacheSelected)
			{
				GameMgr.GetIns().GetSoundMgr().PlaySe(_toggle.value ? Se.TYPE.SYS_TOGGLE_ON : Se.TYPE.SYS_TOGGLE_OFF);
				_cacheSelected = _toggle.value;
				OnValueChange.Call();
			}
		});
	}

	public void Initialize(CardBasePrm.TribeType tribe)
	{
		Type = tribe;
		_label.text = TribeText;
	}
}
