package sh.grimmer.bettershulkers.integration;

import com.terraformersmc.modmenu.api.ConfigScreenFactory;
import com.terraformersmc.modmenu.api.ModMenuApi;
import net.fabricmc.loader.api.FabricLoader;
import sh.grimmer.bettershulkers.BetterShulkers;

public class ModMenuIntegration implements ModMenuApi {

    @Override
    public ConfigScreenFactory<?> getModConfigScreenFactory() {
        if (isClothConfigAvailable()) {
            return ClothConfigScreen::create;
        }
        return parent -> null;
    }

    private static boolean isClothConfigAvailable() {
        if (FabricLoader.getInstance().isModLoaded("cloth-config2")) {
            try {
                Class.forName("me.shedaniel.clothconfig2.api.ConfigBuilder");
                BetterShulkers.LOGGER.info("Cloth Config detected, config screen enabled");
                return true;
            } catch (Exception e) {
                BetterShulkers.LOGGER.warn("Failed to load Cloth Config", e);
            }
        }
        return false;
    }
}
