package androidx.compose.ui.focus;

import androidx.compose.ui.focus.m;
import com.google.firebase.crashlytics.internal.metadata.UserMetadata;
import j2.b1;
import j2.f1;
import j2.g0;
import j2.x0;
import kotlin.jvm.internal.v;
import l1.i;
import rm.n0;

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

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

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

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

        static {
            int[] iArr = new int[q1.a.values().length];
            try {
                iArr[q1.a.None.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                iArr[q1.a.Redirected.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                iArr[q1.a.Cancelled.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
            try {
                iArr[q1.a.RedirectCancelled.ordinal()] = 4;
            } catch (NoSuchFieldError unused4) {
            }
            f2197a = iArr;
            int[] iArr2 = new int[q1.m.values().length];
            try {
                iArr2[q1.m.Active.ordinal()] = 1;
            } catch (NoSuchFieldError unused5) {
            }
            try {
                iArr2[q1.m.Captured.ordinal()] = 2;
            } catch (NoSuchFieldError unused6) {
            }
            try {
                iArr2[q1.m.ActiveParent.ordinal()] = 3;
            } catch (NoSuchFieldError unused7) {
            }
            try {
                iArr2[q1.m.Inactive.ordinal()] = 4;
            } catch (NoSuchFieldError unused8) {
            }
            f2198b = iArr2;
        }
    }

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

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

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        b(FocusTargetNode focusTargetNode) {
            super(0);
            this.f2199p = focusTargetNode;
        }

        @Override // dn.a
        public /* bridge */ /* synthetic */ Object invoke() {
            m13invoke();
            return n0.f34904a;
        }

        /* renamed from: invoke, reason: collision with other method in class */
        public final void m13invoke() {
            this.f2199p.m2();
        }
    }

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

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

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        c(FocusTargetNode focusTargetNode) {
            super(0);
            this.f2200p = focusTargetNode;
        }

        @Override // dn.a
        public /* bridge */ /* synthetic */ Object invoke() {
            m14invoke();
            return n0.f34904a;
        }

        /* renamed from: invoke, reason: collision with other method in class */
        public final void m14invoke() {
            if (this.f2200p.P0().O1()) {
                q1.c.c(this.f2200p);
            }
        }
    }

    private static final boolean a(FocusTargetNode focusTargetNode, boolean z10, boolean z11) {
        FocusTargetNode f10 = r.f(focusTargetNode);
        if (f10 != null) {
            return c(f10, z10, z11);
        }
        return true;
    }

    static /* synthetic */ boolean b(FocusTargetNode focusTargetNode, boolean z10, boolean z11, int i10, Object obj) {
        if ((i10 & 1) != 0) {
            z10 = false;
        }
        if ((i10 & 2) != 0) {
            z11 = true;
        }
        return a(focusTargetNode, z10, z11);
    }

    public static final boolean c(FocusTargetNode focusTargetNode, boolean z10, boolean z11) {
        int i10 = a.f2198b[focusTargetNode.o2().ordinal()];
        if (i10 == 1) {
            focusTargetNode.u2(q1.m.Inactive);
            if (z11) {
                q1.c.c(focusTargetNode);
            }
        } else {
            if (i10 == 2) {
                if (!z10) {
                    return z10;
                }
                focusTargetNode.u2(q1.m.Inactive);
                if (!z11) {
                    return z10;
                }
                q1.c.c(focusTargetNode);
                return z10;
            }
            if (i10 != 3) {
                if (i10 != 4) {
                    throw new rm.t();
                }
            } else {
                if (!a(focusTargetNode, z10, z11)) {
                    return false;
                }
                focusTargetNode.u2(q1.m.Inactive);
                if (z11) {
                    q1.c.c(focusTargetNode);
                }
            }
        }
        return true;
    }

    private static final boolean d(FocusTargetNode focusTargetNode) {
        f1.a(focusTargetNode, new b(focusTargetNode));
        int i10 = a.f2198b[focusTargetNode.o2().ordinal()];
        if (i10 != 3 && i10 != 4) {
            return true;
        }
        focusTargetNode.u2(q1.m.Active);
        return true;
    }

    public static final q1.a e(FocusTargetNode focusTargetNode, int i10) {
        int i11 = a.f2198b[focusTargetNode.o2().ordinal()];
        if (i11 != 1) {
            if (i11 == 2) {
                return q1.a.Cancelled;
            }
            if (i11 == 3) {
                q1.a e10 = e(n(focusTargetNode), i10);
                if (e10 == q1.a.None) {
                    e10 = null;
                }
                return e10 == null ? g(focusTargetNode, i10) : e10;
            }
            if (i11 != 4) {
                throw new rm.t();
            }
        }
        return q1.a.None;
    }

    private static final q1.a f(FocusTargetNode focusTargetNode, int i10) {
        boolean z10;
        z10 = focusTargetNode.D;
        if (!z10) {
            focusTargetNode.D = true;
            try {
                m mVar = (m) focusTargetNode.m2().y().invoke(d.i(i10));
                m.a aVar = m.f2191b;
                if (mVar != aVar.b()) {
                    if (mVar == aVar.a()) {
                        return q1.a.Cancelled;
                    }
                    return mVar.d() ? q1.a.Redirected : q1.a.RedirectCancelled;
                }
            } finally {
                focusTargetNode.D = false;
            }
        }
        return q1.a.None;
    }

    private static final q1.a g(FocusTargetNode focusTargetNode, int i10) {
        boolean z10;
        z10 = focusTargetNode.C;
        if (!z10) {
            focusTargetNode.C = true;
            try {
                m mVar = (m) focusTargetNode.m2().t().invoke(d.i(i10));
                m.a aVar = m.f2191b;
                if (mVar != aVar.b()) {
                    if (mVar == aVar.a()) {
                        return q1.a.Cancelled;
                    }
                    return mVar.d() ? q1.a.Redirected : q1.a.RedirectCancelled;
                }
            } finally {
                focusTargetNode.C = false;
            }
        }
        return q1.a.None;
    }

    public static final q1.a h(FocusTargetNode focusTargetNode, int i10) {
        i.c cVar;
        x0 k02;
        int i11 = a.f2198b[focusTargetNode.o2().ordinal()];
        if (i11 == 1 || i11 == 2) {
            return q1.a.None;
        }
        if (i11 == 3) {
            return e(n(focusTargetNode), i10);
        }
        if (i11 != 4) {
            throw new rm.t();
        }
        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) {
            if (m10 == null) {
                cVar = null;
                break;
            }
            if ((m10.k0().k().E1() & a10) != 0) {
                while (L1 != null) {
                    if ((L1.J1() & a10) != 0) {
                        cVar = L1;
                        a1.b bVar = null;
                        while (cVar != null) {
                            if (cVar instanceof FocusTargetNode) {
                                break loop0;
                            }
                            if (((cVar.J1() & a10) != 0) && (cVar instanceof j2.m)) {
                                int i12 = 0;
                                for (i.c i22 = ((j2.m) cVar).i2(); i22 != null; i22 = i22.F1()) {
                                    if ((i22.J1() & a10) != 0) {
                                        i12++;
                                        if (i12 == 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 (i12 == 1) {
                                }
                            }
                            cVar = j2.k.g(bVar);
                        }
                    }
                    L1 = L1.L1();
                }
            }
            m10 = m10.o0();
            L1 = (m10 == null || (k02 = m10.k0()) == null) ? null : k02.o();
        }
        FocusTargetNode focusTargetNode2 = (FocusTargetNode) cVar;
        if (focusTargetNode2 == null) {
            return q1.a.None;
        }
        int i13 = a.f2198b[focusTargetNode2.o2().ordinal()];
        if (i13 == 1) {
            return f(focusTargetNode2, i10);
        }
        if (i13 == 2) {
            return q1.a.Cancelled;
        }
        if (i13 == 3) {
            return h(focusTargetNode2, i10);
        }
        if (i13 != 4) {
            throw new rm.t();
        }
        q1.a h10 = h(focusTargetNode2, i10);
        q1.a aVar = h10 == q1.a.None ? null : h10;
        return aVar == null ? f(focusTargetNode2, i10) : aVar;
    }

    /* JADX WARN: Code restructure failed: missing block: B:69:0x00e4, code lost:
    
        if (d(r11) != false) goto L79;
     */
    /* JADX WARN: Code restructure failed: missing block: B:96:0x0103, code lost:
    
        if (d(r11) != false) goto L79;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final boolean i(FocusTargetNode focusTargetNode) {
        x0 k02;
        int i10 = a.f2198b[focusTargetNode.o2().ordinal()];
        boolean z10 = true;
        if (i10 != 1 && i10 != 2) {
            i.c cVar = null;
            if (i10 == 3) {
                if (b(focusTargetNode, false, false, 3, null)) {
                }
                z10 = false;
            } else {
                if (i10 != 4) {
                    throw new rm.t();
                }
                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) {
                    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 i11 = 0;
                                        for (i.c i22 = ((j2.m) cVar2).i2(); i22 != null; i22 = i22.F1()) {
                                            if ((i22.J1() & a10) != 0) {
                                                i11++;
                                                if (i11 == 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 (i11 == 1) {
                                        }
                                    }
                                    cVar2 = j2.k.g(bVar);
                                }
                            }
                            L1 = L1.L1();
                        }
                    }
                    m10 = m10.o0();
                    L1 = (m10 == null || (k02 = m10.k0()) == null) ? null : k02.o();
                }
                FocusTargetNode focusTargetNode2 = (FocusTargetNode) cVar;
                if (focusTargetNode2 != null) {
                    q1.m o22 = focusTargetNode2.o2();
                    z10 = l(focusTargetNode2, focusTargetNode);
                    if (z10 && o22 != focusTargetNode2.o2()) {
                        q1.c.c(focusTargetNode2);
                    }
                } else {
                    if (m(focusTargetNode)) {
                    }
                    z10 = false;
                }
            }
        }
        if (z10) {
            q1.c.c(focusTargetNode);
        }
        return z10;
    }

    public static final boolean j(FocusTargetNode focusTargetNode) {
        Boolean k10 = k(focusTargetNode, d.f2163b.b());
        if (k10 != null) {
            return k10.booleanValue();
        }
        return false;
    }

    public static final Boolean k(FocusTargetNode focusTargetNode, int i10) {
        Boolean valueOf;
        q1.q d10 = q1.p.d(focusTargetNode);
        c cVar = new c(focusTargetNode);
        try {
            if (q1.q.e(d10)) {
                q1.q.b(d10);
            }
            q1.q.a(d10);
            q1.q.d(d10).c(cVar);
            int i11 = a.f2197a[h(focusTargetNode, i10).ordinal()];
            if (i11 == 1) {
                valueOf = Boolean.valueOf(i(focusTargetNode));
            } else if (i11 != 2) {
                if (i11 != 3 && i11 != 4) {
                    throw new rm.t();
                }
                valueOf = null;
            } else {
                valueOf = Boolean.TRUE;
            }
            return valueOf;
        } finally {
            q1.q.c(d10);
        }
    }

    private static final boolean l(FocusTargetNode focusTargetNode, FocusTargetNode focusTargetNode2) {
        i.c cVar;
        i.c cVar2;
        x0 k02;
        x0 k03;
        int a10 = b1.a(UserMetadata.MAX_ATTRIBUTE_SIZE);
        if (!focusTargetNode2.P0().O1()) {
            throw new IllegalStateException("visitAncestors called on an unattached node".toString());
        }
        i.c L1 = focusTargetNode2.P0().L1();
        g0 m10 = j2.k.m(focusTargetNode2);
        loop0: while (true) {
            cVar = null;
            if (m10 == null) {
                cVar2 = null;
                break;
            }
            if ((m10.k0().k().E1() & a10) != 0) {
                while (L1 != null) {
                    if ((L1.J1() & a10) != 0) {
                        cVar2 = L1;
                        a1.b bVar = null;
                        while (cVar2 != null) {
                            if (cVar2 instanceof FocusTargetNode) {
                                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 || (k03 = m10.k0()) == null) ? null : k03.o();
        }
        if (!kotlin.jvm.internal.t.b(cVar2, focusTargetNode)) {
            throw new IllegalStateException("Non child node cannot request focus.".toString());
        }
        int i11 = a.f2198b[focusTargetNode.o2().ordinal()];
        if (i11 == 1) {
            boolean d10 = d(focusTargetNode2);
            if (!d10) {
                return d10;
            }
            focusTargetNode.u2(q1.m.ActiveParent);
            return d10;
        }
        if (i11 != 2) {
            if (i11 == 3) {
                n(focusTargetNode);
                if (b(focusTargetNode, false, false, 3, null) && d(focusTargetNode2)) {
                    return true;
                }
            } else {
                if (i11 != 4) {
                    throw new rm.t();
                }
                int a11 = b1.a(UserMetadata.MAX_ATTRIBUTE_SIZE);
                if (!focusTargetNode.P0().O1()) {
                    throw new IllegalStateException("visitAncestors called on an unattached node".toString());
                }
                i.c L12 = focusTargetNode.P0().L1();
                g0 m11 = j2.k.m(focusTargetNode);
                loop4: while (true) {
                    if (m11 == null) {
                        break;
                    }
                    if ((m11.k0().k().E1() & a11) != 0) {
                        while (L12 != null) {
                            if ((L12.J1() & a11) != 0) {
                                i.c cVar3 = L12;
                                a1.b bVar2 = null;
                                while (cVar3 != null) {
                                    if (cVar3 instanceof FocusTargetNode) {
                                        cVar = cVar3;
                                        break loop4;
                                    }
                                    if (((cVar3.J1() & a11) != 0) && (cVar3 instanceof j2.m)) {
                                        int i12 = 0;
                                        for (i.c i23 = ((j2.m) cVar3).i2(); i23 != null; i23 = i23.F1()) {
                                            if ((i23.J1() & a11) != 0) {
                                                i12++;
                                                if (i12 == 1) {
                                                    cVar3 = i23;
                                                } else {
                                                    if (bVar2 == null) {
                                                        bVar2 = new a1.b(new i.c[16], 0);
                                                    }
                                                    if (cVar3 != null) {
                                                        bVar2.c(cVar3);
                                                        cVar3 = null;
                                                    }
                                                    bVar2.c(i23);
                                                }
                                            }
                                        }
                                        if (i12 == 1) {
                                        }
                                    }
                                    cVar3 = j2.k.g(bVar2);
                                }
                            }
                            L12 = L12.L1();
                        }
                    }
                    m11 = m11.o0();
                    L12 = (m11 == null || (k02 = m11.k0()) == null) ? null : k02.o();
                }
                FocusTargetNode focusTargetNode3 = (FocusTargetNode) cVar;
                if (focusTargetNode3 == null && m(focusTargetNode)) {
                    boolean d11 = d(focusTargetNode2);
                    if (!d11) {
                        return d11;
                    }
                    focusTargetNode.u2(q1.m.ActiveParent);
                    return d11;
                }
                if (focusTargetNode3 != null && l(focusTargetNode3, focusTargetNode)) {
                    boolean l10 = l(focusTargetNode, focusTargetNode2);
                    if (!(focusTargetNode.o2() == q1.m.ActiveParent)) {
                        throw new IllegalStateException("Deactivated node is focused".toString());
                    }
                    if (l10) {
                        q1.c.c(focusTargetNode3);
                    }
                    return l10;
                }
            }
        }
        return false;
    }

    private static final boolean m(FocusTargetNode focusTargetNode) {
        return j2.k.n(focusTargetNode).getFocusOwner().b(null, null);
    }

    private static final FocusTargetNode n(FocusTargetNode focusTargetNode) {
        FocusTargetNode f10 = r.f(focusTargetNode);
        if (f10 != null) {
            return f10;
        }
        throw new IllegalArgumentException("ActiveParent with no focused child".toString());
    }
}
