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

public class ModeController : MonoBehaviour
{
    //public enum Mode { Player, Editor};
    //public Mode mode = Mode.Player;
    public GameObject Player;
    public GameObject Locations;
    public GameObject Editor;
    public GameObject EditorTools;
    public GameObject Plane;
    public GameObject Grid;
    public GameObject LineX;
    public GameObject LineY;
    public GameObject Markers;
    public GameObject Beacons;
    public GameObject Walls;

    // Editor
    //Client client = new Client();
    PlayerController player;

    public bool editor = false;
    Button button;

    // Start is called before the first frame update
    void Start()
    {
        player = GameObject.Find("Player").GetComponent<PlayerController>();
        button = gameObject.GetComponent<Button>();
        button.onClick.AddListener(() => {
            Switch();
        });
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    public void Switch()
    {
        editor = !editor;
        transform.GetChild(0).gameObject.SetActive(!editor);
        transform.GetChild(1).gameObject.SetActive(editor);

        if (editor)
        {
            player.StopProgress();
            EditorMode();
        }
        else PlayerMode();
    }

    void PlayerMode()
    {
        Player.SetActive(true);
        Locations.SetActive(true);
        Markers.SetActive(true);
        Beacons.SetActive(true);
        Editor.SetActive(false);
        EditorTools.SetActive(false);
        Plane.SetActive(false);
        Grid.SetActive(false);
        Walls.SetActive(false);

        Destroy(GameObject.Find("SizeX"));
        Destroy(GameObject.Find("SizeY"));
        //PlayerController.markers = new List<Marker>();
        //client.SendGetUsers((uint)PlayerController.active_company + 1);

        //PlayerController.Beacons = new List<Beacon>(); 
        //client.BeaconsRequest((uint)PlayerController.locations[DropdownLocation.value].id);
    }

    void EditorMode()
    {
        Player.SetActive(false);
        Locations.SetActive(false);
        Markers.SetActive(false);
        Beacons.SetActive(false);
        Editor.SetActive(true);
        EditorTools.SetActive(true); 
        Plane.SetActive(true);
        Grid.SetActive(true);
        Walls.SetActive(true);

        //foreach (var m in PlayerController.markers)
        //{
        //    Destroy(m.marker.gameObject);
        //    Destroy(m.marker_line.gameObject);
        //    Destroy(m.toggle.gameObject);
        //}
        //PlayerController.markers.Clear();

        //foreach (var b in PlayerController.Beacons)
        //{
        //    Destroy(b.beacon);
        //    Destroy(b.button);
        //}
        //PlayerController.Beacons.Clear();

    }
}
