using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using WS;

public class SearchViewController : Controller<SearchView, SearchModel>
{
    protected override void BindingViewModel()
    {
        ToggleGroupAddListener();
    }
    public override void OpenView()
    {
        base.OpenView();
    }
    void ToggleGroupAddListener()
    {
        Toggle[] toggles = _View.itemList.GetComponentsInChildren<Toggle>();
        toggles[0].isOn = true;
    }
    void OnEnterBtnClick()
    {
        SearchViewController controller = FacadeComponent.Instance.CreateController<SearchViewController>();
        controller.OpenView();
    }
}
public class SearchView : View
{
    public Button returnBtn;
    public Button enterCourseBtn;
    public Transform itemList;

    List<string> courses = new List<string>
    {
        "中药检索","中药学古文献","药物化学","药物化学","药物化学"
    };
    public override void LoadInit()
    {
        var rc = UIGameObject.GetComponent<ReferenceCollector>();
        returnBtn = rc.GetComponent<Button>("ReturnBtn");
        enterCourseBtn = rc.GetComponent<Button>("EnterCourseBtn");
        itemList = rc.GetComponent<Transform>("Content");
        RefreshCourseList();
    }
    public void RefreshCourseList()
    {
        var choiceItemPre = Resources.Load<GameObject>("UI/Common/Course_Search");
        for (int i = 0; i < courses.Count; i++)
        {
            var choiceItem = GameObject.Instantiate(choiceItemPre, itemList);
            var rc = choiceItem.GetComponent<ReferenceCollector>();

            TextMeshProUGUI courseName = rc.GetComponent<TextMeshProUGUI>("Detail");
            courseName.text = courses[i];
            Toggle toggle = choiceItem.GetComponent<Toggle>();
            toggle.group = itemList.GetComponent<ToggleGroup>();
        }
    }
}

public class SearchModel : Model
{
    public override void InitProperty()
    {
    }
}