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

public class NewGameSlider : MonoBehaviour
{
    public GameObject LocalGameSettings;
    public GameObject OnlineGameSettings;
    // Start is called before the first frame update
    void Start()
    {
        GetComponent<Slider>().onValueChanged.AddListener(SliderChoice);
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    private void SliderChoice(float arg) {
        CanvasGroup localGameSettings = GameObject.Find("LocalGameSettings").gameObject.GetComponent<CanvasGroup>();
        CanvasGroup onlineGameSettings = GameObject.Find("OnlineGameSettings").gameObject.GetComponent<CanvasGroup>();
        if (arg == 0) { // Local game
            SetPanelVisibility("LocalGameSettings", true);
            SetPanelVisibility("OnlineGameSettings", false);
        } else if (arg == 2) { // Online game
            SetPanelVisibility("LocalGameSettings", false);
            SetPanelVisibility("OnlineGameSettings", true);
        } else { // No choice, hide all
            SetPanelVisibility("LocalGameSettings", false);
            SetPanelVisibility("OnlineGameSettings", false);
        }
    }

    private void SetPanelVisibility(string panelName, bool isVisible) {
        CanvasGroup panelCG = GameObject.Find(panelName).gameObject.GetComponent<CanvasGroup>();
        panelCG.alpha = (isVisible ? 1f : 0f);
        panelCG.interactable = (isVisible ? true : false);
        panelCG.blocksRaycasts = (isVisible ? true : false);
    }
}
