using HarmonyLib;
using GadgetCore.API;
using UnityEngine;
using System.Collections;

namespace RecipeMenuCore.Patches
{
  [HarmonyPatch(typeof(GameScript))]
  [HarmonyPatch("RecipeUp")]
  [HarmonyGadget("RecipeMenuCore")]
  public static class Patch_GameScript_RecipeUp
  {
    [HarmonyPrefix]
    public static bool Prefix(GameScript __instance, int ___craftType, ref int ___curRecipePage)
    {
      int pages = 1;
      if (___craftType == 0)
        pages = 6 + Core.pageGearForgeInfoList.Count;
      else if (___craftType == 1)
        pages = 2 + Core.pageAlchemyStationInfoList.Count;
      else if (___craftType == 2)
        pages = 6 + Core.pageUltimateForgeInfoList.Count;
      else if (___craftType == MenuRegistry.Singleton["Gadget Core:Crafter Menu"].GetID())
        pages = Core.pageUniversalCrafterInfoList.Count;

      ___curRecipePage = (___curRecipePage + 1) % pages;
      __instance.RefreshRecipe();
      return false;
    }
  }
}
