using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Octopus.Simulator;
using Octopus.Simulator.Networks;
using TMPro;

public class Panel_SimulationUI : MonoBehaviour
{
    WebManager webmanager;
    Button Button_Play;
    Button Button_FastForward;
    TMP_Text text_FastForward;
    List<int> fastParam = new List<int> { 1, 2, 3, 5, 10 };
    int currentFastIndex = 0;

    private void Awake()
    {
        Button_Play = transform.Find(nameof(Button_Play)).GetComponent<Button>();
        Button_FastForward = transform.Find(nameof(Button_FastForward)).GetComponent<Button>();
        text_FastForward = Button_FastForward.GetComponentInChildren<TMP_Text>();
    }

    private void Start()
    {
        webmanager = WebManager.webManager;
        Button_Play.onClick.AddListener(OnClickPlayBTN);
        Button_FastForward.onClick.AddListener(OnclickFastForwardBTN);
    }

    void OnClickPlayBTN()
    {
        SimulationParameters param = new SimulationParameters();
        param.realtime = true;
        param.speed = WebParameters.speed;
        string requestAPI = $"{webmanager.apiConfig.history}/{WebParameters.id}/start";
        webmanager.Request_Post(param, requestAPI, (flag, value) => { if (flag) { Debug.Log(value); } });
    }

    void OnclickFastForwardBTN()
    {
        if (currentFastIndex++ >= fastParam.Count-1)
        {
            currentFastIndex = 0;
        }
        WebParameters.speed = fastParam[currentFastIndex];
        text_FastForward.text = $"x{fastParam[currentFastIndex]}";
    }
}
