package net.minecraft.client.gui.components;

import net.minecraft.client.gui.components.events.GuiEventListener;
import com.mojang.blaze3d.vertex.PoseStack;
import com.google.common.collect.ImmutableList;
import net.minecraft.client.Options;
import java.util.List;
import java.util.Iterator;
import java.util.Optional;
import javax.annotation.Nullable;
import net.minecraft.client.Option;
import net.minecraft.client.Minecraft;

public class OptionsList extends ContainerObjectSelectionList<Entry> {
    public OptionsList(final Minecraft dlx, final int integer2, final int integer3, final int integer4, final int integer5, final int integer6) {
        super(dlx, integer2, integer3, integer4, integer5, integer6);
        this.centerListVertically = false;
    }
    
    public int addBig(final Option dma) {
        return this.addEntry(Entry.big(this.minecraft.options, this.width, dma));
    }
    
    public void addSmall(final Option dma1, @Nullable final Option dma2) {
        this.addEntry(Entry.small(this.minecraft.options, this.width, dma1, dma2));
    }
    
    public void addSmall(final Option[] arr) {
        for (int integer3 = 0; integer3 < arr.length; integer3 += 2) {
            this.addSmall(arr[integer3], (integer3 < arr.length - 1) ? arr[integer3 + 1] : null);
        }
    }
    
    @Override
    public int getRowWidth() {
        return 400;
    }
    
    @Override
    protected int getScrollbarPosition() {
        return super.getScrollbarPosition() + 32;
    }
    
    public Optional<AbstractWidget> getMouseOver(final double double1, final double double2) {
        for (final Entry a7 : this.children()) {
            for (final AbstractWidget dng9 : a7.children) {
                if (dng9.isMouseOver(double1, double2)) {
                    return Optional.<AbstractWidget>of(dng9);
                }
            }
        }
        return Optional.<AbstractWidget>empty();
    }
    
    public static class Entry extends ContainerObjectSelectionList.Entry<Entry> {
        private final List<AbstractWidget> children;
        
        private Entry(final List<AbstractWidget> list) {
            this.children = list;
        }
        
        public static Entry big(final Options dmb, final int integer, final Option dma) {
            return new Entry(ImmutableList.<AbstractWidget>of(dma.createButton(dmb, integer / 2 - 155, 0, 310)));
        }
        
        public static Entry small(final Options dmb, final int integer, final Option dma3, @Nullable final Option dma4) {
            final AbstractWidget dng5 = dma3.createButton(dmb, integer / 2 - 155, 0, 150);
            if (dma4 == null) {
                return new Entry(ImmutableList.<AbstractWidget>of(dng5));
            }
            return new Entry(ImmutableList.<AbstractWidget>of(dng5, dma4.createButton(dmb, integer / 2 - 155 + 160, 0, 150)));
        }
        
        @Override
        public void render(final PoseStack dhl, final int integer2, final int integer3, final int integer4, final int integer5, final int integer6, final int integer7, final int integer8, final boolean boolean9, final float float10) {
            this.children.forEach(dng -> {
                dng.y = integer3;
                dng.render(dhl, integer7, integer8, float10);
            });
        }
        
        @Override
        public List<? extends GuiEventListener> children() {
            return this.children;
        }
    }
}
