package net.minecraft.client;

import net.minecraft.client.gui.components.Button;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
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 dmb, final String string) {
        this.set(dmb, "true".equals(string));
    }
    
    public void toggle(final Options dmb) {
        this.set(dmb, !this.get(dmb));
        dmb.save();
    }
    
    private void set(final Options dmb, final boolean boolean2) {
        this.setter.accept(dmb, boolean2);
    }
    
    public boolean get(final Options dmb) {
        return this.getter.test(dmb);
    }
    
    @Override
    public AbstractWidget createButton(final Options dmb, final int integer2, final int integer3, final int integer4) {
        return new OptionButton(integer2, integer3, integer4, 20, this, this.getMessage(dmb), dni -> {
            this.toggle(dmb);
            dni.setMessage(this.getMessage(dmb));
        });
    }
    
    public Component getMessage(final Options dmb) {
        return this.createCaption().append(CommonComponents.optionStatus(this.get(dmb)));
    }
}
