package androidx.navigation;

import Y4.c0;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.Log;
import androidx.lifecycle.C1104m;
import androidx.lifecycle.EnumC1108q;
import androidx.lifecycle.InterfaceC1113w;
import j2.C2322C;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.ListIterator;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantLock;
import n2.AbstractC2612c;
import x4.AbstractC3251q;
import x4.AbstractC3252r;
import x4.AbstractC3253s;
import x4.AbstractC3257w;
import x4.C3249o;

/* JADX INFO: loaded from: classes.dex */
public final class H {

    /* JADX INFO: renamed from: A, reason: collision with root package name */
    public int f12664A;

    /* JADX INFO: renamed from: B, reason: collision with root package name */
    public final ArrayList f12665B;

    /* JADX INFO: renamed from: C, reason: collision with root package name */
    public final Y4.N f12666C;

    /* JADX INFO: renamed from: D, reason: collision with root package name */
    public final Y4.I f12667D;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final Context f12668a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final Activity f12669b;

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

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

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public Parcelable[] f12672e;

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

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final C3249o f12674g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final c0 f12675h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public final c0 f12676i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final Y4.J f12677j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public final LinkedHashMap f12678k;
    public final LinkedHashMap l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public final LinkedHashMap f12679m;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public final LinkedHashMap f12680n;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public InterfaceC1113w f12681o;

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    public NavControllerViewModel f12682p;

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public final CopyOnWriteArrayList f12683q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public EnumC1108q f12684r;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public final C1104m f12685s;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public final androidx.fragment.app.X f12686t;

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public final boolean f12687u;

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    public final Y f12688v;

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    public final LinkedHashMap f12689w;

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    public kotlin.jvm.internal.p f12690x;

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    public C1140o f12691y;

    /* JADX INFO: renamed from: z, reason: collision with root package name */
    public final LinkedHashMap f12692z;

    public H(Context context) {
        Object next;
        kotlin.jvm.internal.o.h(context, "context");
        this.f12668a = context;
        Iterator it = R4.n.a0(C1127b.f12737c, context).iterator();
        while (true) {
            if (!it.hasNext()) {
                next = null;
                break;
            } else {
                next = it.next();
                if (((Context) next) instanceof Activity) {
                    break;
                }
            }
        }
        this.f12669b = (Activity) next;
        this.f12674g = new C3249o();
        x4.y yVar = x4.y.f26065a;
        this.f12675h = Y4.O.c(yVar);
        c0 c0VarC = Y4.O.c(yVar);
        this.f12676i = c0VarC;
        this.f12677j = new Y4.J(c0VarC);
        this.f12678k = new LinkedHashMap();
        this.l = new LinkedHashMap();
        this.f12679m = new LinkedHashMap();
        this.f12680n = new LinkedHashMap();
        this.f12683q = new CopyOnWriteArrayList();
        this.f12684r = EnumC1108q.f12181b;
        this.f12685s = new C1104m(this, 1);
        this.f12686t = new androidx.fragment.app.X(this, 1);
        this.f12687u = true;
        Y y6 = new Y();
        this.f12688v = y6;
        this.f12689w = new LinkedHashMap();
        this.f12692z = new LinkedHashMap();
        y6.a(new G(y6));
        y6.a(new C1128c(this.f12668a));
        this.f12665B = new ArrayList();
        m1.g.k(new r(this, 0));
        Y4.N nA = Y4.O.a((1 & 1) != 0 ? 0 : 1, (1 & 2) == 0 ? 16 : 0, X4.a.f8641b);
        this.f12666C = nA;
        this.f12667D = new Y4.I(nA);
    }

    public static B e(B b5, int i6, boolean z6, B b6) {
        E e6;
        if (b5.f12644f == i6 && (b6 == null || (b5.equals(b6) && kotlin.jvm.internal.o.c(b5.f12640b, b6.f12640b)))) {
            return b5;
        }
        if (b5 instanceof E) {
            e6 = (E) b5;
        } else {
            e6 = b5.f12640b;
            kotlin.jvm.internal.o.e(e6);
        }
        return e6.l(i6, e6, z6, b6);
    }

    public static void n(H h5, String route, K k6, int i6) {
        if ((i6 & 2) != 0) {
            k6 = null;
        }
        h5.getClass();
        kotlin.jvm.internal.o.h(route, "route");
        if (h5.f12670c == null) {
            throw new IllegalArgumentException(("Cannot navigate to " + route + ". Navigation graph has not been set for NavController " + h5 + '.').toString());
        }
        E eJ = h5.j(h5.f12674g);
        C1150z c1150zN = eJ.n(route, true, eJ);
        if (c1150zN == null) {
            StringBuilder sbS = com.google.android.recaptcha.internal.a.s("Navigation destination that matches route ", route, " cannot be found in the navigation graph ");
            sbS.append(h5.f12670c);
            throw new IllegalArgumentException(sbS.toString());
        }
        B b5 = c1150zN.f12815a;
        Bundle bundleG = b5.g(c1150zN.f12816b);
        if (bundleG == null) {
            bundleG = new Bundle();
        }
        Intent intent = new Intent();
        int i7 = B.l;
        String str = b5.f12645j;
        Uri uri = Uri.parse(str != null ? "android-app://androidx.navigation/".concat(str) : "");
        kotlin.jvm.internal.o.d(uri);
        intent.setDataAndType(uri, null);
        intent.setAction(null);
        bundleG.putParcelable("android-support-nav:controller:deepLinkIntent", intent);
        h5.l(b5, bundleG, k6);
    }

