package E1;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.Log;
import androidx.lifecycle.EnumC0510o;
import androidx.lifecycle.Z;
import androidx.navigation.fragment.NavHostFragment;
import b7.EnumC0551a;
import c7.C0592C;
import c7.InterfaceC0591B;
import com.google.android.gms.internal.measurement.C1;
import com.google.android.gms.internal.measurement.X1;
import d5.AbstractC0844a;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.ListIterator;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicInteger;
import r.AbstractC1481a;
import v0.AbstractC1664c;

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

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

    /* JADX INFO: renamed from: B, reason: collision with root package name */
    public final A6.k f1995B;

    /* JADX INFO: renamed from: C, reason: collision with root package name */
    public final c7.G f1996C;

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

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

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

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

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

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

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final B6.i f2003g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final c7.K f2004h;
    public final LinkedHashMap i;

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

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

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

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public NavHostFragment f2008m;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public d.x f2009n;

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

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

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public EnumC0510o f2012q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public final C0106m f2013r;

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

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

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

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

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    public P6.h f2018w;

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

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

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

    public F(Context context) {
        Object next;
        this.f1997a = context;
        Iterator it = W6.j.H(context, C0096c.f2065t).iterator();
        while (true) {
            if (!it.hasNext()) {
                next = null;
                break;
            } else {
                next = it.next();
                if (((Context) next) instanceof Activity) {
                    break;
                }
            }
        }
        this.f1998b = (Activity) next;
        this.f2003g = new B6.i();
        this.f2004h = c7.H.b(B6.t.f1032q);
        this.i = new LinkedHashMap();
        this.f2005j = new LinkedHashMap();
        this.f2006k = new LinkedHashMap();
        this.f2007l = new LinkedHashMap();
        this.f2011p = new CopyOnWriteArrayList();
        this.f2012q = EnumC0510o.f8835r;
        int i = 0;
        this.f2013r = new C0106m(i, this);
        this.f2014s = new C0110q(i, this);
        this.f2015t = true;
        T t6 = new T();
        this.f2016u = t6;
        this.f2017v = new LinkedHashMap();
        this.f2020y = new LinkedHashMap();
        t6.a(new E(t6));
        t6.a(new C0097d(this.f1997a));
        this.f1994A = new ArrayList();
        this.f1995B = new A6.k(new A5.f(8, this));
        this.f1996C = c7.H.a(1, EnumC0551a.f9222r);
    }

    public static /* synthetic */ void o(F f3, C0103j c0103j) throws IllegalAccessException, Z6.F, InvocationTargetException {
        f3.n(c0103j, false, new B6.i());
    }

    public final void a(A a3, Bundle bundle, C0103j c0103j, List list) throws IllegalAccessException, Z6.F, InvocationTargetException {
        Object objPrevious;
        Object objPrevious2;
        A a8 = c0103j.f2087r;
        boolean z8 = a8 instanceof InterfaceC0098e;
        int i = 0;
        B6.i iVar = this.f2003g;
        if (!z8) {
            while (!iVar.isEmpty() && (((C0103j) iVar.last()).f2087r instanceof InterfaceC0098e) && m(((C0103j) iVar.last()).f2087r.f1985x, true, false)) {
            }
        }
        B6.i<C0103j> iVar2 = new B6.i();
        boolean z9 = a3 instanceof D;
        Context context = this.f1997a;
        Object obj = null;
        if (z9) {
            A a9 = a8;
            do {
                P6.g.b(a9);
                a9 = a9.f1979r;
                if (a9 != null) {
                    ListIterator listIterator = list.listIterator(list.size());
                    while (true) {
                        if (listIterator.hasPrevious()) {
                            objPrevious2 = listIterator.previous();
                            if (P6.g.a(((C0103j) objPrevious2).f2087r, a9)) {
                                break;
                            }
                        } else {
                            objPrevious2 = null;
                            break;
                        }
                    }
                    C0103j c0103jO = (C0103j) objPrevious2;
                    if (c0103jO == null) {
                        c0103jO = x3.e.o(context, a9, bundle, f(), this.f2010o);
                    }
                    iVar2.addFirst(c0103jO);
                    if (!iVar.isEmpty() && ((C0103j) iVar.last()).f2087r == a9) {
                        o(this, (C0103j) iVar.last());
                    }
                }
                if (a9 == null) {
                    break;
                }
            } while (a9 != a3);
        }
        A a10 = iVar2.isEmpty() ? a8 : ((C0103j) iVar2.first()).f2087r;
        while (a10 != null && c(a10.f1985x) == null) {
            a10 = a10.f1979r;
            if (a10 != null) {
                ListIterator listIterator2 = list.listIterator(list.size());
                while (true) {
                    if (listIterator2.hasPrevious()) {
                        objPrevious = listIterator2.previous();
                        if (P6.g.a(((C0103j) objPrevious).f2087r, a10)) {
                            break;
                        }
                    } else {
                        objPrevious = null;
                        break;
                    }
                }
                C0103j c0103jO2 = (C0103j) objPrevious;
                if (c0103jO2 == null) {
                    c0103jO2 = x3.e.o(context, a10, a10.b(bundle), f(), this.f2010o);
                }
                iVar2.addFirst(c0103jO2);
            }
        }
        if (!iVar2.isEmpty()) {
            a8 = ((C0103j) iVar2.first()).f2087r;
        }
        while (!iVar.isEmpty() && (((C0103j) iVar.last()).f2087r instanceof D) && ((D) ((C0103j) iVar.last()).f2087r).i(a8.f1985x, false) == null) {
            o(this, (C0103j) iVar.last());
        }
        C0103j c0103j2 = (C0103j) (iVar.isEmpty() ? null : iVar.f1027r[iVar.f1026q]);
        if (c0103j2 == null) {
            c0103j2 = (C0103j) (iVar2.isEmpty() ? null : iVar2.f1027r[iVar2.f1026q]);
        }
        if (!P6.g.a(c0103j2 != null ? c0103j2.f2087r : null, this.f1999c)) {
            ListIterator listIterator3 = list.listIterator(list.size());
            while (true) {
                if (!listIterator3.hasPrevious()) {
                    break;
                }
                Object objPrevious3 = listIterator3.previous();
                A a11 = ((C0103j) objPrevious3).f2087r;
                D d8 = this.f1999c;
                P6.g.b(d8);
                if (P6.g.a(a11, d8)) {
                    obj = objPrevious3;
                    break;
                }
            }
            C0103j c0103jO3 = (C0103j) obj;
            if (c0103jO3 == null) {
                D d9 = this.f1999c;
                P6.g.b(d9);
                D d10 = this.f1999c;
                P6.g.b(d10);
                c0103jO3 = x3.e.o(context, d9, d10.b(bundle), f(), this.f2010o);
            }
            iVar2.addFirst(c0103jO3);
        }
        for (C0103j c0103j3 : iVar2) {
            Object obj2 = this.f2017v.get(this.f2016u.b(c0103j3.f2087r.f1978q));
            if (obj2 == null) {
                throw new IllegalStateException(I1.a.r(new StringBuilder("NavigatorBackStack for "), a3.f1978q, " should already be created").toString());
            }
            ((C0107n) obj2).a(c0103j3);
        }
        iVar.addAll(iVar2);
        iVar.addLast(c0103j);
        ArrayList arrayListR0 = B6.k.r0(iVar2, c0103j);
        int size = arrayListR0.size();
        while (i < size) {
            Object obj3 = arrayListR0.get(i);
            i++;
            C0103j c0103j4 = (C0103j) obj3;
            D d11 = c0103j4.f2087r.f1979r;
            if (d11 != null) {
                g(c0103j4, d(d11.f1985x));
            }
        }
    }

    public final boolean b() throws IllegalAccessException, Z6.F, InvocationTargetException {
        B6.i iVar;
        while (true) {
            iVar = this.f2003g;
            if (iVar.isEmpty() || !(((C0103j) iVar.last()).f2087r instanceof D)) {
                break;
            }
            o(this, (C0103j) iVar.last());
        }
        C0103j c0103j = (C0103j) iVar.h();
        ArrayList arrayList = this.f1994A;
        if (c0103j != null) {
            arrayList.add(c0103j);
        }
        this.f2021z++;
        t();
        int i = this.f2021z - 1;
        this.f2021z = i;
        if (i == 0) {
            ArrayList arrayListY0 = B6.k.y0(arrayList);
            arrayList.clear();
            int size = arrayListY0.size();
            int i5 = 0;
            while (i5 < size) {
                Object obj = arrayListY0.get(i5);
                i5++;
                C0103j c0103j2 = (C0103j) obj;
                Iterator it = this.f2011p.iterator();
                if (it.hasNext()) {
                    if (it.next() != null) {
                        throw new ClassCastException();
                    }
                    A a3 = c0103j2.f2087r;
                    throw null;
                }
                this.f1996C.p(c0103j2);
            }
            ArrayList arrayListP = p();
            c7.K k8 = this.f2004h;
            k8.getClass();
            k8.g(null, arrayListP);
        }
        return c0103j != null;
    }

    public final A c(int i) {
        A a3;
        D d8;
        D d9 = this.f1999c;
        if (d9 == null) {
            return null;
        }
        if (d9.f1985x == i) {
            return d9;
        }
        C0103j c0103j = (C0103j) this.f2003g.h();
        if (c0103j == null || (a3 = c0103j.f2087r) == null) {
            a3 = this.f1999c;
            P6.g.b(a3);
        }
        if (a3.f1985x == i) {
            return a3;
        }
        if (a3 instanceof D) {
            d8 = (D) a3;
        } else {
            d8 = a3.f1979r;
            P6.g.b(d8);
        }
        return d8.i(i, true);
    }

    public final C0103j d(int i) {
        Object objPrevious;
        B6.i iVar = this.f2003g;
        ListIterator<E> listIterator = iVar.listIterator(iVar.size());
        while (true) {
            if (!listIterator.hasPrevious()) {
                objPrevious = null;
                break;
            }
            objPrevious = listIterator.previous();
            if (((C0103j) objPrevious).f2087r.f1985x == i) {
                break;
            }
        }
        C0103j c0103j = (C0103j) objPrevious;
        if (c0103j != null) {
            return c0103j;
        }
        StringBuilder sbO = AbstractC0844a.o(i, "No destination with ID ", " is on the NavController's back stack. The current destination is ");
        sbO.append(e());
        throw new IllegalArgumentException(sbO.toString().toString());
    }

    public final A e() {
        C0103j c0103j = (C0103j) this.f2003g.h();
        if (c0103j != null) {
            return c0103j.f2087r;
        }
        return null;
    }

    public final EnumC0510o f() {
        return this.f2008m == null ? EnumC0510o.f8836s : this.f2012q;
    }

    public final void g(C0103j c0103j, C0103j c0103j2) {
        this.i.put(c0103j, c0103j2);
        LinkedHashMap linkedHashMap = this.f2005j;
        if (linkedHashMap.get(c0103j2) == null) {
            linkedHashMap.put(c0103j2, new AtomicInteger(0));
        }
        Object obj = linkedHashMap.get(c0103j2);
        P6.g.b(obj);
        ((AtomicInteger) obj).incrementAndGet();
    }

    public final void h(int i, Bundle bundle) throws IllegalAccessException, Z6.F, InvocationTargetException {
        int i5;
        H h8;
        int i8;
        B6.i iVar = this.f2003g;
        A a3 = iVar.isEmpty() ? this.f1999c : ((C0103j) iVar.last()).f2087r;
        if (a3 == null) {
            throw new IllegalStateException("no current navigation node");
        }
        C0099f c0099fC = a3.c(i);
        Bundle bundle2 = null;
        if (c0099fC != null) {
            h8 = c0099fC.f2076b;
            Bundle bundle3 = c0099fC.f2077c;
            i5 = c0099fC.f2075a;
            if (bundle3 != null) {
                bundle2 = new Bundle();
                bundle2.putAll(bundle3);
            }
        } else {
            i5 = i;
            h8 = null;
        }
        if (bundle != null) {
            if (bundle2 == null) {
                bundle2 = new Bundle();
            }
            bundle2.putAll(bundle);
        }
        if (i5 == 0 && h8 != null && (i8 = h8.f2027c) != -1) {
            l(i8, h8.f2028d);
            return;
        }
        if (i5 == 0) {
            throw new IllegalArgumentException("Destination id == 0 can only be used in conjunction with a valid navOptions.popUpTo");
        }
        A aC = c(i5);
        if (aC != null) {
            i(aC, bundle2, h8);
            return;
        }
        int i9 = A.f1977z;
        Context context = this.f1997a;
        String strS = AbstractC1664c.s(context, i5);
        if (c0099fC == null) {
            throw new IllegalArgumentException("Navigation action/destination " + strS + " cannot be found from the current destination " + a3);
        }
        StringBuilder sbP = AbstractC0844a.p("Navigation destination ", strS, " referenced from action ");
        sbP.append(AbstractC1664c.s(context, i));
        sbP.append(" cannot be found from the current destination ");
        sbP.append(a3);
        throw new IllegalArgumentException(sbP.toString().toString());
    }

    /* JADX WARN: Removed duplicated region for block: B:37:0x00ef A[LOOP:1: B:35:0x00e9->B:37:0x00ef, LOOP_END] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void i(A a3, Bundle bundle, H h8) throws IllegalAccessException, Z6.F, InvocationTargetException {
        A a8;
        boolean z8;
        Iterator it;
        int i;
        LinkedHashMap linkedHashMap = this.f2017v;
        Iterator it2 = linkedHashMap.values().iterator();
        while (it2.hasNext()) {
            ((C0107n) it2.next()).f2106d = true;
        }
        P6.j jVar = new P6.j();
        boolean zM = (h8 == null || (i = h8.f2027c) == -1) ? false : m(i, h8.f2028d, h8.f2029e);
        Bundle bundleB = a3.b(bundle);
        if (h8 != null && h8.f2026b && this.f2006k.containsKey(Integer.valueOf(a3.f1985x))) {
            jVar.f5532q = q(a3.f1985x, bundleB, h8);
        } else {
            B6.i iVar = this.f2003g;
            C0103j c0103j = (C0103j) iVar.h();
            S sB = this.f2016u.b(a3.f1978q);
            if (h8 != null && h8.f2025a && c0103j != null && (a8 = c0103j.f2087r) != null && a3.f1985x == a8.f1985x) {
                s((C0103j) iVar.removeLast());
                C0103j c0103j2 = new C0103j(c0103j.f2086q, c0103j.f2087r, bundleB, c0103j.f2089t, c0103j.f2090u, c0103j.f2091v, c0103j.f2092w);
                c0103j2.f2089t = c0103j.f2089t;
                c0103j2.b(c0103j.f2085B);
                iVar.addLast(c0103j2);
                D d8 = c0103j2.f2087r.f1979r;
                if (d8 != null) {
                    g(c0103j2, d(d8.f1985x));
                }
                sB.f(c0103j2);
                z8 = true;
                u();
                it = linkedHashMap.values().iterator();
                while (it.hasNext()) {
                    ((C0107n) it.next()).f2106d = false;
                }
                if (!zM || jVar.f5532q || z8) {
                    b();
                } else {
                    t();
                    return;
                }
            }
            List listC = C1.C(x3.e.o(this.f1997a, a3, bundleB, f(), this.f2010o));
            this.f2018w = new C0109p(jVar, this, a3, bundleB);
            sB.d(listC, h8);
            this.f2018w = null;
        }
        z8 = false;
        u();
        it = linkedHashMap.values().iterator();
        while (it.hasNext()) {
        }
        if (zM) {
        }
        b();
    }

    public final void j(B b8) {
        h(b8.a(), b8.b());
    }

    public final boolean k() {
        if (this.f2003g.isEmpty()) {
            return false;
        }
        A aE = e();
        P6.g.b(aE);
        return l(aE.f1985x, true);
    }

    public final boolean l(int i, boolean z8) {
        return m(i, z8, false) && b();
    }

    public final boolean m(int i, boolean z8, boolean z9) {
        A a3;
        boolean z10;
        String str;
        int i5 = 1;
        int i8 = 0;
        B6.i iVar = this.f2003g;
        if (iVar.isEmpty()) {
            return false;
        }
        ArrayList arrayList = new ArrayList();
        Iterator it = B6.k.s0(iVar).iterator();
        while (true) {
            if (!it.hasNext()) {
                a3 = null;
                break;
            }
            A a8 = ((C0103j) it.next()).f2087r;
            S sB = this.f2016u.b(a8.f1978q);
            if (z8 || a8.f1985x != i) {
                arrayList.add(sB);
            }
            if (a8.f1985x == i) {
                a3 = a8;
                break;
            }
        }
        if (a3 == null) {
            int i9 = A.f1977z;
            Log.i("NavController", "Ignoring popBackStack to destination " + AbstractC1664c.s(this.f1997a, i) + " as it was not found on the current back stack");
            return false;
        }
        P6.j jVar = new P6.j();
        B6.i iVar2 = new B6.i();
        int size = arrayList.size();
        int i10 = 0;
        while (true) {
            if (i10 >= size) {
                z10 = z9;
                break;
            }
            int i11 = i10 + 1;
            S s8 = (S) arrayList.get(i10);
            P6.j jVar2 = new P6.j();
            C0103j c0103j = (C0103j) iVar.last();
            z10 = z9;
            this.f2019x = new r(jVar2, jVar, this, z10, iVar2);
            s8.i(c0103j, z10);
            this.f2019x = null;
            if (!jVar2.f5532q) {
                break;
            }
            i10 = i11;
        }
        if (z10) {
            LinkedHashMap linkedHashMap = this.f2006k;
            if (!z8) {
                W6.e eVar = new W6.e(new W6.f(W6.j.H(a3, C0096c.f2066u), new C0111s(i8, this)), (byte) 0);
                while (eVar.hasNext()) {
                    Integer numValueOf = Integer.valueOf(((A) eVar.next()).f1985x);
                    C0105l c0105l = (C0105l) (iVar2.isEmpty() ? null : iVar2.f1027r[iVar2.f1026q]);
                    linkedHashMap.put(numValueOf, c0105l != null ? c0105l.f2097q : null);
                }
            }
            if (!iVar2.isEmpty()) {
                C0105l c0105l2 = (C0105l) iVar2.first();
                W6.e eVar2 = new W6.e(new W6.f(W6.j.H(c(c0105l2.f2098r), C0096c.f2067v), new C0111s(i5, this)), (byte) 0);
                while (true) {
                    boolean zHasNext = eVar2.hasNext();
                    str = c0105l2.f2097q;
                    if (!zHasNext) {
                        break;
                    }
                    linkedHashMap.put(Integer.valueOf(((A) eVar2.next()).f1985x), str);
                }
                this.f2007l.put(str, iVar2);
            }
        }
        u();
        return jVar.f5532q;
    }

    public final void n(C0103j c0103j, boolean z8, B6.i iVar) throws IllegalAccessException, Z6.F, InvocationTargetException {
        v vVar;
        C0592C c0592c;
        Set set;
        B6.i iVar2 = this.f2003g;
        C0103j c0103j2 = (C0103j) iVar2.last();
        if (!P6.g.a(c0103j2, c0103j)) {
            throw new IllegalStateException(("Attempted to pop " + c0103j.f2087r + ", which is not the top of the back stack (" + c0103j2.f2087r + ')').toString());
        }
        iVar2.removeLast();
        C0107n c0107n = (C0107n) this.f2017v.get(this.f2016u.b(c0103j2.f2087r.f1978q));
        boolean z9 = true;
        if ((c0107n == null || (c0592c = c0107n.f2108f) == null || (set = (Set) ((c7.K) ((InterfaceC0591B) c0592c.f9369r)).e()) == null || !set.contains(c0103j2)) && !this.f2005j.containsKey(c0103j2)) {
            z9 = false;
        }
        EnumC0510o enumC0510o = c0103j2.f2093x.f8849t;
        EnumC0510o enumC0510o2 = EnumC0510o.f8836s;
        if (enumC0510o.compareTo(enumC0510o2) >= 0) {
            if (z8) {
                c0103j2.b(enumC0510o2);
                iVar.addFirst(new C0105l(c0103j2));
            }
            if (z9) {
                c0103j2.b(enumC0510o2);
            } else {
                c0103j2.b(EnumC0510o.f8834q);
                s(c0103j2);
            }
        }
        if (z8 || z9 || (vVar = this.f2010o) == null) {
            return;
        }
        String str = c0103j2.f2091v;
        P6.g.e(str, "backStackEntryId");
        Z z10 = (Z) vVar.f2135b.remove(str);
        if (z10 != null) {
            z10.a();
        }
    }

    public final ArrayList p() {
        EnumC0510o enumC0510o;
        ArrayList arrayList = new ArrayList();
        Iterator it = this.f2017v.values().iterator();
        while (true) {
            boolean zHasNext = it.hasNext();
            enumC0510o = EnumC0510o.f8837t;
            if (!zHasNext) {
                break;
            }
            Iterable iterable = (Iterable) ((c7.K) ((InterfaceC0591B) ((C0107n) it.next()).f2108f.f9369r)).e();
            ArrayList arrayList2 = new ArrayList();
            for (Object obj : iterable) {
                C0103j c0103j = (C0103j) obj;
                if (!arrayList.contains(c0103j) && c0103j.f2085B.compareTo(enumC0510o) < 0) {
                    arrayList2.add(obj);
                }
            }
            B6.q.d0(arrayList2, arrayList);
        }
        ArrayList arrayList3 = new ArrayList();
        for (Object obj2 : this.f2003g) {
            C0103j c0103j2 = (C0103j) obj2;
            if (!arrayList.contains(c0103j2) && c0103j2.f2085B.compareTo(enumC0510o) >= 0) {
                arrayList3.add(obj2);
            }
        }
        B6.q.d0(arrayList3, arrayList);
        ArrayList arrayList4 = new ArrayList();
        int size = arrayList.size();
        int i = 0;
        while (i < size) {
            Object obj3 = arrayList.get(i);
            i++;
            if (!(((C0103j) obj3).f2087r instanceof D)) {
                arrayList4.add(obj3);
            }
        }
        return arrayList4;
    }

    public final boolean q(int i, Bundle bundle, H h8) {
        A a3;
        C0103j c0103j;
        A a8;
        D d8;
        A aI;
        LinkedHashMap linkedHashMap = this.f2006k;
        int i5 = 0;
        if (!linkedHashMap.containsKey(Integer.valueOf(i))) {
            return false;
        }
        String str = (String) linkedHashMap.get(Integer.valueOf(i));
        Collection collectionValues = linkedHashMap.values();
        P6.g.e(collectionValues, "<this>");
        Iterator it = collectionValues.iterator();
        while (it.hasNext()) {
            if (P6.g.a((String) it.next(), str)) {
                it.remove();
            }
        }
        LinkedHashMap linkedHashMap2 = this.f2007l;
        if ((linkedHashMap2 instanceof Q6.a) && !(linkedHashMap2 instanceof Q6.c)) {
            P6.p.e(linkedHashMap2, "kotlin.collections.MutableMap");
            throw null;
        }
        B6.i<C0105l> iVar = (B6.i) linkedHashMap2.remove(str);
        ArrayList arrayList = new ArrayList();
        C0103j c0103j2 = (C0103j) this.f2003g.h();
        if ((c0103j2 == null || (a3 = c0103j2.f2087r) == null) && (a3 = this.f1999c) == null) {
            throw new IllegalStateException("You must call setGraph() before calling getGraph()");
        }
        if (iVar != null) {
            for (C0105l c0105l : iVar) {
                int i8 = c0105l.f2098r;
                if (a3.f1985x == i8) {
                    aI = a3;
                } else {
                    if (a3 instanceof D) {
                        d8 = (D) a3;
                    } else {
                        d8 = a3.f1979r;
                        P6.g.b(d8);
                    }
                    aI = d8.i(i8, true);
                }
                Context context = this.f1997a;
                if (aI == null) {
                    int i9 = A.f1977z;
                    throw new IllegalStateException(("Restore State failed: destination " + AbstractC1664c.s(context, c0105l.f2098r) + " cannot be found from the current destination " + a3).toString());
                }
                arrayList.add(c0105l.a(context, aI, f(), this.f2010o));
                a3 = aI;
            }
        }
        ArrayList arrayList2 = new ArrayList();
        ArrayList arrayList3 = new ArrayList();
        int size = arrayList.size();
        int i10 = 0;
        while (i10 < size) {
            Object obj = arrayList.get(i10);
            i10++;
            if (!(((C0103j) obj).f2087r instanceof D)) {
                arrayList3.add(obj);
            }
        }
        int size2 = arrayList3.size();
        int i11 = 0;
        while (i11 < size2) {
            Object obj2 = arrayList3.get(i11);
            i11++;
            C0103j c0103j3 = (C0103j) obj2;
            List list = (List) B6.k.o0(arrayList2);
            if (P6.g.a((list == null || (c0103j = (C0103j) B6.k.n0(list)) == null || (a8 = c0103j.f2087r) == null) ? null : a8.f1978q, c0103j3.f2087r.f1978q)) {
                list.add(c0103j3);
            } else {
                arrayList2.add(B6.l.X(c0103j3));
            }
        }
        P6.j jVar = new P6.j();
        int size3 = arrayList2.size();
        while (i5 < size3) {
            Object obj3 = arrayList2.get(i5);
            i5++;
            List list2 = (List) obj3;
            S sB = this.f2016u.b(((C0103j) B6.k.h0(list2)).f2087r.f1978q);
            Bundle bundle2 = bundle;
            this.f2018w = new C0112t(jVar, arrayList, new P6.k(), this, bundle2);
            sB.d(list2, h8);
            this.f2018w = null;
            bundle = bundle2;
        }
        return jVar.f5532q;
    }

    public final void r(D d8, Bundle bundle) throws IllegalAccessException, Z6.F, InvocationTargetException {
        Activity activity;
        Intent intent;
        String strS;
        A aI;
        D d9;
        Bundle bundle2;
        A aI2;
        D d10;
        ArrayList<String> stringArrayList;
        boolean zA = P6.g.a(this.f1999c, d8);
        B6.i iVar = this.f2003g;
        if (zA) {
            q.j jVar = d8.f1990A;
            int iK = jVar.k();
            for (int i = 0; i < iK; i++) {
                A a3 = (A) jVar.l(i);
                D d11 = this.f1999c;
                P6.g.b(d11);
                q.j jVar2 = d11.f1990A;
                if (jVar2.f16191q) {
                    q.h.a(jVar2);
                }
                int iA = AbstractC1481a.a(jVar2.f16194t, i, jVar2.f16192r);
                if (iA >= 0) {
                    Object[] objArr = jVar2.f16193s;
                    Object obj = objArr[iA];
                    objArr[iA] = a3;
                }
                ArrayList arrayList = new ArrayList();
                for (Object obj2 : iVar) {
                    C0103j c0103j = (C0103j) obj2;
                    if (a3 != null && c0103j.f2087r.f1985x == a3.f1985x) {
                        arrayList.add(obj2);
                    }
                }
                int size = arrayList.size();
                int i5 = 0;
                while (i5 < size) {
                    Object obj3 = arrayList.get(i5);
                    i5++;
                    C0103j c0103j2 = (C0103j) obj3;
                    P6.g.d(a3, "newDestination");
                    c0103j2.getClass();
                    c0103j2.f2087r = a3;
                }
            }
            return;
        }
        D d12 = this.f1999c;
        LinkedHashMap linkedHashMap = this.f2017v;
        if (d12 != null) {
            ArrayList arrayList2 = new ArrayList(this.f2006k.keySet());
            int size2 = arrayList2.size();
            int i8 = 0;
            while (i8 < size2) {
                Object obj4 = arrayList2.get(i8);
                i8++;
                Integer num = (Integer) obj4;
                P6.g.d(num, "id");
                int iIntValue = num.intValue();
                Iterator it = linkedHashMap.values().iterator();
                while (it.hasNext()) {
                    ((C0107n) it.next()).f2106d = true;
                }
                boolean zQ = q(iIntValue, null, null);
                Iterator it2 = linkedHashMap.values().iterator();
                while (it2.hasNext()) {
                    ((C0107n) it2.next()).f2106d = false;
                }
                if (zQ) {
                    m(iIntValue, true, false);
                }
            }
            m(d12.f1985x, true, false);
        }
        this.f1999c = d8;
        Bundle bundle3 = this.f2000d;
        T t6 = this.f2016u;
        if (bundle3 != null && (stringArrayList = bundle3.getStringArrayList("android-support-nav:controller:navigatorState:names")) != null) {
            int size3 = stringArrayList.size();
            int i9 = 0;
            while (i9 < size3) {
                String str = stringArrayList.get(i9);
                i9++;
                String str2 = str;
                P6.g.d(str2, "name");
                S sB = t6.b(str2);
                Bundle bundle4 = bundle3.getBundle(str2);
                if (bundle4 != null) {
                    sB.g(bundle4);
                }
            }
        }
        Parcelable[] parcelableArr = this.f2001e;
        Context context = this.f1997a;
        if (parcelableArr != null) {
            for (Parcelable parcelable : parcelableArr) {
                C0105l c0105l = (C0105l) parcelable;
                A aC = c(c0105l.f2098r);
                if (aC == null) {
                    int i10 = A.f1977z;
                    StringBuilder sbP = AbstractC0844a.p("Restoring the Navigation back stack failed: destination ", AbstractC1664c.s(context, c0105l.f2098r), " cannot be found from the current destination ");
                    sbP.append(e());
                    throw new IllegalStateException(sbP.toString());
                }
                C0103j c0103jA = c0105l.a(context, aC, f(), this.f2010o);
                S sB2 = t6.b(aC.f1978q);
                Object c0107n = linkedHashMap.get(sB2);
                if (c0107n == null) {
                    c0107n = new C0107n(this, sB2);
                    linkedHashMap.put(sB2, c0107n);
                }
                iVar.addLast(c0103jA);
                ((C0107n) c0107n).a(c0103jA);
                D d13 = c0103jA.f2087r.f1979r;
                if (d13 != null) {
                    g(c0103jA, d(d13.f1985x));
                }
            }
            u();
            this.f2001e = null;
        }
        Collection collectionValues = B6.w.p0(t6.f2057a).values();
        ArrayList arrayList3 = new ArrayList();
        for (Object obj5 : collectionValues) {
            if (!((S) obj5).f2055b) {
                arrayList3.add(obj5);
            }
        }
        int size4 = arrayList3.size();
        int i11 = 0;
        while (i11 < size4) {
            Object obj6 = arrayList3.get(i11);
            i11++;
            S s8 = (S) obj6;
            Object c0107n2 = linkedHashMap.get(s8);
            if (c0107n2 == null) {
                c0107n2 = new C0107n(this, s8);
                linkedHashMap.put(s8, c0107n2);
            }
            s8.e((C0107n) c0107n2);
        }
        if (this.f1999c == null || !iVar.isEmpty()) {
            b();
            return;
        }
        if (!this.f2002f && (activity = this.f1998b) != null && (intent = activity.getIntent()) != null) {
            Bundle extras = intent.getExtras();
            int[] intArray = extras != null ? extras.getIntArray("android-support-nav:controller:deepLinkIds") : null;
            ArrayList parcelableArrayList = extras != null ? extras.getParcelableArrayList("android-support-nav:controller:deepLinkArgs") : null;
            Bundle bundle5 = new Bundle();
            Bundle bundle6 = extras != null ? extras.getBundle("android-support-nav:controller:deepLinkExtras") : null;
            if (bundle6 != null) {
                bundle5.putAll(bundle6);
            }
            if (intArray == null || intArray.length == 0) {
                D d14 = this.f1999c;
                P6.g.b(d14);
                z zVarF = d14.f(new A1.y(intent));
                if (zVarF != null) {
                    A a8 = zVarF.f2152q;
                    a8.getClass();
                    B6.i iVar2 = new B6.i();
                    A a9 = a8;
                    while (true) {
                        D d15 = a9.f1979r;
                        if (d15 == null || d15.f1991B != a9.f1985x) {
                            iVar2.addFirst(a9);
                        }
                        if (P6.g.a(d15, null) || d15 == null) {
                            break;
                        } else {
                            a9 = d15;
                        }
                    }
                    List listX0 = B6.k.x0(iVar2);
                    ArrayList arrayList4 = new ArrayList(B6.m.a0(listX0));
                    Iterator it3 = listX0.iterator();
                    while (it3.hasNext()) {
                        arrayList4.add(Integer.valueOf(((A) it3.next()).f1985x));
                    }
                    int[] iArr = new int[arrayList4.size()];
                    int size5 = arrayList4.size();
                    int i12 = 0;
                    int i13 = 0;
                    while (i13 < size5) {
                        Object obj7 = arrayList4.get(i13);
                        i13++;
                        iArr[i12] = ((Number) obj7).intValue();
                        i12++;
                    }
                    Bundle bundleB = a8.b(zVarF.f2153r);
                    if (bundleB != null) {
                        bundle5.putAll(bundleB);
                    }
                    intArray = iArr;
                    parcelableArrayList = null;
                }
            }
            if (intArray != null && intArray.length != 0) {
                D d16 = this.f1999c;
                int length = intArray.length;
                int i14 = 0;
                while (true) {
                    if (i14 >= length) {
                        strS = null;
                        break;
                    }
                    int i15 = intArray[i14];
                    if (i14 == 0) {
                        D d17 = this.f1999c;
                        P6.g.b(d17);
                        aI2 = d17.f1985x == i15 ? this.f1999c : null;
                    } else {
                        P6.g.b(d16);
                        aI2 = d16.i(i15, true);
                    }
                    if (aI2 == null) {
                        int i16 = A.f1977z;
                        strS = AbstractC1664c.s(context, i15);
                        break;
                    }
                    if (i14 != intArray.length - 1 && (aI2 instanceof D)) {
                        while (true) {
                            d10 = (D) aI2;
                            P6.g.b(d10);
                            if (!(d10.i(d10.f1991B, true) instanceof D)) {
                                break;
                            } else {
                                aI2 = d10.i(d10.f1991B, true);
                            }
                        }
                        d16 = d10;
                    }
                    i14++;
                }
                if (strS == null) {
                    bundle5.putParcelable("android-support-nav:controller:deepLinkIntent", intent);
                    int length2 = intArray.length;
                    Bundle[] bundleArr = new Bundle[length2];
                    for (int i17 = 0; i17 < length2; i17++) {
                        Bundle bundle7 = new Bundle();
                        bundle7.putAll(bundle5);
                        if (parcelableArrayList != null && (bundle2 = (Bundle) parcelableArrayList.get(i17)) != null) {
                            bundle7.putAll(bundle2);
                        }
                        bundleArr[i17] = bundle7;
                    }
                    int flags = intent.getFlags();
                    int i18 = 268435456 & flags;
                    if (i18 != 0 && (flags & 32768) == 0) {
                        intent.addFlags(32768);
                        ArrayList arrayList5 = new ArrayList();
                        ComponentName component = intent.getComponent();
                        if (component == null) {
                            component = intent.resolveActivity(context.getPackageManager());
                        }
                        if (component != null) {
                            int size6 = arrayList5.size();
                            try {
                                for (Intent intentO = X1.o(context, component); intentO != null; intentO = X1.o(context, intentO.getComponent())) {
                                    arrayList5.add(size6, intentO);
                                }
                            } catch (PackageManager.NameNotFoundException e8) {
                                Log.e("TaskStackBuilder", "Bad ComponentName while traversing activity parent metadata");
                                throw new IllegalArgumentException(e8);
                            }
                        }
                        arrayList5.add(intent);
                        if (arrayList5.isEmpty()) {
                            throw new IllegalStateException("No intents added to TaskStackBuilder; cannot startActivities");
                        }
                        Intent[] intentArr = (Intent[]) arrayList5.toArray(new Intent[0]);
                        intentArr[0] = new Intent(intentArr[0]).addFlags(268484608);
                        context.startActivities(intentArr, null);
                        activity.finish();
                        activity.overridePendingTransition(0, 0);
                        return;
                    }
                    if (i18 != 0) {
                        if (!iVar.isEmpty()) {
                            D d18 = this.f1999c;
                            P6.g.b(d18);
                            m(d18.f1985x, true, false);
                        }
                        int i19 = 0;
                        while (i19 < intArray.length) {
                            int i20 = intArray[i19];
                            int i21 = i19 + 1;
                            Bundle bundle8 = bundleArr[i19];
                            A aC2 = c(i20);
                            if (aC2 == null) {
                                int i22 = A.f1977z;
                                StringBuilder sbP2 = AbstractC0844a.p("Deep Linking failed: destination ", AbstractC1664c.s(context, i20), " cannot be found from the current destination ");
                                sbP2.append(e());
                                throw new IllegalStateException(sbP2.toString());
                            }
                            C0108o c0108o = new C0108o(aC2, 0, this);
                            I i23 = new I();
                            c0108o.b(i23);
                            boolean z8 = i23.f2034b;
                            A7.a aVar = i23.f2033a;
                            i(aC2, bundle8, new H(z8, false, i23.f2035c, false, i23.f2036d, aVar.f460a, aVar.f461b, -1, -1));
                            i19 = i21;
                        }
                        return;
                    }
                    D d19 = this.f1999c;
                    int length3 = intArray.length;
                    for (int i24 = 0; i24 < length3; i24++) {
                        int i25 = intArray[i24];
                        Bundle bundle9 = bundleArr[i24];
                        if (i24 == 0) {
                            aI = this.f1999c;
                        } else {
                            P6.g.b(d19);
                            aI = d19.i(i25, true);
                        }
                        if (aI == null) {
                            int i26 = A.f1977z;
                            throw new IllegalStateException("Deep Linking failed: destination " + AbstractC1664c.s(context, i25) + " cannot be found in graph " + d19);
                        }
                        if (i24 == intArray.length - 1) {
                            D d20 = this.f1999c;
                            P6.g.b(d20);
                            i(aI, bundle9, new H(false, false, d20.f1985x, true, false, 0, 0, -1, -1));
                        } else if (aI instanceof D) {
                            while (true) {
                                d9 = (D) aI;
                                P6.g.b(d9);
                                if (!(d9.i(d9.f1991B, true) instanceof D)) {
                                    break;
                                } else {
                                    aI = d9.i(d9.f1991B, true);
                                }
                            }
                            d19 = d9;
                        }
                    }
                    this.f2002f = true;
                    return;
                }
                Log.i("NavController", "Could not find destination " + strS + " in the navigation graph, ignoring the deep link from " + intent);
            }
        }
        A a10 = this.f1999c;
        P6.g.b(a10);
        i(a10, bundle, null);
    }

    /* JADX WARN: Removed duplicated region for block: B:44:0x00ea  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void s(C0103j c0103j) throws IllegalAccessException, Z6.F, InvocationTargetException {
        v vVar;
        Z z8;
        P6.g.e(c0103j, "child");
        C0103j c0103j2 = (C0103j) this.i.remove(c0103j);
        if (c0103j2 == null) {
            return;
        }
        LinkedHashMap linkedHashMap = this.f2005j;
        AtomicInteger atomicInteger = (AtomicInteger) linkedHashMap.get(c0103j2);
        Integer numValueOf = atomicInteger != null ? Integer.valueOf(atomicInteger.decrementAndGet()) : null;
        if (numValueOf != null && numValueOf.intValue() == 0) {
            C0107n c0107n = (C0107n) this.f2017v.get(this.f2016u.b(c0103j2.f2087r.f1978q));
            if (c0107n != null) {
                F f3 = c0107n.f2110h;
                boolean zA = P6.g.a(f3.f2020y.get(c0103j2), Boolean.TRUE);
                c7.K k8 = c0107n.f2105c;
                Set set = (Set) k8.e();
                P6.g.e(set, "<this>");
                LinkedHashSet linkedHashSet = new LinkedHashSet(B6.w.l0(set.size()));
                boolean z9 = false;
                for (Object obj : set) {
                    boolean z10 = true;
                    if (!z9 && P6.g.a(obj, c0103j2)) {
                        z9 = true;
                        z10 = false;
                    }
                    if (z10) {
                        linkedHashSet.add(obj);
                    }
                }
                k8.g(null, linkedHashSet);
                f3.f2020y.remove(c0103j2);
                B6.i iVar = f3.f2003g;
                boolean zContains = iVar.contains(c0103j2);
                c7.K k9 = f3.f2004h;
                if (!zContains) {
                    f3.s(c0103j2);
                    if (c0103j2.f2093x.f8849t.compareTo(EnumC0510o.f8836s) >= 0) {
                        c0103j2.b(EnumC0510o.f8834q);
                    }
                    boolean zIsEmpty = iVar.isEmpty();
                    String str = c0103j2.f2091v;
                    if (zIsEmpty) {
                        if (!zA && (vVar = f3.f2010o) != null) {
                            P6.g.e(str, "backStackEntryId");
                            z8 = (Z) vVar.f2135b.remove(str);
                            if (z8 != null) {
                                z8.a();
                            }
                        }
                        f3.t();
                        ArrayList arrayListP = f3.p();
                        k9.getClass();
                        k9.g(null, arrayListP);
                    } else {
                        Iterator it = iVar.iterator();
                        while (it.hasNext()) {
                            if (P6.g.a(((C0103j) it.next()).f2091v, str)) {
                                break;
                            }
                        }
                        if (!zA) {
                            P6.g.e(str, "backStackEntryId");
                            z8 = (Z) vVar.f2135b.remove(str);
                            if (z8 != null) {
                            }
                        }
                        f3.t();
                        ArrayList arrayListP2 = f3.p();
                        k9.getClass();
                        k9.g(null, arrayListP2);
                    }
                } else if (!c0107n.f2106d) {
                    f3.t();
                    ArrayList arrayListP3 = f3.p();
                    k9.getClass();
                    k9.g(null, arrayListP3);
                }
            }
            linkedHashMap.remove(c0103j2);
        }
    }

    public final void t() {
        A a3;
        AtomicInteger atomicInteger;
        C0592C c0592c;
        Set set;
        ArrayList arrayListY0 = B6.k.y0(this.f2003g);
        if (arrayListY0.isEmpty()) {
            return;
        }
        A a8 = ((C0103j) B6.k.n0(arrayListY0)).f2087r;
        if (a8 instanceof InterfaceC0098e) {
            Iterator it = B6.k.s0(arrayListY0).iterator();
            while (it.hasNext()) {
                a3 = ((C0103j) it.next()).f2087r;
                if (!(a3 instanceof D) && !(a3 instanceof InterfaceC0098e)) {
                    break;
                }
            }
            a3 = null;
        } else {
            a3 = null;
        }
        HashMap map = new HashMap();
        for (C0103j c0103j : B6.k.s0(arrayListY0)) {
            EnumC0510o enumC0510o = c0103j.f2085B;
            A a9 = c0103j.f2087r;
            EnumC0510o enumC0510o2 = EnumC0510o.f8838u;
            EnumC0510o enumC0510o3 = EnumC0510o.f8837t;
            if (a8 != null && a9.f1985x == a8.f1985x) {
                if (enumC0510o != enumC0510o2) {
                    C0107n c0107n = (C0107n) this.f2017v.get(this.f2016u.b(a9.f1978q));
                    if (P6.g.a((c0107n == null || (c0592c = c0107n.f2108f) == null || (set = (Set) ((c7.K) ((InterfaceC0591B) c0592c.f9369r)).e()) == null) ? null : Boolean.valueOf(set.contains(c0103j)), Boolean.TRUE) || ((atomicInteger = (AtomicInteger) this.f2005j.get(c0103j)) != null && atomicInteger.get() == 0)) {
                        map.put(c0103j, enumC0510o3);
                    } else {
                        map.put(c0103j, enumC0510o2);
                    }
                }
                a8 = a8.f1979r;
            } else if (a3 == null || a9.f1985x != a3.f1985x) {
                c0103j.b(EnumC0510o.f8836s);
            } else {
                if (enumC0510o == enumC0510o2) {
                    c0103j.b(enumC0510o3);
                } else if (enumC0510o != enumC0510o3) {
                    map.put(c0103j, enumC0510o3);
                }
                a3 = a3.f1979r;
            }
        }
        int size = arrayListY0.size();
        int i = 0;
        while (i < size) {
            Object obj = arrayListY0.get(i);
            i++;
            C0103j c0103j2 = (C0103j) obj;
            EnumC0510o enumC0510o4 = (EnumC0510o) map.get(c0103j2);
            if (enumC0510o4 != null) {
                c0103j2.b(enumC0510o4);
            } else {
                c0103j2.c();
            }
        }
    }

    public final void u() {
        int i;
        boolean z8 = false;
        if (this.f2015t) {
            B6.i iVar = this.f2003g;
            if (iVar == null || !iVar.isEmpty()) {
                Iterator it = iVar.iterator();
                i = 0;
                while (it.hasNext()) {
                    if (!(((C0103j) it.next()).f2087r instanceof D) && (i = i + 1) < 0) {
                        throw new ArithmeticException("Count overflow has happened.");
                    }
                }
            } else {
                i = 0;
            }
            if (i > 1) {
                z8 = true;
            }
        }
        this.f2014s.e(z8);
    }
}
