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

public class SelectUsers : MonoBehaviour
{
    GameObject UsersView;
    Button buttonSelectAll;
    Button buttonNoSelectAll;

    // Start is called before the first frame update
    void Start()
    {
        UsersView = GameObject.Find("UsersView");
        buttonSelectAll = transform.GetChild(0).GetComponent<Button>();
        buttonNoSelectAll = transform.GetChild(1).GetComponent<Button>();


        buttonSelectAll.onClick.AddListener(() => { All(true); });
        buttonNoSelectAll.onClick.AddListener(() => { All(false); });
    }

 private void All(bool select)
    {
        var player = PlayerController.instance;

        switch (player.DropdownMode.value)
        {
            case 0:
                foreach (var u in player.users.Values.Where(s => s.online == true))
                    u.toggle.isOn = select;
                break;
            case 1:
                foreach (var u in player.users.Values)
                    u.toggle.isOn = select;
                break;
        }
    }

    public void SetActive(bool value)
    {
        UsersView.SetActive(value);
        gameObject.SetActive(value);
    }
}
