package com.yuyu.srdisassemble.disassemeble;

import com.germ.germplugin.GermPlugin;
import com.germ.germplugin.api.dynamic.gui.GermGuiScreen;
import com.germ.germplugin.api.dynamic.gui.GuiManager;
import com.sakurarealm.sritem.germ.GermGuiService;
import com.yuyu.srdisassemble.SrDisassemble;
import lombok.Getter;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;

import java.io.File;
import java.util.List;

/**
 * @author 峰。
 * @version 1.0
 * @project SrDisassemble
 * @date 2024/6/11 16:42:02
 * @description
 */
public class DisassembleManager {
    @Getter
    private final static DisassembleManager instance = new DisassembleManager();//用于获取实例

    public DisassembleManager() {
    }

    public static ConfigurationSection getGermGui(String directoryPath, String guiName) {
        if (directoryPath != null && !directoryPath.startsWith(File.separator))
            directoryPath = File.separator + directoryPath;

        return YamlConfiguration.loadConfiguration(
                new File(GermGuiService.germPluginFilePath.getAbsolutePath()
                        + File.separator + "gui" + directoryPath + File.separator
                        + guiName + ".yml")
        ).getConfigurationSection(guiName);
    }

    //获取分解gui的背包
    public static ConfigurationSection getDisassemblePlayerInventory() {
        return DisassembleManager.getGermGui( "disassemble","player_inventory-disassemble");
    }

    //获取分解gui
    public static ConfigurationSection getDisassembleGui() {
        return DisassembleManager.getGermGui( "disassemble","disassemble");
    }


    public static ConfigurationSection getTemporarilyBox(){
        return DisassembleManager.getGermGui( "disassemble","TemporarilyBox");
    }

    //用于打开gui
    public void open(Player player) {

        if (TemporarilyBox.isHasGui(player.getName(), "disassemble")){
            SassembleGuiService germGuiScreen = (SassembleGuiService) TemporarilyBox.getGermGuiScreen(player.getName(), "disassemble");
            GermGuiScreen packscreen = GermGuiScreen.getGermGuiScreen("player_inventory-disassemble", this.getDisassemblePlayerInventory());
            if (germGuiScreen != null) {
                germGuiScreen.openGui(player);
                packscreen.openChildGui(player);
                return;
            }
        }


        //分解gui
            SassembleGuiService sassembleGuiService = new SassembleGuiService(getDisassembleGui(), "disassemble", player);

            GermGuiScreen packscreen = GermGuiScreen.getGermGuiScreen("player_inventory-disassemble", this.getDisassemblePlayerInventory());

        sassembleGuiService.openGui(player);
        packscreen.openChildGui(player);
    }

    /**
     * 用于打开回炉gui
     * @param player
     */
    public void openMeltAgain(Player player) {

    }

    /**
     * 用于打开维修gui
     * @param player
     */
    public void openRepair(Player player) {

    }
}
