/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  meteordevelopment.orbit.EventHandler
 *  net.minecraft.class_2960
 */
package meteordevelopment.meteorclient.systems.notifications;

import java.util.ArrayList;
import java.util.List;
import meteordevelopment.meteorclient.MeteorClient;
import meteordevelopment.meteorclient.events.world.TickEvent;
import meteordevelopment.meteorclient.systems.System;
import meteordevelopment.meteorclient.systems.notifications.MeteorNotification;
import meteordevelopment.meteorclient.utils.render.color.Color;
import meteordevelopment.orbit.EventHandler;
import net.minecraft.class_2960;

public class MeteorNotifications
extends System<MeteorNotifications> {
    private final List<MeteorNotification> notifications = new ArrayList<MeteorNotification>();

    public MeteorNotifications() {
        super("notifications");
    }

    public void add(MeteorNotification notification) {
        this.notifications.add(notification);
    }

    public void add(String title, String text, class_2960 icon, Color accent) {
        this.add(new MeteorNotification(title, text, icon, accent));
    }

    public List<MeteorNotification> getNotifications() {
        return this.notifications;
    }

    @Override
    public void init() {
        MeteorClient.EVENT_BUS.subscribe((Object)this);
    }

    @EventHandler
    private void onTick(TickEvent.Post event) {
        long time = java.lang.System.currentTimeMillis();
        this.notifications.removeIf(n -> {
            if (n.start == -1L) {
                n.start = time;
            }
            return time - n.start > n.duration + 500L;
        });
        for (MeteorNotification n2 : this.notifications) {
            if (n2.start == -1L) continue;
            long elapsed = time - n2.start;
            if (elapsed < 500L) {
                n2.xOffset = 300.0 * (1.0 - (double)elapsed / 500.0);
                continue;
            }
            if (elapsed > n2.duration) {
                n2.xOffset = 300.0 * ((double)(elapsed - n2.duration) / 500.0);
                continue;
            }
            n2.xOffset = 0.0;
        }
    }
}

