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

public class OnlyOne_window : MonoBehaviour
{
    [SerializeField] private GameObject panel1, panel2, panel3, panel4, panel5, panel6;
    [SerializeField] private Button button2, button3, button4, button5;
    [SerializeField] private RoscanModelUnity model;
    private ColorBlock ButtonColor2;


    /// <summary> After pressing the button, deactivate all other buttons and change their color to default </summary>
    public void condition()
    {
        bool panelActive = false;

        if (this.transform.name == "Button_Color")
        {
            if (model.AvailableLayers.HasFlag(RoscanModelUnity.ModelLayers.DISTANCE))
                panelActive = panel6.activeSelf;
            else
                panelActive = panel1.activeSelf;
        }
        else
            panelActive = panel1.activeSelf;

        ButtonColor2 = button2.colors;

        ButtonColor2.normalColor = new Color32(255, 255, 255, 255);
        ButtonColor2.selectedColor = new Color32(255, 255, 255, 255);

        if (model.AvailableLayers.HasFlag(RoscanModelUnity.ModelLayers.DISTANCE) && !(this.transform.name == "Button_Color") || !model.AvailableLayers.HasFlag(RoscanModelUnity.ModelLayers.DISTANCE))
        {
            if (panelActive)
            {
                panel2.SetActive(false);
                button2.colors = ButtonColor2;
                panel3.SetActive(false);
                button3.colors = ButtonColor2;
                panel4.SetActive(false);
                button4.colors = ButtonColor2;
                panel5.SetActive(false);
                button5.colors = ButtonColor2;
                panel6.SetActive(false);
            }
        }
        else
        {
            if (panelActive)
            {
                panel2.SetActive(false);
                button2.colors = ButtonColor2;
                panel3.SetActive(false);
                button3.colors = ButtonColor2;
                panel4.SetActive(false);
                button4.colors = ButtonColor2;
                panel5.SetActive(false);
                button5.colors = ButtonColor2;
            }
        }
    }

    /// <summary> When the panel1 is activated, deactivate other panels </summary>
    public void conditionSetting()
    {
        bool panelActive = panel1.activeSelf;

        if (panelActive)
        {
            panel4.SetActive(false);
            panel3.SetActive(false);
            panel2.SetActive(false);
            panel1.SetActive(true);
        }
    }
}
