package de.winniepat.citrus.mixins;

import de.winniepat.citrus.Client;
import de.winniepat.citrus.beta.BetaKeyScreen;
import de.winniepat.citrus.gui.MainMenuScreen;
import icyllis.modernui.mc.MuiModApi;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.TitleScreen;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(TitleScreen.class)
public abstract class TitleScreenMixin {
    @Inject(method = "init", at = @At("HEAD"), cancellable = true)
    private void onInit(CallbackInfo ci) {
        MinecraftClient client = MinecraftClient.getInstance();

        if (!Client.betaFeaturesEnabled) {
            client.setScreen(MuiModApi.get().createScreen(new MainMenuScreen(), null, null));
            ci.cancel();
            return;
        }

        if (!Client.getBetaManager().isVerified()) {
            if ("WinniePat".equals(client.getSession().getUsername())) {
                Client.logger.info("Welcome back! You have bypass from the Beta Restriction :)");
            } else {
                client.setScreen(new BetaKeyScreen());
                ci.cancel();
                return;
            }
        }

        client.setScreen(MuiModApi.get().createScreen(new MainMenuScreen(), null, null));
        ci.cancel();
    }
}
