package androidx.compose.ui.focus;

import androidx.compose.ui.focus.d;
import com.google.firebase.crashlytics.internal.metadata.UserMetadata;
import h2.e;
import j2.b1;
import j2.g0;
import j2.x0;
import kotlin.jvm.internal.v;
import l1.i;

/* loaded from: classes.dex */
public abstract class t {

    /* loaded from: classes.dex */
    public /* synthetic */ class a {

        /* renamed from: a, reason: collision with root package name */
        public static final /* synthetic */ int[] f2204a;

        static {
            int[] iArr = new int[q1.m.values().length];
            try {
                iArr[q1.m.ActiveParent.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                iArr[q1.m.Active.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                iArr[q1.m.Captured.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
            try {
                iArr[q1.m.Inactive.ordinal()] = 4;
            } catch (NoSuchFieldError unused4) {
            }
            f2204a = iArr;
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public static final class b extends v implements dn.l {

        /* renamed from: p, reason: collision with root package name */
        final /* synthetic */ FocusTargetNode f2205p;

        /* renamed from: q, reason: collision with root package name */
        final /* synthetic */ FocusTargetNode f2206q;

        /* renamed from: r, reason: collision with root package name */
        final /* synthetic */ int f2207r;

        /* renamed from: s, reason: collision with root package name */
        final /* synthetic */ dn.l f2208s;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        b(FocusTargetNode focusTargetNode, FocusTargetNode focusTargetNode2, int i10, dn.l lVar) {
            super(1);
            this.f2205p = focusTargetNode;
            this.f2206q = focusTargetNode2;
            this.f2207r = i10;
            this.f2208s = lVar;
        }

        @Override // dn.l
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public final Boolean invoke(e.a aVar) {
            Boolean valueOf = Boolean.valueOf(t.i(this.f2205p, this.f2206q, this.f2207r, this.f2208s));
            if (valueOf.booleanValue() || !aVar.a()) {
                return valueOf;
            }
            return null;
        }
    }

    private static final boolean b(FocusTargetNode focusTargetNode, dn.l lVar) {
        q1.m o22 = focusTargetNode.o2();
        int[] iArr = a.f2204a;
        int i10 = iArr[o22.ordinal()];
        if (i10 == 1) {
            FocusTargetNode f10 = r.f(focusTargetNode);
            if (f10 == null) {
                throw new IllegalStateException("ActiveParent must have a focusedChild".toString());
            }
            int i11 = iArr[f10.o2().ordinal()];
            if (i11 != 1) {
                if (i11 == 2 || i11 == 3) {
                    return d(focusTargetNode, f10, d.f2163b.f(), lVar);
                }
                if (i11 != 4) {
                    throw new rm.t();
                }
                throw new IllegalStateException("ActiveParent must have a focusedChild".toString());
            }
            if (!b(f10, lVar) && !d(focusTargetNode, f10, d.f2163b.f(), lVar) && (!f10.m2().o() || !((Boolean) lVar.invoke(f10)).booleanValue())) {
                return false;
            }
        } else {
            if (i10 == 2 || i10 == 3) {
                return g(focusTargetNode, lVar);
            }
            if (i10 != 4) {
                throw new rm.t();
            }
            if (!g(focusTargetNode, lVar)) {
                if (!(focusTargetNode.m2().o() ? ((Boolean) lVar.invoke(focusTargetNode)).booleanValue() : false)) {
                    return false;
                }
            }
        }
        return true;
    }

    private static final boolean c(FocusTargetNode focusTargetNode, dn.l lVar) {
        int i10 = a.f2204a[focusTargetNode.o2().ordinal()];
        if (i10 == 1) {
            FocusTargetNode f10 = r.f(focusTargetNode);
            if (f10 != null) {
                return c(f10, lVar) || d(focusTargetNode, f10, d.f2163b.e(), lVar);
            }
            throw new IllegalStateException("ActiveParent must have a focusedChild".toString());
        }
        if (i10 == 2 || i10 == 3) {
            return h(focusTargetNode, lVar);
        }
        if (i10 == 4) {
            return focusTargetNode.m2().o() ? ((Boolean) lVar.invoke(focusTargetNode)).booleanValue() : h(focusTargetNode, lVar);
        }
        throw new rm.t();
    }

    private static final boolean d(FocusTargetNode focusTargetNode, FocusTargetNode focusTargetNode2, int i10, dn.l lVar) {
        if (i(focusTargetNode, focusTargetNode2, i10, lVar)) {
            return true;
        }
        Boolean bool = (Boolean) androidx.compose.ui.focus.a.a(focusTargetNode, i10, new b(focusTargetNode, focusTargetNode2, i10, lVar));
        if (bool != null) {
            return bool.booleanValue();
        }
        return false;
    }

    private static final boolean e(FocusTargetNode focusTargetNode) {
        i.c cVar;
        x0 k02;
        int a10 = b1.a(UserMetadata.MAX_ATTRIBUTE_SIZE);
        if (!focusTargetNode.P0().O1()) {
            throw new IllegalStateException("visitAncestors called on an unattached node".toString());
        }
        i.c L1 = focusTargetNode.P0().L1();
        g0 m10 = j2.k.m(focusTargetNode);
        loop0: while (true) {
            cVar = null;
            if (m10 == null) {
                break;
            }
            if ((m10.k0().k().E1() & a10) != 0) {
                while (L1 != null) {
                    if ((L1.J1() & a10) != 0) {
                        i.c cVar2 = L1;
                        a1.b bVar = null;
                        while (cVar2 != null) {
                            if (cVar2 instanceof FocusTargetNode) {
                                cVar = cVar2;
                                break loop0;
                            }
                            if (((cVar2.J1() & a10) != 0) && (cVar2 instanceof j2.m)) {
                                int i10 = 0;
                                for (i.c i22 = ((j2.m) cVar2).i2(); i22 != null; i22 = i22.F1()) {
                                    if ((i22.J1() & a10) != 0) {
                                        i10++;
                                        if (i10 == 1) {
                                            cVar2 = i22;
                                        } else {
                                            if (bVar == null) {
                                                bVar = new a1.b(new i.c[16], 0);
                                            }
                                            if (cVar2 != null) {
                                                bVar.c(cVar2);
                                                cVar2 = null;
                                            }
                                            bVar.c(i22);
                                        }
                                    }
                                }
                                if (i10 == 1) {
                                }
                            }
                            cVar2 = j2.k.g(bVar);
                        }
                    }
                    L1 = L1.L1();
                }
            }
            m10 = m10.o0();
            L1 = (m10 == null || (k02 = m10.k0()) == null) ? null : k02.o();
        }
        return cVar == null;
    }

    public static final boolean f(FocusTargetNode focusTargetNode, int i10, dn.l lVar) {
        d.a aVar = d.f2163b;
        if (d.l(i10, aVar.e())) {
            return c(focusTargetNode, lVar);
        }
        if (d.l(i10, aVar.f())) {
            return b(focusTargetNode, lVar);
        }
        throw new IllegalStateException("This function should only be used for 1-D focus search".toString());
    }

    private static final boolean g(FocusTargetNode focusTargetNode, dn.l lVar) {
        a1.b bVar = new a1.b(new FocusTargetNode[16], 0);
        int a10 = b1.a(UserMetadata.MAX_ATTRIBUTE_SIZE);
        if (!focusTargetNode.P0().O1()) {
            throw new IllegalStateException("visitChildren called on an unattached node".toString());
        }
        a1.b bVar2 = new a1.b(new i.c[16], 0);
        i.c F1 = focusTargetNode.P0().F1();
        if (F1 == null) {
            j2.k.c(bVar2, focusTargetNode.P0());
        } else {
            bVar2.c(F1);
        }
        while (bVar2.t()) {
            i.c cVar = (i.c) bVar2.z(bVar2.q() - 1);
            if ((cVar.E1() & a10) == 0) {
                j2.k.c(bVar2, cVar);
            } else {
                while (true) {
                    if (cVar == null) {
                        break;
                    }
                    if ((cVar.J1() & a10) != 0) {
                        a1.b bVar3 = null;
                        while (cVar != null) {
                            if (cVar instanceof FocusTargetNode) {
                                bVar.c((FocusTargetNode) cVar);
                            } else if (((cVar.J1() & a10) != 0) && (cVar instanceof j2.m)) {
                                int i10 = 0;
                                for (i.c i22 = ((j2.m) cVar).i2(); i22 != null; i22 = i22.F1()) {
                                    if ((i22.J1() & a10) != 0) {
                                        i10++;
                                        if (i10 == 1) {
                                            cVar = i22;
                                        } else {
                                            if (bVar3 == null) {
                                                bVar3 = new a1.b(new i.c[16], 0);
                                            }
                                            if (cVar != null) {
                                                bVar3.c(cVar);
                                                cVar = null;
                                            }
                                            bVar3.c(i22);
                                        }
                                    }
                                }
                                if (i10 == 1) {
                                }
                            }
                            cVar = j2.k.g(bVar3);
                        }
                    } else {
                        cVar = cVar.F1();
                    }
                }
            }
        }
        bVar.F(s.f2203p);
        int q10 = bVar.q();
        if (q10 > 0) {
            int i11 = q10 - 1;
            Object[] p10 = bVar.p();
            do {
                FocusTargetNode focusTargetNode2 = (FocusTargetNode) p10[i11];
                if (r.g(focusTargetNode2) && b(focusTargetNode2, lVar)) {
                    return true;
                }
                i11--;
            } while (i11 >= 0);
        }
        return false;
    }

    private static final boolean h(FocusTargetNode focusTargetNode, dn.l lVar) {
        a1.b bVar = new a1.b(new FocusTargetNode[16], 0);
        int a10 = b1.a(UserMetadata.MAX_ATTRIBUTE_SIZE);
        if (!focusTargetNode.P0().O1()) {
            throw new IllegalStateException("visitChildren called on an unattached node".toString());
        }
        a1.b bVar2 = new a1.b(new i.c[16], 0);
        i.c F1 = focusTargetNode.P0().F1();
        if (F1 == null) {
            j2.k.c(bVar2, focusTargetNode.P0());
        } else {
            bVar2.c(F1);
        }
        while (bVar2.t()) {
            i.c cVar = (i.c) bVar2.z(bVar2.q() - 1);
            if ((cVar.E1() & a10) == 0) {
                j2.k.c(bVar2, cVar);
            } else {
                while (true) {
                    if (cVar == null) {
                        break;
                    }
                    if ((cVar.J1() & a10) != 0) {
                        a1.b bVar3 = null;
                        while (cVar != null) {
                            if (cVar instanceof FocusTargetNode) {
                                bVar.c((FocusTargetNode) cVar);
                            } else if (((cVar.J1() & a10) != 0) && (cVar instanceof j2.m)) {
                                int i10 = 0;
                                for (i.c i22 = ((j2.m) cVar).i2(); i22 != null; i22 = i22.F1()) {
                                    if ((i22.J1() & a10) != 0) {
                                        i10++;
                                        if (i10 == 1) {
                                            cVar = i22;
                                        } else {
                                            if (bVar3 == null) {
                                                bVar3 = new a1.b(new i.c[16], 0);
                                            }
                                            if (cVar != null) {
                                                bVar3.c(cVar);
                                                cVar = null;
                                            }
                                            bVar3.c(i22);
                                        }
                                    }
                                }
                                if (i10 == 1) {
                                }
                            }
                            cVar = j2.k.g(bVar3);
                        }
                    } else {
                        cVar = cVar.F1();
                    }
                }
            }
        }
        bVar.F(s.f2203p);
        int q10 = bVar.q();
        if (q10 <= 0) {
            return false;
        }
        Object[] p10 = bVar.p();
        int i11 = 0;
        do {
            FocusTargetNode focusTargetNode2 = (FocusTargetNode) p10[i11];
            if (r.g(focusTargetNode2) && c(focusTargetNode2, lVar)) {
                return true;
            }
            i11++;
        } while (i11 < q10);
        return false;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final boolean i(FocusTargetNode focusTargetNode, FocusTargetNode focusTargetNode2, int i10, dn.l lVar) {
        if (!(focusTargetNode.o2() == q1.m.ActiveParent)) {
            throw new IllegalStateException("This function should only be used within a parent that has focus.".toString());
        }
        a1.b bVar = new a1.b(new FocusTargetNode[16], 0);
        int a10 = b1.a(UserMetadata.MAX_ATTRIBUTE_SIZE);
        if (!focusTargetNode.P0().O1()) {
            throw new IllegalStateException("visitChildren called on an unattached node".toString());
        }
        a1.b bVar2 = new a1.b(new i.c[16], 0);
        i.c F1 = focusTargetNode.P0().F1();
        if (F1 == null) {
            j2.k.c(bVar2, focusTargetNode.P0());
        } else {
            bVar2.c(F1);
        }
        while (bVar2.t()) {
            i.c cVar = (i.c) bVar2.z(bVar2.q() - 1);
            if ((cVar.E1() & a10) == 0) {
                j2.k.c(bVar2, cVar);
            } else {
                while (true) {
                    if (cVar == null) {
                        break;
                    }
                    if ((cVar.J1() & a10) != 0) {
                        a1.b bVar3 = null;
                        while (cVar != null) {
                            if (cVar instanceof FocusTargetNode) {
                                bVar.c((FocusTargetNode) cVar);
                            } else if (((cVar.J1() & a10) != 0) && (cVar instanceof j2.m)) {
                                int i11 = 0;
                                for (i.c i22 = ((j2.m) cVar).i2(); i22 != null; i22 = i22.F1()) {
                                    if ((i22.J1() & a10) != 0) {
                                        i11++;
                                        if (i11 == 1) {
                                            cVar = i22;
                                        } else {
                                            if (bVar3 == null) {
                                                bVar3 = new a1.b(new i.c[16], 0);
                                            }
                                            if (cVar != null) {
                                                bVar3.c(cVar);
                                                cVar = null;
                                            }
                                            bVar3.c(i22);
                                        }
                                    }
                                }
                                if (i11 == 1) {
                                }
                            }
                            cVar = j2.k.g(bVar3);
                        }
                    } else {
                        cVar = cVar.F1();
                    }
                }
            }
        }
        bVar.F(s.f2203p);
        d.a aVar = d.f2163b;
        if (d.l(i10, aVar.e())) {
            jn.i iVar = new jn.i(0, bVar.q() - 1);
            int g10 = iVar.g();
            int m10 = iVar.m();
            if (g10 <= m10) {
                boolean z10 = false;
                while (true) {
                    if (z10) {
                        FocusTargetNode focusTargetNode3 = (FocusTargetNode) bVar.p()[g10];
                        if (r.g(focusTargetNode3) && c(focusTargetNode3, lVar)) {
                            return true;
                        }
                    }
                    if (kotlin.jvm.internal.t.b(bVar.p()[g10], focusTargetNode2)) {
                        z10 = true;
                    }
                    if (g10 == m10) {
                        break;
                    }
                    g10++;
                }
            }
        } else {
            if (!d.l(i10, aVar.f())) {
                throw new IllegalStateException("This function should only be used for 1-D focus search".toString());
            }
            jn.i iVar2 = new jn.i(0, bVar.q() - 1);
            int g11 = iVar2.g();
            int m11 = iVar2.m();
            if (g11 <= m11) {
                boolean z11 = false;
                while (true) {
                    if (z11) {
                        FocusTargetNode focusTargetNode4 = (FocusTargetNode) bVar.p()[m11];
                        if (r.g(focusTargetNode4) && b(focusTargetNode4, lVar)) {
                            return true;
                        }
                    }
                    if (kotlin.jvm.internal.t.b(bVar.p()[m11], focusTargetNode2)) {
                        z11 = true;
                    }
                    if (m11 == g11) {
                        break;
                    }
                    m11--;
                }
            }
        }
        if (d.l(i10, d.f2163b.e()) || !focusTargetNode.m2().o() || e(focusTargetNode)) {
            return false;
        }
        return ((Boolean) lVar.invoke(focusTargetNode)).booleanValue();
    }
}
