/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  it.unimi.dsi.fastutil.objects.Reference2IntArrayMap
 *  it.unimi.dsi.fastutil.objects.Reference2IntMap
 *  it.unimi.dsi.fastutil.objects.Reference2IntOpenHashMap
 *  net.minecraft.class_1291
 *  net.minecraft.class_2487
 *  net.minecraft.class_2520
 *  net.minecraft.class_2960
 *  net.minecraft.class_7923
 */
package meteordevelopment.meteorclient.settings;

import it.unimi.dsi.fastutil.objects.Reference2IntArrayMap;
import it.unimi.dsi.fastutil.objects.Reference2IntMap;
import it.unimi.dsi.fastutil.objects.Reference2IntOpenHashMap;
import java.util.function.Consumer;
import meteordevelopment.meteorclient.settings.IVisible;
import meteordevelopment.meteorclient.settings.Setting;
import net.minecraft.class_1291;
import net.minecraft.class_2487;
import net.minecraft.class_2520;
import net.minecraft.class_2960;
import net.minecraft.class_7923;

public class StatusEffectAmplifierMapSetting
extends Setting<Reference2IntMap<class_1291>> {
    public static final Reference2IntMap<class_1291> EMPTY_STATUS_EFFECT_MAP = StatusEffectAmplifierMapSetting.createStatusEffectMap();

    public StatusEffectAmplifierMapSetting(String name, String description, Reference2IntMap<class_1291> defaultValue, Consumer<Reference2IntMap<class_1291>> onChanged, Consumer<Setting<Reference2IntMap<class_1291>>> onModuleActivated, IVisible visible) {
        super(name, description, defaultValue, onChanged, onModuleActivated, visible);
    }

    @Override
    public void resetImpl() {
        this.value = new Reference2IntOpenHashMap((Reference2IntMap)this.defaultValue);
    }

    @Override
    protected Reference2IntMap<class_1291> parseImpl(String str) {
        String[] values = str.split(",");
        Reference2IntOpenHashMap effects = new Reference2IntOpenHashMap(EMPTY_STATUS_EFFECT_MAP);
        try {
            for (String value : values) {
                String[] split = value.split(" ");
                class_1291 effect = (class_1291)StatusEffectAmplifierMapSetting.parseId(class_7923.field_41174, split[0]);
                int level = Integer.parseInt(split[1]);
                effects.put((Object)effect, level);
            }
        }
        catch (Exception exception) {
            // empty catch block
        }
        return effects;
    }

    @Override
    protected boolean isValueValid(Reference2IntMap<class_1291> value) {
        return true;
    }

    @Override
    public class_2487 save(class_2487 tag) {
        class_2487 valueTag = new class_2487();
        for (class_1291 statusEffect : ((Reference2IntMap)this.get()).keySet()) {
            class_2960 id = class_7923.field_41174.method_10221((Object)statusEffect);
            if (id == null) continue;
            valueTag.method_10569(id.toString(), ((Reference2IntMap)this.get()).getInt((Object)statusEffect));
        }
        tag.method_10566("value", (class_2520)valueTag);
        return tag;
    }

    private static Reference2IntMap<class_1291> createStatusEffectMap() {
        Reference2IntArrayMap map = new Reference2IntArrayMap(class_7923.field_41174.method_10235().size());
        class_7923.field_41174.forEach(arg_0 -> StatusEffectAmplifierMapSetting.lambda$createStatusEffectMap$0((Reference2IntMap)map, arg_0));
        return map;
    }

    @Override
    public Reference2IntMap<class_1291> load(class_2487 tag) {
        ((Reference2IntMap)this.get()).clear();
        class_2487 valueTag = tag.method_68568("value");
        for (String key : valueTag.method_10541()) {
            class_1291 statusEffect = (class_1291)class_7923.field_41174.method_63535(class_2960.method_60654((String)key));
            if (statusEffect == null) continue;
            ((Reference2IntMap)this.get()).put((Object)statusEffect, valueTag.method_68083(key, 0));
        }
        return (Reference2IntMap)this.get();
    }

    private static /* synthetic */ void lambda$createStatusEffectMap$0(Reference2IntMap map, class_1291 potion) {
        map.put((Object)potion, 0);
    }

    public static class Builder
    extends Setting.SettingBuilder<Builder, Reference2IntMap<class_1291>, StatusEffectAmplifierMapSetting> {
        public Builder() {
            super(new Reference2IntOpenHashMap(0));
        }

        @Override
        public StatusEffectAmplifierMapSetting build() {
            return new StatusEffectAmplifierMapSetting(this.name, this.description, (Reference2IntMap<class_1291>)((Reference2IntMap)this.defaultValue), this.onChanged, this.onModuleActivated, this.visible);
        }
    }
}

