package v4;

import android.app.Activity;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.Log;
import androidx.lifecycle.d1;
import androidx.lifecycle.n;
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.Map;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicInteger;
import kotlin.jvm.internal.k0;
import kotlin.jvm.internal.m0;
import rm.n0;
import v4.g;
import v4.k;
import v4.o;
import v4.t;
import v4.z;
import wp.h0;
import wp.j0;

/* loaded from: classes.dex */
public abstract class j {
    public static final a G = new a(null);
    private static boolean H = true;
    private final Map A;
    private int B;
    private final List C;
    private final rm.o D;
    private final wp.s E;
    private final wp.e F;

    /* renamed from: a, reason: collision with root package name */
    private final Context f39078a;

    /* renamed from: b, reason: collision with root package name */
    private Activity f39079b;

    /* renamed from: c, reason: collision with root package name */
    private s f39080c;

    /* renamed from: d, reason: collision with root package name */
    private p f39081d;

    /* renamed from: e, reason: collision with root package name */
    private Bundle f39082e;

    /* renamed from: f, reason: collision with root package name */
    private Parcelable[] f39083f;

    /* renamed from: g, reason: collision with root package name */
    private boolean f39084g;

    /* renamed from: h, reason: collision with root package name */
    private final sm.k f39085h;

    /* renamed from: i, reason: collision with root package name */
    private final wp.t f39086i;

    /* renamed from: j, reason: collision with root package name */
    private final h0 f39087j;

    /* renamed from: k, reason: collision with root package name */
    private final Map f39088k;

    /* renamed from: l, reason: collision with root package name */
    private final Map f39089l;

    /* renamed from: m, reason: collision with root package name */
    private final Map f39090m;

    /* renamed from: n, reason: collision with root package name */
    private final Map f39091n;

    /* renamed from: o, reason: collision with root package name */
    private androidx.lifecycle.u f39092o;

    /* renamed from: p, reason: collision with root package name */
    private androidx.activity.q f39093p;

    /* renamed from: q, reason: collision with root package name */
    private v4.k f39094q;

    /* renamed from: r, reason: collision with root package name */
    private final CopyOnWriteArrayList f39095r;

    /* renamed from: s, reason: collision with root package name */
    private n.b f39096s;

    /* renamed from: t, reason: collision with root package name */
    private final androidx.lifecycle.t f39097t;

    /* renamed from: u, reason: collision with root package name */
    private final androidx.activity.p f39098u;

    /* renamed from: v, reason: collision with root package name */
    private boolean f39099v;

    /* renamed from: w, reason: collision with root package name */
    private a0 f39100w;

    /* renamed from: x, reason: collision with root package name */
    private final Map f39101x;

    /* renamed from: y, reason: collision with root package name */
    private dn.l f39102y;

    /* renamed from: z, reason: collision with root package name */
    private dn.l f39103z;

    /* loaded from: classes.dex */
    public static final class a {
        private a() {
        }

