using System;
using Cute;
using UnityEngine;

namespace Wizard;

public class PracticePuzzlePlate : MonoBehaviour
{
	[SerializeField]
	private UILabel _title;

	[SerializeField]
	private UIButton _button;

	[SerializeField]
	private UILabel _clearCountLabel;

	[SerializeField]
	private UITexture _plateTexture;

	[SerializeField]
	private GameObject _selectSprite;

	[SerializeField]
	private GameObject _alreadyClear;

	[SerializeField]
	private TweenAlpha _selectSpriteTween;

	[SerializeField]
	private GameObject _missionTarget;

	public PracticePuzzleData PuzzleData { get; private set; }

	public void UpdateView(PracticePuzzleData data, Action<PracticePuzzleData> onSelect, bool isSelected)
	{
		PuzzleData = data;
		_title.text = data.Title;
		_clearCountLabel.text = $"{data.CurrentClearCount}/{data.MaxClearCount}";
		_alreadyClear.gameObject.SetActive(data.IsClear);
		_clearCountLabel.gameObject.SetActive(!data.IsClear);
		_missionTarget.SetActive(data.IsMissionTarget);
		_plateTexture.mainTexture = Toolbox.ResourcesManager.LoadObject<Texture>(GetPlateTexturePath(data, isFetch: true));
		UpdateSelectSpriteVisible(isSelected);
		UIEventListener.Get(_button.gameObject).onClick = delegate
		{
			onSelect.Call(data);
		};
	}

	public static string GetPlateTexturePath(PracticePuzzleData data, bool isFetch)
	{
		return Toolbox.ResourcesManager.GetAssetTypePath(data.GroupdId.ToString(), ResourcesManager.AssetLoadPathType.PracticePuzzleThumbnail, isFetch);
	}

	public void UpdateSelectSpriteVisible(bool visible)
	{
		_selectSprite.SetActive(visible);
		if (visible)
		{
			_selectSpriteTween.PlayPingPong(isIncreaseAlpha: false);
		}
	}
}
