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

public class DropDownSliders : MonoBehaviour
{
    [SerializeField] private GameObject Panel1, Panel2, Panel3;
    [SerializeField] private Button button, button2;
    [SerializeField] private Dropdown dropDown;
    [SerializeField] private RoscanModelUnity model;
    [SerializeField] private AlignModels condition;
    [SerializeField] private Toggle toggleTemp;

    /// <summary> Open/Close panel, depending on Value of Dropdown </summary>
    public void OutputValue(int value)
    {
        Panel1.SetActive(false);
        Panel2.SetActive(false);
        Panel3.SetActive(false);

        switch (value)
        {
            case 0:
                Panel1.SetActive(true);
                break;
            case 1:
                Panel2.SetActive(true);
                break;
            case 2:
                Panel3.SetActive(true);
                break;
            default:
                Panel1.SetActive(true);
                Panel2.SetActive(false);
                Panel3.SetActive(false);
                break;
        }

        model.ReflectionPalette = value;
        model.SwitchLayer(model.ActualLayer);
    }

    /// <summary> When the user changes layers with pallete changes, the panels are changed to their dropdown default values </summary>
    public void SwitchBetweenLayers()
    {
        if (button)
        {
            if (model.ActualLayer == RoscanModelUnity.ModelLayers.REFLECTIVITY || model.ActualLayer == RoscanModelUnity.ModelLayers.REFL_WIDTH || model.ActualLayer == RoscanModelUnity.ModelLayers.DISTANCE)
            {
                model.ReflectionPalette = 0;
                dropDown.value = 0;
                dropDown.RefreshShownValue();
                model.SwitchLayer(model.ActualLayer);
            }

            else
            {
                model.ReflectionPalette = 2;
                dropDown.value = 2;
                dropDown.RefreshShownValue();
                model.SwitchLayer(model.ActualLayer);
            }
        }
    }

    /// <summary> Get a units for measurement </summary>
    public void DropdownUnits()
    {
        switch(dropDown.value)
        {
            case 0:         //mm
                model.UnitName = "mm";
                model.Unit = 1;
                break;

            case 1:         //cm
                model.UnitName = "cm";
                model.Unit = 10;
                break;

            case 2:         //dm
                model.UnitName = "dm";
                model.Unit = 100;
                break;

            case 3:         //m
                model.UnitName = "m";
                model.Unit = 1000;
                break;

            default:        //mm
                model.UnitName = "mm";
                model.Unit = 1;
                break;
        }
    }

    /// <summary> Get a type of shape for measurement </summary>
    public void DropdownShape()
    {
        switch (dropDown.value)
        {
            case 0:         //SNAPPED_SHAPE_SURFACE
                model.MeasShape = "SNAPPED_SHAPE_SURFACE";
                model.CreateLines();
                break;

            case 1:         //DIRECT_SHAPES_ONLY
                model.MeasShape = "DIRECT_SHAPES_ONLY";
                model.CreateLines();
                break;

            case 2:         //SNAPPED_SHAPE_VOLUME
                model.MeasShape = "SNAPPED_SHAPE_VOLUME";
                model.CreateLines();
                break;

            case 3:         //INTERSHAPE_VOLUME
                model.MeasShape = "INTERSHAPE_VOLUME";
                model.CreateLines();
                break;

            case 4:         //SELECTED_POINTS_ONLY
                model.MeasShape = "SELECTED_POINTS_ONLY";
                model.CreateLines();
                break;

            default:        //SNAPPED_SHAPE_SURFACE
                model.MeasShape = "SNAPPED_SHAPE_SURFACE";
                model.CreateLines();
                break;
        }
    }

    /// <summary> Get a type of shape for measurement </summary>
    public void DropdownAlignment()
    {
        switch (dropDown.value)
        {
            case 0:         //Automatically
                button.interactable = false;
                button2.interactable = false;
                toggleTemp.interactable = false;
                condition.AlignCondition = true;
                break;

            case 1:         //Manually
                button.interactable = true;
                button2.interactable = true;
                toggleTemp.interactable = true;
                condition.AlignCondition = false;
                break;

            default:        //Automatically
                button.interactable = false;
                button2.interactable = false;
                toggleTemp.interactable = false;
                condition.AlignCondition = true;
                break;
        }
    }
}
