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

public class DisposalPlanPanel : UIView
{
    public Button NewButton;
    public GameObject PlanItem;
    public GameObject NodeItem;
    //灾情
    public List<Plan> Plans = new List<Plan>();
    public override void Awake()
    {
        base.Awake();

        NewButton.OnClickAsObservable()
            .Subscribe(_ =>
            {
                UIManager.Instance.Show<NewSchemePanel>();
                PowerManager.Instance.PlanMode = DisposalPlanMode.方案;
            });
        LoadPlanList();//加载灾情
    }

    //加载灾情
    void LoadPlanList()
    {
        string url = HttpManager.Instance.GetDisposalPlanList;
        HttpManager.Instance.Get<List<Plan>>(url, actionResult =>
        {
            Plans = actionResult;
            foreach (var item in Plans)
            {
                string id = item.Name;
                GameObject plan = Instantiate(PlanItem) as GameObject;
                plan.SetActive(true);
                plan.name = id;
                plan.transform.SetParent(PlanItem.transform.parent, false);
                plan.transform.Find("Subtitles/Toggle/Label").GetComponent<Text>().text = id;
            }
        });
    }
    //保存灾情列表
    public void SavePlanList()
    {
        string url = HttpManager.Instance.PostDisposalPlanList;
        HttpManager.Instance.Post(url, Plans);
    }
}