package rip.tilly.bedwars.menusystem.menu;

import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;
import rip.tilly.bedwars.BedWars;
import rip.tilly.bedwars.game.GameType;
import rip.tilly.bedwars.menusystem.Menu;
import rip.tilly.bedwars.menusystem.PlayerMenuUtil;
import rip.tilly.bedwars.utils.CC;
import rip.tilly.bedwars.utils.ItemBuilder;

import java.util.ArrayList;
import java.util.List;

public class PlayAGameMenu extends Menu {

    private BedWars main = BedWars.getInstance();

    private GameType gameType;

    public PlayAGameMenu(PlayerMenuUtil playerMenuUtil, GameType gameType) {
        super(playerMenuUtil);

        this.gameType = gameType;
    }

    @Override
    public String getMenuName() {
        return CC.translate("&eSelect a game to play...");
    }

    @Override
    public int getSlots() {
        return 27;
    }

    @Override
    public void handleMenu(InventoryClickEvent event) {
        Player player = (Player) event.getWhoClicked();

        if (event.getView().getTitle().equalsIgnoreCase(CC.translate("&eSelect a game to play..."))) {
            this.main.getQueueManager().addPlayerToQueue(player, BedWars.getInstance().getPlayerDataManager().getPlayerData(player.getUniqueId()), this.gameType);

            player.closeInventory();
        }
    }

    @Override
    public void setMenuItems() {
        List<String> bedWars1v1Lore = new ArrayList<String>();
        bedWars1v1Lore.add(CC.translate(""));
        bedWars1v1Lore.add(CC.translate("&9You have to start somewhere,"));
        bedWars1v1Lore.add(CC.translate("&9so why not start here?"));
        bedWars1v1Lore.add(CC.translate(""));
        bedWars1v1Lore.add(CC.translate("&fPlaying: &b" + this.main.getGameManager().getPlayingByType(this.gameType)));

        ItemStack bedWars1v1ItemStack = new ItemBuilder(Material.WOOD_SWORD).name(CC.translate("&dBedWars 1v1")).lore(bedWars1v1Lore).build();

        List<String> bedWars2v2Lore = new ArrayList<String>();
        bedWars2v2Lore.add(CC.translate(""));
        bedWars2v2Lore.add(CC.translate("&9Adapt, overcome, and conquer,"));
        bedWars2v2Lore.add(CC.translate("&9you are advancing rapidly"));
        bedWars2v2Lore.add(CC.translate(""));
        bedWars2v2Lore.add(CC.translate("&fPlaying: &b" + this.main.getGameManager().getPlayingByType(this.gameType)));

        ItemStack bedWars2v2ItemStack = new ItemBuilder(Material.STONE_SWORD).name(CC.translate("&dBedWars 2v2")).lore(bedWars2v2Lore).build();

        List<String> bedWars3v3Lore = new ArrayList<String>();
        bedWars3v3Lore.add(CC.translate(""));
        bedWars3v3Lore.add(CC.translate("&9How crazy is this,"));
        bedWars3v3Lore.add(CC.translate("&9it seems like it was just yesterday"));
        bedWars3v3Lore.add(CC.translate("&9since you started"));
        bedWars3v3Lore.add(CC.translate(""));
        bedWars3v3Lore.add(CC.translate("&fPlaying: &b" + this.main.getGameManager().getPlayingByType(this.gameType)));


        ItemStack bedWars3v3ItemStack = new ItemBuilder(Material.IRON_SWORD).name(CC.translate("&dBedWars 3v3")).lore(bedWars3v3Lore).build();

        List<String> bedWars4v4Lore = new ArrayList<String>();
        bedWars4v4Lore.add(CC.translate(""));
        bedWars4v4Lore.add(CC.translate("&9You are now a master,"));
        bedWars4v4Lore.add(CC.translate("&9you can go up against"));
        bedWars4v4Lore.add(CC.translate("&9the undefeated PvP bot &7(Coming soon)"));
        bedWars4v4Lore.add(CC.translate(""));
        bedWars4v4Lore.add(CC.translate("&fPlaying: &b" + this.main.getGameManager().getPlayingByType(this.gameType)));

        ItemStack bedWars4v4ItemStack = new ItemBuilder(Material.DIAMOND_SWORD).name(CC.translate("&dBedWars 4v4")).lore(bedWars4v4Lore).build();

        this.inventory.setItem(10, bedWars1v1ItemStack);
        this.inventory.setItem(12, bedWars2v2ItemStack);
        this.inventory.setItem(14, bedWars3v3ItemStack);
        this.inventory.setItem(16, bedWars4v4ItemStack);

        this.setFillerGlass();
    }
}