    public static /* synthetic */ void s(H h5, C1137l c1137l) {
        h5.r(c1137l, false, new C3249o());
    }

    public final void a(B b5, Bundle bundle, C1137l c1137l, List list) {
        Object objPrevious;
        Object objPrevious2;
        B b6 = c1137l.f12757b;
        boolean z6 = b6 instanceof InterfaceC1129d;
        C3249o c3249o = this.f12674g;
        if (!z6) {
            while (!c3249o.isEmpty() && (((C1137l) c3249o.last()).f12757b instanceof InterfaceC1129d) && q(true, ((C1137l) c3249o.last()).f12757b.f12644f, false)) {
            }
        }
        C3249o<C1137l> c3249o2 = new C3249o();
        boolean z7 = b5 instanceof E;
        Context context = this.f12668a;
        Object obj = null;
        if (z7) {
            B b7 = b6;
            do {
                kotlin.jvm.internal.o.e(b7);
                b7 = b7.f12640b;
                if (b7 != null) {
                    ListIterator listIterator = list.listIterator(list.size());
                    while (true) {
                        if (listIterator.hasPrevious()) {
                            objPrevious2 = listIterator.previous();
                            if (kotlin.jvm.internal.o.c(((C1137l) objPrevious2).f12757b, b7)) {
                                break;
                            }
                        } else {
                            objPrevious2 = null;
                            break;
                        }
                    }
                    C1137l c1137lJ = (C1137l) objPrevious2;
                    if (c1137lJ == null) {
                        c1137lJ = C1134i.j(context, b7, bundle, i(), this.f12682p);
                    }
                    c3249o2.addFirst(c1137lJ);
                    if (!c3249o.isEmpty() && ((C1137l) c3249o.last()).f12757b == b7) {
                        s(this, (C1137l) c3249o.last());
                    }
                }
                if (b7 == null) {
                    break;
                }
            } while (b7 != b5);
        }
        B b8 = c3249o2.isEmpty() ? b6 : ((C1137l) c3249o2.first()).f12757b;
        while (b8 != null && d(b8.f12644f, b8) != b8) {
            b8 = b8.f12640b;
            if (b8 != null) {
                Bundle bundle2 = (bundle == null || !bundle.isEmpty()) ? bundle : null;
                ListIterator listIterator2 = list.listIterator(list.size());
                while (true) {
                    if (listIterator2.hasPrevious()) {
                        objPrevious = listIterator2.previous();
                        if (kotlin.jvm.internal.o.c(((C1137l) objPrevious).f12757b, b8)) {
                            break;
                        }
                    } else {
                        objPrevious = null;
                        break;
                    }
                }
                C1137l c1137lJ2 = (C1137l) objPrevious;
                if (c1137lJ2 == null) {
                    c1137lJ2 = C1134i.j(context, b8, b8.g(bundle2), i(), this.f12682p);
                }
                c3249o2.addFirst(c1137lJ2);
            }
        }
        if (!c3249o2.isEmpty()) {
            b6 = ((C1137l) c3249o2.first()).f12757b;
        }
        while (!c3249o.isEmpty() && (((C1137l) c3249o.last()).f12757b instanceof E)) {
            B b9 = ((C1137l) c3249o.last()).f12757b;
            kotlin.jvm.internal.o.f(b9, "null cannot be cast to non-null type androidx.navigation.NavGraph");
            if (((E) b9).f12656m.b(b6.f12644f) != null) {
                break;
            } else {
                s(this, (C1137l) c3249o.last());
            }
        }
        C1137l c1137l2 = (C1137l) c3249o.j();
        if (c1137l2 == null) {
            c1137l2 = (C1137l) c3249o2.j();
        }
        if (!kotlin.jvm.internal.o.c(c1137l2 != null ? c1137l2.f12757b : null, this.f12670c)) {
            ListIterator listIterator3 = list.listIterator(list.size());
            while (true) {
                if (!listIterator3.hasPrevious()) {
                    break;
                }
                Object objPrevious3 = listIterator3.previous();
                B b10 = ((C1137l) objPrevious3).f12757b;
                E e6 = this.f12670c;
                kotlin.jvm.internal.o.e(e6);
                if (kotlin.jvm.internal.o.c(b10, e6)) {
                    obj = objPrevious3;
                    break;
                }
            }
            C1137l c1137lJ3 = (C1137l) obj;
            if (c1137lJ3 == null) {
                E e7 = this.f12670c;
                kotlin.jvm.internal.o.e(e7);
                E e8 = this.f12670c;
                kotlin.jvm.internal.o.e(e8);
                c1137lJ3 = C1134i.j(context, e7, e8.g(bundle), i(), this.f12682p);
            }
            c3249o2.addFirst(c1137lJ3);
        }
        for (C1137l c1137l3 : c3249o2) {
            Object obj2 = this.f12689w.get(this.f12688v.b(c1137l3.f12757b.f12639a));
            if (obj2 == null) {
                throw new IllegalStateException(com.google.android.recaptcha.internal.a.n(new StringBuilder("NavigatorBackStack for "), b5.f12639a, " should already be created").toString());
            }
            ((C1139n) obj2).a(c1137l3);
        }
        c3249o.addAll(c3249o2);
        c3249o.addLast(c1137l);
        for (C1137l c1137l4 : AbstractC3251q.t0(c3249o2, c1137l)) {
            E e9 = c1137l4.f12757b.f12640b;
            if (e9 != null) {
                k(c1137l4, f(e9.f12644f));
            }
        }
    }

