package net.minecraft.client;

import net.minecraft.client.gui.components.Button;
import net.minecraft.client.resources.language.I18n;
import net.minecraft.client.gui.components.OptionButton;
import net.minecraft.client.gui.components.AbstractWidget;
import java.util.function.BiConsumer;
import java.util.function.Predicate;

public class BooleanOption extends Option {
    private final Predicate<Options> getter;
    private final BiConsumer<Options, Boolean> setter;
    
    public BooleanOption(final String string, final Predicate<Options> predicate, final BiConsumer<Options, Boolean> biConsumer) {
        super(string);
        this.getter = predicate;
        this.setter = biConsumer;
    }
    
    public void set(final Options dbr, final String string) {
        this.set(dbr, "true".equals(string));
    }
    
    public void toggle(final Options dbr) {
        this.set(dbr, !this.get(dbr));
        dbr.save();
    }
    
    private void set(final Options dbr, final boolean boolean2) {
        this.setter.accept(dbr, boolean2);
    }
    
    public boolean get(final Options dbr) {
        return this.getter.test(dbr);
    }
    
    @Override
    public AbstractWidget createButton(final Options dbr, final int integer2, final int integer3, final int integer4) {
        return new OptionButton(integer2, integer3, integer4, 20, this, this.getMessage(dbr), dcv -> {
            this.toggle(dbr);
            dcv.setMessage(this.getMessage(dbr));
        });
    }
    
    public String getMessage(final Options dbr) {
        return this.getCaption() + I18n.get(this.get(dbr) ? "options.on" : "options.off");
    }
}
