/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  net.minecraft.class_2487
 *  net.minecraft.class_2520
 */
package meteordevelopment.meteorclient.settings;

import java.util.function.Consumer;
import meteordevelopment.meteorclient.gui.GuiTheme;
import meteordevelopment.meteorclient.gui.WidgetScreen;
import meteordevelopment.meteorclient.settings.IGeneric;
import meteordevelopment.meteorclient.settings.IVisible;
import meteordevelopment.meteorclient.settings.Setting;
import net.minecraft.class_2487;
import net.minecraft.class_2520;

public class GenericSetting<T extends IGeneric<T>>
extends Setting<T> {
    public GenericSetting(String name, String description, T defaultValue, Consumer<T> onChanged, Consumer<Setting<T>> onModuleActivated, IVisible visible) {
        super(name, description, defaultValue, onChanged, onModuleActivated, visible);
    }

    public WidgetScreen createScreen(GuiTheme theme) {
        return ((IGeneric)this.get()).createScreen(theme, this);
    }

    @Override
    public void resetImpl() {
        if (this.value == null) {
            this.value = ((IGeneric)this.defaultValue).copy();
        }
        ((IGeneric)this.value).set((IGeneric)this.defaultValue);
    }

    @Override
    protected T parseImpl(String str) {
        return (T)((IGeneric)((IGeneric)this.defaultValue).copy());
    }

    @Override
    protected boolean isValueValid(T value) {
        return true;
    }

    @Override
    public class_2487 save(class_2487 tag) {
        tag.method_10566("value", (class_2520)((IGeneric)this.get()).toTag());
        return tag;
    }

    @Override
    public T load(class_2487 tag) {
        ((IGeneric)this.get()).fromTag(tag.method_68568("value"));
        return (T)((IGeneric)this.get());
    }

    public static class Builder<T extends IGeneric<T>>
    extends Setting.SettingBuilder<Builder<T>, T, GenericSetting<T>> {
        public Builder() {
            super(null);
        }

        @Override
        public GenericSetting<T> build() {
            return new GenericSetting<IGeneric>(this.name, this.description, (IGeneric)this.defaultValue, this.onChanged, this.onModuleActivated, this.visible);
        }
    }
}

