package androidx.view;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.Log;
import androidx.lifecycle.k;
import androidx.media3.container.NalUnitUtil;
import androidx.media3.exoplayer.upstream.CmcdData;
import androidx.media3.extractor.text.ttml.TtmlNode;
import androidx.view.NavBackStackEntry;
import androidx.view.ak;
import androidx.view.ao;
import androidx.view.at;
import androidx.view.aw;
import com.google.android.gms.measurement.api.AppMeasurementSdk;
import defpackage.C0611ld1;
import defpackage.C0746xy8;
import defpackage.cr4;
import defpackage.ds;
import defpackage.dw7;
import defpackage.f43;
import defpackage.fi7;
import defpackage.hz9;
import defpackage.i49;
import defpackage.i85;
import defpackage.ig6;
import defpackage.ik2;
import defpackage.ika;
import defpackage.j43;
import defpackage.j65;
import defpackage.ji6;
import defpackage.k63;
import defpackage.kj9;
import defpackage.lj9;
import defpackage.mj6;
import defpackage.n41;
import defpackage.o29;
import defpackage.q07;
import defpackage.sg8;
import defpackage.sh6;
import defpackage.sq3;
import defpackage.st;
import defpackage.u55;
import defpackage.ug0;
import defpackage.uk0;
import defpackage.v65;
import defpackage.vp8;
import defpackage.vw2;
import defpackage.vx8;
import defpackage.wj9;
import defpackage.wm3;
import defpackage.wo5;
import defpackage.wy8;
import defpackage.xp8;
import defpackage.y41;
import defpackage.zh6;
import defpackage.zj6;
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.Objects;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicInteger;
import kotlin.Metadata;

