using System.Collections;
using System.Collections.Generic;
using UniRx;
using UnityEngine;
using UnityEngine.UI;

public class DebugOptionManager : MonoBehaviour
{
    // シーン取得
    public static readonly string DebugPrevSceneTag = "DebugPrevScene";
    [SerializeField] private Button resetButton;
    [SerializeField] private Button backButton;
    [SerializeField] private Button resetFieldButton;
    [SerializeField] private Button refillMaterialButton;
    [SerializeField] private Toggle fastGrowingToggle;
    // Start is called before the first frame update
    void Start()
    {
        var prevScene = LocalCacheManager.Load<GameScenes>(DebugPrevSceneTag);
        resetButton.OnClickAsObservable().Subscribe(_ =>
        {
            GameDataManager.ResetData();
            TransitionManager.Instance.LoadScene(GameScenes.DebugOption);
        }).AddTo(this);

        backButton.OnClickAsObservable().Subscribe(_ =>
        {
            GameDataManager.SaveGameData();
            TransitionManager.Instance.LoadScene(prevScene);
        });

        var gameData = GameDataManager.GameData;
        resetFieldButton.OnClickAsObservable().Subscribe(_ =>
        {
            gameData.SeedlingDataList = null;
        }).AddTo(this);

        refillMaterialButton.OnClickAsObservable().Subscribe(_ =>
        {
            // 所持素材
            foreach (var material in gameData.Material)
            {
                material.Amount = 10;
            }
        }).AddTo(this);
        
        // debugfielddata
        // gameData.PlantLines = new List<PlantLineData>
        // {
        //     new PlantLineData(PlantLineType.Top, CornFieldRank.Rank2),
        //     new PlantLineData(PlantLineType.Center, CornFieldRank.Rank1),
        //     new PlantLineData(PlantLineType.Bottom, CornFieldRank.Rank3)
        // };

        fastGrowingToggle.isOn = UsayaStorageManager.LoadOrDefault(UsayaStorageFilename.Settings_Data, "DebugFastGrowing", false);
        fastGrowingToggle.OnValueChangedAsObservable().Subscribe(x =>
        {
            UsayaStorageManager.Save(UsayaStorageFilename.Settings_Data, "DebugFastGrowing", x);
        }).AddTo(this);
    }
}
