package o;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashSet;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.zR, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public final class C3092zR {
    public final Ba0 a = AbstractC0752ap.h(AR.m);
    public final Ba0 b;
    public final C1537j00 c;
    public final C1172f9 d;
    public final C1172f9 e;
    public AT f;
    public int g;
    public AbstractC2997yR h;
    public final LinkedHashSet i;
    public final LinkedHashSet j;
    public final LinkedHashSet k;
    public boolean l;
    public boolean m;
    public boolean n;

    public C3092zR() {
        Ba0 ba0H = AbstractC0752ap.h(new C2902xR());
        this.b = ba0H;
        this.c = new C1537j00(ba0H);
        this.d = new C1172f9();
        this.e = new C1172f9();
        this.i = new LinkedHashSet();
        this.j = new LinkedHashSet();
        this.k = new LinkedHashSet();
    }

    public final void a(C2807wR c2807wR, AbstractC2997yR abstractC2997yR, int i) {
        if (abstractC2997yR.a == null) {
            (i != 0 ? i != 1 ? this.i : this.j : this.k).add(abstractC2997yR);
            abstractC2997yR.a = c2807wR;
            abstractC2997yR.b(i != 0 ? i != 1 ? this.n : this.l : this.m);
            return;
        }
        throw new IllegalArgumentException(("Input '" + abstractC2997yR + "' is already added to dispatcher " + abstractC2997yR.a + '.').toString());
    }

    public final void b() {
        boolean z;
        boolean z2;
        C2902xR c2902xR;
        C1172f9 c1172f9 = this.d;
        if (c1172f9 == null || !c1172f9.isEmpty()) {
            Iterator it = c1172f9.iterator();
            while (it.hasNext()) {
                if (((AT) it.next()).b) {
                    z = true;
                    break;
                }
            }
            z = false;
        } else {
            z = false;
        }
        C1172f9 c1172f92 = this.e;
        if (c1172f92 == null || !c1172f92.isEmpty()) {
            Iterator it2 = c1172f92.iterator();
            while (it2.hasNext()) {
                if (((AT) it2.next()).b) {
                    z2 = true;
                    break;
                }
            }
            z2 = false;
        } else {
            z2 = false;
        }
        boolean z3 = z || z2;
        boolean z4 = this.m != z;
        boolean z5 = this.l != z2;
        boolean z6 = this.n != z3;
        LinkedHashSet linkedHashSet = this.k;
        if (z4) {
            Iterator it3 = linkedHashSet.iterator();
            while (it3.hasNext()) {
                ((AbstractC2997yR) it3.next()).b(z);
            }
        }
        LinkedHashSet linkedHashSet2 = this.j;
        if (z5) {
            Iterator it4 = linkedHashSet2.iterator();
            while (it4.hasNext()) {
                ((AbstractC2997yR) it4.next()).b(z2);
            }
        }
        LinkedHashSet linkedHashSet3 = this.i;
        if (z6) {
            Iterator it5 = linkedHashSet3.iterator();
            while (it5.hasNext()) {
                ((AbstractC2997yR) it5.next()).b(z3);
            }
        }
        this.m = z;
        this.l = z2;
        this.n = z3;
        AT atC = this.f;
        if (atC == null) {
            atC = c(0);
        }
        AT atC2 = this.f;
        if (atC2 == null) {
            atC2 = c(0);
        }
        if (F3.c(atC2, atC)) {
            if (atC2 == null) {
                c2902xR = new C2902xR();
            } else {
                ArrayList arrayList = new ArrayList();
                Iterator<E> it6 = c1172f9.iterator();
                while (it6.hasNext()) {
                    ((AT) it6.next()).getClass();
                }
                Iterator<E> it7 = c1172f92.iterator();
                while (it7.hasNext()) {
                    ((AT) it7.next()).getClass();
                }
                BT bt = atC2.a;
                HL hl = new HL(10);
                AbstractC0138Fi.Y(arrayList, hl);
                hl.add(bt);
                AbstractC0138Fi.Y(C0332Mv.l, hl);
                c2902xR = new C2902xR(arrayList.size(), AbstractC0662Zn.i(hl));
            }
            Ba0 ba0 = this.b;
            if (F3.c((C2902xR) ba0.getValue(), c2902xR)) {
                return;
            }
            ba0.i(null, c2902xR);
            Iterator it8 = linkedHashSet.iterator();
            while (it8.hasNext()) {
                ((AbstractC2997yR) it8.next()).getClass();
            }
            Iterator it9 = linkedHashSet2.iterator();
            while (it9.hasNext()) {
                ((AbstractC2997yR) it9.next()).getClass();
            }
            Iterator it10 = linkedHashSet3.iterator();
            while (it10.hasNext()) {
                ((AbstractC2997yR) it10.next()).getClass();
            }
        }
    }

    public final AT c(int i) {
        Object next;
        Object next2;
        C1172f9 c1172f9 = this.e;
        C1172f9 c1172f92 = this.d;
        Object obj = null;
        if (i == -1) {
            Iterator it = c1172f92.iterator();
            while (true) {
                if (!it.hasNext()) {
                    next = null;
                    break;
                }
                next = it.next();
                if (((AT) next).b) {
                    break;
                }
            }
            AT at = (AT) next;
            if (at != null) {
                return at;
            }
            Iterator it2 = c1172f9.iterator();
            while (true) {
                if (!it2.hasNext()) {
                    break;
                }
                Object next3 = it2.next();
                if (((AT) next3).b) {
                    obj = next3;
                    break;
                }
            }
            return (AT) obj;
        }
        if (i != 0) {
            if (i != 1) {
                throw new IllegalStateException(("Unsupported direction: '" + i + "'.").toString());
            }
            Iterator it3 = c1172f92.iterator();
            while (it3.hasNext()) {
                ((AT) it3.next()).getClass();
            }
            Iterator it4 = c1172f9.iterator();
            while (it4.hasNext()) {
                ((AT) it4.next()).getClass();
            }
            return null;
        }
        Iterator it5 = c1172f92.iterator();
        while (true) {
            if (!it5.hasNext()) {
                next2 = null;
                break;
            }
            next2 = it5.next();
            if (((AT) next2).b) {
                break;
            }
        }
        AT at2 = (AT) next2;
        if (at2 != null) {
            return at2;
        }
        Iterator it6 = c1172f9.iterator();
        while (true) {
            if (!it6.hasNext()) {
                break;
            }
            Object next4 = it6.next();
            if (((AT) next4).b) {
                obj = next4;
                break;
            }
        }
        return (AT) obj;
    }
}