    public final boolean b() {
        C3249o c3249o;
        while (true) {
            c3249o = this.f12674g;
            if (c3249o.isEmpty() || !(((C1137l) c3249o.last()).f12757b instanceof E)) {
                break;
            }
            s(this, (C1137l) c3249o.last());
        }
        C1137l c1137l = (C1137l) c3249o.l();
        ArrayList arrayList = this.f12665B;
        if (c1137l != null) {
            arrayList.add(c1137l);
        }
        this.f12664A++;
        w();
        int i6 = this.f12664A - 1;
        this.f12664A = i6;
        if (i6 == 0) {
            ArrayList<C1137l> arrayListE0 = AbstractC3251q.E0(arrayList);
            arrayList.clear();
            for (C1137l c1137l2 : arrayListE0) {
                Iterator it = this.f12683q.iterator();
                if (it.hasNext()) {
                    if (it.next() != null) {
                        throw new ClassCastException();
                    }
                    B b5 = c1137l2.f12757b;
                    c1137l2.a();
                    throw null;
                }
                this.f12666C.c(c1137l2);
            }
            ArrayList arrayListE02 = AbstractC3251q.E0(c3249o);
            c0 c0Var = this.f12675h;
            c0Var.getClass();
            c0Var.k(null, arrayListE02);
            ArrayList arrayListT = t();
            c0 c0Var2 = this.f12676i;
            c0Var2.getClass();
            c0Var2.k(null, arrayListT);
        }
        return c1137l != null;
    }

    public final boolean c(ArrayList arrayList, B b5, boolean z6, boolean z7) {
        H h5;
        boolean z8;
        String str;
        kotlin.jvm.internal.y yVar = new kotlin.jvm.internal.y();
        C3249o c3249o = new C3249o();
        Iterator it = arrayList.iterator();
        while (true) {
            if (!it.hasNext()) {
                h5 = this;
                z8 = z7;
                break;
            }
            X x6 = (X) it.next();
            kotlin.jvm.internal.y yVar2 = new kotlin.jvm.internal.y();
            C1137l c1137l = (C1137l) this.f12674g.last();
            h5 = this;
            z8 = z7;
            h5.f12691y = new C1140o(yVar2, yVar, h5, z8, c3249o);
            x6.e(c1137l, z8);
            h5.f12691y = null;
            if (!yVar2.f20130a) {
                break;
            }
            z7 = z8;
        }
        if (z8) {
            LinkedHashMap linkedHashMap = h5.f12679m;
            if (!z6) {
                R4.f fVar = new R4.f(new R4.j(R4.n.a0(C1127b.f12739e, b5), new C1141p(this, 0)));
                while (fVar.hasNext()) {
                    Integer numValueOf = Integer.valueOf(((B) fVar.next()).f12644f);
                    C1138m c1138m = (C1138m) c3249o.j();
                    linkedHashMap.put(numValueOf, c1138m != null ? c1138m.f12767a : null);
                }
            }
            if (!c3249o.isEmpty()) {
                C1138m c1138m2 = (C1138m) c3249o.first();
                R4.f fVar2 = new R4.f(new R4.j(R4.n.a0(C1127b.f12740f, d(c1138m2.f12768b, null)), new C1141p(this, 1)));
                while (true) {
                    boolean zHasNext = fVar2.hasNext();
                    str = c1138m2.f12767a;
                    if (!zHasNext) {
                        break;
                    }
                    linkedHashMap.put(Integer.valueOf(((B) fVar2.next()).f12644f), str);
                }
                if (linkedHashMap.values().contains(str)) {
                    h5.f12680n.put(str, c3249o);
                }
            }
        }
        x();
        return yVar.f20130a;
    }

