/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  net.minecraft.class_1792
 *  net.minecraft.class_1802
 *  net.minecraft.class_7923
 *  org.apache.commons.lang3.Strings
 */
package meteordevelopment.meteorclient.gui.screens.settings;

import meteordevelopment.meteorclient.gui.GuiTheme;
import meteordevelopment.meteorclient.gui.WindowScreen;
import meteordevelopment.meteorclient.gui.widgets.WItemWithLabel;
import meteordevelopment.meteorclient.gui.widgets.containers.WTable;
import meteordevelopment.meteorclient.gui.widgets.input.WTextBox;
import meteordevelopment.meteorclient.gui.widgets.pressable.WButton;
import meteordevelopment.meteorclient.settings.ItemSetting;
import meteordevelopment.meteorclient.utils.misc.Names;
import net.minecraft.class_1792;
import net.minecraft.class_1802;
import net.minecraft.class_7923;
import org.apache.commons.lang3.Strings;

public class ItemSettingScreen
extends WindowScreen {
    private final ItemSetting setting;
    private WTable table;
    private WTextBox filter;
    private String filterText = "";

    public ItemSettingScreen(GuiTheme theme, ItemSetting setting) {
        super(theme, "Select item");
        this.setting = setting;
    }

    @Override
    public void initWidgets() {
        this.filter = this.add(this.theme.textBox("")).minWidth(400.0).expandX().widget();
        this.filter.setFocused(true);
        this.filter.action = () -> {
            this.filterText = this.filter.get().trim();
            this.table.clear();
            this.initTable();
        };
        this.table = this.add(this.theme.table()).expandX().widget();
        this.initTable();
    }

    public void initTable() {
        for (class_1792 item : class_7923.field_41178) {
            if (this.setting.filter != null && !this.setting.filter.test(item) || item == class_1802.field_8162) continue;
            WItemWithLabel itemLabel = this.theme.itemWithLabel(item.method_7854(), Names.get(item));
            if (!this.filterText.isEmpty() && !Strings.CI.contains((CharSequence)itemLabel.getLabelText(), (CharSequence)this.filterText)) continue;
            this.table.add(itemLabel);
            WButton select = this.table.add(this.theme.button("Select")).expandCellX().right().widget();
            select.action = () -> {
                this.setting.set(item);
                this.method_25419();
            };
            this.table.row();
        }
    }
}