/* JADX INFO: loaded from: classes.dex */
@Metadata(d1 = {"\u0000\f\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0004\b\u0016\u0018\u00002\u00020\u0001:\u0003\u0002\u0003\u0004¨\u0006\u0005"}, d2 = {"Landroidx/navigation/j;", "", CmcdData.OBJECT_TYPE_AUDIO_ONLY, "b", "c", "navigation-runtime_release"}, k = 1, mv = {1, 8, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
@vx8
public class j {
    public final Context a;
    public final LinkedHashMap aa;
    public int ab;
    public final ArrayList ac;
    public final j65 ad;
    public final vp8 ae;
    public final j43 af;
    public final Activity b;
    public at c;
    public Bundle d;
    public Parcelable[] e;
    public boolean f;
    public final ds g;
    public final ig6 h;
    public final o29 i;
    public final ig6 j;
    public final o29 k;
    public final LinkedHashMap l;
    public final LinkedHashMap m;
    public final LinkedHashMap n;
    public final LinkedHashMap o;
    public i85 p;
    public NavControllerViewModel q;
    public final CopyOnWriteArrayList r;
    public k.b s;
    public final wm3 t;
    public final zh6 u;
    public final boolean v;
    public final bf w;
    public final LinkedHashMap x;
    public u55 y;
    public sq3 z;

    @Metadata(d1 = {"\u0000\u0018\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\u0010\u000e\n\u0002\b\r\n\u0002\u0010\u000b\n\u0002\b\u0003\b\u0086\u0003\u0018\u00002\u00020\u0001R\u0014\u0010\u0003\u001a\u00020\u00028\u0002X\u0082T¢\u0006\u0006\n\u0004\b\u0003\u0010\u0004R\u0014\u0010\u0005\u001a\u00020\u00028\u0002X\u0082T¢\u0006\u0006\n\u0004\b\u0005\u0010\u0004R\u0014\u0010\u0006\u001a\u00020\u00028\u0002X\u0082T¢\u0006\u0006\n\u0004\b\u0006\u0010\u0004R\u0014\u0010\u0007\u001a\u00020\u00028\u0002X\u0082T¢\u0006\u0006\n\u0004\b\u0007\u0010\u0004R\u0014\u0010\b\u001a\u00020\u00028\u0002X\u0082T¢\u0006\u0006\n\u0004\b\b\u0010\u0004R\u0014\u0010\t\u001a\u00020\u00028\u0006X\u0087T¢\u0006\u0006\n\u0004\b\t\u0010\u0004R\u0014\u0010\n\u001a\u00020\u00028\u0006X\u0087T¢\u0006\u0006\n\u0004\b\n\u0010\u0004R\u0014\u0010\u000b\u001a\u00020\u00028\u0006X\u0087T¢\u0006\u0006\n\u0004\b\u000b\u0010\u0004R\u0014\u0010\f\u001a\u00020\u00028\u0006X\u0086T¢\u0006\u0006\n\u0004\b\f\u0010\u0004R\u0014\u0010\r\u001a\u00020\u00028\u0002X\u0082T¢\u0006\u0006\n\u0004\b\r\u0010\u0004R\u0014\u0010\u000e\u001a\u00020\u00028\u0002X\u0082T¢\u0006\u0006\n\u0004\b\u000e\u0010\u0004R\u0014\u0010\u000f\u001a\u00020\u00028\u0002X\u0082T¢\u0006\u0006\n\u0004\b\u000f\u0010\u0004R\u0016\u0010\u0011\u001a\u00020\u00108\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b\u0011\u0010\u0012¨\u0006\u0013"}, d2 = {"Landroidx/navigation/j$a;", "", "", "KEY_BACK_STACK", "Ljava/lang/String;", "KEY_BACK_STACK_DEST_IDS", "KEY_BACK_STACK_IDS", "KEY_BACK_STACK_STATES_IDS", "KEY_BACK_STACK_STATES_PREFIX", "KEY_DEEP_LINK_ARGS", "KEY_DEEP_LINK_HANDLED", "KEY_DEEP_LINK_IDS", "KEY_DEEP_LINK_INTENT", "KEY_NAVIGATOR_STATE", "KEY_NAVIGATOR_STATE_NAMES", "TAG", "", "deepLinkSaveState", "Z", "navigation-runtime_release"}, k = 1, mv = {1, 8, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    public static final class a {
    }

    @Metadata(d1 = {"\u0000\n\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\b\u0082\u0004\u0018\u00002\u00020\u0001¨\u0006\u0002"}, d2 = {"Landroidx/navigation/j$b;", "Lzj6;", "navigation-runtime_release"}, k = 1, mv = {1, 8, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    @vx8
    public final class b extends zj6 {
        public final bc g;
        public final /* synthetic */ j h;

        public b(j jVar, bc bcVar) {
            cr4.g(bcVar, "navigator");
            this.h = jVar;
            this.g = bcVar;
        }

        @Override // defpackage.zj6
        public final NavBackStackEntry a(ao aoVar, Bundle bundle) {
            j jVar = this.h;
            return NavBackStackEntry.a.a(jVar.a, aoVar, bundle, jVar.i(), jVar.q);
        }

        /* JADX WARN: Removed duplicated region for block: B:22:0x0070  */
        @Override // defpackage.zj6
        /*
            Code decompiled incorrectly, please refer to instructions dump.
        */
        public final void b(NavBackStackEntry navBackStackEntry) {
            NavControllerViewModel navControllerViewModel;
            ika ikaVar;
            cr4.g(navBackStackEntry, "entry");
            String str = navBackStackEntry.f;
            j jVar = this.h;
            ig6 ig6Var = jVar.j;
            LinkedHashMap linkedHashMap = jVar.aa;
            boolean zB = cr4.b(linkedHashMap.get(navBackStackEntry), Boolean.TRUE);
            super.b(navBackStackEntry);
            linkedHashMap.remove(navBackStackEntry);
            ds dsVar = jVar.g;
            if (dsVar.contains(navBackStackEntry)) {
                if (this.d) {
                    return;
                }
                jVar.w();
                jVar.h.a(y41.bp(dsVar));
                ig6Var.a(jVar.s());
                return;
            }
            jVar.v(navBackStackEntry);
            if (navBackStackEntry.j.d.compareTo(k.b.c) >= 0) {
                navBackStackEntry.b(k.b.a);
            }
            if (dsVar == null || !dsVar.isEmpty()) {
                Iterator<E> it = dsVar.iterator();
                while (it.hasNext()) {
                    if (cr4.b(((NavBackStackEntry) it.next()).f, str)) {
                        break;
                    }
                }
                if (!zB && (navControllerViewModel = jVar.q) != null) {
                    cr4.g(str, "backStackEntryId");
                    ikaVar = (ika) navControllerViewModel.a.remove(str);
                    if (ikaVar != null) {
                        ikaVar.a();
                    }
                }
            } else if (!zB) {
                cr4.g(str, "backStackEntryId");
                ikaVar = (ika) navControllerViewModel.a.remove(str);
                if (ikaVar != null) {
                }
            }
            jVar.w();
            ig6Var.a(jVar.s());
        }

        @Override // defpackage.zj6
        public final void d(NavBackStackEntry navBackStackEntry, boolean z) {
            cr4.g(navBackStackEntry, "popUpTo");
            j jVar = this.h;
            bc bcVarB = jVar.w.b(navBackStackEntry.b.a);
            if (!cr4.b(bcVarB, this.g)) {
                Object obj = jVar.x.get(bcVarB);
                cr4.d(obj);
                ((b) obj).d(navBackStackEntry, z);
                return;
            }
            sq3 sq3Var = jVar.z;
            if (sq3Var != null) {
                ((n) sq3Var).invoke(navBackStackEntry);
                super.d(navBackStackEntry, z);
                return;
            }
            k kVar = new k(this, navBackStackEntry, z);
            ds dsVar = jVar.g;
            int iIndexOf = dsVar.indexOf(navBackStackEntry);
            if (iIndexOf < 0) {
                navBackStackEntry.toString();
                return;
            }
            int i = iIndexOf + 1;
            if (i != dsVar.c) {
                jVar.p(((NavBackStackEntry) dsVar.get(i)).b.j, true, false);
            }
            j.r(jVar, navBackStackEntry);
            kVar.invoke();
            jVar.x();
            jVar.b();
        }

        @Override // defpackage.zj6
        public final void e(NavBackStackEntry navBackStackEntry, boolean z) {
            cr4.g(navBackStackEntry, "popUpTo");
            super.e(navBackStackEntry, z);
            this.h.aa.put(navBackStackEntry, Boolean.valueOf(z));
        }

        @Override // defpackage.zj6
        public final void f(NavBackStackEntry navBackStackEntry) {
            super.f(navBackStackEntry);
            if (!this.h.g.contains(navBackStackEntry)) {
                throw new IllegalStateException("Cannot transition entry that is not in the back stack");
            }
            navBackStackEntry.b(k.b.d);
        }

        /* JADX WARN: Type inference failed for: r0v7, types: [sq3, u55] */
        @Override // defpackage.zj6
        public final void g(NavBackStackEntry navBackStackEntry) {
            cr4.g(navBackStackEntry, "backStackEntry");
            j jVar = this.h;
            bc bcVarB = jVar.w.b(navBackStackEntry.b.a);
            if (!cr4.b(bcVarB, this.g)) {
                Object obj = jVar.x.get(bcVarB);
                if (obj == null) {
                    throw new IllegalStateException(n41.s(new StringBuilder("NavigatorBackStack for "), navBackStackEntry.b.a, " should already be created").toString());
                }
                ((b) obj).g(navBackStackEntry);
                return;
            }
            ?? r0 = jVar.y;
            if (r0 == 0) {
                Objects.toString(navBackStackEntry.b);
            } else {
                r0.invoke(navBackStackEntry);
                super.g(navBackStackEntry);
            }
        }

        public final void j(NavBackStackEntry navBackStackEntry) {
            super.g(navBackStackEntry);
        }
    }

    @Metadata(d1 = {"\u0000\n\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\bæ\u0080\u0001\u0018\u00002\u00020\u0001ø\u0001\u0000\u0082\u0002\u0006\n\u0004\b!0\u0001¨\u0006\u0002À\u0006\u0001"}, d2 = {"Landroidx/navigation/j$c;", "", "navigation-runtime_release"}, k = 1, mv = {1, 8, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    public interface c {
        void a(j jVar, ao aoVar, Bundle bundle);
    }

    public j(Context context) {
        Object next;
        this.a = context;
        Iterator a2 = sg8.j(l.a, context).getA();
        while (true) {
            if (!a2.hasNext()) {
                next = null;
                break;
            } else {
                next = a2.next();
                if (((Context) next) instanceof Activity) {
                    break;
                }
            }
        }
        this.b = (Activity) next;
        this.g = new ds();
        ik2 ik2Var = ik2.a;
        ig6 ig6VarA = i49.a(ik2Var);
        this.h = ig6VarA;
        this.i = k63.b(ig6VarA);
        ig6 ig6VarA2 = i49.a(ik2Var);
        this.j = ig6VarA2;
        this.k = k63.b(ig6VarA2);
        this.l = new LinkedHashMap();
        this.m = new LinkedHashMap();
        this.n = new LinkedHashMap();
        this.o = new LinkedHashMap();
        this.r = new CopyOnWriteArrayList();
        this.s = k.b.b;
        this.t = new wm3(this, 2);
        this.u = new zh6(this);
        this.v = true;
        bf bfVar = new bf();
        this.w = bfVar;
        this.x = new LinkedHashMap();
        this.aa = new LinkedHashMap();
        bfVar.a(new au(bfVar));
        bfVar.a(new androidx.view.a(this.a));
        this.ac = new ArrayList();
        this.ad = v65.a(new w(this));
        ug0 ug0Var = ug0.a;
        vp8 vp8VarB = xp8.b(1, 0, 2);
        this.ae = vp8VarB;
        this.af = k63.a(vp8VarB);
    }

    public static ao d(ao aoVar, int i) {
        at atVar;
        if (aoVar.j == i) {
            return aoVar;
        }
        if (aoVar instanceof at) {
            atVar = (at) aoVar;
        } else {
            atVar = aoVar.b;
            cr4.d(atVar);
        }
        return atVar.h(i, true);
    }

    public static /* synthetic */ void r(j jVar, NavBackStackEntry navBackStackEntry) {
        jVar.q(navBackStackEntry, false, new ds());
    }

    public final void a(ao aoVar, Bundle bundle, NavBackStackEntry navBackStackEntry, List list) {
        Object objPrevious;
        Object objPrevious2;
        ao aoVar2 = navBackStackEntry.b;
        boolean z = aoVar2 instanceof f43;
        boolean z2 = true;
        ds dsVar = this.g;
        if (!z) {
            while (!dsVar.isEmpty() && (((NavBackStackEntry) dsVar.last()).b instanceof f43) && p(((NavBackStackEntry) dsVar.last()).b.j, true, false)) {
            }
        }
        ds<NavBackStackEntry> dsVar2 = new ds();
        boolean z3 = aoVar instanceof at;
        Context context = this.a;
        Object obj = null;
        if (z3) {
            ao aoVar3 = aoVar2;
            do {
                cr4.d(aoVar3);
                aoVar3 = aoVar3.b;
                if (aoVar3 != null) {
                    ListIterator listIterator = list.listIterator(list.size());
                    while (true) {
                        if (listIterator.hasPrevious()) {
                            objPrevious2 = listIterator.previous();
                            if (cr4.b(((NavBackStackEntry) objPrevious2).b, aoVar3)) {
                                break;
                            }
                        } else {
                            objPrevious2 = null;
                            break;
                        }
                    }
                    NavBackStackEntry navBackStackEntryA = (NavBackStackEntry) objPrevious2;
                    if (navBackStackEntryA == null) {
                        navBackStackEntryA = NavBackStackEntry.a.a(context, aoVar3, bundle, i(), this.q);
                    }
                    dsVar2.addFirst(navBackStackEntryA);
                    if (!dsVar.isEmpty() && ((NavBackStackEntry) dsVar.last()).b == aoVar3) {
                        r(this, (NavBackStackEntry) dsVar.last());
                    }
                }
                if (aoVar3 == null) {
                    break;
                }
            } while (aoVar3 != aoVar);
        }
        ao aoVar4 = dsVar2.isEmpty() ? aoVar2 : ((NavBackStackEntry) dsVar2.first()).b;
        while (aoVar4 != null && c(aoVar4.j) != aoVar4) {
            aoVar4 = aoVar4.b;
            if (aoVar4 != null) {
                Bundle bundle2 = (bundle == null || bundle.isEmpty() != z2) ? bundle : null;
                ListIterator listIterator2 = list.listIterator(list.size());
                while (true) {
                    if (listIterator2.hasPrevious()) {
                        objPrevious = listIterator2.previous();
                        if (cr4.b(((NavBackStackEntry) objPrevious).b, aoVar4)) {
                            break;
                        }
                    } else {
                        objPrevious = null;
                        break;
                    }
                }
                NavBackStackEntry navBackStackEntryA2 = (NavBackStackEntry) objPrevious;
                if (navBackStackEntryA2 == null) {
                    navBackStackEntryA2 = NavBackStackEntry.a.a(context, aoVar4, aoVar4.b(bundle2), i(), this.q);
                }
                dsVar2.addFirst(navBackStackEntryA2);
            }
            z2 = true;
        }
        if (!dsVar2.isEmpty()) {
            aoVar2 = ((NavBackStackEntry) dsVar2.first()).b;
        }
        while (!dsVar.isEmpty() && (((NavBackStackEntry) dsVar.last()).b instanceof at)) {
            ao aoVar5 = ((NavBackStackEntry) dsVar.last()).b;
            cr4.e(aoVar5, "null cannot be cast to non-null type androidx.navigation.NavGraph");
            if (((at) aoVar5).h(aoVar2.j, false) != null) {
                break;
            } else {
                r(this, (NavBackStackEntry) dsVar.last());
            }
        }
        NavBackStackEntry navBackStackEntry2 = (NavBackStackEntry) (dsVar.isEmpty() ? null : dsVar.b[dsVar.a]);
        if (navBackStackEntry2 == null) {
            navBackStackEntry2 = (NavBackStackEntry) (dsVar2.isEmpty() ? null : dsVar2.b[dsVar2.a]);
        }
        if (!cr4.b(navBackStackEntry2 != null ? navBackStackEntry2.b : null, this.c)) {
            ListIterator listIterator3 = list.listIterator(list.size());
            while (true) {
                if (!listIterator3.hasPrevious()) {
                    break;
                }
                Object objPrevious3 = listIterator3.previous();
                ao aoVar6 = ((NavBackStackEntry) objPrevious3).b;
                at atVar = this.c;
                cr4.d(atVar);
                if (cr4.b(aoVar6, atVar)) {
                    obj = objPrevious3;
                    break;
                }
            }
            NavBackStackEntry navBackStackEntryA3 = (NavBackStackEntry) obj;
            if (navBackStackEntryA3 == null) {
                at atVar2 = this.c;
                cr4.d(atVar2);
                at atVar3 = this.c;
                cr4.d(atVar3);
                navBackStackEntryA3 = NavBackStackEntry.a.a(context, atVar2, atVar3.b(bundle), i(), this.q);
            }
            dsVar2.addFirst(navBackStackEntryA3);
        }
        for (NavBackStackEntry navBackStackEntry3 : dsVar2) {
            Object obj2 = this.x.get(this.w.b(navBackStackEntry3.b.a));
            if (obj2 == null) {
                throw new IllegalStateException(n41.s(new StringBuilder("NavigatorBackStack for "), aoVar.a, " should already be created").toString());
            }
            ((b) obj2).j(navBackStackEntry3);
        }
        dsVar.addAll(dsVar2);
        dsVar.addLast(navBackStackEntry);
        for (NavBackStackEntry navBackStackEntry4 : y41.av(dsVar2, navBackStackEntry)) {
            at atVar4 = navBackStackEntry4.b.b;
            if (atVar4 != null) {
                j(navBackStackEntry4, e(atVar4.j));
            }
        }
    }

    public final boolean b() {
        ds dsVar;
        while (true) {
            dsVar = this.g;
            if (dsVar.isEmpty() || !(((NavBackStackEntry) dsVar.last()).b instanceof at)) {
                break;
            }
            r(this, (NavBackStackEntry) dsVar.last());
        }
        NavBackStackEntry navBackStackEntry = (NavBackStackEntry) dsVar.f();
        ArrayList arrayList = this.ac;
        if (navBackStackEntry != null) {
            arrayList.add(navBackStackEntry);
        }
        this.ab++;
        w();
        int i = this.ab - 1;
        this.ab = i;
        if (i == 0) {
            ArrayList<NavBackStackEntry> arrayListBp = y41.bp(arrayList);
            arrayList.clear();
            for (NavBackStackEntry navBackStackEntry2 : arrayListBp) {
                Iterator it = this.r.iterator();
                while (it.hasNext()) {
                    ((c) it.next()).a(this, navBackStackEntry2.b, navBackStackEntry2.a());
                }
                this.ae.a(navBackStackEntry2);
            }
            this.h.a(y41.bp(dsVar));
            this.j.a(s());
        }
        return navBackStackEntry != null;
    }

    public final ao c(int i) {
        ao aoVar;
        at atVar = this.c;
        if (atVar == null) {
            return null;
        }
        if (atVar.j == i) {
            return atVar;
        }
        NavBackStackEntry navBackStackEntry = (NavBackStackEntry) this.g.f();
        if (navBackStackEntry == null || (aoVar = navBackStackEntry.b) == null) {
            aoVar = this.c;
            cr4.d(aoVar);
        }
        return d(aoVar, i);
    }

    public final NavBackStackEntry e(int i) {
        Object objPrevious;
        ds dsVar = this.g;
        ListIterator<E> listIterator = dsVar.listIterator(dsVar.size());
        while (true) {
            if (!listIterator.hasPrevious()) {
                objPrevious = null;
                break;
            }
            objPrevious = listIterator.previous();
            if (((NavBackStackEntry) objPrevious).b.j == i) {
                break;
            }
        }
        NavBackStackEntry navBackStackEntry = (NavBackStackEntry) objPrevious;
        if (navBackStackEntry != null) {
            return navBackStackEntry;
        }
        StringBuilder sbJ = fi7.j(i, "No destination with ID ", " is on the NavController's back stack. The current destination is ");
        sbJ.append(f());
        throw new IllegalArgumentException(sbJ.toString().toString());
    }

    public final ao f() {
        NavBackStackEntry navBackStackEntry = (NavBackStackEntry) this.g.f();
        if (navBackStackEntry != null) {
            return navBackStackEntry.b;
        }
        return null;
    }

    public final int g() {
        int i = 0;
        ds dsVar = this.g;
        if (dsVar != null && dsVar.isEmpty()) {
            return 0;
        }
        Iterator<E> it = dsVar.iterator();
        while (it.hasNext()) {
            if (!(((NavBackStackEntry) it.next()).b instanceof at) && (i = i + 1) < 0) {
                y41.bl();
                throw null;
            }
        }
        return i;
    }

    public final at h() {
        at atVar = this.c;
        if (atVar == null) {
            throw new IllegalStateException("You must call setGraph() before calling getGraph()");
        }
        cr4.e(atVar, "null cannot be cast to non-null type androidx.navigation.NavGraph");
        return atVar;
    }

    public final k.b i() {
        return this.p == null ? k.b.c : this.s;
    }

    public final void j(NavBackStackEntry navBackStackEntry, NavBackStackEntry navBackStackEntry2) {
        this.l.put(navBackStackEntry, navBackStackEntry2);
        LinkedHashMap linkedHashMap = this.m;
        if (linkedHashMap.get(navBackStackEntry2) == null) {
            linkedHashMap.put(navBackStackEntry2, new AtomicInteger(0));
        }
        Object obj = linkedHashMap.get(navBackStackEntry2);
        cr4.d(obj);
        ((AtomicInteger) obj).incrementAndGet();
    }

    public final void k(int i, Bundle bundle, aw awVar) {
        int i2;
        ds dsVar = this.g;
        ao aoVar = dsVar.isEmpty() ? this.c : ((NavBackStackEntry) dsVar.last()).b;
        if (aoVar == null) {
            throw new IllegalStateException("No current destination found. Ensure a navigation graph has been set for NavController " + this + '.');
        }
        sh6 sh6VarD = aoVar.d(i);
        Bundle bundle2 = null;
        if (sh6VarD != null) {
            if (awVar == null) {
                awVar = sh6VarD.b;
            }
            i2 = sh6VarD.a;
            Bundle bundle3 = sh6VarD.c;
            if (bundle3 != null) {
                bundle2 = new Bundle();
                bundle2.putAll(bundle3);
            }
        } else {
            i2 = i;
        }
        if (bundle != null) {
            if (bundle2 == null) {
                bundle2 = new Bundle();
            }
            bundle2.putAll(bundle);
        }
        if (i2 == 0 && awVar != null) {
            boolean z = awVar.d;
            int i3 = awVar.c;
            if (i3 != -1) {
                if (i3 == -1 || !p(i3, z, false)) {
                    return;
                }
                b();
                return;
            }
        }
        if (i2 == 0) {
            throw new IllegalArgumentException("Destination id == 0 can only be used in conjunction with a valid navOptions.popUpTo");
        }
        ao aoVarC = c(i2);
        if (aoVarC != null) {
            m(aoVarC, bundle2, awVar);
            return;
        }
        int i4 = ao.l;
        Context context = this.a;
        String strA = ao.b.a(context, i2);
        if (sh6VarD == null) {
            throw new IllegalArgumentException("Navigation action/destination " + strA + " cannot be found from the current destination " + aoVar);
        }
        StringBuilder sbS = vw2.s("Navigation destination ", strA, " referenced from action ");
        sbS.append(ao.b.a(context, i));
        sbS.append(" cannot be found from the current destination ");
        sbS.append(aoVar);
        throw new IllegalArgumentException(sbS.toString().toString());
    }

    public final void l(ji6 ji6Var) {
        k(ji6Var.a(), ji6Var.getArguments(), null);
    }

    /* JADX WARN: Removed duplicated region for block: B:11:0x0037  */
    /* JADX WARN: Removed duplicated region for block: B:19:0x005d  */
    /* JADX WARN: Removed duplicated region for block: B:53:0x0131  */
    /* JADX WARN: Removed duplicated region for block: B:55:0x0136  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void m(ao aoVar, Bundle bundle, aw awVar) {
        boolean zP;
        LinkedHashMap linkedHashMap;
        boolean z;
        int i;
        ao aoVar2;
        LinkedHashMap linkedHashMap2 = this.x;
        Iterator it = linkedHashMap2.values().iterator();
        while (it.hasNext()) {
            ((b) it.next()).d = true;
        }
        dw7.a aVar = new dw7.a();
        int iNextIndex = -1;
        if (awVar != null) {
            boolean z2 = awVar.e;
            boolean z3 = awVar.d;
            int i2 = awVar.c;
            zP = i2 != -1 ? p(i2, z3, z2) : false;
        }
        Bundle bundleB = aoVar.b(bundle);
        if (awVar == null || !awVar.b) {
            bf bfVar = this.w;
            if (awVar == null || !awVar.a) {
                linkedHashMap = linkedHashMap2;
                z = false;
                if (!z) {
                    NavBackStackEntry navBackStackEntryA = NavBackStackEntry.a.a(this.a, aoVar, bundleB, i(), this.q);
                    bc bcVarB = bfVar.b(aoVar.a);
                    List listAm = y41.am(navBackStackEntryA);
                    this.y = new x(aVar, this, aoVar, bundleB);
                    bcVarB.d(listAm, awVar);
                    this.y = null;
                }
            } else {
                ds dsVar = this.g;
                NavBackStackEntry navBackStackEntry = (NavBackStackEntry) dsVar.f();
                if (aoVar instanceof at) {
                    int i3 = at.p;
                    i = at.a.a((at) aoVar).j;
                } else {
                    i = aoVar.j;
                }
                if (navBackStackEntry != null && (aoVar2 = navBackStackEntry.b) != null && i == aoVar2.j) {
                    ds<NavBackStackEntry> dsVar2 = new ds();
                    ListIterator<E> listIterator = dsVar.listIterator(dsVar.getC());
                    while (true) {
                        if (listIterator.hasPrevious()) {
                            if (((NavBackStackEntry) listIterator.previous()).b == aoVar) {
                                iNextIndex = listIterator.nextIndex();
                                break;
                            }
                        } else {
                            break;
                        }
                    }
                    while (y41.ae(dsVar) >= iNextIndex) {
                        NavBackStackEntry navBackStackEntry2 = (NavBackStackEntry) dsVar.removeLast();
                        v(navBackStackEntry2);
                        NavBackStackEntry navBackStackEntry3 = new NavBackStackEntry(navBackStackEntry2.a, navBackStackEntry2.b, navBackStackEntry2.b.b(bundle), navBackStackEntry2.d, navBackStackEntry2.e, navBackStackEntry2.f, navBackStackEntry2.i);
                        navBackStackEntry3.d = navBackStackEntry2.d;
                        navBackStackEntry3.b(navBackStackEntry2.o);
                        dsVar2.addFirst(navBackStackEntry3);
                        linkedHashMap2 = linkedHashMap2;
                    }
                    linkedHashMap = linkedHashMap2;
                    for (NavBackStackEntry navBackStackEntry4 : dsVar2) {
                        at atVar = navBackStackEntry4.b.b;
                        if (atVar != null) {
                            j(navBackStackEntry4, e(atVar.j));
                        }
                        dsVar.addLast(navBackStackEntry4);
                    }
                    for (NavBackStackEntry navBackStackEntry5 : dsVar2) {
                        bfVar.b(navBackStackEntry5.b.a).f(navBackStackEntry5);
                    }
                    z = true;
                }
                if (!z) {
                }
            }
        } else if (this.n.containsKey(Integer.valueOf(aoVar.j))) {
            aVar.a = t(aoVar.j, bundleB, awVar);
            linkedHashMap = linkedHashMap2;
            z = false;
        }
        x();
        Iterator it2 = linkedHashMap.values().iterator();
        while (it2.hasNext()) {
            ((b) it2.next()).d = false;
        }
        if (zP || aVar.a || z) {
            b();
        } else {
            w();
        }
    }

    public final boolean n() {
        Intent intent;
        if (g() != 1) {
            return o();
        }
        Activity activity = this.b;
        Bundle extras = (activity == null || (intent = activity.getIntent()) == null) ? null : intent.getExtras();
        int i = 0;
        if ((extras != null ? extras.getIntArray("android-support-nav:controller:deepLinkIds") : null) == null) {
            ao aoVarF = f();
            cr4.d(aoVarF);
            int i2 = aoVarF.j;
            for (at atVar = aoVarF.b; atVar != null; atVar = atVar.b) {
                if (atVar.n != i2) {
                    Bundle bundle = new Bundle();
                    if (activity != null && activity.getIntent() != null && activity.getIntent().getData() != null) {
                        bundle.putParcelable("android-support-nav:controller:deepLinkIntent", activity.getIntent());
                        at atVar2 = this.c;
                        cr4.d(atVar2);
                        Intent intent2 = activity.getIntent();
                        cr4.f(intent2, "activity!!.intent");
                        ao.c cVarE = atVar2.e(new an(intent2));
                        if ((cVarE != null ? cVarE.b : null) != null) {
                            bundle.putAll(cVarE.a.b(cVarE.b));
                        }
                    }
                    ak akVar = new ak(this);
                    int i3 = atVar.j;
                    ArrayList arrayList = akVar.d;
                    arrayList.clear();
                    arrayList.add(new ak.a(i3, null));
                    if (akVar.c != null) {
                        akVar.c();
                    }
                    akVar.b.putExtra("android-support-nav:controller:deepLinkExtras", bundle);
                    akVar.a().b();
                    if (activity != null) {
                        activity.finish();
                    }
                    return true;
                }
                i2 = atVar.j;
            }
        } else if (this.f) {
            cr4.d(activity);
            Intent intent3 = activity.getIntent();
            Bundle extras2 = intent3.getExtras();
            cr4.d(extras2);
            int[] intArray = extras2.getIntArray("android-support-nav:controller:deepLinkIds");
            cr4.d(intArray);
            ArrayList arrayListAm = st.am(intArray);
            ArrayList parcelableArrayList = extras2.getParcelableArrayList("android-support-nav:controller:deepLinkArgs");
            int iIntValue = ((Number) y41.ay(arrayListAm)).intValue();
            if (parcelableArrayList != null) {
            }
            if (!arrayListAm.isEmpty()) {
                ao aoVarD = d(h(), iIntValue);
                if (aoVarD instanceof at) {
                    int i4 = at.p;
                    iIntValue = at.a.a((at) aoVarD).j;
                }
                ao aoVarF2 = f();
                if (aoVarF2 != null && iIntValue == aoVarF2.j) {
                    ak akVar2 = new ak(this);
                    Bundle bundleA = uk0.a(new q07("android-support-nav:controller:deepLinkIntent", intent3));
                    Bundle bundle2 = extras2.getBundle("android-support-nav:controller:deepLinkExtras");
                    if (bundle2 != null) {
                        bundleA.putAll(bundle2);
                    }
                    akVar2.b.putExtra("android-support-nav:controller:deepLinkExtras", bundleA);
                    for (Object obj : arrayListAm) {
                        int i5 = i + 1;
                        if (i < 0) {
                            y41.bm();
                            throw null;
                        }
                        akVar2.d.add(new ak.a(((Number) obj).intValue(), parcelableArrayList != null ? (Bundle) parcelableArrayList.get(i) : null));
                        if (akVar2.c != null) {
                            akVar2.c();
                        }
                        i = i5;
                    }
                    akVar2.a().b();
                    activity.finish();
                    return true;
                }
            }
        }
        return false;
    }

    public final boolean o() {
        if (this.g.isEmpty()) {
            return false;
        }
        ao aoVarF = f();
        cr4.d(aoVarF);
        return p(aoVarF.j, true, false) && b();
    }

    public final boolean p(int i, boolean z, boolean z2) {
        ao aoVar;
        j jVar;
        boolean z3;
        ds dsVar = this.g;
        if (dsVar.isEmpty()) {
            return false;
        }
        ArrayList arrayList = new ArrayList();
        Iterator it = y41.bb(dsVar).iterator();
        while (true) {
            if (!it.hasNext()) {
                aoVar = null;
                break;
            }
            aoVar = ((NavBackStackEntry) it.next()).b;
            bc bcVarB = this.w.b(aoVar.a);
            if (z || aoVar.j != i) {
                arrayList.add(bcVarB);
            }
            if (aoVar.j == i) {
                break;
            }
        }
        if (aoVar == null) {
            int i2 = ao.l;
            ao.b.a(this.a, i);
            return false;
        }
        dw7.a aVar = new dw7.a();
        ds dsVar2 = new ds();
        Iterator it2 = arrayList.iterator();
        while (true) {
            if (!it2.hasNext()) {
                jVar = this;
                z3 = z2;
                break;
            }
            bc bcVar = (bc) it2.next();
            dw7.a aVar2 = new dw7.a();
            NavBackStackEntry navBackStackEntry = (NavBackStackEntry) dsVar.last();
            jVar = this;
            z3 = z2;
            jVar.z = new n(aVar2, aVar, jVar, z3, dsVar2);
            bcVar.i(navBackStackEntry, z3);
            jVar.z = null;
            if (!aVar2.a) {
                break;
            }
            z2 = z3;
        }
        if (z3) {
            LinkedHashMap linkedHashMap = jVar.n;
            if (!z) {
                kj9 kj9Var = new kj9(new lj9(sg8.j(o.a, aoVar), new p(this)));
                while (kj9Var.hasNext()) {
                    Integer numValueOf = Integer.valueOf(((ao) kj9Var.next()).j);
                    i iVar = (i) (dsVar2.isEmpty() ? null : dsVar2.b[dsVar2.a]);
                    linkedHashMap.put(numValueOf, iVar != null ? iVar.a : null);
                }
            }
            if (!dsVar2.isEmpty()) {
                i iVar2 = (i) dsVar2.first();
                int i3 = iVar2.b;
                String str = iVar2.a;
                kj9 kj9Var2 = new kj9(new lj9(sg8.j(q.a, c(i3)), new r(this)));
                while (kj9Var2.hasNext()) {
                    linkedHashMap.put(Integer.valueOf(((ao) kj9Var2.next()).j), str);
                }
                if (linkedHashMap.values().contains(str)) {
                    jVar.o.put(str, dsVar2);
                }
            }
        }
        x();
        return aVar.a;
    }

    public final void q(NavBackStackEntry navBackStackEntry, boolean z, ds dsVar) {
        NavControllerViewModel navControllerViewModel;
        o29 o29Var;
        Set set;
        ds dsVar2 = this.g;
        NavBackStackEntry navBackStackEntry2 = (NavBackStackEntry) dsVar2.last();
        if (!cr4.b(navBackStackEntry2, navBackStackEntry)) {
            throw new IllegalStateException(("Attempted to pop " + navBackStackEntry.b + ", which is not the top of the back stack (" + navBackStackEntry2.b + ')').toString());
        }
        dsVar2.removeLast();
        b bVar = (b) this.x.get(this.w.b(navBackStackEntry2.b.a));
        boolean z2 = true;
        if ((bVar == null || (o29Var = bVar.f) == null || (set = (Set) o29Var.getValue()) == null || !set.contains(navBackStackEntry2)) && !this.m.containsKey(navBackStackEntry2)) {
            z2 = false;
        }
        k.b bVar2 = navBackStackEntry2.j.d;
        k.b bVar3 = k.b.c;
        if (bVar2.compareTo(bVar3) >= 0) {
            if (z) {
                navBackStackEntry2.b(bVar3);
                dsVar.addFirst(new i(navBackStackEntry2));
            }
            if (z2) {
                navBackStackEntry2.b(bVar3);
            } else {
                navBackStackEntry2.b(k.b.a);
                v(navBackStackEntry2);
            }
        }
        if (z || z2 || (navControllerViewModel = this.q) == null) {
            return;
        }
        String str = navBackStackEntry2.f;
        cr4.g(str, "backStackEntryId");
        ika ikaVar = (ika) navControllerViewModel.a.remove(str);
        if (ikaVar != null) {
            ikaVar.a();
        }
    }

    public final ArrayList s() {
        k.b bVar;
        ArrayList arrayList = new ArrayList();
        Iterator it = this.x.values().iterator();
        while (true) {
            boolean zHasNext = it.hasNext();
            bVar = k.b.d;
            if (!zHasNext) {
                break;
            }
            Iterable iterable = (Iterable) ((b) it.next()).f.getValue();
            ArrayList arrayList2 = new ArrayList();
            for (Object obj : iterable) {
                NavBackStackEntry navBackStackEntry = (NavBackStackEntry) obj;
                if (!arrayList.contains(navBackStackEntry) && navBackStackEntry.o.compareTo(bVar) < 0) {
                    arrayList2.add(obj);
                }
            }
            y41.i(arrayList2, arrayList);
        }
        ArrayList arrayList3 = new ArrayList();
        for (Object obj2 : this.g) {
            NavBackStackEntry navBackStackEntry2 = (NavBackStackEntry) obj2;
            if (!arrayList.contains(navBackStackEntry2) && navBackStackEntry2.o.compareTo(bVar) >= 0) {
                arrayList3.add(obj2);
            }
        }
        y41.i(arrayList3, arrayList);
        ArrayList arrayList4 = new ArrayList();
        for (Object obj3 : arrayList) {
            if (!(((NavBackStackEntry) obj3).b instanceof at)) {
                arrayList4.add(obj3);
            }
        }
        return arrayList4;
    }

    public final boolean t(int i, Bundle bundle, aw awVar) {
        ao aoVarH;
        NavBackStackEntry navBackStackEntry;
        ao aoVar;
        Integer numValueOf = Integer.valueOf(i);
        LinkedHashMap linkedHashMap = this.n;
        if (!linkedHashMap.containsKey(numValueOf)) {
            return false;
        }
        String str = (String) linkedHashMap.get(Integer.valueOf(i));
        y41.aw(linkedHashMap.values(), new z(str));
        ds<i> dsVar = (ds) hz9.c(this.o).remove(str);
        ArrayList arrayList = new ArrayList();
        NavBackStackEntry navBackStackEntry2 = (NavBackStackEntry) this.g.f();
        if (navBackStackEntry2 == null || (aoVarH = navBackStackEntry2.b) == null) {
            aoVarH = h();
        }
        if (dsVar != null) {
            for (i iVar : dsVar) {
                ao aoVarD = d(aoVarH, iVar.b);
                Context context = this.a;
                if (aoVarD == null) {
                    int i2 = ao.l;
                    throw new IllegalStateException(("Restore State failed: destination " + ao.b.a(context, iVar.b) + " cannot be found from the current destination " + aoVarH).toString());
                }
                arrayList.add(iVar.c(context, aoVarD, i(), this.q));
                aoVarH = aoVarD;
            }
        }
        ArrayList<List> arrayList2 = new ArrayList();
        ArrayList arrayList3 = new ArrayList();
        for (Object obj : arrayList) {
            if (!(((NavBackStackEntry) obj).b instanceof at)) {
                arrayList3.add(obj);
            }
        }
        Iterator it = arrayList3.iterator();
        while (true) {
            String str2 = null;
            if (!it.hasNext()) {
                break;
            }
            NavBackStackEntry navBackStackEntry3 = (NavBackStackEntry) it.next();
            List list = (List) y41.al(arrayList2);
            if (list != null && (navBackStackEntry = (NavBackStackEntry) y41.ak(list)) != null && (aoVar = navBackStackEntry.b) != null) {
                str2 = aoVar.a;
            }
            if (cr4.b(str2, navBackStackEntry3.b.a)) {
                list.add(navBackStackEntry3);
            } else {
                arrayList2.add(y41.ar(navBackStackEntry3));
            }
        }
        dw7.a aVar = new dw7.a();
        for (List list2 : arrayList2) {
            bc bcVarB = this.w.b(((NavBackStackEntry) y41.z(list2)).b.a);
            this.y = new s(aVar, arrayList, new dw7.f(), this, bundle);
            bcVarB.d(list2, awVar);
            this.y = null;
        }
        return aVar.a;
    }

    /* JADX WARN: Removed duplicated region for block: B:101:0x020c  */
    /* JADX WARN: Removed duplicated region for block: B:122:0x0256  */
    /* JADX WARN: Removed duplicated region for block: B:123:0x025b  */
    /* JADX WARN: Removed duplicated region for block: B:229:0x0253 A[SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:78:0x01bb  */
    /* JADX WARN: Removed duplicated region for block: B:79:0x01c2  */
    /* JADX WARN: Removed duplicated region for block: B:82:0x01ca  */
    /* JADX WARN: Removed duplicated region for block: B:83:0x01d1  */
    /* JADX WARN: Removed duplicated region for block: B:85:0x01d4  */
    /* JADX WARN: Removed duplicated region for block: B:89:0x01dc  */
    /* JADX WARN: Removed duplicated region for block: B:91:0x01ec  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void u(at atVar, Bundle bundle) {
        Activity activity;
        Intent intent;
        int[] intArray;
        Bundle bundle2;
        ao.c cVarE;
        int length;
        int i;
        String strA;
        ao aoVarH;
        at atVar2;
        Bundle bundle3;
        ao aoVarH2;
        at atVar3;
        ArrayList<String> stringArrayList;
        wy8 wy8Var = atVar.m;
        boolean zB = cr4.b(this.c, atVar);
        ds<NavBackStackEntry> dsVar = this.g;
        int i2 = 0;
        if (zB) {
            int iF = wy8Var.f();
            while (i2 < iF) {
                ao aoVar = (ao) wy8Var.g(i2);
                at atVar4 = this.c;
                cr4.d(atVar4);
                int iD = atVar4.m.d(i2);
                at atVar5 = this.c;
                cr4.d(atVar5);
                wy8 wy8Var2 = atVar5.m;
                if (wy8Var2.a) {
                    C0746xy8.a(wy8Var2);
                }
                int iA = C0611ld1.a(wy8Var2.d, iD, wy8Var2.b);
                if (iA >= 0) {
                    Object[] objArr = wy8Var2.c;
                    Object obj = objArr[iA];
                    objArr[iA] = aoVar;
                }
                i2++;
            }
            for (NavBackStackEntry navBackStackEntry : dsVar) {
                int i3 = ao.l;
                List<ao> listK = y41.k(sg8.s(ao.b.b(navBackStackEntry.b)));
                ao aoVarH3 = this.c;
                cr4.d(aoVarH3);
                for (ao aoVar2 : listK) {
                    if (!cr4.b(aoVar2, this.c) || !cr4.b(aoVarH3, atVar)) {
                        if (aoVarH3 instanceof at) {
                            aoVarH3 = ((at) aoVarH3).h(aoVar2.j, true);
                            cr4.d(aoVarH3);
                        }
                    }
                }
                cr4.g(aoVarH3, "<set-?>");
                navBackStackEntry.b = aoVarH3;
            }
            return;
        }
        at atVar6 = this.c;
        LinkedHashMap linkedHashMap = this.x;
        if (atVar6 != null) {
            for (Integer num : new ArrayList(this.n.keySet())) {
                cr4.f(num, TtmlNode.ATTR_ID);
                int iIntValue = num.intValue();
                Iterator it = linkedHashMap.values().iterator();
                while (it.hasNext()) {
                    ((b) it.next()).d = true;
                }
                boolean zT = t(iIntValue, null, mj6.a(m.a));
                Iterator it2 = linkedHashMap.values().iterator();
                while (it2.hasNext()) {
                    ((b) it2.next()).d = false;
                }
                if (zT) {
                    p(iIntValue, true, false);
                }
            }
            p(atVar6.j, true, false);
        }
        this.c = atVar;
        Bundle bundle4 = this.d;
        bf bfVar = this.w;
        if (bundle4 != null && (stringArrayList = bundle4.getStringArrayList("android-support-nav:controller:navigatorState:names")) != null) {
            for (String str : stringArrayList) {
                cr4.f(str, AppMeasurementSdk.ConditionalUserProperty.NAME);
                bc bcVarB = bfVar.b(str);
                Bundle bundle5 = bundle4.getBundle(str);
                if (bundle5 != null) {
                    bcVarB.g(bundle5);
                }
            }
        }
        Parcelable[] parcelableArr = this.e;
        Context context = this.a;
        if (parcelableArr != null) {
            for (Parcelable parcelable : parcelableArr) {
                cr4.e(parcelable, "null cannot be cast to non-null type androidx.navigation.NavBackStackEntryState");
                i iVar = (i) parcelable;
                int i4 = iVar.b;
                ao aoVarC = c(i4);
                if (aoVarC == null) {
                    int i5 = ao.l;
                    StringBuilder sbS = vw2.s("Restoring the Navigation back stack failed: destination ", ao.b.a(context, i4), " cannot be found from the current destination ");
                    sbS.append(f());
                    throw new IllegalStateException(sbS.toString());
                }
                NavBackStackEntry navBackStackEntryC = iVar.c(context, aoVarC, i(), this.q);
                bc bcVarB2 = bfVar.b(aoVarC.a);
                Object bVar = linkedHashMap.get(bcVarB2);
                if (bVar == null) {
                    bVar = new b(this, bcVarB2);
                    linkedHashMap.put(bcVarB2, bVar);
                }
                dsVar.addLast(navBackStackEntryC);
                ((b) bVar).j(navBackStackEntryC);
                at atVar7 = navBackStackEntryC.b.b;
                if (atVar7 != null) {
                    j(navBackStackEntryC, e(atVar7.j));
                }
            }
            x();
            this.e = null;
        }
        Collection collectionValues = wo5.n(bfVar.a).values();
        ArrayList<bc> arrayList = new ArrayList();
        for (Object obj2 : collectionValues) {
            if (!((bc) obj2).b) {
                arrayList.add(obj2);
            }
        }
        for (bc bcVar : arrayList) {
            Object bVar2 = linkedHashMap.get(bcVar);
            if (bVar2 == null) {
                bVar2 = new b(this, bcVar);
                linkedHashMap.put(bcVar, bVar2);
            }
            bcVar.e((b) bVar2);
        }
        if (this.c == null || !dsVar.isEmpty()) {
            b();
            return;
        }
        if (!this.f && (activity = this.b) != null && (intent = activity.getIntent()) != null) {
            Bundle extras = intent.getExtras();
            if (extras != null) {
                try {
                    intArray = extras.getIntArray("android-support-nav:controller:deepLinkIds");
                } catch (Exception e) {
                    Log.e("NavController", "handleDeepLink() could not extract deepLink from " + intent, e);
                    intArray = null;
                }
                ArrayList parcelableArrayList = extras == null ? extras.getParcelableArrayList("android-support-nav:controller:deepLinkArgs") : null;
                Bundle bundle6 = new Bundle();
                bundle2 = extras == null ? extras.getBundle("android-support-nav:controller:deepLinkExtras") : null;
                if (bundle2 != null) {
                    bundle6.putAll(bundle2);
                }
                if (intArray != null || intArray.length == 0) {
                    at atVar8 = this.c;
                    cr4.d(atVar8);
                    cVarE = atVar8.e(new an(intent));
                    if (cVarE != null) {
                        ao aoVar3 = cVarE.a;
                        int[] iArrC = aoVar3.c(null);
                        Bundle bundleB = aoVar3.b(cVarE.b);
                        if (bundleB != null) {
                            bundle6.putAll(bundleB);
                        }
                        intArray = iArrC;
                        parcelableArrayList = null;
                    }
                }
                if (intArray != null && intArray.length != 0) {
                    at atVar9 = this.c;
                    length = intArray.length;
                    i = 0;
                    while (true) {
                        if (i < length) {
                            strA = null;
                            break;
                        }
                        int i6 = intArray[i];
                        if (i == 0) {
                            at atVar10 = this.c;
                            cr4.d(atVar10);
                            aoVarH2 = atVar10.j == i6 ? this.c : null;
                        } else {
                            cr4.d(atVar9);
                            aoVarH2 = atVar9.h(i6, true);
                        }
                        if (aoVarH2 == null) {
                            int i7 = ao.l;
                            strA = ao.b.a(context, i6);
                            break;
                        }
                        if (i != intArray.length - 1 && (aoVarH2 instanceof at)) {
                            while (true) {
                                atVar3 = (at) aoVarH2;
                                cr4.d(atVar3);
                                if (!(atVar3.h(atVar3.n, true) instanceof at)) {
                                    break;
                                } else {
                                    aoVarH2 = atVar3.h(atVar3.n, true);
                                }
                            }
                            atVar9 = atVar3;
                        }
                        i++;
                    }
                    if (strA != null) {
                        bundle6.putParcelable("android-support-nav:controller:deepLinkIntent", intent);
                        int length2 = intArray.length;
                        Bundle[] bundleArr = new Bundle[length2];
                        for (int i8 = 0; i8 < length2; i8++) {
                            Bundle bundle7 = new Bundle();
                            bundle7.putAll(bundle6);
                            if (parcelableArrayList != null && (bundle3 = (Bundle) parcelableArrayList.get(i8)) != null) {
                                bundle7.putAll(bundle3);
                            }
                            bundleArr[i8] = bundle7;
                        }
                        int flags = intent.getFlags();
                        int i9 = 268435456 & flags;
                        if (i9 != 0 && (flags & 32768) == 0) {
                            intent.addFlags(32768);
                            wj9 wj9Var = new wj9(context);
                            ComponentName component = intent.getComponent();
                            if (component == null) {
                                component = intent.resolveActivity(wj9Var.b.getPackageManager());
                            }
                            if (component != null) {
                                wj9Var.a(component);
                            }
                            wj9Var.a.add(intent);
                            wj9Var.b();
                            activity.finish();
                            activity.overridePendingTransition(0, 0);
                            return;
                        }
                        if (i9 != 0) {
                            if (!dsVar.isEmpty()) {
                                at atVar11 = this.c;
                                cr4.d(atVar11);
                                p(atVar11.j, true, false);
                            }
                            while (i2 < intArray.length) {
                                int i10 = intArray[i2];
                                int i11 = i2 + 1;
                                Bundle bundle8 = bundleArr[i2];
                                ao aoVarC2 = c(i10);
                                if (aoVarC2 == null) {
                                    int i12 = ao.l;
                                    StringBuilder sbS2 = vw2.s("Deep Linking failed: destination ", ao.b.a(context, i10), " cannot be found from the current destination ");
                                    sbS2.append(f());
                                    throw new IllegalStateException(sbS2.toString());
                                }
                                m(aoVarC2, bundle8, mj6.a(new v(aoVarC2, this)));
                                i2 = i11;
                            }
                            this.f = true;
                            return;
                        }
                        at atVar12 = this.c;
                        int length3 = intArray.length;
                        for (int i13 = 0; i13 < length3; i13++) {
                            int i14 = intArray[i13];
                            Bundle bundle9 = bundleArr[i13];
                            if (i13 == 0) {
                                aoVarH = this.c;
                            } else {
                                cr4.d(atVar12);
                                aoVarH = atVar12.h(i14, true);
                            }
                            if (aoVarH == null) {
                                int i15 = ao.l;
                                throw new IllegalStateException("Deep Linking failed: destination " + ao.b.a(context, i14) + " cannot be found in graph " + atVar12);
                            }
                            if (i13 == intArray.length - 1) {
                                aw.a aVar = new aw.a();
                                at atVar13 = this.c;
                                cr4.d(atVar13);
                                aVar.c = atVar13.j;
                                aVar.d = true;
                                aVar.e = false;
                                aVar.f = 0;
                                aVar.g = 0;
                                m(aoVarH, bundle9, aVar.a());
                            } else if (aoVarH instanceof at) {
                                while (true) {
                                    atVar2 = (at) aoVarH;
                                    cr4.d(atVar2);
                                    if (!(atVar2.h(atVar2.n, true) instanceof at)) {
                                        break;
                                    } else {
                                        aoVarH = atVar2.h(atVar2.n, true);
                                    }
                                }
                                atVar12 = atVar2;
                            }
                        }
                        this.f = true;
                        return;
                    }
                    intent.toString();
                }
            } else {
                intArray = null;
                if (extras == null) {
                }
                Bundle bundle62 = new Bundle();
                if (extras == null) {
                }
                if (bundle2 != null) {
                }
                if (intArray != null) {
                    at atVar82 = this.c;
                    cr4.d(atVar82);
                    cVarE = atVar82.e(new an(intent));
                    if (cVarE != null) {
                    }
                    if (intArray != null) {
                        at atVar92 = this.c;
                        length = intArray.length;
                        i = 0;
                        while (true) {
                            if (i < length) {
                            }
                            i++;
                        }
                        if (strA != null) {
                        }
                    }
                }
            }
        }
        ao aoVar4 = this.c;
        cr4.d(aoVar4);
        m(aoVar4, bundle, null);
    }

    public final void v(NavBackStackEntry navBackStackEntry) {
        cr4.g(navBackStackEntry, "child");
        NavBackStackEntry navBackStackEntry2 = (NavBackStackEntry) this.l.remove(navBackStackEntry);
        if (navBackStackEntry2 == null) {
            return;
        }
        LinkedHashMap linkedHashMap = this.m;
        AtomicInteger atomicInteger = (AtomicInteger) linkedHashMap.get(navBackStackEntry2);
        Integer numValueOf = atomicInteger != null ? Integer.valueOf(atomicInteger.decrementAndGet()) : null;
        if (numValueOf != null && numValueOf.intValue() == 0) {
            b bVar = (b) this.x.get(this.w.b(navBackStackEntry2.b.a));
            if (bVar != null) {
                bVar.b(navBackStackEntry2);
            }
            linkedHashMap.remove(navBackStackEntry2);
        }
    }

    public final void w() {
        AtomicInteger atomicInteger;
        o29 o29Var;
        Set set;
        ArrayList<NavBackStackEntry> arrayListBp = y41.bp(this.g);
        if (arrayListBp.isEmpty()) {
            return;
        }
        ao aoVar = ((NavBackStackEntry) y41.ak(arrayListBp)).b;
        ArrayList arrayList = new ArrayList();
        if (aoVar instanceof f43) {
            Iterator it = y41.bb(arrayListBp).iterator();
            while (it.hasNext()) {
                ao aoVar2 = ((NavBackStackEntry) it.next()).b;
                arrayList.add(aoVar2);
                if (!(aoVar2 instanceof f43) && !(aoVar2 instanceof at)) {
                    break;
                }
            }
        }
        HashMap map = new HashMap();
        for (NavBackStackEntry navBackStackEntry : y41.bb(arrayListBp)) {
            k.b bVar = navBackStackEntry.o;
            ao aoVar3 = navBackStackEntry.b;
            k.b bVar2 = k.b.e;
            k.b bVar3 = k.b.d;
            if (aoVar != null && aoVar3.j == aoVar.j) {
                if (bVar != bVar2) {
                    b bVar4 = (b) this.x.get(this.w.b(aoVar3.a));
                    if (cr4.b((bVar4 == null || (o29Var = bVar4.f) == null || (set = (Set) o29Var.getValue()) == null) ? null : Boolean.valueOf(set.contains(navBackStackEntry)), Boolean.TRUE) || ((atomicInteger = (AtomicInteger) this.m.get(navBackStackEntry)) != null && atomicInteger.get() == 0)) {
                        map.put(navBackStackEntry, bVar3);
                    } else {
                        map.put(navBackStackEntry, bVar2);
                    }
                }
                ao aoVar4 = (ao) y41.ab(arrayList);
                if (aoVar4 != null && aoVar4.j == aoVar3.j) {
                    if (arrayList.isEmpty()) {
                        throw new NoSuchElementException("List is empty.");
                    }
                    arrayList.remove(0);
                }
                aoVar = aoVar.b;
            } else if (arrayList.isEmpty() || aoVar3.j != ((ao) y41.z(arrayList)).j) {
                navBackStackEntry.b(k.b.c);
            } else {
                if (arrayList.isEmpty()) {
                    throw new NoSuchElementException("List is empty.");
                }
                ao aoVar5 = (ao) arrayList.remove(0);
                if (bVar == bVar2) {
                    navBackStackEntry.b(bVar3);
                } else if (bVar != bVar3) {
                    map.put(navBackStackEntry, bVar3);
                }
                at atVar = aoVar5.b;
                if (atVar != null && !arrayList.contains(atVar)) {
                    arrayList.add(atVar);
                }
            }
        }
        for (NavBackStackEntry navBackStackEntry2 : arrayListBp) {
            k.b bVar5 = (k.b) map.get(navBackStackEntry2);
            if (bVar5 != null) {
                navBackStackEntry2.b(bVar5);
            } else {
                navBackStackEntry2.c();
            }
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x000c  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void x() {
        boolean z;
        if (this.v) {
            z = g() > 1;
        }
        this.u.h(z);
    }
}
