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

public class MenueManager : MonoBehaviour {

    public Button menuButtonShow;
    public Button menuButtonHide;
    public GameObject  menuPanel;

    public bool menuHidden = false;
    private bool triggerHideHideButton = false;
    private bool triggerHideShowButton = false;

    //The Navigation Menu and the correct spacing placing and LayoutGroup adjustment is described in the Unity tutorial
    //Shop UI - Adding Buttons[2 / 9] Live 2016/10/31
    //Shop UI - Adding Buttons[3 / 9] Live 2016/10/31 <--!Important https://www.youtube.com/watch?v=XXrPD97q-OE&ab_channel=Unity

    //On off Buttons for the UI are a pain in the a## I have a backup routine to call the Button from outside the OnClickEvent (via trigger) because I guess the setActive = false disables the propper execution of the code.




    private void Awake()
    {
        if (menuButtonShow == null)
        {
            Debug.LogError("menuButtonShow not assigned! Please add in Inspector");
        }
        if (menuButtonHide == null)
        {
            Debug.LogError("menuButtonHide not assigned! Please add in Inspector");
        }
        if (menuPanel == null)
        {
            Debug.LogError("menuPanel not assigned! Please add in Inspector");
        }
    }

    // Use this for initialization
    void Start () {

        //This is also used later but its also the "how to start with hidden menu"
        if (menuHidden==true)
        {
            OnMenuHideClick();
            triggerHideShowButton = false;
        }
    
	}
	
	// Update is called once per frame
	void Update () {
        if (triggerHideHideButton || triggerHideShowButton)
        {
            if (triggerHideHideButton) {
                triggerHideHideButton = false;
                ShowHideMenu(true);
            }
            if (triggerHideShowButton) {
                triggerHideShowButton = false;
                ShowHideMenu(false);
            }
        }
   }



    private void ShowHideMenu(bool v)
    {
        if (!v) { 
            menuHidden = false;
            menuButtonShow.GetComponent<Button>().enabled = false;
            menuButtonShow.transform.localScale = new Vector3(0, 0, 0);
            menuButtonHide.enabled = true;
            menuButtonHide.transform.localScale = new Vector3(1, 1, 1);
            //(menuPanel as GameObject).GetComponent<Image>().enabled = true;
            (menuPanel as GameObject).SetActive(true);
        }
        else
        {
            menuHidden = true;
            menuButtonShow.GetComponent<Button>().enabled = true;
            menuButtonShow.transform.localScale = new Vector3(1, 1, 1);
            menuButtonHide.enabled = false;
            menuButtonHide.transform.localScale = new Vector3(0, 0, 0);
            //(menuPanel as GameObject).GetComponent<Image>().enabled = false;
            (menuPanel as GameObject).SetActive(false);
        }
    }

    public void OnMenuHideClick()
    {
        ShowHideMenu(true);
        triggerHideHideButton = true;
        //Debug.Log("OnMenuHideClick ");
    }
    public void OnMenuShowClick()
    {
        ShowHideMenu(true);
        triggerHideShowButton = true;
        //Debug.Log("OnMenuShowClick ");
    }

    public void OnMenuButton1Click()
    {
        Debug.Log("OnMenuButton1Click but nothing in here yet!");
    }
    public void OnMenuButton2Click()
    {
        Debug.Log("OnMenuButton2Click but nothing in here yet!");
    }
    public void OnMenuButton3Click()
    {
        Debug.Log("OnMenuButton3Click but nothing in here yet!");
    }
    public void OnMenuButton4Click()
    {
        Debug.Log("OnMenuButton4Click but nothing in here yet!");
    }
    public void OnMenuButton5Click()
    {
        Debug.Log("OnMenuButton5Click but nothing in here yet!");
    }

}
