using System;
using UniRx;
using UnityEngine;
using UnityEngine.UI;

namespace MyGame.Scenes.MiniGame.Scripts
{
    public class StageSelectItemView : MonoBehaviour
    {
        // [SerializeField] private Text stageName;
        [SerializeField] private Text stageHiScore;
        [SerializeField] private Button button;
        [SerializeField] private GameObject lockObject;
        private readonly IntReactiveProperty hiScore = new IntReactiveProperty();
        private int needScore;

        private void Start()
        {
            hiScore.AddTo(this);
            hiScore.Subscribe(val =>
            {
                stageHiScore.text = $"ハイスコア：{val}";
            }).AddTo(this);
        }

        public void SetStageHiScore(int num) => hiScore.Value = num;

        public IObservable<Unit> OnClick => button.OnClickAsObservable().TakeUntilDestroy(this);

        public void SetData(ScrollGameStageData stageData)
        {
            needScore = stageData.needScore;
            // stageName.text = stageData.id.ToString();
        }

        public void SetStageActive(bool active)
        {
            button.enabled = active;
            lockObject.SetActive(!active);
        }
    }
}