using GadgetCore.API;
using HarmonyLib;
using UnityEngine;

namespace StorageExpansion.Patches
{

  [HarmonyPatch(typeof(GameScript))]
  [HarmonyPatch("Storage")]
  [HarmonyGadget("StorageExpansion")]
  public static class Patch_GameScript_Storage
  {
    [HarmonyPostfix]
    public static void Postfix(GameScript __instance, int ___storageLevel, bool ___enteringCombatMode)
    {
      if (!___enteringCombatMode)
      {
        for (int i = 0; i < __instance.storageButton.Length; i++)
        {
          if (i <= ___storageLevel)
          {
            __instance.storageButton[i].GetComponent<Renderer>().enabled = false;
          }
          else
          {
            __instance.storageButton[i].GetComponent<Renderer>().enabled = true;
          }
        }
        int storageUpgradeCost = __instance.GetStorageUpgradeCost(___storageLevel);
        if (___storageLevel == __instance.storageButton.Length - 1)
        {
          __instance.txtStorageCost[0].text = "Max Lvl";
          __instance.txtStorageCost[1].text = "Max Lvl";
        }
        else
        {
          __instance.txtStorageCost[0].text = string.Empty + storageUpgradeCost;
          __instance.txtStorageCost[1].text = string.Empty + storageUpgradeCost;
        }
      }
    }
  }
}