    public final B d(int i6, B b5) {
        B b6;
        E e6 = this.f12670c;
        if (e6 == null) {
            return null;
        }
        if (e6.f12644f == i6) {
            if (b5 == null) {
                return e6;
            }
            if (kotlin.jvm.internal.o.c(e6, b5) && b5.f12640b == null) {
                return this.f12670c;
            }
        }
        C1137l c1137l = (C1137l) this.f12674g.l();
        if (c1137l == null || (b6 = c1137l.f12757b) == null) {
            b6 = this.f12670c;
            kotlin.jvm.internal.o.e(b6);
        }
        return e(b6, i6, false, b5);
    }

    public final C1137l f(int i6) {
        Object objPrevious;
        C3249o c3249o = this.f12674g;
        ListIterator<E> listIterator = c3249o.listIterator(c3249o.size());
        while (true) {
            if (!listIterator.hasPrevious()) {
                objPrevious = null;
                break;
            }
            objPrevious = listIterator.previous();
            if (((C1137l) objPrevious).f12757b.f12644f == i6) {
                break;
            }
        }
        C1137l c1137l = (C1137l) objPrevious;
        if (c1137l != null) {
            return c1137l;
        }
        StringBuilder sbR = com.google.android.recaptcha.internal.a.r(i6, "No destination with ID ", " is on the NavController's back stack. The current destination is ");
        sbR.append(g());
        throw new IllegalArgumentException(sbR.toString().toString());
    }

    public final B g() {
        C1137l c1137l = (C1137l) this.f12674g.l();
        if (c1137l != null) {
            return c1137l.f12757b;
        }
        return null;
    }

    public final E h() {
        E e6 = this.f12670c;
        if (e6 == null) {
            throw new IllegalStateException("You must call setGraph() before calling getGraph()");
        }
        kotlin.jvm.internal.o.f(e6, "null cannot be cast to non-null type androidx.navigation.NavGraph");
        return e6;
    }

    public final EnumC1108q i() {
        return this.f12681o == null ? EnumC1108q.f12182c : this.f12684r;
    }

    public final E j(C3249o c3249o) {
        B b5;
        C1137l c1137l = (C1137l) c3249o.l();
        if (c1137l == null || (b5 = c1137l.f12757b) == null) {
            b5 = this.f12670c;
            kotlin.jvm.internal.o.e(b5);
        }
        if (b5 instanceof E) {
            return (E) b5;
        }
        E e6 = b5.f12640b;
        kotlin.jvm.internal.o.e(e6);
        return e6;
    }

    public final void k(C1137l c1137l, C1137l c1137l2) {
        this.f12678k.put(c1137l, c1137l2);
        LinkedHashMap linkedHashMap = this.l;
        if (linkedHashMap.get(c1137l2) == null) {
            linkedHashMap.put(c1137l2, new AtomicInteger(0));
        }
        Object obj = linkedHashMap.get(c1137l2);
        kotlin.jvm.internal.o.e(obj);
        ((AtomicInteger) obj).incrementAndGet();
    }

