using UnityEngine;
using GadgetCore.API;
using UnityEngine.SceneManagement;
using GadgetCore.API.ConfigMenu;
using System;
using System.Collections.Generic;

namespace ShadowOne
{
  [Gadget("ShadowOne", RequiredOnClients: false)]
  public class ShadowOne : Gadget<ShadowOne>
  {
    public const string MOD_VERSION = "1.2"; // Set this to the version of your mod.
    public const string CONFIG_VERSION = "1.0"; // Increment this whenever you change your mod's config file.

    public override IGadgetConfigMenu GetConfigMenu() { return null; }

    public override string GetModDescription()
    {
      return "A mod that adds the missing shadow to the version number.";
    }

    protected override void Initialize()
    {
      Logger.Log("Shadow One v" + Info.Mod.Version);
      Core.logger = Logger;
      SceneManager.sceneLoaded += OnSceneLoaded;
      ChangeMenuText();
    }

    internal static void OnSceneLoaded(Scene scene, LoadSceneMode mode)
    {
      if (scene.buildIndex == 0)
      {
        ChangeMenuText();
      }
    }

    private static void ChangeMenuText()
    {
      try
      {
        var text = "v1.5.1";

        var textElement = GameObject.Find("MAIN").transform.Find("-").Find("txtALPHA").gameObject;
        var textElementShadow = textElement.transform.Find("txt0").gameObject;

        textElement.GetComponent<TextMesh>().text = text;
        textElementShadow.GetComponent<TextMesh>().text = text;
      }
      catch (Exception e) { Core.logger.Log(e); }
    }
  }
}
