package com.google.android.material.internal;

import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.Nullable;
import com.google.android.gms.measurement.internal.u1;
import com.google.android.material.chip.ChipGroup;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;

/* JADX INFO: loaded from: classes2.dex */
public final class b {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final HashMap f22692a = new HashMap();

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final HashSet f22693b = new HashSet();

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public a f22694c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public boolean f22695d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public boolean f22696e;

    public final boolean a(o oVar) {
        int id2 = oVar.getId();
        HashSet hashSet = this.f22693b;
        if (hashSet.contains(Integer.valueOf(id2))) {
            return false;
        }
        o oVar2 = (o) this.f22692a.get(Integer.valueOf(c()));
        if (oVar2 != null) {
            e(oVar2, false);
        }
        boolean zAdd = hashSet.add(Integer.valueOf(id2));
        if (!oVar.isChecked()) {
            oVar.setChecked(true);
        }
        return zAdd;
    }

    public final ArrayList b(ViewGroup viewGroup) {
        HashSet hashSet = new HashSet(this.f22693b);
        ArrayList arrayList = new ArrayList();
        for (int i10 = 0; i10 < viewGroup.getChildCount(); i10++) {
            View childAt = viewGroup.getChildAt(i10);
            if ((childAt instanceof o) && hashSet.contains(Integer.valueOf(childAt.getId()))) {
                arrayList.add(Integer.valueOf(childAt.getId()));
            }
        }
        return arrayList;
    }

    public final int c() {
        if (this.f22695d) {
            HashSet hashSet = this.f22693b;
            if (!hashSet.isEmpty()) {
                return ((Integer) hashSet.iterator().next()).intValue();
            }
        }
        return -1;
    }

    public final void d() {
        a aVar = this.f22694c;
        if (aVar != null) {
            new HashSet(this.f22693b);
            xyz.stream.utils.a0 a0Var = (xyz.stream.utils.a0) aVar;
            if (((ChipGroup) a0Var.f36098a).onCheckedStateChangeListener != null) {
                f9.h hVar = ((ChipGroup) a0Var.f36098a).onCheckedStateChangeListener;
                ChipGroup chipGroup = (ChipGroup) a0Var.f36098a;
                chipGroup.f22437g.b(chipGroup);
                xyz.stream.utils.f fVar = (xyz.stream.utils.f) hVar;
                if (((ChipGroup) fVar.f36133c).f22437g.f22695d) {
                    u1.x(fVar.f36132b);
                    ((ChipGroup) fVar.f36133c).getCheckedChipId();
                    throw null;
                }
            }
        }
    }

    public final boolean e(o oVar, boolean z10) {
        int id2 = oVar.getId();
        HashSet hashSet = this.f22693b;
        if (!hashSet.contains(Integer.valueOf(id2))) {
            return false;
        }
        if (z10 && hashSet.size() == 1 && hashSet.contains(Integer.valueOf(id2))) {
            oVar.setChecked(true);
            return false;
        }
        boolean zRemove = hashSet.remove(Integer.valueOf(id2));
        if (oVar.isChecked()) {
            oVar.setChecked(false);
        }
        return zRemove;
    }

    public void setOnCheckedStateChangeListener(@Nullable a aVar) {
        this.f22694c = aVar;
    }
}
