using System;
using EscapeRoomEngine.Engine.Runtime;
using EscapeRoomEngine.Engine.Runtime.Measurements;
using EscapeRoomEngine.Engine.Runtime.Modules;
using EscapeRoomEngine.Engine.Runtime.Modules.State;
using EscapeRoomEngine.VR.Runtime;
using NaughtyAttributes;
using TMPro;
using UnityEngine;

namespace Station46.Modules.End_Terminal.Scripts
{
    public class EndTerminal : ModuleState
    {
        [BoxGroup("Internal")] [SerializeField] private TMP_Text text;
        [BoxGroup("Internal")] [SerializeField] private Transform rotation;

        public int BeaconsActivated
        {
            set
            {
                var currentText = text.text;
                currentText = value == 1
                    ? currentText.Replace("beacons", "beacon")
                    : currentText.Replace("beacon", "beacons");
                text.text = value + currentText[currentText.IndexOf(' ')..];
            }
        }

        private void Start()
        {
            BeaconsActivated = Measure.PuzzlesSolved;
        }

        private void Update()
        {
            var lookAt =
                Quaternion.LookRotation(Player.Instance.camera.transform.position - rotation.transform.position, Vector3.up);
            rotation.eulerAngles = new Vector3(0, lookAt.eulerAngles.y, 0);
        }

        public override void SetModule(Module module) {}
    }
}