package E1;

import android.util.Log;
import c7.C0592C;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.locks.ReentrantLock;

/* JADX INFO: renamed from: E1.n, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C0107n {

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final c7.K f2104b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final c7.K f2105c;

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

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final C0592C f2107e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final C0592C f2108f;

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

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final /* synthetic */ F f2110h;

    public C0107n(F f3, S s8) {
        P6.g.e(s8, "navigator");
        this.f2110h = f3;
        this.f2103a = new ReentrantLock(true);
        c7.K kB = c7.H.b(B6.t.f1032q);
        this.f2104b = kB;
        c7.K kB2 = c7.H.b(B6.v.f1034q);
        this.f2105c = kB2;
        this.f2107e = new C0592C(kB, 1);
        this.f2108f = new C0592C(kB2, 1);
        this.f2109g = s8;
    }

    public final void a(C0103j c0103j) {
        P6.g.e(c0103j, "backStackEntry");
        ReentrantLock reentrantLock = this.f2103a;
        reentrantLock.lock();
        try {
            c7.K k8 = this.f2104b;
            ArrayList arrayListR0 = B6.k.r0((Collection) k8.e(), c0103j);
            k8.getClass();
            k8.g(null, arrayListR0);
        } finally {
            reentrantLock.unlock();
        }
    }

    public final void b(C0103j c0103j) {
        c7.K k8 = this.f2104b;
        Iterable iterable = (Iterable) k8.e();
        Object objN0 = B6.k.n0((List) k8.e());
        P6.g.e(iterable, "<this>");
        ArrayList arrayList = new ArrayList(B6.m.a0(iterable));
        boolean z8 = false;
        for (Object obj : iterable) {
            boolean z9 = true;
            if (!z8 && P6.g.a(obj, objN0)) {
                z8 = true;
                z9 = false;
            }
            if (z9) {
                arrayList.add(obj);
            }
        }
        ArrayList arrayListR0 = B6.k.r0(arrayList, c0103j);
        k8.getClass();
        k8.g(null, arrayListR0);
    }

    public final void c(C0103j c0103j) {
        P6.g.e(c0103j, "popUpTo");
        F f3 = this.f2110h;
        S sB = f3.f2016u.b(c0103j.f2087r.f1978q);
        if (!sB.equals(this.f2109g)) {
            Object obj = f3.f2017v.get(sB);
            P6.g.b(obj);
            ((C0107n) obj).c(c0103j);
            return;
        }
        r rVar = f3.f2019x;
        if (rVar != null) {
            rVar.b(c0103j);
            d(c0103j);
            return;
        }
        B6.i iVar = f3.f2003g;
        int iIndexOf = iVar.indexOf(c0103j);
        if (iIndexOf < 0) {
            Log.i("NavController", "Ignoring pop of " + c0103j + " as it was not found on the current back stack");
            return;
        }
        int i = iIndexOf + 1;
        if (i != iVar.f1028s) {
            f3.m(((C0103j) iVar.get(i)).f2087r.f1985x, true, false);
        }
        F.o(f3, c0103j);
        d(c0103j);
        f3.u();
        f3.b();
    }

    public final void d(C0103j c0103j) {
        P6.g.e(c0103j, "popUpTo");
        ReentrantLock reentrantLock = this.f2103a;
        reentrantLock.lock();
        try {
            c7.K k8 = this.f2104b;
            Iterable iterable = (Iterable) k8.e();
            ArrayList arrayList = new ArrayList();
            for (Object obj : iterable) {
                if (P6.g.a((C0103j) obj, c0103j)) {
                    break;
                } else {
                    arrayList.add(obj);
                }
            }
            k8.getClass();
            k8.g(null, arrayList);
            reentrantLock.unlock();
        } catch (Throwable th) {
            reentrantLock.unlock();
            throw th;
        }
    }

    /* JADX WARN: Type inference failed for: r0v7, types: [O6.l, P6.h] */
    public final void e(C0103j c0103j) {
        P6.g.e(c0103j, "backStackEntry");
        F f3 = this.f2110h;
        S sB = f3.f2016u.b(c0103j.f2087r.f1978q);
        if (!sB.equals(this.f2109g)) {
            Object obj = f3.f2017v.get(sB);
            if (obj == null) {
                throw new IllegalStateException(I1.a.r(new StringBuilder("NavigatorBackStack for "), c0103j.f2087r.f1978q, " should already be created").toString());
            }
            ((C0107n) obj).e(c0103j);
            return;
        }
        ?? r02 = f3.f2018w;
        if (r02 != 0) {
            r02.b(c0103j);
            a(c0103j);
        } else {
            Log.i("NavController", "Ignoring add of destination " + c0103j.f2087r + " outside of the call to navigate(). ");
        }
    }
}
