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

namespace Assets.Scripts
{
    public class ButtonHandler : MonoBehaviour
    {
        UIHandler uihandler;
        Player player;
        AudioHandler audioHandler;

        private void Start()
        {
            uihandler = GameObject.Find("UIHandler").GetComponent<UIHandler>();
            player = GameObject.Find("Player").GetComponent<Player>();
            audioHandler = GameObject.Find("AudioHandler").GetComponent<AudioHandler>();
        }

        public void startGame()
        {
            audioHandler.playButtonClick();
            uihandler.openTutorial();
        }

        public void closeGame()
        {
            audioHandler.playButtonClick();
            #if UNITY_EDITOR
                UnityEditor.EditorApplication.isPlaying = false;
            #endif
            Application.Quit();
        }

        public void openOptions()
        {
            audioHandler.playButtonClick();
            uihandler.openOptions();
        }

        public void closeOptions()
        {
            audioHandler.loadAudioSettings();
            audioHandler.playButtonClick();
            uihandler.closeOptions();
        }

        public void openCreation()
        {
            audioHandler.playButtonClick();
            uihandler.openCharacterCreation();
        }

        public void closeCreation()
        {
            audioHandler.playButtonClick();
            uihandler.closeCharacterCreation();
        }

        public void exitToMenu()
        {
            audioHandler.playButtonClick();
            uihandler.openMainMenu();
        }

        public void closePauseMenu()
        {
            audioHandler.playButtonClick();
            uihandler.closePauseMenu();
        }

        public void upgradeStrength()
        {
            audioHandler.playButtonClick();
            player.upgradeStrength();
            EventSystem.current.SetSelectedGameObject(null);
        }

        public void upgradeDexterity()
        {
            audioHandler.playButtonClick();
            player.upgradeDexterity();
            EventSystem.current.SetSelectedGameObject(null);
        }

        public void upgradeIntelligence()
        {
            audioHandler.playButtonClick();
            player.upgradeIntelligence();
            EventSystem.current.SetSelectedGameObject(null);
        }

        public void upgradeHealth()
        {
            audioHandler.playButtonClick();
            player.upgradeHealth();
            EventSystem.current.SetSelectedGameObject(null);
        }

        public void upgradeSecondary()
        {
            audioHandler.playButtonClick();
            player.upgradeSecondary();
            EventSystem.current.SetSelectedGameObject(null);
        }

        public void saveOptions()
        {
            audioHandler.playButtonClick();
            uihandler.adaptScreen();
            audioHandler.saveAudioSettings();
        }

        public void closeTutorial()
        {
            audioHandler.playButtonClick();
            uihandler.startGame();
            EventSystem.current.SetSelectedGameObject(null);
        }
    }

}