        public /* synthetic */ a(kotlin.jvm.internal.k kVar) {
            this();
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: classes.dex */
    public final class b extends b0 {

        /* renamed from: g, reason: collision with root package name */
        private final z f39104g;

        /* renamed from: h, reason: collision with root package name */
        final /* synthetic */ j f39105h;

        /* loaded from: classes.dex */
        static final class a extends kotlin.jvm.internal.v implements dn.a {

            /* renamed from: q, reason: collision with root package name */
            final /* synthetic */ v4.g f39107q;

            /* renamed from: r, reason: collision with root package name */
            final /* synthetic */ boolean f39108r;

            /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
            a(v4.g gVar, boolean z10) {
                super(0);
                this.f39107q = gVar;
                this.f39108r = z10;
            }

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

            /* renamed from: invoke, reason: collision with other method in class */
            public final void m447invoke() {
                b.super.g(this.f39107q, this.f39108r);
            }
        }

        public b(j this$0, z navigator) {
            kotlin.jvm.internal.t.g(this$0, "this$0");
            kotlin.jvm.internal.t.g(navigator, "navigator");
            this.f39105h = this$0;
            this.f39104g = navigator;
        }

        @Override // v4.b0
        public v4.g a(v4.o destination, Bundle bundle) {
            kotlin.jvm.internal.t.g(destination, "destination");
            return g.a.b(v4.g.C, this.f39105h.z(), destination, bundle, this.f39105h.E(), this.f39105h.f39094q, null, null, 96, null);
        }

        @Override // v4.b0
        public void e(v4.g entry) {
            v4.k kVar;
            kotlin.jvm.internal.t.g(entry, "entry");
            boolean b10 = kotlin.jvm.internal.t.b(this.f39105h.A.get(entry), Boolean.TRUE);
            super.e(entry);
            this.f39105h.A.remove(entry);
            if (this.f39105h.x().contains(entry)) {
                if (d()) {
                    return;
                }
                this.f39105h.s0();
                this.f39105h.f39086i.d(this.f39105h.d0());
                return;
            }
            this.f39105h.r0(entry);
            if (entry.getLifecycle().b().isAtLeast(n.b.CREATED)) {
                entry.m(n.b.DESTROYED);
            }
            sm.k x10 = this.f39105h.x();
            boolean z10 = true;
            if (!(x10 instanceof Collection) || !x10.isEmpty()) {
                Iterator<E> it = x10.iterator();
                while (true) {
                    if (!it.hasNext()) {
                        break;
                    } else if (kotlin.jvm.internal.t.b(((v4.g) it.next()).g(), entry.g())) {
                        z10 = false;
                        break;
                    }
                }
            }
            if (z10 && !b10 && (kVar = this.f39105h.f39094q) != null) {
                kVar.Q(entry.g());
            }
            this.f39105h.s0();
            this.f39105h.f39086i.d(this.f39105h.d0());
        }

        @Override // v4.b0
        public void g(v4.g popUpTo, boolean z10) {
            kotlin.jvm.internal.t.g(popUpTo, "popUpTo");
            z d10 = this.f39105h.f39100w.d(popUpTo.f().F());
            if (!kotlin.jvm.internal.t.b(d10, this.f39104g)) {
                Object obj = this.f39105h.f39101x.get(d10);
                kotlin.jvm.internal.t.d(obj);
                ((b) obj).g(popUpTo, z10);
            } else {
                dn.l lVar = this.f39105h.f39103z;
                if (lVar == null) {
                    this.f39105h.X(popUpTo, new a(popUpTo, z10));
                } else {
                    lVar.invoke(popUpTo);
                    super.g(popUpTo, z10);
                }
            }
        }

        @Override // v4.b0
        public void h(v4.g backStackEntry) {
            kotlin.jvm.internal.t.g(backStackEntry, "backStackEntry");
            z d10 = this.f39105h.f39100w.d(backStackEntry.f().F());
            if (!kotlin.jvm.internal.t.b(d10, this.f39104g)) {
                Object obj = this.f39105h.f39101x.get(d10);
                if (obj != null) {
                    ((b) obj).h(backStackEntry);
                    return;
                }
                throw new IllegalStateException(("NavigatorBackStack for " + backStackEntry.f().F() + " should already be created").toString());
            }
            dn.l lVar = this.f39105h.f39102y;
            if (lVar != null) {
                lVar.invoke(backStackEntry);
                k(backStackEntry);
                return;
            }
            Log.i("NavController", "Ignoring add of destination " + backStackEntry.f() + " outside of the call to navigate(). ");
        }

        public final void k(v4.g backStackEntry) {
            kotlin.jvm.internal.t.g(backStackEntry, "backStackEntry");
            super.h(backStackEntry);
        }
    }

    /* loaded from: classes.dex */
    public interface c {
        void a(j jVar, v4.o oVar, Bundle bundle);
    }

    /* loaded from: classes.dex */
    static final class d extends kotlin.jvm.internal.v implements dn.l {

        /* renamed from: p, reason: collision with root package name */
        public static final d f39109p = new d();

        d() {
            super(1);
        }

        @Override // dn.l
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public final Context invoke(Context it) {
            kotlin.jvm.internal.t.g(it, "it");
            if (it instanceof ContextWrapper) {
                return ((ContextWrapper) it).getBaseContext();
            }
            return null;
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public static final class e extends kotlin.jvm.internal.v implements dn.l {

        /* renamed from: p, reason: collision with root package name */
        final /* synthetic */ v4.o f39110p;

        /* renamed from: q, reason: collision with root package name */
        final /* synthetic */ j f39111q;

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

            /* renamed from: p, reason: collision with root package name */
            public static final a f39112p = new a();

            a() {
                super(1);
            }

            public final void a(v4.c anim) {
                kotlin.jvm.internal.t.g(anim, "$this$anim");
                anim.e(0);
                anim.f(0);
            }

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

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

            /* renamed from: p, reason: collision with root package name */
            public static final b f39113p = new b();

            b() {
                super(1);
            }

            public final void a(c0 popUpTo) {
                kotlin.jvm.internal.t.g(popUpTo, "$this$popUpTo");
                popUpTo.c(true);
            }

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

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        e(v4.o oVar, j jVar) {
            super(1);
            this.f39110p = oVar;
            this.f39111q = jVar;
        }

        public final void a(u navOptions) {
            boolean z10;
            kotlin.jvm.internal.t.g(navOptions, "$this$navOptions");
            navOptions.a(a.f39112p);
            v4.o oVar = this.f39110p;
            boolean z11 = false;
            if (oVar instanceof p) {
                rp.h c10 = v4.o.f39171y.c(oVar);
                j jVar = this.f39111q;
                Iterator it = c10.iterator();
                while (true) {
                    if (!it.hasNext()) {
                        z10 = true;
                        break;
                    }
                    v4.o oVar2 = (v4.o) it.next();
                    v4.o B = jVar.B();
                    if (kotlin.jvm.internal.t.b(oVar2, B == null ? null : B.G())) {
                        z10 = false;
                        break;
                    }
                }
                if (z10) {
                    z11 = true;
                }
            }
            if (z11 && j.H) {
                navOptions.g(p.E.a(this.f39111q.D()).D(), b.f39113p);
            }
        }

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

    /* loaded from: classes.dex */
    static final class f extends kotlin.jvm.internal.v implements dn.a {
        f() {
            super(0);
        }

        @Override // dn.a
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public final s invoke() {
            s sVar = j.this.f39080c;
            return sVar == null ? new s(j.this.z(), j.this.f39100w) : sVar;
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public static final class g extends kotlin.jvm.internal.v implements dn.l {

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

        /* renamed from: q, reason: collision with root package name */
        final /* synthetic */ j f39116q;

        /* renamed from: r, reason: collision with root package name */
        final /* synthetic */ v4.o f39117r;

        /* renamed from: s, reason: collision with root package name */
        final /* synthetic */ Bundle f39118s;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        g(k0 k0Var, j jVar, v4.o oVar, Bundle bundle) {
            super(1);
            this.f39115p = k0Var;
            this.f39116q = jVar;
            this.f39117r = oVar;
            this.f39118s = bundle;
        }

        public final void a(v4.g it) {
            kotlin.jvm.internal.t.g(it, "it");
            this.f39115p.f26193p = true;
            j.o(this.f39116q, this.f39117r, this.f39118s, it, null, 8, null);
        }

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

    /* loaded from: classes.dex */
    public static final class h extends androidx.activity.p {
        h() {
            super(false);
        }

        @Override // androidx.activity.p
        public void d() {
            j.this.U();
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public static final class i extends kotlin.jvm.internal.v implements dn.l {

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

        /* renamed from: q, reason: collision with root package name */
        final /* synthetic */ k0 f39121q;

        /* renamed from: r, reason: collision with root package name */
        final /* synthetic */ j f39122r;

        /* renamed from: s, reason: collision with root package name */
        final /* synthetic */ boolean f39123s;

        /* renamed from: t, reason: collision with root package name */
        final /* synthetic */ sm.k f39124t;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        i(k0 k0Var, k0 k0Var2, j jVar, boolean z10, sm.k kVar) {
            super(1);
            this.f39120p = k0Var;
            this.f39121q = k0Var2;
            this.f39122r = jVar;
            this.f39123s = z10;
            this.f39124t = kVar;
        }

        public final void a(v4.g entry) {
            kotlin.jvm.internal.t.g(entry, "entry");
            this.f39120p.f26193p = true;
            this.f39121q.f26193p = true;
            this.f39122r.b0(entry, this.f39123s, this.f39124t);
        }

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

    /* JADX INFO: Access modifiers changed from: package-private */
    /* renamed from: v4.j$j, reason: collision with other inner class name */
    /* loaded from: classes.dex */
    public static final class C0925j extends kotlin.jvm.internal.v implements dn.l {

        /* renamed from: p, reason: collision with root package name */
        public static final C0925j f39125p = new C0925j();

        C0925j() {
            super(1);
        }

        @Override // dn.l
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public final v4.o invoke(v4.o destination) {
            kotlin.jvm.internal.t.g(destination, "destination");
            p G = destination.G();
            boolean z10 = false;
            if (G != null && G.Z() == destination.D()) {
                z10 = true;
            }
            if (z10) {
                return destination.G();
            }
            return null;
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public static final class k extends kotlin.jvm.internal.v implements dn.l {
        k() {
            super(1);
        }

        @Override // dn.l
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public final Boolean invoke(v4.o destination) {
            kotlin.jvm.internal.t.g(destination, "destination");
            return Boolean.valueOf(!j.this.f39090m.containsKey(Integer.valueOf(destination.D())));
        }
    }

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

        /* renamed from: p, reason: collision with root package name */
        public static final l f39127p = new l();

        l() {
            super(1);
        }

        @Override // dn.l
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public final v4.o invoke(v4.o destination) {
            kotlin.jvm.internal.t.g(destination, "destination");
            p G = destination.G();
            boolean z10 = false;
            if (G != null && G.Z() == destination.D()) {
                z10 = true;
            }
            if (z10) {
                return destination.G();
            }
            return null;
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public static final class m extends kotlin.jvm.internal.v implements dn.l {
        m() {
            super(1);
        }

        @Override // dn.l
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public final Boolean invoke(v4.o destination) {
            kotlin.jvm.internal.t.g(destination, "destination");
            return Boolean.valueOf(!j.this.f39090m.containsKey(Integer.valueOf(destination.D())));
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public static final class n extends kotlin.jvm.internal.v implements dn.l {

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

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        n(String str) {
            super(1);
            this.f39129p = str;
        }

        @Override // dn.l
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public final Boolean invoke(String str) {
            return Boolean.valueOf(kotlin.jvm.internal.t.b(str, this.f39129p));
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public static final class o extends kotlin.jvm.internal.v implements dn.l {

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

        /* renamed from: q, reason: collision with root package name */
        final /* synthetic */ List f39131q;

        /* renamed from: r, reason: collision with root package name */
        final /* synthetic */ m0 f39132r;

        /* renamed from: s, reason: collision with root package name */
        final /* synthetic */ j f39133s;

        /* renamed from: t, reason: collision with root package name */
        final /* synthetic */ Bundle f39134t;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        o(k0 k0Var, List list, m0 m0Var, j jVar, Bundle bundle) {
            super(1);
            this.f39130p = k0Var;
            this.f39131q = list;
            this.f39132r = m0Var;
            this.f39133s = jVar;
            this.f39134t = bundle;
        }

        public final void a(v4.g entry) {
            List k10;
            kotlin.jvm.internal.t.g(entry, "entry");
            this.f39130p.f26193p = true;
            int indexOf = this.f39131q.indexOf(entry);
            if (indexOf != -1) {
                int i10 = indexOf + 1;
                k10 = this.f39131q.subList(this.f39132r.f26197p, i10);
                this.f39132r.f26197p = i10;
            } else {
                k10 = sm.u.k();
            }
            this.f39133s.n(entry.f(), this.f39134t, entry, k10);
        }

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

    public j(Context context) {
        rp.h i10;
        Object obj;
        List k10;
        rm.o a10;
        kotlin.jvm.internal.t.g(context, "context");
        this.f39078a = context;
        i10 = rp.n.i(context, d.f39109p);
        Iterator it = i10.iterator();
        while (true) {
            if (!it.hasNext()) {
                obj = null;
                break;
            } else {
                obj = it.next();
                if (((Context) obj) instanceof Activity) {
                    break;
                }
            }
        }
        this.f39079b = (Activity) obj;
        this.f39085h = new sm.k();
        k10 = sm.u.k();
        wp.t a11 = j0.a(k10);
        this.f39086i = a11;
        this.f39087j = wp.g.b(a11);
        this.f39088k = new LinkedHashMap();
        this.f39089l = new LinkedHashMap();
        this.f39090m = new LinkedHashMap();
        this.f39091n = new LinkedHashMap();
        this.f39095r = new CopyOnWriteArrayList();
        this.f39096s = n.b.INITIALIZED;
        this.f39097t = new androidx.lifecycle.r() { // from class: v4.i
            @Override // androidx.lifecycle.r
            public final void f(androidx.lifecycle.u uVar, n.a aVar) {
                j.K(j.this, uVar, aVar);
            }
        };
        this.f39098u = new h();
        this.f39099v = true;
        this.f39100w = new a0();
        this.f39101x = new LinkedHashMap();
        this.A = new LinkedHashMap();
        a0 a0Var = this.f39100w;
        a0Var.c(new q(a0Var));
        this.f39100w.c(new v4.b(this.f39078a));
        this.C = new ArrayList();
        a10 = rm.q.a(new f());
        this.D = a10;
        wp.s b10 = wp.z.b(1, 0, vp.a.DROP_OLDEST, 2, null);
        this.E = b10;
        this.F = wp.g.a(b10);
    }

    private final int C() {
        sm.k x10 = x();
        int i10 = 0;
        if (!(x10 instanceof Collection) || !x10.isEmpty()) {
            Iterator<E> it = x10.iterator();
            while (it.hasNext()) {
                if ((!(((v4.g) it.next()).f() instanceof p)) && (i10 = i10 + 1) < 0) {
                    sm.u.t();
                }
            }
        }
        return i10;
    }

    private final List J(sm.k kVar) {
        ArrayList arrayList = new ArrayList();
        v4.g gVar = (v4.g) x().C();
        v4.o f10 = gVar == null ? null : gVar.f();
        if (f10 == null) {
            f10 = D();
        }
        if (kVar != null) {
            Iterator<E> it = kVar.iterator();
            while (it.hasNext()) {
                v4.h hVar = (v4.h) it.next();
                v4.o v10 = v(f10, hVar.a());
                if (v10 == null) {
                    throw new IllegalStateException(("Restore State failed: destination " + v4.o.f39171y.b(z(), hVar.a()) + " cannot be found from the current destination " + f10).toString());
                }
                arrayList.add(hVar.c(z(), v10, E(), this.f39094q));
                f10 = v10;
            }
        }
        return arrayList;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void K(j this$0, androidx.lifecycle.u noName_0, n.a event) {
        kotlin.jvm.internal.t.g(this$0, "this$0");
        kotlin.jvm.internal.t.g(noName_0, "$noName_0");
        kotlin.jvm.internal.t.g(event, "event");
        n.b targetState = event.getTargetState();
        kotlin.jvm.internal.t.f(targetState, "event.targetState");
        this$0.f39096s = targetState;
        if (this$0.f39081d != null) {
            Iterator<E> it = this$0.x().iterator();
            while (it.hasNext()) {
                ((v4.g) it.next()).j(event);
            }
        }
    }

    private final void L(v4.g gVar, v4.g gVar2) {
        this.f39088k.put(gVar, gVar2);
        if (this.f39089l.get(gVar2) == null) {
            this.f39089l.put(gVar2, new AtomicInteger(0));
        }
        Object obj = this.f39089l.get(gVar2);
        kotlin.jvm.internal.t.d(obj);
        ((AtomicInteger) obj).incrementAndGet();
    }

    /* JADX WARN: Removed duplicated region for block: B:22:0x011e A[LOOP:1: B:20:0x0118->B:22:0x011e, LOOP_END] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    private final void Q(v4.o oVar, Bundle bundle, t tVar, z.a aVar) {
        boolean z10;
        List e10;
        v4.o f10;
        Iterator it;
        Iterator it2 = this.f39101x.values().iterator();
        while (true) {
            z10 = true;
            if (!it2.hasNext()) {
                break;
            } else {
                ((b) it2.next()).i(true);
            }
        }
        k0 k0Var = new k0();
        boolean Z = (tVar == null || tVar.e() == -1) ? false : Z(tVar.e(), tVar.f(), tVar.h());
        Bundle m10 = oVar.m(bundle);
        if ((tVar != null && tVar.i()) && this.f39090m.containsKey(Integer.valueOf(oVar.D()))) {
            k0Var.f26193p = g0(oVar.D(), m10, tVar, aVar);
        } else {
            v4.g A = A();
            z d10 = this.f39100w.d(oVar.F());
            if (tVar != null && tVar.g()) {
                if ((A == null || (f10 = A.f()) == null || oVar.D() != f10.D()) ? false : true) {
                    r0((v4.g) x().removeLast());
                    v4.g gVar = new v4.g(A, m10);
                    x().addLast(gVar);
                    p G2 = gVar.f().G();
                    if (G2 != null) {
                        L(gVar, y(G2.D()));
                    }
                    d10.g(gVar);
                    t0();
                    it = this.f39101x.values().iterator();
                    while (it.hasNext()) {
                        ((b) it.next()).i(false);
                    }
                    if (!Z || k0Var.f26193p || z10) {
                        s();
                    } else {
                        s0();
                        return;
                    }
                }
            }
            e10 = sm.t.e(g.a.b(v4.g.C, this.f39078a, oVar, m10, E(), this.f39094q, null, null, 96, null));
            R(d10, e10, tVar, aVar, new g(k0Var, this, oVar, m10));
        }
        z10 = false;
        t0();
        it = this.f39101x.values().iterator();
        while (it.hasNext()) {
        }
        if (Z) {
        }
        s();
    }

    private final void R(z zVar, List list, t tVar, z.a aVar, dn.l lVar) {
        this.f39102y = lVar;
        zVar.e(list, tVar, aVar);
        this.f39102y = null;
    }

    private final void T(Bundle bundle) {
        Activity activity;
        ArrayList<String> stringArrayList;
        Bundle bundle2 = this.f39082e;
        if (bundle2 != null && (stringArrayList = bundle2.getStringArrayList("android-support-nav:controller:navigatorState:names")) != null) {
            Iterator<String> it = stringArrayList.iterator();
            while (it.hasNext()) {
                String name = it.next();
                a0 a0Var = this.f39100w;
                kotlin.jvm.internal.t.f(name, "name");
                z d10 = a0Var.d(name);
                Bundle bundle3 = bundle2.getBundle(name);
                if (bundle3 != null) {
                    d10.h(bundle3);
                }
            }
        }
        Parcelable[] parcelableArr = this.f39083f;
        boolean z10 = false;
        if (parcelableArr != null) {
            int length = parcelableArr.length;
            int i10 = 0;
            while (i10 < length) {
                Parcelable parcelable = parcelableArr[i10];
                i10++;
                v4.h hVar = (v4.h) parcelable;
                v4.o u10 = u(hVar.a());
                if (u10 == null) {
                    throw new IllegalStateException("Restoring the Navigation back stack failed: destination " + v4.o.f39171y.b(z(), hVar.a()) + " cannot be found from the current destination " + B());
                }
                v4.g c10 = hVar.c(z(), u10, E(), this.f39094q);
                z d11 = this.f39100w.d(u10.F());
                Map map = this.f39101x;
                Object obj = map.get(d11);
                if (obj == null) {
                    obj = new b(this, d11);
                    map.put(d11, obj);
                }
                x().add(c10);
                ((b) obj).k(c10);
                p G2 = c10.f().G();
                if (G2 != null) {
                    L(c10, y(G2.D()));
                }
            }
            t0();
            this.f39083f = null;
        }
        Collection values = this.f39100w.e().values();
        ArrayList<z> arrayList = new ArrayList();
        for (Object obj2 : values) {
            if (!((z) obj2).c()) {
                arrayList.add(obj2);
            }
        }
        for (z zVar : arrayList) {
            Map map2 = this.f39101x;
            Object obj3 = map2.get(zVar);
            if (obj3 == null) {
                obj3 = new b(this, zVar);
                map2.put(zVar, obj3);
            }
            zVar.f((b) obj3);
        }
        if (this.f39081d == null || !x().isEmpty()) {
            s();
            return;
        }
        if (!this.f39084g && (activity = this.f39079b) != null) {
            kotlin.jvm.internal.t.d(activity);
            if (I(activity.getIntent())) {
                z10 = true;
            }
        }
        if (z10) {
            return;
        }
        p pVar = this.f39081d;
        kotlin.jvm.internal.t.d(pVar);
        Q(pVar, bundle, null, null);
    }

    private final void Y(z zVar, v4.g gVar, boolean z10, dn.l lVar) {
        this.f39103z = lVar;
        zVar.j(gVar, z10);
        this.f39103z = null;
    }

    private final boolean Z(int i10, boolean z10, boolean z11) {
        List B0;
        v4.o oVar;
        rp.h i11;
        rp.h C;
        rp.h i12;
        rp.h<v4.o> C2;
        if (x().isEmpty()) {
            return false;
        }
        ArrayList<z> arrayList = new ArrayList();
        B0 = sm.c0.B0(x());
        Iterator it = B0.iterator();
        while (true) {
            if (!it.hasNext()) {
                oVar = null;
                break;
            }
            v4.o f10 = ((v4.g) it.next()).f();
            z d10 = this.f39100w.d(f10.F());
            if (z10 || f10.D() != i10) {
                arrayList.add(d10);
            }
            if (f10.D() == i10) {
                oVar = f10;
                break;
            }
        }
        if (oVar == null) {
            Log.i("NavController", "Ignoring popBackStack to destination " + v4.o.f39171y.b(this.f39078a, i10) + " as it was not found on the current back stack");
            return false;
        }
        k0 k0Var = new k0();
        sm.k kVar = new sm.k();
        for (z zVar : arrayList) {
            k0 k0Var2 = new k0();
            Y(zVar, (v4.g) x().last(), z11, new i(k0Var2, k0Var, this, z11, kVar));
            if (!k0Var2.f26193p) {
                break;
            }
        }
        if (z11) {
            if (!z10) {
                i12 = rp.n.i(oVar, C0925j.f39125p);
                C2 = rp.p.C(i12, new k());
                for (v4.o oVar2 : C2) {
                    Map map = this.f39090m;
                    Integer valueOf = Integer.valueOf(oVar2.D());
                    v4.h hVar = (v4.h) kVar.z();
                    map.put(valueOf, hVar == null ? null : hVar.b());
                }
            }
            if (!kVar.isEmpty()) {
                v4.h hVar2 = (v4.h) kVar.first();
                i11 = rp.n.i(u(hVar2.a()), l.f39127p);
                C = rp.p.C(i11, new m());
                Iterator it2 = C.iterator();
                while (it2.hasNext()) {
                    this.f39090m.put(Integer.valueOf(((v4.o) it2.next()).D()), hVar2.b());
                }
                this.f39091n.put(hVar2.b(), kVar);
            }
        }
        t0();
        return k0Var.f26193p;
    }

    static /* synthetic */ boolean a0(j jVar, int i10, boolean z10, boolean z11, int i11, Object obj) {
        if (obj != null) {
            throw new UnsupportedOperationException("Super calls with default arguments not supported in this target, function: popBackStackInternal");
        }
        if ((i11 & 4) != 0) {
            z11 = false;
        }
        return jVar.Z(i10, z10, z11);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void b0(v4.g gVar, boolean z10, sm.k kVar) {
        h0 c10;
        Set set;
        v4.k kVar2;
        v4.g gVar2 = (v4.g) x().last();
        if (!kotlin.jvm.internal.t.b(gVar2, gVar)) {
            throw new IllegalStateException(("Attempted to pop " + gVar.f() + ", which is not the top of the back stack (" + gVar2.f() + ')').toString());
        }
        x().removeLast();
        b bVar = (b) this.f39101x.get(G().d(gVar2.f().F()));
        boolean z11 = true;
        if (!((bVar == null || (c10 = bVar.c()) == null || (set = (Set) c10.getValue()) == null || !set.contains(gVar2)) ? false : true) && !this.f39089l.containsKey(gVar2)) {
            z11 = false;
        }
        n.b b10 = gVar2.getLifecycle().b();
        n.b bVar2 = n.b.CREATED;
        if (b10.isAtLeast(bVar2)) {
            if (z10) {
                gVar2.m(bVar2);
                kVar.addFirst(new v4.h(gVar2));
            }
            if (z11) {
                gVar2.m(bVar2);
            } else {
                gVar2.m(n.b.DESTROYED);
                r0(gVar2);
            }
        }
        if (z10 || z11 || (kVar2 = this.f39094q) == null) {
            return;
        }
        kVar2.Q(gVar2.g());
    }

    static /* synthetic */ void c0(j jVar, v4.g gVar, boolean z10, sm.k kVar, int i10, Object obj) {
        if (obj != null) {
            throw new UnsupportedOperationException("Super calls with default arguments not supported in this target, function: popEntryFromBackStack");
        }
        if ((i10 & 2) != 0) {
            z10 = false;
        }
        if ((i10 & 4) != 0) {
            kVar = new sm.k();
        }
        jVar.b0(gVar, z10, kVar);
    }

    private final boolean g0(int i10, Bundle bundle, t tVar, z.a aVar) {
        Object c02;
        Object q02;
        List q10;
        Object o02;
        v4.o f10;
        if (!this.f39090m.containsKey(Integer.valueOf(i10))) {
            return false;
        }
        String str = (String) this.f39090m.get(Integer.valueOf(i10));
        sm.z.E(this.f39090m.values(), new n(str));
        List J = J((sm.k) this.f39091n.remove(str));
        ArrayList<List> arrayList = new ArrayList();
        ArrayList<v4.g> arrayList2 = new ArrayList();
        for (Object obj : J) {
            if (!(((v4.g) obj).f() instanceof p)) {
                arrayList2.add(obj);
            }
        }
        for (v4.g gVar : arrayList2) {
            q02 = sm.c0.q0(arrayList);
            List list = (List) q02;
            String str2 = null;
            if (list != null) {
                o02 = sm.c0.o0(list);
                v4.g gVar2 = (v4.g) o02;
                if (gVar2 != null && (f10 = gVar2.f()) != null) {
                    str2 = f10.F();
                }
            }
            if (kotlin.jvm.internal.t.b(str2, gVar.f().F())) {
                list.add(gVar);
            } else {
                q10 = sm.u.q(gVar);
                arrayList.add(q10);
            }
        }
        k0 k0Var = new k0();
        for (List list2 : arrayList) {
            a0 a0Var = this.f39100w;
            c02 = sm.c0.c0(list2);
            R(a0Var.d(((v4.g) c02).f().F()), list2, tVar, aVar, new o(k0Var, J, new m0(), this, bundle));
        }
        return k0Var.f26193p;
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX WARN: Code restructure failed: missing block: B:100:0x027b, code lost:
    
        ((v4.j.b) r2).k(r1);
     */
    /* JADX WARN: Code restructure failed: missing block: B:103:0x02a4, code lost:
    
        throw new java.lang.IllegalStateException(("NavigatorBackStack for " + r31.F() + " should already be created").toString());
     */
    /* JADX WARN: Code restructure failed: missing block: B:106:0x02a5, code lost:
    
        x().addAll(r10);
        x().add(r8);
        r0 = sm.c0.A0(r10, r8);
        r0 = r0.iterator();
     */
    /* JADX WARN: Code restructure failed: missing block: B:108:0x02c1, code lost:
    
        if (r0.hasNext() == false) goto L132;
     */
    /* JADX WARN: Code restructure failed: missing block: B:109:0x02c3, code lost:
    
        r1 = (v4.g) r0.next();
        r2 = r1.f().G();
     */
    /* JADX WARN: Code restructure failed: missing block: B:110:0x02d1, code lost:
    
        if (r2 == null) goto L134;
     */
    /* JADX WARN: Code restructure failed: missing block: B:112:0x02d3, code lost:
    
        L(r1, y(r2.D()));
     */
    /* JADX WARN: Code restructure failed: missing block: B:117:0x02df, code lost:
    
        return;
     */
    /* JADX WARN: Code restructure failed: missing block: B:118:0x01f0, code lost:
    
        r0 = r0.f();
     */
    /* JADX WARN: Code restructure failed: missing block: B:122:0x0114, code lost:
    
        r0 = ((v4.g) r10.first()).f();
     */
    /* JADX WARN: Code restructure failed: missing block: B:124:0x00eb, code lost:
    
        r12 = r0;
        r13 = r2;
        r9 = r4;
        r10 = r5;
     */
    /* JADX WARN: Code restructure failed: missing block: B:125:0x00ab, code lost:
    
        r19 = r12;
        r0 = r13;
        r8 = r14;
        r2 = r15;
     */
    /* JADX WARN: Code restructure failed: missing block: B:128:0x0082, code lost:
    
        r1 = null;
     */
    /* JADX WARN: Code restructure failed: missing block: B:129:0x00f0, code lost:
    
        r9 = r4;
        r10 = r5;
        r19 = r12;
        r12 = r13;
        r8 = r14;
        r13 = r15;
     */
    /* JADX WARN: Code restructure failed: missing block: B:130:0x0105, code lost:
    
        r10 = r5;
        r19 = r12;
        r12 = r13;
        r8 = r14;
        r13 = r15;
     */
    /* JADX WARN: Code restructure failed: missing block: B:13:0x004d, code lost:
    
        r5 = new sm.k();
        r18 = null;
     */
    /* JADX WARN: Code restructure failed: missing block: B:14:0x0056, code lost:
    
        if ((r31 instanceof v4.p) == false) goto L38;
     */
    /* JADX WARN: Code restructure failed: missing block: B:15:0x0058, code lost:
    
        r0 = r12;
     */
    /* JADX WARN: Code restructure failed: missing block: B:16:0x0059, code lost:
    
        kotlin.jvm.internal.t.d(r0);
        r4 = r0.G();
     */
    /* JADX WARN: Code restructure failed: missing block: B:17:0x0060, code lost:
    
        if (r4 == null) goto L33;
     */
    /* JADX WARN: Code restructure failed: missing block: B:18:0x0062, code lost:
    
        r0 = r13.listIterator(r34.size());
     */
    /* JADX WARN: Code restructure failed: missing block: B:20:0x006e, code lost:
    
        if (r0.hasPrevious() == false) goto L109;
     */
    /* JADX WARN: Code restructure failed: missing block: B:21:0x0070, code lost:
    
        r1 = r0.previous();
     */
    /* JADX WARN: Code restructure failed: missing block: B:22:0x007f, code lost:
    
        if (kotlin.jvm.internal.t.b(((v4.g) r1).f(), r4) == false) goto L111;
     */
    /* JADX WARN: Code restructure failed: missing block: B:24:0x0084, code lost:
    
        r1 = (v4.g) r1;
     */
    /* JADX WARN: Code restructure failed: missing block: B:25:0x0086, code lost:
    
        if (r1 != null) goto L26;
     */
    /* JADX WARN: Code restructure failed: missing block: B:26:0x0088, code lost:
    
        r19 = r12;
        r0 = r13;
        r2 = r15;
        r8 = r14;
        r1 = v4.g.a.b(v4.g.C, r30.f39078a, r4, r32, E(), r30.f39094q, null, null, 96, null);
     */
    /* JADX WARN: Code restructure failed: missing block: B:27:0x00b0, code lost:
    
        r5.addFirst(r1);
     */
    /* JADX WARN: Code restructure failed: missing block: B:28:0x00bd, code lost:
    
        if ((!x().isEmpty()) == false) goto L32;
     */
    /* JADX WARN: Code restructure failed: missing block: B:2:0x0010, code lost:
    
        if ((r12 instanceof v4.d) == false) goto L4;
     */
    /* JADX WARN: Code restructure failed: missing block: B:30:0x00cd, code lost:
    
        if (((v4.g) x().last()).f() != r4) goto L32;
     */
    /* JADX WARN: Code restructure failed: missing block: B:31:0x00cf, code lost:
    
        r12 = r0;
        r13 = r2;
        r9 = r4;
        r10 = r5;
        c0(r30, (v4.g) x().last(), false, null, 6, null);
     */
    /* JADX WARN: Code restructure failed: missing block: B:32:0x00f7, code lost:
    
        if (r9 == null) goto L107;
     */
    /* JADX WARN: Code restructure failed: missing block: B:33:0x00f9, code lost:
    
        if (r9 != r31) goto L37;
     */
    /* JADX WARN: Code restructure failed: missing block: B:34:0x00fc, code lost:
    
        r14 = r8;
        r0 = r9;
        r5 = r10;
        r15 = r13;
        r13 = r12;
        r12 = r19;
     */
    /* JADX WARN: Code restructure failed: missing block: B:37:0x010f, code lost:
    
        if (r10.isEmpty() == false) goto L42;
     */
    /* JADX WARN: Code restructure failed: missing block: B:38:0x0111, code lost:
    
        r0 = r19;
     */
    /* JADX WARN: Code restructure failed: missing block: B:40:0x011e, code lost:
    
        if (r0 == null) goto L113;
     */
    /* JADX WARN: Code restructure failed: missing block: B:42:0x0128, code lost:
    
        if (u(r0.D()) != null) goto L112;
     */
    /* JADX WARN: Code restructure failed: missing block: B:43:0x012a, code lost:
    
        r0 = r0.G();
     */
    /* JADX WARN: Code restructure failed: missing block: B:44:0x012e, code lost:
    
        if (r0 == null) goto L116;
     */
    /* JADX WARN: Code restructure failed: missing block: B:46:0x0130, code lost:
    
        r1 = r12.listIterator(r34.size());
     */
    /* JADX WARN: Code restructure failed: missing block: B:48:0x013c, code lost:
    
        if (r1.hasPrevious() == false) goto L119;
     */
    /* JADX WARN: Code restructure failed: missing block: B:49:0x013e, code lost:
    
        r2 = r1.previous();
     */
    /* JADX WARN: Code restructure failed: missing block: B:4:0x001a, code lost:
    
        if (x().isEmpty() != false) goto L104;
     */
    /* JADX WARN: Code restructure failed: missing block: B:50:0x014d, code lost:
    
        if (kotlin.jvm.internal.t.b(((v4.g) r2).f(), r0) == false) goto L121;
     */
    /* JADX WARN: Code restructure failed: missing block: B:52:0x0152, code lost:
    
        r2 = (v4.g) r2;
     */
    /* JADX WARN: Code restructure failed: missing block: B:53:0x0154, code lost:
    
        if (r2 != null) goto L58;
     */
    /* JADX WARN: Code restructure failed: missing block: B:54:0x0156, code lost:
    
        r2 = v4.g.a.b(v4.g.C, r30.f39078a, r0, r0.m(r13), E(), r30.f39094q, null, null, 96, null);
     */
    /* JADX WARN: Code restructure failed: missing block: B:55:0x0176, code lost:
    
        r10.addFirst(r2);
     */
    /* JADX WARN: Code restructure failed: missing block: B:60:0x0150, code lost:
    
        r2 = null;
     */
    /* JADX WARN: Code restructure failed: missing block: B:64:0x017e, code lost:
    
        if (r10.isEmpty() == false) goto L62;
     */
    /* JADX WARN: Code restructure failed: missing block: B:65:0x0181, code lost:
    
        r19 = ((v4.g) r10.last()).f();
     */
    /* JADX WARN: Code restructure failed: missing block: B:68:0x0195, code lost:
    
        if (x().isEmpty() != false) goto L123;
     */
    /* JADX WARN: Code restructure failed: missing block: B:6:0x002c, code lost:
    
        if ((((v4.g) x().last()).f() instanceof v4.d) == false) goto L105;
     */
    /* JADX WARN: Code restructure failed: missing block: B:70:0x01a7, code lost:
    
        if ((((v4.g) x().last()).f() instanceof v4.p) == false) goto L124;
     */
    /* JADX WARN: Code restructure failed: missing block: B:72:0x01c2, code lost:
    
        if (((v4.p) ((v4.g) x().last()).f()).U(r19.D(), false) != null) goto L122;
     */
    /* JADX WARN: Code restructure failed: missing block: B:73:0x01c4, code lost:
    
        c0(r30, (v4.g) x().last(), false, null, 6, null);
     */
    /* JADX WARN: Code restructure failed: missing block: B:75:0x01d9, code lost:
    
        r0 = (v4.g) x().z();
     */
    /* JADX WARN: Code restructure failed: missing block: B:76:0x01e3, code lost:
    
        if (r0 != null) goto L73;
     */
    /* JADX WARN: Code restructure failed: missing block: B:77:0x01e5, code lost:
    
        r0 = (v4.g) r10.z();
     */
    /* JADX WARN: Code restructure failed: missing block: B:78:0x01eb, code lost:
    
        if (r0 != null) goto L75;
     */
    /* JADX WARN: Code restructure failed: missing block: B:79:0x01ed, code lost:
    
        r0 = null;
     */
    /* JADX WARN: Code restructure failed: missing block: B:81:0x01fa, code lost:
    
        if (kotlin.jvm.internal.t.b(r0, r30.f39081d) != false) goto L88;
     */
    /* JADX WARN: Code restructure failed: missing block: B:82:0x01fc, code lost:
    
        r0 = r12.listIterator(r34.size());
     */
    /* JADX WARN: Code restructure failed: missing block: B:84:0x0208, code lost:
    
        if (r0.hasPrevious() == false) goto L126;
     */
    /* JADX WARN: Code restructure failed: missing block: B:85:0x020a, code lost:
    
        r1 = r0.previous();
        r2 = ((v4.g) r1).f();
        r3 = r30.f39081d;
        kotlin.jvm.internal.t.d(r3);
     */
    /* JADX WARN: Code restructure failed: missing block: B:86:0x021e, code lost:
    
        if (kotlin.jvm.internal.t.b(r2, r3) == false) goto L128;
     */
    /* JADX WARN: Code restructure failed: missing block: B:88:0x0220, code lost:
    
        r18 = r1;
     */
    /* JADX WARN: Code restructure failed: missing block: B:89:0x0222, code lost:
    
        r18 = (v4.g) r18;
     */
    /* JADX WARN: Code restructure failed: missing block: B:8:0x004a, code lost:
    
        if (a0(r30, ((v4.g) x().last()).f().D(), true, false, 4, null) == false) goto L103;
     */
    /* JADX WARN: Code restructure failed: missing block: B:90:0x0224, code lost:
    
        if (r18 != null) goto L87;
     */
    /* JADX WARN: Code restructure failed: missing block: B:91:0x0226, code lost:
    
        r19 = v4.g.C;
        r0 = r30.f39078a;
        r1 = r30.f39081d;
        kotlin.jvm.internal.t.d(r1);
        r2 = r30.f39081d;
        kotlin.jvm.internal.t.d(r2);
        r18 = v4.g.a.b(r19, r0, r1, r2.m(r13), E(), r30.f39094q, null, null, 96, null);
     */
    /* JADX WARN: Code restructure failed: missing block: B:92:0x0250, code lost:
    
        r10.addFirst(r18);
     */
    /* JADX WARN: Code restructure failed: missing block: B:95:0x0255, code lost:
    
        r0 = r10.iterator();
     */
    /* JADX WARN: Code restructure failed: missing block: B:97:0x025d, code lost:
    
        if (r0.hasNext() == false) goto L130;
     */
    /* JADX WARN: Code restructure failed: missing block: B:98:0x025f, code lost:
    
        r1 = (v4.g) r0.next();
        r2 = r30.f39101x.get(r30.f39100w.d(r1.f().F()));
     */
    /* JADX WARN: Code restructure failed: missing block: B:99:0x0279, code lost:
    
        if (r2 == null) goto L129;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void n(v4.o oVar, Bundle bundle, v4.g gVar, List list) {
        Bundle bundle2 = bundle;
        v4.g gVar2 = gVar;
        List list2 = list;
        v4.o f10 = gVar.f();
    }

    static /* synthetic */ void o(j jVar, v4.o oVar, Bundle bundle, v4.g gVar, List list, int i10, Object obj) {
        if (obj != null) {
            throw new UnsupportedOperationException("Super calls with default arguments not supported in this target, function: addEntryToBackStack");
        }
        if ((i10 & 8) != 0) {
            list = sm.u.k();
        }
        jVar.n(oVar, bundle, gVar, list);
    }

    private final boolean p0() {
        List Q0;
        Object H2;
        Object H3;
        int i10 = 0;
        if (!this.f39084g) {
            return false;
        }
        Activity activity = this.f39079b;
        kotlin.jvm.internal.t.d(activity);
        Intent intent = activity.getIntent();
        Bundle extras = intent.getExtras();
        kotlin.jvm.internal.t.d(extras);
        int[] intArray = extras.getIntArray("android-support-nav:controller:deepLinkIds");
        kotlin.jvm.internal.t.d(intArray);
        kotlin.jvm.internal.t.f(intArray, "extras!!.getIntArray(KEY_DEEP_LINK_IDS)!!");
        Q0 = sm.p.Q0(intArray);
        ArrayList parcelableArrayList = extras.getParcelableArrayList("android-support-nav:controller:deepLinkArgs");
        H2 = sm.z.H(Q0);
        int intValue = ((Number) H2).intValue();
        if (parcelableArrayList != null) {
            H3 = sm.z.H(parcelableArrayList);
        }
        if (Q0.isEmpty()) {
            return false;
        }
        v4.o v10 = v(D(), intValue);
        if (v10 instanceof p) {
            intValue = p.E.a((p) v10).D();
        }
        v4.o B = B();
        if (!(B != null && intValue == B.D())) {
            return false;
        }
        v4.m r10 = r();
        Bundle a10 = androidx.core.os.c.a(rm.c0.a("android-support-nav:controller:deepLinkIntent", intent));
        Bundle bundle = extras.getBundle("android-support-nav:controller:deepLinkExtras");
        if (bundle != null) {
            a10.putAll(bundle);
        }
        r10.e(a10);
        for (Object obj : Q0) {
            int i11 = i10 + 1;
            if (i10 < 0) {
                sm.u.u();
            }
            r10.a(((Number) obj).intValue(), parcelableArrayList == null ? null : (Bundle) parcelableArrayList.get(i10));
            i10 = i11;
        }
        r10.b().o();
        Activity activity2 = this.f39079b;
        if (activity2 != null) {
            activity2.finish();
        }
        return true;
    }

    private final boolean q(int i10) {
        Iterator it = this.f39101x.values().iterator();
        while (it.hasNext()) {
            ((b) it.next()).i(true);
        }
        boolean g02 = g0(i10, null, null, null);
        Iterator it2 = this.f39101x.values().iterator();
        while (it2.hasNext()) {
            ((b) it2.next()).i(false);
        }
        return g02 && Z(i10, true, false);
    }

    private final boolean q0() {
        v4.o B = B();
        kotlin.jvm.internal.t.d(B);
        int D = B.D();
        for (p G2 = B.G(); G2 != null; G2 = G2.G()) {
            if (G2.Z() != D) {
                Bundle bundle = new Bundle();
                Activity activity = this.f39079b;
                if (activity != null) {
                    kotlin.jvm.internal.t.d(activity);
                    if (activity.getIntent() != null) {
                        Activity activity2 = this.f39079b;
                        kotlin.jvm.internal.t.d(activity2);
                        if (activity2.getIntent().getData() != null) {
                            Activity activity3 = this.f39079b;
                            kotlin.jvm.internal.t.d(activity3);
                            bundle.putParcelable("android-support-nav:controller:deepLinkIntent", activity3.getIntent());
                            p pVar = this.f39081d;
                            kotlin.jvm.internal.t.d(pVar);
                            Activity activity4 = this.f39079b;
                            kotlin.jvm.internal.t.d(activity4);
                            Intent intent = activity4.getIntent();
                            kotlin.jvm.internal.t.f(intent, "activity!!.intent");
                            o.b I = pVar.I(new v4.n(intent));
                            if (I != null) {
                                bundle.putAll(I.e().m(I.g()));
                            }
                        }
                    }
                }
                v4.m.g(new v4.m(this), G2.D(), null, 2, null).e(bundle).b().o();
                Activity activity5 = this.f39079b;
                if (activity5 == null) {
                    return true;
                }
                activity5.finish();
                return true;
            }
            D = G2.D();
        }
        return false;
    }

    private final boolean s() {
        List<v4.g> V0;
        while (!x().isEmpty() && (((v4.g) x().last()).f() instanceof p)) {
            c0(this, (v4.g) x().last(), false, null, 6, null);
        }
        v4.g gVar = (v4.g) x().C();
        if (gVar != null) {
            this.C.add(gVar);
        }
        this.B++;
        s0();
        int i10 = this.B - 1;
        this.B = i10;
        if (i10 == 0) {
            V0 = sm.c0.V0(this.C);
            this.C.clear();
            for (v4.g gVar2 : V0) {
                Iterator it = this.f39095r.iterator();
                while (it.hasNext()) {
                    ((c) it.next()).a(this, gVar2.f(), gVar2.d());
                }
                this.E.d(gVar2);
            }
            this.f39086i.d(d0());
        }
        return gVar != null;
    }

    /* JADX WARN: Code restructure failed: missing block: B:4:0x000b, code lost:
    
        if (C() > 1) goto L8;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    private final void t0() {
        androidx.activity.p pVar = this.f39098u;
        boolean z10 = this.f39099v;
        pVar.j(z10);
    }

    private final v4.o v(v4.o oVar, int i10) {
        p G2;
        if (oVar.D() == i10) {
            return oVar;
        }
        if (oVar instanceof p) {
            G2 = (p) oVar;
        } else {
            G2 = oVar.G();
            kotlin.jvm.internal.t.d(G2);
        }
        return G2.T(i10);
    }

    private final String w(int[] iArr) {
        p pVar = this.f39081d;
        int length = iArr.length;
        int i10 = 0;
        while (true) {
            v4.o oVar = null;
            if (i10 >= length) {
                return null;
            }
            int i11 = i10 + 1;
            int i12 = iArr[i10];
            if (i10 == 0) {
                p pVar2 = this.f39081d;
                kotlin.jvm.internal.t.d(pVar2);
                if (pVar2.D() == i12) {
                    oVar = this.f39081d;
                }
            } else {
                kotlin.jvm.internal.t.d(pVar);
                oVar = pVar.T(i12);
            }
            if (oVar == null) {
                return v4.o.f39171y.b(this.f39078a, i12);
            }
            if (i10 != iArr.length - 1 && (oVar instanceof p)) {
                pVar = (p) oVar;
                while (true) {
                    kotlin.jvm.internal.t.d(pVar);
                    if (pVar.T(pVar.Z()) instanceof p) {
                        pVar = (p) pVar.T(pVar.Z());
                    }
                }
            }
            i10 = i11;
        }
    }

    public v4.g A() {
        return (v4.g) x().C();
    }

    public v4.o B() {
        v4.g A = A();
        if (A == null) {
            return null;
        }
        return A.f();
    }

    public p D() {
        p pVar = this.f39081d;
        if (pVar == null) {
            throw new IllegalStateException("You must call setGraph() before calling getGraph()".toString());
        }
        if (pVar != null) {
            return pVar;
        }
        throw new NullPointerException("null cannot be cast to non-null type androidx.navigation.NavGraph");
    }

    public final n.b E() {
        return this.f39092o == null ? n.b.CREATED : this.f39096s;
    }

    public s F() {
        return (s) this.D.getValue();
    }

    public a0 G() {
        return this.f39100w;
    }

    public v4.g H() {
        List B0;
        rp.h c10;
        Object obj;
        B0 = sm.c0.B0(x());
        Iterator it = B0.iterator();
        if (it.hasNext()) {
            it.next();
        }
        c10 = rp.n.c(it);
        Iterator it2 = c10.iterator();
        while (true) {
            if (!it2.hasNext()) {
                obj = null;
                break;
            }
            obj = it2.next();
            if (!(((v4.g) obj).f() instanceof p)) {
                break;
            }
        }
        return (v4.g) obj;
    }

    /* JADX WARN: Code restructure failed: missing block: B:20:0x003e, code lost:
    
        if ((r2.length == 0) != false) goto L25;
     */
    /* JADX WARN: Removed duplicated region for block: B:23:0x006b  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public boolean I(Intent intent) {
        int[] iArr;
        v4.o T;
        Bundle bundle;
        int i10 = 0;
        if (intent == null) {
            return false;
        }
        Bundle extras = intent.getExtras();
        int[] intArray = extras == null ? null : extras.getIntArray("android-support-nav:controller:deepLinkIds");
        ArrayList parcelableArrayList = extras == null ? null : extras.getParcelableArrayList("android-support-nav:controller:deepLinkArgs");
        Bundle bundle2 = new Bundle();
        Bundle bundle3 = extras == null ? null : extras.getBundle("android-support-nav:controller:deepLinkExtras");
        if (bundle3 != null) {
            bundle2.putAll(bundle3);
        }
        if (intArray != null) {
        }
        p pVar = this.f39081d;
        kotlin.jvm.internal.t.d(pVar);
        o.b I = pVar.I(new v4.n(intent));
        if (I != null) {
            v4.o e10 = I.e();
            int[] x10 = v4.o.x(e10, null, 1, null);
            Bundle m10 = e10.m(I.g());
            if (m10 != null) {
                bundle2.putAll(m10);
            }
            iArr = x10;
            parcelableArrayList = null;
            if (iArr != null) {
                if (!(iArr.length == 0)) {
                    String w10 = w(iArr);
                    if (w10 != null) {
                        Log.i("NavController", "Could not find destination " + ((Object) w10) + " in the navigation graph, ignoring the deep link from " + intent);
                        return false;
                    }
                    bundle2.putParcelable("android-support-nav:controller:deepLinkIntent", intent);
                    int length = iArr.length;
                    Bundle[] bundleArr = new Bundle[length];
                    int i11 = 0;
                    while (i11 < length) {
                        int i12 = i11 + 1;
                        Bundle bundle4 = new Bundle();
                        bundle4.putAll(bundle2);
                        if (parcelableArrayList != null && (bundle = (Bundle) parcelableArrayList.get(i11)) != null) {
                            bundle4.putAll(bundle);
                        }
                        bundleArr[i11] = bundle4;
                        i11 = i12;
                    }
                    int flags = intent.getFlags();
                    int i13 = 268435456 & flags;
                    if (i13 != 0 && (flags & 32768) == 0) {
                        intent.addFlags(32768);
                        androidx.core.app.v g10 = androidx.core.app.v.l(this.f39078a).g(intent);
                        kotlin.jvm.internal.t.f(g10, "create(context)\n        …ntWithParentStack(intent)");
                        g10.o();
                        Activity activity = this.f39079b;
                        if (activity != null) {
                            activity.finish();
                            activity.overridePendingTransition(0, 0);
                        }
                        return true;
                    }
                    if (i13 != 0) {
                        if (!x().isEmpty()) {
                            p pVar2 = this.f39081d;
                            kotlin.jvm.internal.t.d(pVar2);
                            a0(this, pVar2.D(), true, false, 4, null);
                        }
                        while (i10 < iArr.length) {
                            int i14 = iArr[i10];
                            int i15 = i10 + 1;
                            Bundle bundle5 = bundleArr[i10];
                            v4.o u10 = u(i14);
                            if (u10 == null) {
                                throw new IllegalStateException("Deep Linking failed: destination " + v4.o.f39171y.b(this.f39078a, i14) + " cannot be found from the current destination " + B());
                            }
                            Q(u10, bundle5, v.a(new e(u10, this)), null);
                            i10 = i15;
                        }
                        return true;
                    }
                    p pVar3 = this.f39081d;
                    int length2 = iArr.length;
                    int i16 = 0;
                    while (i16 < length2) {
                        int i17 = i16 + 1;
                        int i18 = iArr[i16];
                        Bundle bundle6 = bundleArr[i16];
                        if (i16 == 0) {
                            T = this.f39081d;
                        } else {
                            kotlin.jvm.internal.t.d(pVar3);
                            T = pVar3.T(i18);
                        }
                        if (T == null) {
                            throw new IllegalStateException("Deep Linking failed: destination " + v4.o.f39171y.b(this.f39078a, i18) + " cannot be found in graph " + pVar3);
                        }
                        if (i16 == iArr.length - 1) {
                            t.a aVar = new t.a();
                            p pVar4 = this.f39081d;
                            kotlin.jvm.internal.t.d(pVar4);
                            Q(T, bundle6, t.a.i(aVar, pVar4.D(), true, false, 4, null).b(0).c(0).a(), null);
                        } else if (T instanceof p) {
                            pVar3 = (p) T;
                            while (true) {
                                kotlin.jvm.internal.t.d(pVar3);
                                if (pVar3.T(pVar3.Z()) instanceof p) {
                                    pVar3 = (p) pVar3.T(pVar3.Z());
                                }
                            }
                        }
                        i16 = i17;
                    }
                    this.f39084g = true;
                    return true;
                }
            }
            return false;
        }
        iArr = intArray;
        if (iArr != null) {
        }
        return false;
    }

    public void M(int i10) {
        N(i10, null);
    }

    public void N(int i10, Bundle bundle) {
        O(i10, bundle, null);
    }

    public void O(int i10, Bundle bundle, t tVar) {
        P(i10, bundle, tVar, null);
    }

    public void P(int i10, Bundle bundle, t tVar, z.a aVar) {
        int i11;
        v4.o f10 = x().isEmpty() ? this.f39081d : ((v4.g) x().last()).f();
        if (f10 == null) {
            throw new IllegalStateException("no current navigation node");
        }
        v4.e z10 = f10.z(i10);
        Bundle bundle2 = null;
        if (z10 != null) {
            if (tVar == null) {
                tVar = z10.c();
            }
            i11 = z10.b();
            Bundle a10 = z10.a();
            if (a10 != null) {
                bundle2 = new Bundle();
                bundle2.putAll(a10);
            }
        } else {
            i11 = i10;
        }
        if (bundle != null) {
            if (bundle2 == null) {
                bundle2 = new Bundle();
            }
            bundle2.putAll(bundle);
        }
        if (i11 == 0 && tVar != null && tVar.e() != -1) {
            V(tVar.e(), tVar.f());
            return;
        }
        if (!(i11 != 0)) {
            throw new IllegalArgumentException("Destination id == 0 can only be used in conjunction with a valid navOptions.popUpTo".toString());
        }
        v4.o u10 = u(i11);
        if (u10 != null) {
            Q(u10, bundle2, tVar, aVar);
            return;
        }
        o.a aVar2 = v4.o.f39171y;
        String b10 = aVar2.b(this.f39078a, i11);
        if (z10 == null) {
            throw new IllegalArgumentException("Navigation action/destination " + b10 + " cannot be found from the current destination " + f10);
        }
        throw new IllegalArgumentException(("Navigation destination " + b10 + " referenced from action " + aVar2.b(z(), i10) + " cannot be found from the current destination " + f10).toString());
    }

    public boolean S() {
        Intent intent;
        if (C() != 1) {
            return U();
        }
        Activity activity = this.f39079b;
        Bundle extras = (activity == null || (intent = activity.getIntent()) == null) ? null : intent.getExtras();
        return (extras != null ? extras.getIntArray("android-support-nav:controller:deepLinkIds") : null) != null ? p0() : q0();
    }

    public boolean U() {
        if (x().isEmpty()) {
            return false;
        }
        v4.o B = B();
        kotlin.jvm.internal.t.d(B);
        return V(B.D(), true);
    }

    public boolean V(int i10, boolean z10) {
        return W(i10, z10, false);
    }

    public boolean W(int i10, boolean z10, boolean z11) {
        return Z(i10, z10, z11) && s();
    }

    public final void X(v4.g popUpTo, dn.a onComplete) {
        kotlin.jvm.internal.t.g(popUpTo, "popUpTo");
        kotlin.jvm.internal.t.g(onComplete, "onComplete");
        int indexOf = x().indexOf(popUpTo);
        if (indexOf < 0) {
            Log.i("NavController", "Ignoring pop of " + popUpTo + " as it was not found on the current back stack");
            return;
        }
        int i10 = indexOf + 1;
        if (i10 != x().size()) {
            Z(((v4.g) x().get(i10)).f().D(), true, false);
        }
        c0(this, popUpTo, false, null, 6, null);
        onComplete.invoke();
        t0();
        s();
    }

    public final List d0() {
        ArrayList arrayList = new ArrayList();
        Iterator it = this.f39101x.values().iterator();
        while (it.hasNext()) {
            Iterable iterable = (Iterable) ((b) it.next()).c().getValue();
            ArrayList arrayList2 = new ArrayList();
            for (Object obj : iterable) {
                v4.g gVar = (v4.g) obj;
                if ((arrayList.contains(gVar) || gVar.getLifecycle().b().isAtLeast(n.b.STARTED)) ? false : true) {
                    arrayList2.add(obj);
                }
            }
            sm.z.A(arrayList, arrayList2);
        }
        sm.k x10 = x();
        ArrayList arrayList3 = new ArrayList();
        for (Object obj2 : x10) {
            v4.g gVar2 = (v4.g) obj2;
            if (!arrayList.contains(gVar2) && gVar2.getLifecycle().b().isAtLeast(n.b.STARTED)) {
                arrayList3.add(obj2);
            }
        }
        sm.z.A(arrayList, arrayList3);
        ArrayList arrayList4 = new ArrayList();
        for (Object obj3 : arrayList) {
            if (!(((v4.g) obj3).f() instanceof p)) {
                arrayList4.add(obj3);
            }
        }
        return arrayList4;
    }

    public void e0(c listener) {
        kotlin.jvm.internal.t.g(listener, "listener");
        this.f39095r.remove(listener);
    }

    public void f0(Bundle bundle) {
        if (bundle == null) {
            return;
        }
        bundle.setClassLoader(this.f39078a.getClassLoader());
        this.f39082e = bundle.getBundle("android-support-nav:controller:navigatorState");
        this.f39083f = bundle.getParcelableArray("android-support-nav:controller:backStack");
        this.f39091n.clear();
        int[] intArray = bundle.getIntArray("android-support-nav:controller:backStackDestIds");
        ArrayList<String> stringArrayList = bundle.getStringArrayList("android-support-nav:controller:backStackIds");
        if (intArray != null && stringArrayList != null) {
            int length = intArray.length;
            int i10 = 0;
            int i11 = 0;
            while (i10 < length) {
                int i12 = intArray[i10];
                i10++;
                this.f39090m.put(Integer.valueOf(i12), stringArrayList.get(i11));
                i11++;
            }
        }
        ArrayList<String> stringArrayList2 = bundle.getStringArrayList("android-support-nav:controller:backStackStates");
        if (stringArrayList2 != null) {
            for (String id2 : stringArrayList2) {
                Parcelable[] parcelableArray = bundle.getParcelableArray(kotlin.jvm.internal.t.p("android-support-nav:controller:backStackStates:", id2));
                if (parcelableArray != null) {
                    Map map = this.f39091n;
                    kotlin.jvm.internal.t.f(id2, "id");
                    sm.k kVar = new sm.k(parcelableArray.length);
                    Iterator a10 = kotlin.jvm.internal.c.a(parcelableArray);
                    while (a10.hasNext()) {
                        Parcelable parcelable = (Parcelable) a10.next();
                        if (parcelable == null) {
                            throw new NullPointerException("null cannot be cast to non-null type androidx.navigation.NavBackStackEntryState");
                        }
                        kVar.add((v4.h) parcelable);
                    }
                    n0 n0Var = n0.f34904a;
                    map.put(id2, kVar);
                }
            }
        }
        this.f39084g = bundle.getBoolean("android-support-nav:controller:deepLinkHandled");
    }

    public Bundle h0() {
        Bundle bundle;
        ArrayList<String> arrayList = new ArrayList<>();
        Bundle bundle2 = new Bundle();
        for (Map.Entry entry : this.f39100w.e().entrySet()) {
            String str = (String) entry.getKey();
            Bundle i10 = ((z) entry.getValue()).i();
            if (i10 != null) {
                arrayList.add(str);
                bundle2.putBundle(str, i10);
            }
        }
        if (!arrayList.isEmpty()) {
            bundle = new Bundle();
            bundle2.putStringArrayList("android-support-nav:controller:navigatorState:names", arrayList);
            bundle.putBundle("android-support-nav:controller:navigatorState", bundle2);
        } else {
            bundle = null;
        }
        if (!x().isEmpty()) {
            if (bundle == null) {
                bundle = new Bundle();
            }
            Parcelable[] parcelableArr = new Parcelable[x().size()];
            Iterator<E> it = x().iterator();
            int i11 = 0;
            while (it.hasNext()) {
                parcelableArr[i11] = new v4.h((v4.g) it.next());
                i11++;
            }
            bundle.putParcelableArray("android-support-nav:controller:backStack", parcelableArr);
        }
        if (!this.f39090m.isEmpty()) {
            if (bundle == null) {
                bundle = new Bundle();
            }
            int[] iArr = new int[this.f39090m.size()];
            ArrayList<String> arrayList2 = new ArrayList<>();
            int i12 = 0;
            for (Map.Entry entry2 : this.f39090m.entrySet()) {
                int intValue = ((Number) entry2.getKey()).intValue();
                String str2 = (String) entry2.getValue();
                iArr[i12] = intValue;
                arrayList2.add(str2);
                i12++;
            }
            bundle.putIntArray("android-support-nav:controller:backStackDestIds", iArr);
            bundle.putStringArrayList("android-support-nav:controller:backStackIds", arrayList2);
        }
        if (!this.f39091n.isEmpty()) {
            if (bundle == null) {
                bundle = new Bundle();
            }
            ArrayList<String> arrayList3 = new ArrayList<>();
            for (Map.Entry entry3 : this.f39091n.entrySet()) {
                String str3 = (String) entry3.getKey();
                sm.k kVar = (sm.k) entry3.getValue();
                arrayList3.add(str3);
                Parcelable[] parcelableArr2 = new Parcelable[kVar.size()];
                int i13 = 0;
                for (Object obj : kVar) {
                    int i14 = i13 + 1;
                    if (i13 < 0) {
                        sm.u.u();
                    }
                    parcelableArr2[i13] = (v4.h) obj;
                    i13 = i14;
                }
                bundle.putParcelableArray(kotlin.jvm.internal.t.p("android-support-nav:controller:backStackStates:", str3), parcelableArr2);
            }
            bundle.putStringArrayList("android-support-nav:controller:backStackStates", arrayList3);
        }
        if (this.f39084g) {
            if (bundle == null) {
                bundle = new Bundle();
            }
            bundle.putBoolean("android-support-nav:controller:deepLinkHandled", this.f39084g);
        }
        return bundle;
    }

    public void i0(int i10) {
        l0(F().b(i10), null);
    }

    public void j0(int i10, Bundle bundle) {
        l0(F().b(i10), bundle);
    }

    public void k0(p graph) {
        kotlin.jvm.internal.t.g(graph, "graph");
        l0(graph, null);
    }

    public void l0(p graph, Bundle bundle) {
        kotlin.jvm.internal.t.g(graph, "graph");
        if (!kotlin.jvm.internal.t.b(this.f39081d, graph)) {
            p pVar = this.f39081d;
            if (pVar != null) {
                for (Integer id2 : new ArrayList(this.f39090m.keySet())) {
                    kotlin.jvm.internal.t.f(id2, "id");
                    q(id2.intValue());
                }
                a0(this, pVar.D(), true, false, 4, null);
            }
            this.f39081d = graph;
            T(bundle);
            return;
        }
        int q10 = graph.X().q();
        int i10 = 0;
        while (i10 < q10) {
            int i11 = i10 + 1;
            v4.o newDestination = (v4.o) graph.X().s(i10);
            p pVar2 = this.f39081d;
            kotlin.jvm.internal.t.d(pVar2);
            pVar2.X().p(i10, newDestination);
            sm.k x10 = x();
            ArrayList<v4.g> arrayList = new ArrayList();
            for (Object obj : x10) {
                if (newDestination != null && ((v4.g) obj).f().D() == newDestination.D()) {
                    arrayList.add(obj);
                }
            }
            for (v4.g gVar : arrayList) {
                kotlin.jvm.internal.t.f(newDestination, "newDestination");
                gVar.l(newDestination);
            }
            i10 = i11;
        }
    }

    public void m0(androidx.lifecycle.u owner) {
        androidx.lifecycle.n lifecycle;
        kotlin.jvm.internal.t.g(owner, "owner");
        if (kotlin.jvm.internal.t.b(owner, this.f39092o)) {
            return;
        }
        androidx.lifecycle.u uVar = this.f39092o;
        if (uVar != null && (lifecycle = uVar.getLifecycle()) != null) {
            lifecycle.d(this.f39097t);
        }
        this.f39092o = owner;
        owner.getLifecycle().a(this.f39097t);
    }

    public void n0(androidx.activity.q dispatcher) {
        kotlin.jvm.internal.t.g(dispatcher, "dispatcher");
        if (kotlin.jvm.internal.t.b(dispatcher, this.f39093p)) {
            return;
        }
        androidx.lifecycle.u uVar = this.f39092o;
        if (uVar == null) {
            throw new IllegalStateException("You must call setLifecycleOwner() before calling setOnBackPressedDispatcher()".toString());
        }
        this.f39098u.h();
        this.f39093p = dispatcher;
        dispatcher.i(uVar, this.f39098u);
        androidx.lifecycle.n lifecycle = uVar.getLifecycle();
        lifecycle.d(this.f39097t);
        lifecycle.a(this.f39097t);
    }

    public void o0(d1 viewModelStore) {
        kotlin.jvm.internal.t.g(viewModelStore, "viewModelStore");
        v4.k kVar = this.f39094q;
        k.b bVar = v4.k.f39135c;
        if (kotlin.jvm.internal.t.b(kVar, bVar.a(viewModelStore))) {
            return;
        }
        if (!x().isEmpty()) {
            throw new IllegalStateException("ViewModelStore should be set before setGraph call".toString());
        }
        this.f39094q = bVar.a(viewModelStore);
    }

    public void p(c listener) {
        kotlin.jvm.internal.t.g(listener, "listener");
        this.f39095r.add(listener);
        if (!x().isEmpty()) {
            v4.g gVar = (v4.g) x().last();
            listener.a(this, gVar.f(), gVar.d());
        }
    }

    public v4.m r() {
        return new v4.m(this);
    }

    public final v4.g r0(v4.g child) {
        kotlin.jvm.internal.t.g(child, "child");
        v4.g gVar = (v4.g) this.f39088k.remove(child);
        if (gVar == null) {
            return null;
        }
        AtomicInteger atomicInteger = (AtomicInteger) this.f39089l.get(gVar);
        Integer valueOf = atomicInteger != null ? Integer.valueOf(atomicInteger.decrementAndGet()) : null;
        if (valueOf != null && valueOf.intValue() == 0) {
            b bVar = (b) this.f39101x.get(this.f39100w.d(gVar.f().F()));
            if (bVar != null) {
                bVar.e(gVar);
            }
            this.f39089l.remove(gVar);
        }
        return gVar;
    }

    public final void s0() {
        List<v4.g> V0;
        Object o02;
        v4.o oVar;
        List<v4.g> B0;
        h0 c10;
        Set set;
        List B02;
        V0 = sm.c0.V0(x());
        if (V0.isEmpty()) {
            return;
        }
        o02 = sm.c0.o0(V0);
        v4.o f10 = ((v4.g) o02).f();
        if (f10 instanceof v4.d) {
            B02 = sm.c0.B0(V0);
            Iterator it = B02.iterator();
            while (it.hasNext()) {
                oVar = ((v4.g) it.next()).f();
                if (!(oVar instanceof p) && !(oVar instanceof v4.d)) {
                    break;
                }
            }
        }
        oVar = null;
        HashMap hashMap = new HashMap();
        B0 = sm.c0.B0(V0);
        for (v4.g gVar : B0) {
            n.b h10 = gVar.h();
            v4.o f11 = gVar.f();
            if (f10 != null && f11.D() == f10.D()) {
                n.b bVar = n.b.RESUMED;
                if (h10 != bVar) {
                    b bVar2 = (b) this.f39101x.get(G().d(gVar.f().F()));
                    if (!kotlin.jvm.internal.t.b((bVar2 == null || (c10 = bVar2.c()) == null || (set = (Set) c10.getValue()) == null) ? null : Boolean.valueOf(set.contains(gVar)), Boolean.TRUE)) {
                        AtomicInteger atomicInteger = (AtomicInteger) this.f39089l.get(gVar);
                        boolean z10 = false;
                        if (atomicInteger != null && atomicInteger.get() == 0) {
                            z10 = true;
                        }
                        if (!z10) {
                            hashMap.put(gVar, bVar);
                        }
                    }
                    hashMap.put(gVar, n.b.STARTED);
                }
                f10 = f10.G();
            } else if (oVar == null || f11.D() != oVar.D()) {
                gVar.m(n.b.CREATED);
            } else {
                if (h10 == n.b.RESUMED) {
                    gVar.m(n.b.STARTED);
                } else {
                    n.b bVar3 = n.b.STARTED;
                    if (h10 != bVar3) {
                        hashMap.put(gVar, bVar3);
                    }
                }
                oVar = oVar.G();
            }
        }
        for (v4.g gVar2 : V0) {
            n.b bVar4 = (n.b) hashMap.get(gVar2);
            if (bVar4 != null) {
                gVar2.m(bVar4);
            } else {
                gVar2.n();
            }
        }
    }

    public void t(boolean z10) {
        this.f39099v = z10;
        t0();
    }

    public final v4.o u(int i10) {
        p pVar = this.f39081d;
        if (pVar == null) {
            return null;
        }
        kotlin.jvm.internal.t.d(pVar);
        if (pVar.D() == i10) {
            return this.f39081d;
        }
        v4.g gVar = (v4.g) x().C();
        v4.o f10 = gVar != null ? gVar.f() : null;
        if (f10 == null) {
            f10 = this.f39081d;
            kotlin.jvm.internal.t.d(f10);
        }
        return v(f10, i10);
    }

    public sm.k x() {
        return this.f39085h;
    }

    public v4.g y(int i10) {
        Object obj;
        sm.k x10 = x();
        ListIterator<E> listIterator = x10.listIterator(x10.size());
        while (true) {
            if (!listIterator.hasPrevious()) {
                obj = null;
                break;
            }
            obj = listIterator.previous();
            if (((v4.g) obj).f().D() == i10) {
                break;
            }
        }
        v4.g gVar = (v4.g) obj;
        if (gVar != null) {
            return gVar;
        }
        throw new IllegalArgumentException(("No destination with ID " + i10 + " is on the NavController's back stack. The current destination is " + B()).toString());
    }

    public final Context z() {
        return this.f39078a;
    }
}
