/*
 *   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.bausystem.features.simulator.gui;

import de.steamwar.bausystem.features.simulator.SimulatorWatcher;
import de.steamwar.bausystem.features.simulator.data.Simulator;
import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui;
import de.steamwar.data.CMDs;
import de.steamwar.inventory.SWItem;
import org.bukkit.Material;
import org.bukkit.entity.Player;

import java.util.Arrays;

public class SimulatorSettingsGui extends SimulatorBaseGui {

    private final SimulatorBaseGui back;

    public SimulatorSettingsGui(Player player, Simulator simulator, SimulatorBaseGui back) {
        super(player, simulator, 5 * 9);
        this.back = back;
    }

    @Override
    public String title() {
        return simulator.getName() + " Settings";
    }

    @Override
    public void populate() {
        // Back Arrow
        inventory.setItem(0, new SWItem(Material.ARROW, "§eBack", clickType -> {
            back.open();
        }).setCustomModelData(CMDs.BACK));

        // Material Chooser
        inventory.setItem(4, simulator.toItem(player, clickType -> {
            new SimulatorMaterialGui(player, simulator, simulator::getMaterial, simulator::setMaterial, this).open();
        }));

        //AutoTrace
        inventory.setItem(19, new SWItem(simulator.isAutoTrace() ? Material.CHAIN_COMMAND_BLOCK : Material.COMMAND_BLOCK, "§eAutoTrace§8: " + (simulator.isAutoTrace() ? "§aOn" : "§cOff"), clickType -> {
            simulator.setAutoTrace(!simulator.isAutoTrace());
            SimulatorWatcher.update(simulator);
        }));
        inventory.setItem(20, new SWItem(simulator.isAutoTestblock() ? Material.END_STONE : Material.BARRIER, "§eTestblock§8: " + (simulator.isAutoTestblock() ? "§aOn" : "§cOff"), clickType -> {
            simulator.setAutoTestblock(!simulator.isAutoTestblock());
            SimulatorWatcher.update(simulator);
        }));

        //Pos X
        inventory.setItem(15, new SWItem(Material.LIME_DYE, "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
            simulator.move(clickType.isShiftClick() ? 5 : 1, 0, 0);
            SimulatorWatcher.update(simulator);
        }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
        inventory.setItem(24, new SWItem(Material.PAPER, "§eX", clickType -> {
        }));
        inventory.setItem(33, new SWItem(Material.RED_DYE, "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
            simulator.move(clickType.isShiftClick() ? -5 : -1, 0, 0);
            SimulatorWatcher.update(simulator);
        }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));

        //Pos Y
        inventory.setItem(16, new SWItem(Material.LIME_DYE, "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
            simulator.move(0, clickType.isShiftClick() ? 5 : 1, 0);
            SimulatorWatcher.update(simulator);
        }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
        inventory.setItem(25, new SWItem(Material.PAPER, "§eY", clickType -> {
        }));
        inventory.setItem(34, new SWItem(Material.RED_DYE, "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
            simulator.move(0, clickType.isShiftClick() ? -5 : -1, 0);
            SimulatorWatcher.update(simulator);
        }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));

        //Pos Z
        inventory.setItem(17, new SWItem(Material.LIME_DYE, "§e+1", Arrays.asList("§7Shift§8: §e+5"), false, clickType -> {
            simulator.move(0, 0, clickType.isShiftClick() ? 5 : 1);
            SimulatorWatcher.update(simulator);
        }).setCustomModelData(CMDs.Simulator.INCREMENT_OR_DISABLED));
        inventory.setItem(26, new SWItem(Material.PAPER, "§eZ", clickType -> {
        }));
        inventory.setItem(35, new SWItem(Material.RED_DYE, "§e-1", Arrays.asList("§7Shift§8: §e-5"), false, clickType -> {
            simulator.move(0, 0, clickType.isShiftClick() ? -5 : -1);
            SimulatorWatcher.update(simulator);
        }).setCustomModelData(CMDs.Simulator.DECREMENT_OR_DISABLED));
    }
}
