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

public class Select_button : MonoBehaviour
{
    [SerializeField] private GameObject Panel, panel2;
    [SerializeField] private Button button, button2, button3;
    [SerializeField] private RoscanModelUnity model;
    private ColorBlock buttonColor;
    private ColorBlock buttoncolor1;
    private ColorBlock buttoncolor2;

 /// <summary> Open/close panel after click on button</summary>
    public void openPanel()
    {
        if (Panel != null)
        {
            bool IsActive = Panel.activeSelf;

            Panel.SetActive(!IsActive);
        }
    }

 /// <summary> Open/close panel with buttons after click on button</summary>
    public void openPanelWithButton()
    {
        if (Panel != null)
        {
            bool IsActive = Panel.activeSelf;

            button2.gameObject.SetActive(!IsActive);
            button3.gameObject.SetActive(!IsActive);
            Panel.SetActive(!IsActive);
        }
    }

 /// <summary> Close the panels (used for invisible buttons)</summary>
    public void ClosePanelButton()
    {
        if(Panel != null)
        {
            Panel.SetActive(false);
            button2.gameObject.SetActive(false);
            button3.gameObject.SetActive(false);
        }   
    }

 /// <summary> Open/Close the panel, change the color of button and layer</summary>
    public void OpenPanelImage()
    {
        if (Panel != null)
        {
            buttonColor = button.colors;
            bool IsActive = false;

            if (!model.AvailableLayers.HasFlag(RoscanModelUnity.ModelLayers.DISTANCE))
                IsActive = Panel.activeSelf;
            else
            {
                if (button.transform.name == "Button_Color")
                    IsActive = panel2.activeSelf;
                else
                    IsActive = Panel.activeSelf;
            }


            if (!IsActive)
            {
                buttonColor.normalColor = new Color32(22, 196, 207, 255);
                buttonColor.selectedColor = new Color32(22, 196, 207, 255);
            }
            else
            {
                buttonColor.normalColor = new Color32(255, 255, 255, 255);
                buttonColor.selectedColor = new Color32(255, 255, 255, 255);

            }
            button.colors = buttonColor;
            
            if(!model.AvailableLayers.HasFlag(RoscanModelUnity.ModelLayers.DISTANCE))
                Panel.SetActive(!IsActive);
            else
            {
                if (button.transform.name == "Button_Color")
                    panel2.SetActive(!IsActive);
                else
                    Panel.SetActive(!IsActive);
            }

            if (Panel.activeSelf)
            {
                switch(Panel.name)
                {
                    case "Panel_SURFACE":
                        model.ActualLayer = RoscanModelUnity.ModelLayers.SURFACE;
                        break;

                    case "Panel_REFLECTIVITY":
                        model.ActualLayer = RoscanModelUnity.ModelLayers.REFLECTIVITY;
                        break;
                    
                    case "Panel_RELWIDTH":
                            model.ActualLayer = RoscanModelUnity.ModelLayers.REFL_WIDTH;
                        break;
                    
                    case "Panel_COLOR":
                        model.ActualLayer = RoscanModelUnity.ModelLayers.COLOR;
                        break;

                    case "Panel_TEMPERATURE":
                            model.ActualLayer = RoscanModelUnity.ModelLayers.TEMPERATURE;
                        break;

                    default:
                        model.ActualLayer = RoscanModelUnity.ModelLayers.SURFACE;
                        break;
                }
                model.SwitchLayer(model.ActualLayer);
            }
            else
            {
                model.ActualLayer = RoscanModelUnity.ModelLayers.DISTANCE;
                model.SwitchLayer(model.ActualLayer);
            }
        }
    }

 /// <summary> Measurment - get shape point of measurment - RED </summary>
    public void SelectmeasStateRED()
    {
        model.measState = "RED";

        buttoncolor1 = button.colors;
        buttoncolor2 = button2.colors;

        buttoncolor1.normalColor = new Color32(212, 112, 109, 255);
        buttoncolor2.normalColor = new Color32(0, 89, 253, 188);

        button.colors = buttoncolor1;
        button2.colors = buttoncolor2;

    }

    /// <summary> Measurment - get shape point of measurment - BLUE </summary>
    public void SelectmeasStateBLUE()
    {
        model.measState = "BLUE";

        buttoncolor1 = button.colors;
        buttoncolor2 = button2.colors;

        buttoncolor1.normalColor = Color.red;
        buttoncolor2.normalColor = new Color32(110,134,178,255);

        button.colors = buttoncolor1;
        button2.colors = buttoncolor2;
    }

 /// <summary> When the button RECOMPUTE was clicked </summary>
    public void buttonPressed()
    {
        model.wasClicked = true;
    }

}
