package d;

import J0.C0379q;
import android.os.Build;
import android.window.OnBackInvokedCallback;
import android.window.OnBackInvokedDispatcher;
import androidx.lifecycle.EnumC1108q;
import androidx.lifecycle.InterfaceC1113w;
import java.util.Iterator;
import java.util.ListIterator;
import x4.C3249o;

/* JADX INFO: renamed from: d.B, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C1818B {

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final C3249o f14457b = new C3249o();

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final OnBackInvokedCallback f14459d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public OnBackInvokedDispatcher f14460e;

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

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

    public C1818B(Runnable runnable) {
        this.f14456a = runnable;
        int i6 = Build.VERSION.SDK_INT;
        if (i6 >= 33) {
            this.f14459d = i6 >= 34 ? new C1846y(new C1843v(this, 0), new C1843v(this, 1), new C1844w(this, 0), new C1844w(this, 1)) : new C1845x(new C1844w(this, 2), 0);
        }
    }

    public final void a(InterfaceC1113w owner, AbstractC1842u onBackPressedCallback) {
        kotlin.jvm.internal.o.h(owner, "owner");
        kotlin.jvm.internal.o.h(onBackPressedCallback, "onBackPressedCallback");
        androidx.lifecycle.r lifecycle = owner.getLifecycle();
        if (lifecycle.getCurrentState() == EnumC1108q.f12180a) {
            return;
        }
        onBackPressedCallback.f14499b.add(new C1847z(this, lifecycle, onBackPressedCallback));
        e();
        onBackPressedCallback.f14500c = new C0379q(0, this, C1818B.class, "updateEnabledCallbacks", "updateEnabledCallbacks()V", 0, 2);
    }

    public final void b() {
        Object objPrevious;
        AbstractC1842u abstractC1842u = this.f14458c;
        if (abstractC1842u == null) {
            C3249o c3249o = this.f14457b;
            ListIterator<E> listIterator = c3249o.listIterator(c3249o.size());
            while (true) {
                if (!listIterator.hasPrevious()) {
                    objPrevious = null;
                    break;
                } else {
                    objPrevious = listIterator.previous();
                    if (((AbstractC1842u) objPrevious).f14498a) {
                        break;
                    }
                }
            }
            abstractC1842u = (AbstractC1842u) objPrevious;
        }
        this.f14458c = null;
        if (abstractC1842u != null) {
            abstractC1842u.a();
        }
    }

    public final void c() {
        Object objPrevious;
        AbstractC1842u abstractC1842u = this.f14458c;
        if (abstractC1842u == null) {
            C3249o c3249o = this.f14457b;
            ListIterator listIterator = c3249o.listIterator(c3249o.size());
            while (true) {
                if (!listIterator.hasPrevious()) {
                    objPrevious = null;
                    break;
                } else {
                    objPrevious = listIterator.previous();
                    if (((AbstractC1842u) objPrevious).f14498a) {
                        break;
                    }
                }
            }
            abstractC1842u = (AbstractC1842u) objPrevious;
        }
        this.f14458c = null;
        if (abstractC1842u != null) {
            abstractC1842u.b();
        } else {
            this.f14456a.run();
        }
    }

    public final void d(boolean z6) {
        OnBackInvokedDispatcher onBackInvokedDispatcher = this.f14460e;
        OnBackInvokedCallback onBackInvokedCallback = this.f14459d;
        if (onBackInvokedDispatcher == null || onBackInvokedCallback == null) {
            return;
        }
        if (z6 && !this.f14461f) {
            B1.b.k(onBackInvokedDispatcher, onBackInvokedCallback);
            this.f14461f = true;
        } else {
            if (z6 || !this.f14461f) {
                return;
            }
            B1.b.l(onBackInvokedDispatcher, onBackInvokedCallback);
            this.f14461f = false;
        }
    }

    public final void e() {
        boolean z6 = this.f14462g;
        boolean z7 = false;
        C3249o c3249o = this.f14457b;
        if (c3249o == null || !c3249o.isEmpty()) {
            Iterator<E> it = c3249o.iterator();
            while (true) {
                if (!it.hasNext()) {
                    break;
                } else if (((AbstractC1842u) it.next()).f14498a) {
                    z7 = true;
                    break;
                }
            }
        }
        this.f14462g = z7;
        if (z7 == z6 || Build.VERSION.SDK_INT < 33) {
            return;
        }
        d(z7);
    }
}
