package eu.mhsl.minecraft.pixelblocks.listeners;

import eu.mhsl.minecraft.pixelblocks.Main;
import eu.mhsl.minecraft.pixelblocks.PixelBlockItem;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;

import java.util.List;
import java.util.logging.Level;

public class DiscoverRecipesListener implements Listener {
    @EventHandler
    public void shouldDiscover(InventoryClickEvent event) {
        ItemStack clickedItem = event.getCurrentItem();
        if(clickedItem == null) return;
        if(!(event.getWhoClicked() instanceof Player player)) return;
        if(!List.of(Material.HEART_OF_THE_SEA, Material.END_CRYSTAL).contains(clickedItem.getType())) return;
        if(player.hasDiscoveredRecipe(PixelBlockItem.recipeKey)) return;
        Main.logger().log(Level.INFO, String.format("%s unlocked the PixelBlock recipe!", player.getName()));
        player.discoverRecipe(PixelBlockItem.recipeKey);
    }
}
