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

public class MainGameDebugView : MonoBehaviour
{
    [SerializeField] private Button showDebugButton;
    [SerializeField] private Button closeDebugButton;
    [SerializeField] private Button gameResetButton;
    [SerializeField] private Button backMainButton;
    [SerializeField] private GameObject view;

    [SerializeField] private Button pattern1;
    [SerializeField] private Button pattern2;

    private void Awake()
    {
#if DEVELOPMENT_BUILD || UNITY_EDITOR
        view.transform.SetLocalScale(0f);
        view.SetActive(true);
        Observable.NextFrame().Subscribe(_ =>
        {
            view.transform.SetLocalScale(1f);
            view.SetActive(false);
        });
#else
        gameObject.SetActive(false);
        return;
#endif
    }
    // Start is called before the first frame update

    void Start()
    {
        showDebugButton.OnClickAsObservable().Subscribe(_ =>
        {
            view.SetActive(true);
        }).AddTo(this);
        closeDebugButton.OnClickAsObservable().Subscribe(_ =>
        {
            view.SetActive(false);
        }).AddTo(this);
        gameResetButton.OnClickAsObservable().Subscribe(_ =>
        {
            view.SetActive(false);
        }).AddTo(this);
        backMainButton.OnClickAsObservable().Subscribe(_ =>
        {
            TransitionManager.Instance.LoadScene(GameScenes.Main);
        }).AddTo(this);
        // pattern1.OnClickAsObservable().Subscribe(_ =>
        // {
        //     SetPreset(preset1);
        // }).AddTo(this);
        // pattern2.OnClickAsObservable().Subscribe(_ =>
        // {
        //     SetPreset(preset2);
        // }).AddTo(this);
    }

    private float[] preset1 = 
    {
        0.002f,
        0.009f,
        0.18f,
        0.18f,
        0.18f,
        0.5f,
        0.35f,
        0.65f,
        50f,
        10f,
        .1f,
        2f,
        12.5f,
        1.5f,
        1f,
        45f,
        20f,
    };

    private float[] preset2 =
    {
        0.003f,
        0.009f,
        0.5f,
        0.5f,
        0.18f,
        0.5f,
        0.45f,
        0.55f,
        50f,
        20f,
        .1f,
        2f,
        12.5f,
        1.5f,
        1f,
        45f,
        20f,
    };

    void SetPreset(float[] preset)
    {
        var parameters = view.GetComponentsInChildren<MainGameDebugParameter>();
        for (int i = 0; i < parameters.Length; i++)
        {
            parameters[i].SetValue(preset[i]);
        }
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}
