package androidx.compose.ui.focus;

import androidx.compose.ui.focus.d;
import com.google.firebase.crashlytics.internal.metadata.UserMetadata;
import j2.b1;
import j2.g0;
import j2.x0;
import j2.z0;
import l1.i;

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

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

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

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

        static {
            int[] iArr = new int[c3.t.values().length];
            try {
                iArr[c3.t.Ltr.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                iArr[c3.t.Rtl.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            f2201a = iArr;
            int[] iArr2 = new int[q1.m.values().length];
            try {
                iArr2[q1.m.Active.ordinal()] = 1;
            } catch (NoSuchFieldError unused3) {
            }
            try {
                iArr2[q1.m.ActiveParent.ordinal()] = 2;
            } catch (NoSuchFieldError unused4) {
            }
            try {
                iArr2[q1.m.Captured.ordinal()] = 3;
            } catch (NoSuchFieldError unused5) {
            }
            try {
                iArr2[q1.m.Inactive.ordinal()] = 4;
            } catch (NoSuchFieldError unused6) {
            }
            f2202b = iArr2;
        }
    }

    public static final m a(FocusTargetNode focusTargetNode, int i10, c3.t tVar) {
        m u10;
        i m22 = focusTargetNode.m2();
        d.a aVar = d.f2163b;
        if (d.l(i10, aVar.e())) {
            return m22.s();
        }
        if (d.l(i10, aVar.f())) {
            return m22.p();
        }
        if (d.l(i10, aVar.h())) {
            return m22.q();
        }
        if (d.l(i10, aVar.a())) {
            return m22.w();
        }
        if (d.l(i10, aVar.d())) {
            int i11 = a.f2201a[tVar.ordinal()];
            if (i11 == 1) {
                u10 = m22.i();
            } else {
                if (i11 != 2) {
                    throw new rm.t();
                }
                u10 = m22.u();
            }
            if (u10 == m.f2191b.b()) {
                u10 = null;
            }
            if (u10 == null) {
                return m22.g();
            }
        } else {
            if (!d.l(i10, aVar.g())) {
                if (d.l(i10, aVar.b())) {
                    return (m) m22.y().invoke(d.i(i10));
                }
                if (d.l(i10, aVar.c())) {
                    return (m) m22.t().invoke(d.i(i10));
                }
                throw new IllegalStateException("invalid FocusDirection".toString());
            }
            int i12 = a.f2201a[tVar.ordinal()];
            if (i12 == 1) {
                u10 = m22.u();
            } else {
                if (i12 != 2) {
                    throw new rm.t();
                }
                u10 = m22.i();
            }
            if (u10 == m.f2191b.b()) {
                u10 = null;
            }
            if (u10 == null) {
                return m22.n();
            }
        }
        return u10;
    }

    /* JADX WARN: Code restructure failed: missing block: B:75:0x004f, code lost:
    
        continue;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final FocusTargetNode b(FocusTargetNode focusTargetNode) {
        int i10 = a.f2202b[focusTargetNode.o2().ordinal()];
        if (i10 != 1) {
            if (i10 == 2) {
                int a10 = b1.a(UserMetadata.MAX_ATTRIBUTE_SIZE);
                if (!focusTargetNode.P0().O1()) {
                    throw new IllegalStateException("visitChildren called on an unattached node".toString());
                }
                a1.b bVar = new a1.b(new i.c[16], 0);
                i.c F1 = focusTargetNode.P0().F1();
                if (F1 == null) {
                    j2.k.c(bVar, focusTargetNode.P0());
                } else {
                    bVar.c(F1);
                }
                while (bVar.t()) {
                    i.c cVar = (i.c) bVar.z(bVar.q() - 1);
                    if ((cVar.E1() & a10) == 0) {
                        j2.k.c(bVar, cVar);
                    } else {
                        while (true) {
                            if (cVar == null) {
                                break;
                            }
                            if ((cVar.J1() & a10) != 0) {
                                a1.b bVar2 = null;
                                while (cVar != null) {
                                    if (cVar instanceof FocusTargetNode) {
                                        FocusTargetNode b10 = b((FocusTargetNode) cVar);
                                        if (b10 != null) {
                                            return b10;
                                        }
                                    } 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 (bVar2 == null) {
                                                        bVar2 = new a1.b(new i.c[16], 0);
                                                    }
                                                    if (cVar != null) {
                                                        bVar2.c(cVar);
                                                        cVar = null;
                                                    }
                                                    bVar2.c(i22);
                                                }
                                            }
                                        }
                                        if (i11 == 1) {
                                        }
                                    }
                                    cVar = j2.k.g(bVar2);
                                }
                            } else {
                                cVar = cVar.F1();
                            }
                        }
                    }
                }
                return null;
            }
            if (i10 != 3) {
                if (i10 == 4) {
                    return null;
                }
                throw new rm.t();
            }
        }
        return focusTargetNode;
    }

    private static final FocusTargetNode c(FocusTargetNode focusTargetNode) {
        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);
        while (m10 != null) {
            if ((m10.k0().k().E1() & a10) != 0) {
                while (L1 != null) {
                    if ((L1.J1() & a10) != 0) {
                        i.c cVar = L1;
                        a1.b bVar = null;
                        while (cVar != null) {
                            if (cVar instanceof FocusTargetNode) {
                                FocusTargetNode focusTargetNode2 = (FocusTargetNode) cVar;
                                if (focusTargetNode2.m2().o()) {
                                    return focusTargetNode2;
                                }
                            } 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 (bVar == null) {
                                                bVar = new a1.b(new i.c[16], 0);
                                            }
                                            if (cVar != null) {
                                                bVar.c(cVar);
                                                cVar = null;
                                            }
                                            bVar.c(i22);
                                        }
                                    }
                                }
                                if (i10 == 1) {
                                }
                            }
                            cVar = j2.k.g(bVar);
                        }
                    }
                    L1 = L1.L1();
                }
            }
            m10 = m10.o0();
            L1 = (m10 == null || (k02 = m10.k0()) == null) ? null : k02.o();
        }
        return null;
    }

    public static final r1.i d(FocusTargetNode focusTargetNode) {
        r1.i f02;
        z0 G1 = focusTargetNode.G1();
        return (G1 == null || (f02 = h2.t.d(G1).f0(G1, false)) == null) ? r1.i.f34323e.a() : f02;
    }

    public static final Boolean e(FocusTargetNode focusTargetNode, int i10, c3.t tVar, r1.i iVar, dn.l lVar) {
        int g10;
        d.a aVar = d.f2163b;
        if (d.l(i10, aVar.e()) ? true : d.l(i10, aVar.f())) {
            return Boolean.valueOf(t.f(focusTargetNode, i10, lVar));
        }
        if (d.l(i10, aVar.d()) ? true : d.l(i10, aVar.g()) ? true : d.l(i10, aVar.h()) ? true : d.l(i10, aVar.a())) {
            return u.t(focusTargetNode, i10, iVar, lVar);
        }
        if (!d.l(i10, aVar.b())) {
            if (d.l(i10, aVar.c())) {
                FocusTargetNode b10 = b(focusTargetNode);
                FocusTargetNode c10 = b10 != null ? c(b10) : null;
                return Boolean.valueOf((c10 == null || kotlin.jvm.internal.t.b(c10, focusTargetNode)) ? false : ((Boolean) lVar.invoke(c10)).booleanValue());
            }
            throw new IllegalStateException(("Focus search invoked with invalid FocusDirection " + ((Object) d.n(i10))).toString());
        }
        int i11 = a.f2201a[tVar.ordinal()];
        if (i11 == 1) {
            g10 = aVar.g();
        } else {
            if (i11 != 2) {
                throw new rm.t();
            }
            g10 = aVar.d();
        }
        FocusTargetNode b11 = b(focusTargetNode);
        if (b11 != null) {
            return u.t(b11, g10, iVar, lVar);
        }
        return null;
    }

    /* JADX WARN: Code restructure failed: missing block: B:75:0x003b, code lost:
    
        continue;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final FocusTargetNode f(FocusTargetNode focusTargetNode) {
        if (!focusTargetNode.P0().O1()) {
            return null;
        }
        int a10 = b1.a(UserMetadata.MAX_ATTRIBUTE_SIZE);
        if (!focusTargetNode.P0().O1()) {
            throw new IllegalStateException("visitChildren called on an unattached node".toString());
        }
        a1.b bVar = new a1.b(new i.c[16], 0);
        i.c F1 = focusTargetNode.P0().F1();
        if (F1 == null) {
            j2.k.c(bVar, focusTargetNode.P0());
        } else {
            bVar.c(F1);
        }
        while (bVar.t()) {
            i.c cVar = (i.c) bVar.z(bVar.q() - 1);
            if ((cVar.E1() & a10) == 0) {
                j2.k.c(bVar, cVar);
            } else {
                while (true) {
                    if (cVar == null) {
                        break;
                    }
                    if ((cVar.J1() & a10) != 0) {
                        a1.b bVar2 = null;
                        while (cVar != null) {
                            if (cVar instanceof FocusTargetNode) {
                                FocusTargetNode focusTargetNode2 = (FocusTargetNode) cVar;
                                if (focusTargetNode2.P0().O1()) {
                                    int i10 = a.f2202b[focusTargetNode2.o2().ordinal()];
                                    if (i10 == 1 || i10 == 2 || i10 == 3) {
                                        return focusTargetNode2;
                                    }
                                }
                            } 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 (bVar2 == null) {
                                                bVar2 = new a1.b(new i.c[16], 0);
                                            }
                                            if (cVar != null) {
                                                bVar2.c(cVar);
                                                cVar = null;
                                            }
                                            bVar2.c(i22);
                                        }
                                    }
                                }
                                if (i11 == 1) {
                                }
                            }
                            cVar = j2.k.g(bVar2);
                        }
                    } else {
                        cVar = cVar.F1();
                    }
                }
            }
        }
        return null;
    }

    public static final boolean g(FocusTargetNode focusTargetNode) {
        g0 w12;
        g0 w13;
        z0 G1 = focusTargetNode.G1();
        if ((G1 == null || (w13 = G1.w1()) == null || !w13.q()) ? false : true) {
            z0 G12 = focusTargetNode.G1();
            if ((G12 == null || (w12 = G12.w1()) == null || !w12.K0()) ? false : true) {
                return true;
            }
        }
        return false;
    }
}
