package jesse.keeblarcraft.GuiMgr.ShopKeeper;

import jesse.keeblarcraft.Utils.CustomSlot;

import java.util.HashMap;
import java.util.Map;

// Until I find the will and way to mixin slots to be able to be removed (i.e: not backed by an Inventory) I am patching
// slots in its own registration class (like ShopKeeperSlots). The time to do the mixin stuff far exceeds what is worth
// it for the time being.
public class ShopKeeperSlots {
    // Key = The GUI menu the slot belongs to. Helpful in parsing
    // Value = Map Key = Name of slot; Value = Slot itself. Name of slot is helpful for parsing if set
    private final Map<String, HashMap<String, CustomSlot>> shopKeeperSlots = new HashMap<>();

    public ShopKeeperSlots() {}

    public void AddSlot(String menuName, String slotName, CustomSlot newSlot) {
        if (!shopKeeperSlots.containsKey(slotName)) {
            shopKeeperSlots.put(menuName, new HashMap<>());
            shopKeeperSlots.get(menuName).put(slotName, newSlot);
        } else {
            shopKeeperSlots.get(menuName).put(slotName, newSlot);
        }
    }

    public HashMap<String, CustomSlot> GetSlotsByMenu(String menu) {
        return this.shopKeeperSlots.get(menu);
    }

    public void HideSlot(String menuName, String slotName) {
        for (Map.Entry<String, HashMap<String, CustomSlot>> entry : shopKeeperSlots.entrySet()) {
            if (entry.getKey().equals(menuName)) {
                for (Map.Entry<String, CustomSlot> menuSlots : entry.getValue().entrySet()) {
                    if (menuSlots.getKey().equals(slotName)) {
                        menuSlots.getValue().setEnabled(false);
                    }
                }
                break;
            }
        }
    }

    public void ShowSlot(String menuName, String slotName) {
        for (Map.Entry<String, HashMap<String, CustomSlot>> entry : shopKeeperSlots.entrySet()) {
//            System.out.println("Menu name: " + entry.getKey());
            if (entry.getKey().equals(menuName)) {
                for (Map.Entry<String, CustomSlot> menuSlots : entry.getValue().entrySet()) {
//                    System.out.println("Slot name: " + menuSlots.getKey());
                    if (menuSlots.getKey().equals(slotName)) {
                        menuSlots.getValue().setEnabled(true);
                    }
                }
                break;
            }
        }
    }
}
