package com.loganmagnan.eventcore.menusystem;

import com.loganmagnan.eventcore.utils.ColorUtils;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

public abstract class PaginatedMenu extends Menu {

    protected int page = 0;
    protected int maxItemsPerPage = 18;
    protected int index = 0;

    public PaginatedMenu(PlayerMenuUtil playerMenuUtil) {
        super(playerMenuUtil);
    }

    public void addMenuBorder() {
        ItemStack previousPageItemStack = new ItemStack(Material.OAK_BUTTON, 1);

        ItemMeta previousPageItemMeta = previousPageItemStack.getItemMeta();
        previousPageItemMeta.setDisplayName(ColorUtils.getMessageType("&ePrevious Page"));

        previousPageItemStack.setItemMeta(previousPageItemMeta);

        this.inventory.setItem(18, previousPageItemStack);
        this.inventory.setItem(22, makeItemStack(Material.BARRIER, ChatColor.DARK_RED + "Close", new String[]{""}));

        ItemStack nextPageItemStack = new ItemStack(Material.STONE_BUTTON, 1);

        ItemMeta nextPageItemMeta = nextPageItemStack.getItemMeta();
        nextPageItemMeta.setDisplayName(ColorUtils.getMessageType("&eNext Page"));

        nextPageItemStack.setItemMeta(nextPageItemMeta);

        this.inventory.setItem(26, nextPageItemStack);

        for (int i = 18; i < 26; i++) {
            if (this.inventory.getItem(i) == null) {
                this.inventory.setItem(i, this.FILLER_GLASS);
            }
        }
    }

    public int getMaxItemsPerPage() {
        return maxItemsPerPage;
    }
}