using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;

public class CanvasHandler : MonoBehaviour {

    public GameObject gameplayCanvas, spectatorCanvas, gameoverCanvas;

    public enum CanvasType {
        Gameplay = 0,
        Spectator,
        GameOver,
    }

    // Use this for initialization
    void Start () {
        bool joinAsSpectator = false;
        object prop;
        if (PhotonNetwork.IsConnected && PhotonNetwork.LocalPlayer.CustomProperties.TryGetValue("IsSpectator", out prop)) {
            joinAsSpectator = (bool)prop;
        }

        if(joinAsSpectator) {
            SetCanvasAsActive(CanvasType.Spectator);
            return;
        }
        SetCanvasAsActive(CanvasType.Gameplay);
    }

    public void SetCanvasAsActive(CanvasType type) {

        GameObject canvas = GetCanvasObjectFromType(type);
        gameplayCanvas.SetActive(canvas == gameplayCanvas);
        spectatorCanvas.SetActive(canvas == spectatorCanvas);
        gameoverCanvas.SetActive(canvas == gameoverCanvas);
    }

    GameObject GetCanvasObjectFromType(CanvasType type) {
        switch (type) {
            case CanvasType.Spectator:
                return spectatorCanvas;
            case CanvasType.GameOver:
                return gameoverCanvas;
            case CanvasType.Gameplay:
            default:
                return gameplayCanvas;
        }
    }
}
