// Path: src/main/java/com/gmail/jannyboy11/customrecipes/gui/ListRecipesInventoryHolder.java
// public class ListRecipesInventoryHolder implements InventoryHolder {
// 	
// 	private static final int MAX_RECIPES_PER_PAGE = 9 * 5;
// 	
// 	private final List<ItemStack> recipeItems = new ArrayList<>();
// 	private final List<Inventory> pages = new ArrayList<>();
// 	private int pageNr = 0;
// 	
// 	public ListRecipesInventoryHolder(String type, Iterable<? extends ItemStack> items) {
// 		items.forEach(recipeItems::add);
// 		
// 		//fill page inventories
// 		int recipeIndex = 0;
// 		Inventory inventory = null;
// 		do {
// 			int inPageIndex = recipeIndex % MAX_RECIPES_PER_PAGE;
// 			if (inPageIndex == 0) {
// 				inventory = Bukkit.createInventory(this, 54, type + " recipes");
// 				pages.add(inventory);
// 			}
// 			
// 			inventory.setItem(inPageIndex, recipeItems.get(recipeIndex));
// 		} while (++recipeIndex < recipeItems.size());
// 		
// 		//add previous and next buttons where applicable
// 		for (int pageNr = 0; pageNr < pages.size(); pageNr++) {
// 			Inventory page = pages.get(pageNr);
// 			if (pageNr != 0) {
// 				page.setItem(45, ListRecipesListener.previousItem());
// 			}
// 			if (pageNr != pages.size() - 1) {
// 				page.setItem(53, ListRecipesListener.nextItem());
// 			}
// 		}
// 	}
// 
// 	@Override
// 	public Inventory getInventory() {
// 		return pages.get(pageNr);
// 	}
// 
// 	public void nextPage() {
// 		this.pageNr = Math.min(pageNr + 1, pages.size());
// 	}
// 
// 	public void previousPage() {
// 		this.pageNr = Math.max(pageNr - 1, 0);
// 	}
// 
// }


import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.Recipe;
import com.gmail.jannyboy11.customrecipes.gui.ListRecipesInventoryHolder;
		this.recipeToCommandSenderDiplayMap = recipeToCommandSenderDiplayMap;
	}
	
	@Override
	public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
		if (args.length == 0) return false;
		
		String recipeType = args[0];
		List<? extends Recipe> recipes = recipesByTypeMapper.apply(recipeType);
		
		if (recipes == null) {
			sender.sendMessage(ChatColor.RED + "Unknown recipe type: " + recipeType);
			return true;
		} else if (recipes.isEmpty()) {
			sender.sendMessage(ChatColor.RED + "No recipes found for type: " + recipeType);
			return true;
		}
		
		return sender instanceof Player ? listPlayer((Player) sender, recipeType, recipes) : listSender(sender, recipeType, recipes);
	}
	
	
	private boolean listPlayer(Player player, String recipeType, List<? extends Recipe> recipes) {
		Function<? super Recipe, ? extends ItemStack> representationFunction = recipeToItemMap.get(recipeType);
		if (representationFunction == null) {
			player.sendMessage(ChatColor.RED + "No representation function found for this type of recipe. Trying chat messages..");
			return listSender(player, recipeType, recipes);
		}
		
		List<? extends ItemStack> representations = recipes.stream().map(representationFunction).collect(Collectors.toList());
// Path: src/main/java/com/gmail/jannyboy11/customrecipes/gui/ListRecipesInventoryHolder.java
// public class ListRecipesInventoryHolder implements InventoryHolder {
// 	
// 	private static final int MAX_RECIPES_PER_PAGE = 9 * 5;
// 	
// 	private final List<ItemStack> recipeItems = new ArrayList<>();
// 	private final List<Inventory> pages = new ArrayList<>();
// 	private int pageNr = 0;
// 	
// 	public ListRecipesInventoryHolder(String type, Iterable<? extends ItemStack> items) {
// 		items.forEach(recipeItems::add);
// 		
// 		//fill page inventories
// 		int recipeIndex = 0;
// 		Inventory inventory = null;
// 		do {
// 			int inPageIndex = recipeIndex % MAX_RECIPES_PER_PAGE;
// 			if (inPageIndex == 0) {
// 				inventory = Bukkit.createInventory(this, 54, type + " recipes");
// 				pages.add(inventory);
// 			}
// 			
// 			inventory.setItem(inPageIndex, recipeItems.get(recipeIndex));
// 		} while (++recipeIndex < recipeItems.size());
// 		
// 		//add previous and next buttons where applicable
// 		for (int pageNr = 0; pageNr < pages.size(); pageNr++) {
// 			Inventory page = pages.get(pageNr);
// 			if (pageNr != 0) {
// 				page.setItem(45, ListRecipesListener.previousItem());
// 			}
// 			if (pageNr != pages.size() - 1) {
// 				page.setItem(53, ListRecipesListener.nextItem());
// 			}
// 		}
// 	}
// 
// 	@Override
// 	public Inventory getInventory() {
// 		return pages.get(pageNr);
// 	}
// 
// 	public void nextPage() {
// 		this.pageNr = Math.min(pageNr + 1, pages.size());
// 	}
// 
// 	public void previousPage() {
// 		this.pageNr = Math.max(pageNr - 1, 0);
// 	}
// 
// }


// Path: src/main/java/com/gmail/jannyboy11/customrecipes/commands/ListRecipesCommandExecutor.java
import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.Recipe;
import com.gmail.jannyboy11.customrecipes.gui.ListRecipesInventoryHolder;

		this.recipeToCommandSenderDiplayMap = recipeToCommandSenderDiplayMap;
	}
	
	@Override
	public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
		if (args.length == 0) return false;
		
		String recipeType = args[0];
		List<? extends Recipe> recipes = recipesByTypeMapper.apply(recipeType);
		
		if (recipes == null) {
			sender.sendMessage(ChatColor.RED + "Unknown recipe type: " + recipeType);
			return true;
		} else if (recipes.isEmpty()) {
			sender.sendMessage(ChatColor.RED + "No recipes found for type: " + recipeType);
			return true;
		}
		
		return sender instanceof Player ? listPlayer((Player) sender, recipeType, recipes) : listSender(sender, recipeType, recipes);
	}
	
	
	private boolean listPlayer(Player player, String recipeType, List<? extends Recipe> recipes) {
		Function<? super Recipe, ? extends ItemStack> representationFunction = recipeToItemMap.get(recipeType);
		if (representationFunction == null) {
			player.sendMessage(ChatColor.RED + "No representation function found for this type of recipe. Trying chat messages..");
			return listSender(player, recipeType, recipes);
		}
		
		List<? extends ItemStack> representations = recipes.stream().map(representationFunction).collect(Collectors.toList());
		player.openInventory(new ListRecipesInventoryHolder(recipeType, representations).getInventory());