using GadgetCore.API;
using GadgetCore.API.ConfigMenu;
using ScrapYard.API;
using UnityEngine;

namespace AncientReassembler
{
  [Gadget("AncientReassembler", LoadAfter: new string[] { "ScrapYard" }, Dependencies: new string[] { "ScrapYard" })]
  public class AncientReassembler : Gadget<AncientReassembler>
  {
    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; }
    protected override void LoadConfig() { Config.Reset(); Config.Save(); }

    public override string GetModDescription()
    {
      return "A mod that adds an Ancient Reassembler which can be used to upgrade items to a higher rarity.";
    }

    protected override void Initialize()
    {
      Logger.Log("Ancient Reassembler v" + Info.Mod.Version);
      Core.logger = Logger;

      var tile = ItemUtil.CreatePlacableItem("cAncientReassembler.png", "iAncientReassembler.png", "Ancient Reassembler");
      Core.itemAncientReassemblerId = tile.Item.GetID();

      Core.npcID = tile.GetID();

      var asset = GadgetCoreAPI.LoadAssetBundle("menuancientreassembler");

      var menuAncient = UnityEngine.Object.Instantiate((GameObject)asset.LoadAsset("assets/resources/menuancientreassembler.prefab"));
      menuAncient.transform.localPosition = new Vector3(7.75f, 0, -2);

      menuAncient.transform.GetChild(5).GetChild(0).gameObject.AddComponent<CraftButtonScript>();

      menuAncient.AddComponent<MenuOpenCloseEventScript>();

      Core.menu = new MenuInfo(MenuType.SIMPLE, menuAncient, tile);
      Core.menu.Register("Ancient Reassembler");

      ShopPlatform.DefaultObjects.AddShopPlatformEntry(new ShopPlatformEntry(Core.itemAncientReassemblerId, 2, 1, ItemRegistry.GetItemIDByRegistryName("ScrapYard:Scrap Trophy")));
    }
  }
}
