/*
 *   This file is a part of the SteamWar software.
 *
 *   Copyright (C) 2025 SteamWar.de-Serverteam
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU Affero General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *   GNU Affero General Public License for more details.
 *
 *   You should have received a copy of the GNU Affero General Public License
 *   along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

package de.steamwar.inventory;

import de.steamwar.core.Core;
import lombok.experimental.UtilityClass;
import org.bukkit.Material;
import org.bukkit.entity.Player;

import java.util.LinkedList;
import java.util.List;
import java.util.function.Consumer;

@UtilityClass
public class UtilGui {

    public static void openMaterialSelector(Player player, Consumer<Material> callback) {
        openMaterialSelector(player, Core.MESSAGE.parse("MATERIAL_SELECTOR_TITLE", player), callback);
    }

    public static void openMaterialSelector(Player player, String title, Consumer<Material> callback) {
        List<SWListInv.SWListEntry<Material>> materials = new LinkedList<>();
        for (Material material : Material.values()) {
            if (material.name().startsWith(Material.LEGACY_PREFIX) || !material.isItem()) continue;
            SWItem item = new SWItem(material, "§7" + material.name());
            if (item.getItemMeta() != null && material.isItem()) {
                materials.add(new SWListInv.SWListEntry<>(item, material));
            }
        }

        SWListInv<Material> swListInv = new SWListInv<>(player, title, materials, (clickType3, material) -> callback.accept(material));
        swListInv.open();
    }
}