    /* JADX WARN: Removed duplicated region for block: B:14:0x0040  */
    /* JADX WARN: Removed duplicated region for block: B:52:0x0101  */
    /* JADX WARN: Removed duplicated region for block: B:87:0x01f0  */
    /* JADX WARN: Removed duplicated region for block: B:89:0x01f5  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void l(B b5, Bundle bundle, K k6) {
        boolean zQ;
        LinkedHashMap linkedHashMap;
        boolean z6;
        int iNextIndex;
        B b6;
        int iNextIndex2;
        LinkedHashMap linkedHashMap2 = this.f12689w;
        Iterator it = linkedHashMap2.values().iterator();
        while (it.hasNext()) {
            ((C1139n) it.next()).f12774d = true;
        }
        kotlin.jvm.internal.y yVar = new kotlin.jvm.internal.y();
        if (k6 != null) {
            String str = k6.f12706h;
            boolean z7 = k6.f12703e;
            boolean z8 = k6.f12702d;
            if (str != null) {
                zQ = p(str, z8, z7);
            } else {
                int i6 = k6.f12701c;
                zQ = i6 != -1 ? q(z8, i6, z7) : false;
            }
        }
        Bundle bundleG = b5.g(bundle);
        if (k6 != null && k6.f12700b && this.f12679m.containsKey(Integer.valueOf(b5.f12644f))) {
            yVar.f20130a = u(b5.f12644f, bundleG, k6);
            linkedHashMap = linkedHashMap2;
            z6 = false;
        } else {
            Y y6 = this.f12688v;
            if (k6 == null || !k6.f12699a) {
                linkedHashMap = linkedHashMap2;
                z6 = false;
                if (!z6) {
                    C1137l c1137lJ = C1134i.j(this.f12668a, b5, bundleG, i(), this.f12682p);
                    X xB = y6.b(b5.f12639a);
                    List listQ = AbstractC2612c.q(c1137lJ);
                    this.f12690x = new C2322C(yVar, this, b5, bundleG);
                    xB.d(listQ, k6);
                    this.f12690x = null;
                }
            } else {
                C3249o c3249o = this.f12674g;
                C1137l c1137l = (C1137l) c3249o.l();
                ListIterator listIterator = c3249o.listIterator(c3249o.size());
                while (true) {
                    if (listIterator.hasPrevious()) {
                        if (((C1137l) listIterator.previous()).f12757b == b5) {
                            iNextIndex = listIterator.nextIndex();
                            break;
                        }
                    } else {
                        iNextIndex = -1;
                        break;
                    }
                }
                if (iNextIndex != -1) {
                    if (b5 instanceof E) {
                        int i7 = E.f12655q;
                        List listD0 = R4.n.d0(R4.n.b0(R4.n.a0(C1127b.l, (E) b5), C1127b.f12741j));
                        if (c3249o.size() - iNextIndex == listD0.size()) {
                            List listSubList = c3249o.subList(iNextIndex, c3249o.size());
                            ArrayList arrayList = new ArrayList(AbstractC3253s.G(listSubList, 10));
                            Iterator it2 = listSubList.iterator();
                            while (it2.hasNext()) {
                                arrayList.add(Integer.valueOf(((C1137l) it2.next()).f12757b.f12644f));
                            }
                            if (arrayList.equals(listD0)) {
                                C3249o<C1137l> c3249o2 = new C3249o();
                                while (AbstractC3252r.A(c3249o) >= iNextIndex) {
                                    C1137l c1137l2 = (C1137l) AbstractC3257w.U(c3249o);
                                    v(c1137l2);
                                    C1137l c1137l3 = new C1137l(c1137l2.f12756a, c1137l2.f12757b, c1137l2.f12757b.g(bundle), c1137l2.f12759d, c1137l2.f12760e, c1137l2.f12761f, c1137l2.f12762j);
                                    c1137l3.f12759d = c1137l2.f12759d;
                                    c1137l3.b(c1137l2.f12765n);
                                    c3249o2.addFirst(c1137l3);
                                    linkedHashMap2 = linkedHashMap2;
                                }
                                linkedHashMap = linkedHashMap2;
                                for (C1137l c1137l4 : c3249o2) {
                                    E e6 = c1137l4.f12757b.f12640b;
                                    if (e6 != null) {
                                        k(c1137l4, f(e6.f12644f));
                                    }
                                    c3249o.addLast(c1137l4);
                                }
                                for (C1137l c1137l5 : c3249o2) {
                                    X xB2 = y6.b(c1137l5.f12757b.f12639a);
                                    B b7 = c1137l5.f12757b;
                                    if (b7 == null) {
                                        b7 = null;
                                    }
                                    if (b7 != null) {
                                        AbstractC1131f.f(C1127b.f12743m);
                                        xB2.c(b7);
                                        C1139n c1139nB = xB2.b();
                                        ReentrantLock reentrantLock = c1139nB.f12771a;
                                        reentrantLock.lock();
                                        try {
                                            ArrayList arrayListE0 = AbstractC3251q.E0((Collection) ((c0) c1139nB.f12775e.f8871a).getValue());
                                            ListIterator listIterator2 = arrayListE0.listIterator(arrayListE0.size());
                                            while (true) {
                                                if (listIterator2.hasPrevious()) {
                                                    if (kotlin.jvm.internal.o.c(((C1137l) listIterator2.previous()).f12761f, c1137l5.f12761f)) {
                                                        iNextIndex2 = listIterator2.nextIndex();
                                                        break;
                                                    }
                                                } else {
                                                    iNextIndex2 = -1;
                                                    break;
                                                }
                                            }
                                            arrayListE0.set(iNextIndex2, c1137l5);
                                            c0 c0Var = c1139nB.f12772b;
                                            c0Var.getClass();
                                            c0Var.k(null, arrayListE0);
                                            reentrantLock.unlock();
                                        } catch (Throwable th) {
                                            reentrantLock.unlock();
                                            throw th;
                                        }
                                    }
                                }
                                z6 = true;
                            }
                        }
                        linkedHashMap = linkedHashMap2;
                        z6 = false;
                    } else if (c1137l == null || (b6 = c1137l.f12757b) == null || b5.f12644f != b6.f12644f) {
                    }
                    if (!z6) {
                    }
                }
            }
        }
        x();
        Iterator it3 = linkedHashMap.values().iterator();
        while (it3.hasNext()) {
            ((C1139n) it3.next()).f12774d = false;
        }
        if (zQ || yVar.f20130a || z6) {
            b();
        } else {
            w();
        }
    }

    public final void m(String route, J4.c cVar) {
        kotlin.jvm.internal.o.h(route, "route");
        n(this, route, AbstractC1131f.f(cVar), 4);
    }

    public final boolean o() {
        if (!this.f12674g.isEmpty()) {
            B bG = g();
            kotlin.jvm.internal.o.e(bG);
            if (q(true, bG.f12644f, false) && b()) {
                return true;
            }
        }
        return false;
    }

    /* JADX WARN: Removed duplicated region for block: B:48:0x00ca  */
    /* JADX WARN: Removed duplicated region for block: B:51:0x00da A[LOOP:0: B:6:0x001d->B:51:0x00da, LOOP_END] */
    /* JADX WARN: Removed duplicated region for block: B:63:0x00e1 A[EDGE_INSN: B:63:0x00e1->B:53:0x00e1 BREAK  A[LOOP:0: B:6:0x001d->B:51:0x00da], SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final boolean p(String route, boolean z6, boolean z7) {
        boolean z8;
        Object objPrevious;
        Object objA;
        Object objA2;
        C3249o c3249o = this.f12674g;
        boolean z9 = false;
        if (c3249o.isEmpty()) {
            return false;
        }
        ArrayList arrayList = new ArrayList();
        ListIterator listIterator = c3249o.listIterator(c3249o.size());
        while (true) {
            if (!listIterator.hasPrevious()) {
                z8 = z9;
                objPrevious = null;
                break;
            }
            objPrevious = listIterator.previous();
            C1137l c1137l = (C1137l) objPrevious;
            B b5 = c1137l.f12757b;
            Bundle bundleA = c1137l.a();
            b5.getClass();
            kotlin.jvm.internal.o.h(route, "route");
            boolean z10 = true;
            if (kotlin.jvm.internal.o.c(b5.f12645j, route)) {
                z8 = z9;
                if (!z6) {
                    arrayList.add(this.f12688v.b(c1137l.f12757b.f12639a));
                    if (!z10) {
                    }
                }
            } else {
                C1150z c1150zJ = b5.j(route);
                if (b5.equals(c1150zJ != null ? c1150zJ.f12815a : null)) {
                    if (bundleA != null) {
                        Bundle bundle = c1150zJ.f12816b;
                        if (bundle == null) {
                            z8 = z9;
                        } else {
                            Set<String> setKeySet = bundle.keySet();
                            kotlin.jvm.internal.o.g(setKeySet, "matchingArgs.keySet()");
                            for (String key : setKeySet) {
                                if (bundleA.containsKey(key)) {
                                    C1132g c1132g = (C1132g) c1150zJ.f12815a.f12643e.get(key);
                                    U u6 = c1132g != null ? c1132g.f12748a : null;
                                    z8 = z9;
                                    if (u6 != null) {
                                        kotlin.jvm.internal.o.g(key, "key");
                                        objA = u6.a(bundle, key);
                                    } else {
                                        objA = null;
                                    }
                                    if (u6 != null) {
                                        kotlin.jvm.internal.o.g(key, "key");
                                        objA2 = u6.a(bundleA, key);
                                    } else {
                                        objA2 = null;
                                    }
                                    if (u6 == null || u6.f(objA, objA2)) {
                                        z9 = z8;
                                    }
                                } else {
                                    z8 = z9;
                                }
                            }
                            z8 = z9;
                        }
                    } else {
                        z8 = z9;
                        c1150zJ.getClass();
                    }
                    z10 = z8;
                    break;
                }
                z10 = z9;
                z8 = z10;
                if (!z6 || !z10) {
                    arrayList.add(this.f12688v.b(c1137l.f12757b.f12639a));
                }
                if (!z10) {
                    break;
                }
                z9 = z8;
            }
        }
        C1137l c1137l2 = (C1137l) objPrevious;
        B b6 = c1137l2 != null ? c1137l2.f12757b : null;
        if (b6 != null) {
            return c(arrayList, b6, z6, z7);
        }
        Log.i("NavController", "Ignoring popBackStack to route " + route + " as it was not found on the current back stack");
        return z8;
    }

    public final boolean q(boolean z6, int i6, boolean z7) {
        B b5;
        C3249o c3249o = this.f12674g;
        if (c3249o.isEmpty()) {
            return false;
        }
        ArrayList arrayList = new ArrayList();
        Iterator it = AbstractC3251q.u0(c3249o).iterator();
        while (true) {
            if (!it.hasNext()) {
                b5 = null;
                break;
            }
            b5 = ((C1137l) it.next()).f12757b;
            X xB = this.f12688v.b(b5.f12639a);
            if (z6 || b5.f12644f != i6) {
                arrayList.add(xB);
            }
            if (b5.f12644f == i6) {
                break;
            }
        }
        if (b5 != null) {
            return c(arrayList, b5, z6, z7);
        }
        int i7 = B.l;
        Log.i("NavController", "Ignoring popBackStack to destination " + AbstractC1131f.a(this.f12668a, i6) + " as it was not found on the current back stack");
        return false;
    }

    public final void r(C1137l c1137l, boolean z6, C3249o c3249o) {
        NavControllerViewModel navControllerViewModel;
        Y4.J j4;
        Set set;
        C3249o c3249o2 = this.f12674g;
        C1137l c1137l2 = (C1137l) c3249o2.last();
        if (!kotlin.jvm.internal.o.c(c1137l2, c1137l)) {
            throw new IllegalStateException(("Attempted to pop " + c1137l.f12757b + ", which is not the top of the back stack (" + c1137l2.f12757b + ')').toString());
        }
        AbstractC3257w.U(c3249o2);
        C1139n c1139n = (C1139n) this.f12689w.get(this.f12688v.b(c1137l2.f12757b.f12639a));
        boolean z7 = true;
        if ((c1139n == null || (j4 = c1139n.f12776f) == null || (set = (Set) ((c0) j4.f8871a).getValue()) == null || !set.contains(c1137l2)) && !this.l.containsKey(c1137l2)) {
            z7 = false;
        }
        EnumC1108q enumC1108q = c1137l2.f12763k.f12191c;
        EnumC1108q enumC1108q2 = EnumC1108q.f12182c;
        if (enumC1108q.compareTo(enumC1108q2) >= 0) {
            if (z6) {
                c1137l2.b(enumC1108q2);
                c3249o.addFirst(new C1138m(c1137l2));
            }
            if (z7) {
                c1137l2.b(enumC1108q2);
            } else {
                c1137l2.b(EnumC1108q.f12180a);
                v(c1137l2);
            }
        }
        if (z6 || z7 || (navControllerViewModel = this.f12682p) == null) {
            return;
        }
        navControllerViewModel.clear(c1137l2.f12761f);
    }

    public final ArrayList t() {
        ArrayList arrayList = new ArrayList();
        Iterator it = this.f12689w.values().iterator();
        while (it.hasNext()) {
            Iterable iterable = (Iterable) ((c0) ((C1139n) it.next()).f12776f.f8871a).getValue();
            ArrayList arrayList2 = new ArrayList();
            for (Object obj : iterable) {
                C1137l c1137l = (C1137l) obj;
                if (!arrayList.contains(c1137l) && c1137l.f12765n.compareTo(EnumC1108q.f12183d) < 0) {
                    arrayList2.add(obj);
                }
            }
            AbstractC3257w.L(arrayList2, arrayList);
        }
        ArrayList arrayList3 = new ArrayList();
        for (Object obj2 : this.f12674g) {
            C1137l c1137l2 = (C1137l) obj2;
            if (!arrayList.contains(c1137l2) && c1137l2.f12765n.compareTo(EnumC1108q.f12183d) >= 0) {
                arrayList3.add(obj2);
            }
        }
        AbstractC3257w.L(arrayList3, arrayList);
        ArrayList arrayList4 = new ArrayList();
        for (Object obj3 : arrayList) {
            if (!(((C1137l) obj3).f12757b instanceof E)) {
                arrayList4.add(obj3);
            }
        }
        return arrayList4;
    }

    public final boolean u(int i6, Bundle bundle, K k6) {
        B bH;
        C1137l c1137l;
        B b5;
        int i7 = 0;
        LinkedHashMap linkedHashMap = this.f12679m;
        if (!linkedHashMap.containsKey(Integer.valueOf(i6))) {
            return false;
        }
        String str = (String) linkedHashMap.get(Integer.valueOf(i6));
        AbstractC3257w.Q(linkedHashMap.values(), new C1143s(i7, str));
        C3249o<C1138m> c3249o = (C3249o) kotlin.jvm.internal.F.b(this.f12680n).remove(str);
        ArrayList arrayList = new ArrayList();
        C1137l c1137l2 = (C1137l) this.f12674g.l();
        if (c1137l2 == null || (bH = c1137l2.f12757b) == null) {
            bH = h();
        }
        if (c3249o != null) {
            for (C1138m c1138m : c3249o) {
                B bE = e(bH, c1138m.f12768b, true, null);
                Context context = this.f12668a;
                if (bE == null) {
                    int i8 = B.l;
                    throw new IllegalStateException(("Restore State failed: destination " + AbstractC1131f.a(context, c1138m.f12768b) + " cannot be found from the current destination " + bH).toString());
                }
                arrayList.add(c1138m.a(context, bE, i(), this.f12682p));
                bH = bE;
            }
        }
        ArrayList<List> arrayList2 = new ArrayList();
        ArrayList<C1137l> arrayList3 = new ArrayList();
        for (Object obj : arrayList) {
            if (!(((C1137l) obj).f12757b instanceof E)) {
                arrayList3.add(obj);
            }
        }
        for (C1137l c1137l3 : arrayList3) {
            List list = (List) AbstractC3251q.o0(arrayList2);
            if (kotlin.jvm.internal.o.c((list == null || (c1137l = (C1137l) AbstractC3251q.n0(list)) == null || (b5 = c1137l.f12757b) == null) ? null : b5.f12639a, c1137l3.f12757b.f12639a)) {
                list.add(c1137l3);
            } else {
                arrayList2.add(AbstractC3252r.C(c1137l3));
            }
        }
        kotlin.jvm.internal.y yVar = new kotlin.jvm.internal.y();
        for (List list2 : arrayList2) {
            X xB = this.f12688v.b(((C1137l) AbstractC3251q.e0(list2)).f12757b.f12639a);
            Bundle bundle2 = bundle;
            this.f12690x = new C1142q(yVar, arrayList, new kotlin.jvm.internal.A(), this, bundle2, 0);
            xB.d(list2, k6);
            this.f12690x = null;
            bundle = bundle2;
        }
        return yVar.f20130a;
    }

    public final void v(C1137l child) {
        kotlin.jvm.internal.o.h(child, "child");
        C1137l c1137l = (C1137l) this.f12678k.remove(child);
        if (c1137l == null) {
            return;
        }
        LinkedHashMap linkedHashMap = this.l;
        AtomicInteger atomicInteger = (AtomicInteger) linkedHashMap.get(c1137l);
        Integer numValueOf = atomicInteger != null ? Integer.valueOf(atomicInteger.decrementAndGet()) : null;
        if (numValueOf != null && numValueOf.intValue() == 0) {
            C1139n c1139n = (C1139n) this.f12689w.get(this.f12688v.b(c1137l.f12757b.f12639a));
            if (c1139n != null) {
                c1139n.b(c1137l);
            }
            linkedHashMap.remove(c1137l);
        }
    }

    public final void w() {
        AtomicInteger atomicInteger;
        Y4.J j4;
        Set set;
        ArrayList<C1137l> arrayListE0 = AbstractC3251q.E0(this.f12674g);
        if (arrayListE0.isEmpty()) {
            return;
        }
        B b5 = ((C1137l) AbstractC3251q.n0(arrayListE0)).f12757b;
        ArrayList arrayList = new ArrayList();
        if (b5 instanceof InterfaceC1129d) {
            Iterator it = AbstractC3251q.u0(arrayListE0).iterator();
            while (it.hasNext()) {
                B b6 = ((C1137l) it.next()).f12757b;
                arrayList.add(b6);
                if (!(b6 instanceof InterfaceC1129d) && !(b6 instanceof E)) {
                    break;
                }
            }
        }
        HashMap map = new HashMap();
        for (C1137l c1137l : AbstractC3251q.u0(arrayListE0)) {
            EnumC1108q enumC1108q = c1137l.f12765n;
            B b7 = c1137l.f12757b;
            if (b5 != null && b7.f12644f == b5.f12644f) {
                EnumC1108q enumC1108q2 = EnumC1108q.f12184e;
                if (enumC1108q != enumC1108q2) {
                    C1139n c1139n = (C1139n) this.f12689w.get(this.f12688v.b(b7.f12639a));
                    if (kotlin.jvm.internal.o.c((c1139n == null || (j4 = c1139n.f12776f) == null || (set = (Set) ((c0) j4.f8871a).getValue()) == null) ? null : Boolean.valueOf(set.contains(c1137l)), Boolean.TRUE) || ((atomicInteger = (AtomicInteger) this.l.get(c1137l)) != null && atomicInteger.get() == 0)) {
                        map.put(c1137l, EnumC1108q.f12183d);
                    } else {
                        map.put(c1137l, enumC1108q2);
                    }
                }
                B b8 = (B) AbstractC3251q.g0(arrayList);
                if (b8 != null && b8.f12644f == b7.f12644f) {
                    if (arrayList.isEmpty()) {
                        throw new NoSuchElementException("List is empty.");
                    }
                    arrayList.remove(0);
                }
                b5 = b5.f12640b;
            } else if (arrayList.isEmpty() || b7.f12644f != ((B) AbstractC3251q.e0(arrayList)).f12644f) {
                c1137l.b(EnumC1108q.f12182c);
            } else {
                if (arrayList.isEmpty()) {
                    throw new NoSuchElementException("List is empty.");
                }
                B b9 = (B) arrayList.remove(0);
                if (enumC1108q == EnumC1108q.f12184e) {
                    c1137l.b(EnumC1108q.f12183d);
                } else {
                    EnumC1108q enumC1108q3 = EnumC1108q.f12183d;
                    if (enumC1108q != enumC1108q3) {
                        map.put(c1137l, enumC1108q3);
                    }
                }
                E e6 = b9.f12640b;
                if (e6 != null && !arrayList.contains(e6)) {
                    arrayList.add(e6);
                }
            }
        }
        for (C1137l c1137l2 : arrayListE0) {
            EnumC1108q enumC1108q4 = (EnumC1108q) map.get(c1137l2);
            if (enumC1108q4 != null) {
                c1137l2.b(enumC1108q4);
            } else {
                c1137l2.c();
            }
        }
    }

    /* JADX WARN: Type inference failed for: r0v2, types: [J4.a, kotlin.jvm.internal.l] */
    public final void x() {
        int i6;
        boolean z6 = false;
        if (this.f12687u) {
            C3249o c3249o = this.f12674g;
            if (c3249o == null || !c3249o.isEmpty()) {
                Iterator it = c3249o.iterator();
                i6 = 0;
                while (it.hasNext()) {
                    if (!(((C1137l) it.next()).f12757b instanceof E) && (i6 = i6 + 1) < 0) {
                        throw new ArithmeticException("Count overflow has happened.");
                    }
                }
            } else {
                i6 = 0;
            }
            if (i6 > 1) {
                z6 = true;
            }
        }
        androidx.fragment.app.X x6 = this.f12686t;
        x6.f14498a = z6;
        ?? r02 = x6.f14500c;
        if (r02 != 0) {
            r02.invoke();
        }
    }
}
