/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  net.minecraft.class_10799
 *  net.minecraft.class_332
 */
package meteordevelopment.meteorclient.systems.hud.elements;

import java.awt.Color;
import meteordevelopment.meteorclient.systems.Systems;
import meteordevelopment.meteorclient.systems.hud.Hud;
import meteordevelopment.meteorclient.systems.hud.HudElement;
import meteordevelopment.meteorclient.systems.hud.HudElementInfo;
import meteordevelopment.meteorclient.systems.hud.HudRenderer;
import meteordevelopment.meteorclient.systems.notifications.MeteorNotification;
import meteordevelopment.meteorclient.systems.notifications.MeteorNotifications;
import meteordevelopment.meteorclient.utils.render.RenderUtils;
import net.minecraft.class_10799;
import net.minecraft.class_332;

public class NotificationsHud
extends HudElement {
    public static final HudElementInfo<NotificationsHud> INFO = new HudElementInfo<NotificationsHud>(Hud.GROUP, "notifications", "Displays custom Meteor notifications.", NotificationsHud::new);

    public NotificationsHud() {
        super(INFO);
    }

    @Override
    public void render(HudRenderer renderer) {
        MeteorNotifications system = Systems.get(MeteorNotifications.class);
        if (system == null) {
            return;
        }
        double x = this.box.getRenderX();
        double y = this.box.getRenderY();
        int i = 0;
        for (MeteorNotification n : system.getNotifications()) {
            this.renderNotification(renderer, n, x + n.xOffset, y + (double)(i * 40));
            ++i;
        }
        this.box.setSize(200.0, Math.max(32, i * 40));
    }

    private void renderNotification(HudRenderer renderer, MeteorNotification n, double x, double y) {
        int width = 180;
        int height = 32;
        class_332 context = renderer.drawContext;
        context.method_51448().pushMatrix();
        context.method_51448().translate((float)x, (float)y);
        Color bg = new Color(10, 10, 10, 200);
        RenderUtils.renderRoundedQuad(context.method_51448(), bg, 0.0, 0.0, width, height, 6.0, 20.0);
        Color border = new Color(n.accent.r, n.accent.g, n.accent.b, n.accent.a);
        RenderUtils.renderRoundedOutline(context, border, 0.0, 0.0, width, height, 6.0, 6.0, 6.0, 6.0, 1.0, 20.0);
        renderer.quad(4.0, 6.0, 3.0, height - 12, n.accent);
        renderer.text(n.title, 12.0, 6.0, meteordevelopment.meteorclient.utils.render.color.Color.WHITE, false);
        renderer.text(n.text, 12.0, 18.0, new meteordevelopment.meteorclient.utils.render.color.Color(200, 200, 200), false);
        if (n.icon != null) {
            context.method_25290(class_10799.field_56883, n.icon, width - 24, 8, 0.0f, 0.0f, 16, 16, 16, 16);
        }
        context.method_51448().popMatrix();
    }
}

