package xyz.illuc.neuralgiacore.moodles;


import net.adinvas.prototype_pain.PlayerHealthProvider;
import net.adinvas.prototype_pain.client.moodles.AbstractMoodleVisual;
import net.adinvas.prototype_pain.client.moodles.MoodleStatus;
import net.minecraft.ChatFormatting;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Player;
import xyz.illuc.neuralgiacore.interfaces.IPlayerHealthDataAccessor;

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

public class SepsisMoodle extends AbstractMoodleVisual {
    public SepsisMoodle() {
    }
    //noinspection ConstantConditions
    @Override
    public MoodleStatus calculateStatus(Player player) {
        if (!player.isLocalPlayer()) return MoodleStatus.NONE;

        return player.getCapability(PlayerHealthProvider.PLAYER_HEALTH_DATA).map(ph -> {
            IPlayerHealthDataAccessor accessor = (IPlayerHealthDataAccessor) ph;
            float sepsis = accessor.getSepsis();


            if (sepsis > 80F) {
                return MoodleStatus.CRITICAL;
            } else if (sepsis > 50F) {
                return MoodleStatus.HEAVY;
            } else if (sepsis > 10F){
                return MoodleStatus.NORMAL;
            } else {
                return MoodleStatus.NONE;
            }
        }).orElse(MoodleStatus.NONE);
    }

    @Override
    public ResourceLocation renderIcon(GuiGraphics ms, float partialTicks, int x, int y) {
        ResourceLocation tex = new ResourceLocation("neuralgia", "textures/moodles/sepsis.png");
        ms.blit(tex, x, y, 0.0F, 0.0F, 16, 16, 16, 16);
        return tex;
    }

    @Override
    public List<Component> getTooltip(Player player) {
        List<Component> componentList = new ArrayList();
        switch (this.getMoodleStatus()) {
            case NORMAL:
                componentList.add(Component.translatable("neuralgia.gui.moodle.sepsis.title1").withStyle(ChatFormatting.YELLOW));
                componentList.add(Component.translatable("neuralgia.gui.moodle.sepsis.description1").withStyle(ChatFormatting.GRAY));
                break;
            case HEAVY:
                componentList.add(Component.translatable("neuralgia.gui.moodle.sepsis.title2").withStyle(ChatFormatting.GOLD));
                componentList.add(Component.translatable("neuralgia.gui.moodle.sepsis.description2").withStyle(ChatFormatting.GRAY));
                break;
            case CRITICAL:
                componentList.add(Component.translatable("neuralgia.gui.moodle.sepsis.title3").withStyle(ChatFormatting.RED));
                componentList.add(Component.translatable("neuralgia.gui.moodle.sepsis.description3").withStyle(ChatFormatting.GRAY));
        }

        return componentList;
    }

}
