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

public class HueBridgeShower : MonoBehaviour
{
    [SerializeField] private TMP_Dropdown dropdown;
    private void Awake()
    {
        if(dropdown == null)
        {
            dropdown = GetComponent<TMP_Dropdown>();
        }
        dropdown.ClearOptions();
        dropdown.AddOptions(new List<string> { "" });
    }

    private void LateUpdate()
    {
        if(GameManager.Instance.FoundBridges != null && GameManager.Instance.FoundBridges.Any())
        {
            dropdown.AddOptions(GameManager.Instance.FoundBridges.Select(x=>$"{x.IpAddress}: {x.BridgeId}").ToList());
            this.enabled = false;
        }
    }

    public void DropdownChanged(int index)
    {
        GameManager.Instance.SetCurrentBridge(GameManager.Instance.FoundBridges[index - 1]);
    }
}
