package x4;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.util.Log;
import androidx.fragment.app.d0;
import androidx.lifecycle.n;
import androidx.lifecycle.r;
import androidx.lifecycle.u;
import com.google.firebase.remoteconfig.RemoteConfigConstants;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.ListIterator;
import java.util.Set;
import kotlin.Metadata;
import kotlin.jvm.internal.k;
import kotlin.jvm.internal.t;
import rm.n0;
import sm.c0;
import v4.b0;
import v4.o;
import v4.z;

@Metadata(d1 = {"\u0000b\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u000b\n\u0002\b\u0003\n\u0002\u0010 \n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0010#\n\u0002\u0010\u000e\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\b\b\u0007\u0018\u0000 '2\b\u0012\u0004\u0012\u00020\u00020\u0001:\u0002()B\u0017\u0012\u0006\u0010\u0019\u001a\u00020\u0016\u0012\u0006\u0010\u001d\u001a\u00020\u001a¢\u0006\u0004\b%\u0010&J\u0010\u0010\u0006\u001a\u00020\u00052\u0006\u0010\u0004\u001a\u00020\u0003H\u0002J\u0018\u0010\n\u001a\u00020\u00052\u0006\u0010\u0007\u001a\u00020\u00032\u0006\u0010\t\u001a\u00020\bH\u0016J\b\u0010\u000b\u001a\u00020\u0002H\u0016J*\u0010\u0012\u001a\u00020\u00052\f\u0010\r\u001a\b\u0012\u0004\u0012\u00020\u00030\f2\b\u0010\u000f\u001a\u0004\u0018\u00010\u000e2\b\u0010\u0011\u001a\u0004\u0018\u00010\u0010H\u0016J\u0010\u0010\u0015\u001a\u00020\u00052\u0006\u0010\u0014\u001a\u00020\u0013H\u0016R\u0014\u0010\u0019\u001a\u00020\u00168\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\u0017\u0010\u0018R\u0014\u0010\u001d\u001a\u00020\u001a8\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\u001b\u0010\u001cR\u001a\u0010!\u001a\b\u0012\u0004\u0012\u00020\u001f0\u001e8\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\u0012\u0010 R\u0014\u0010$\u001a\u00020\"8\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\u0015\u0010#¨\u0006*"}, d2 = {"Lx4/c;", "Lv4/z;", "Lx4/c$b;", "Lv4/g;", "entry", "Lrm/n0;", "o", "popUpTo", "", "savedState", "j", "n", "", RemoteConfigConstants.ResponseFieldKey.ENTRIES, "Lv4/t;", "navOptions", "Lv4/z$a;", "navigatorExtras", "e", "Lv4/b0;", RemoteConfigConstants.ResponseFieldKey.STATE, "f", "Landroid/content/Context;", "c", "Landroid/content/Context;", "context", "Landroidx/fragment/app/z;", "d", "Landroidx/fragment/app/z;", "fragmentManager", "", "", "Ljava/util/Set;", "restoredTagsAwaitingAttach", "Landroidx/lifecycle/r;", "Landroidx/lifecycle/r;", "observer", "<init>", "(Landroid/content/Context;Landroidx/fragment/app/z;)V", "g", "a", "b", "navigation-fragment_release"}, k = 1, mv = {1, 6, 0})
@z.b("dialog")
/* loaded from: classes.dex */
public final class c extends z {

    /* renamed from: g, reason: collision with root package name */
    private static final a f50470g = new a(null);

    /* renamed from: c, reason: collision with root package name and from kotlin metadata */
    private final Context context;

    /* renamed from: d, reason: collision with root package name and from kotlin metadata */
    private final androidx.fragment.app.z fragmentManager;

    /* renamed from: e, reason: collision with root package name and from kotlin metadata */
    private final Set restoredTagsAwaitingAttach;

    /* renamed from: f, reason: collision with root package name and from kotlin metadata */
    private final r observer;

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

        public /* synthetic */ a(k kVar) {
            this();
        }
    }

    /* loaded from: classes.dex */
    public static class b extends o implements v4.d {
        private String A;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public b(z fragmentNavigator) {
            super(fragmentNavigator);
            t.g(fragmentNavigator, "fragmentNavigator");
        }

        @Override // v4.o
        public void J(Context context, AttributeSet attrs) {
            t.g(context, "context");
            t.g(attrs, "attrs");
            super.J(context, attrs);
            TypedArray obtainAttributes = context.getResources().obtainAttributes(attrs, g.f50481a);
            t.f(obtainAttributes, "context.resources.obtain…ntNavigator\n            )");
            String string = obtainAttributes.getString(g.f50482b);
            if (string != null) {
                T(string);
            }
            obtainAttributes.recycle();
        }

        public final String S() {
            String str = this.A;
            if (str == null) {
                throw new IllegalStateException("DialogFragment class was not set".toString());
            }
            if (str != null) {
                return str;
            }
            throw new NullPointerException("null cannot be cast to non-null type kotlin.String");
        }

        public final b T(String className) {
            t.g(className, "className");
            this.A = className;
            return this;
        }

        @Override // v4.o
        public boolean equals(Object obj) {
            return obj != null && (obj instanceof b) && super.equals(obj) && t.b(this.A, ((b) obj).A);
        }

        @Override // v4.o
        public int hashCode() {
            int hashCode = super.hashCode() * 31;
            String str = this.A;
            return hashCode + (str == null ? 0 : str.hashCode());
        }
    }

    public c(Context context, androidx.fragment.app.z fragmentManager) {
        t.g(context, "context");
        t.g(fragmentManager, "fragmentManager");
        this.context = context;
        this.fragmentManager = fragmentManager;
        this.restoredTagsAwaitingAttach = new LinkedHashSet();
        this.observer = new r() { // from class: x4.b
            @Override // androidx.lifecycle.r
            public final void f(u uVar, n.a aVar) {
                c.p(c.this, uVar, aVar);
            }
        };
    }

    private final void o(v4.g gVar) {
        b bVar = (b) gVar.f();
        String S = bVar.S();
        if (S.charAt(0) == '.') {
            S = t.p(this.context.getPackageName(), S);
        }
        androidx.fragment.app.f a10 = this.fragmentManager.x0().a(this.context.getClassLoader(), S);
        t.f(a10, "fragmentManager.fragment…ader, className\n        )");
        if (!androidx.fragment.app.e.class.isAssignableFrom(a10.getClass())) {
            throw new IllegalArgumentException(("Dialog destination " + bVar.S() + " is not an instance of DialogFragment").toString());
        }
        androidx.fragment.app.e eVar = (androidx.fragment.app.e) a10;
        eVar.setArguments(gVar.d());
        eVar.getLifecycle().a(this.observer);
        eVar.show(this.fragmentManager, gVar.g());
        b().h(gVar);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void p(c this$0, u source, n.a event) {
        Object obj;
        Object q02;
        t.g(this$0, "this$0");
        t.g(source, "source");
        t.g(event, "event");
        boolean z10 = false;
        if (event == n.a.ON_CREATE) {
            androidx.fragment.app.e eVar = (androidx.fragment.app.e) source;
            Iterable iterable = (Iterable) this$0.b().b().getValue();
            if (!(iterable instanceof Collection) || !((Collection) iterable).isEmpty()) {
                Iterator it = iterable.iterator();
                while (true) {
                    if (!it.hasNext()) {
                        break;
                    } else if (t.b(((v4.g) it.next()).g(), eVar.getTag())) {
                        z10 = true;
                        break;
                    }
                }
            }
            if (z10) {
                return;
            }
            eVar.dismiss();
            return;
        }
        if (event == n.a.ON_STOP) {
            androidx.fragment.app.e eVar2 = (androidx.fragment.app.e) source;
            if (eVar2.requireDialog().isShowing()) {
                return;
            }
            List list = (List) this$0.b().b().getValue();
            ListIterator listIterator = list.listIterator(list.size());
            while (true) {
                if (!listIterator.hasPrevious()) {
                    obj = null;
                    break;
                } else {
                    obj = listIterator.previous();
                    if (t.b(((v4.g) obj).g(), eVar2.getTag())) {
                        break;
                    }
                }
            }
            if (obj == null) {
                throw new IllegalStateException(("Dialog " + eVar2 + " has already been popped off of the Navigation back stack").toString());
            }
            v4.g gVar = (v4.g) obj;
            q02 = c0.q0(list);
            if (!t.b(q02, gVar)) {
                Log.i("DialogFragmentNavigator", "Dialog " + eVar2 + " was dismissed while it was not the top of the back stack, popping all dialogs above this dismissed dialog");
            }
            this$0.j(gVar, false);
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void q(c this$0, androidx.fragment.app.z noName_0, androidx.fragment.app.f childFragment) {
        t.g(this$0, "this$0");
        t.g(noName_0, "$noName_0");
        t.g(childFragment, "childFragment");
        if (this$0.restoredTagsAwaitingAttach.remove(childFragment.getTag())) {
            childFragment.getLifecycle().a(this$0.observer);
        }
    }

    @Override // v4.z
    public void e(List entries, v4.t tVar, z.a aVar) {
        t.g(entries, "entries");
        if (this.fragmentManager.T0()) {
            Log.i("DialogFragmentNavigator", "Ignoring navigate() call: FragmentManager has already saved its state");
            return;
        }
        Iterator it = entries.iterator();
        while (it.hasNext()) {
            o((v4.g) it.next());
        }
    }

    @Override // v4.z
    public void f(b0 state) {
        n lifecycle;
        t.g(state, "state");
        super.f(state);
        for (v4.g gVar : (List) state.b().getValue()) {
            androidx.fragment.app.e eVar = (androidx.fragment.app.e) this.fragmentManager.l0(gVar.g());
            n0 n0Var = null;
            if (eVar != null && (lifecycle = eVar.getLifecycle()) != null) {
                lifecycle.a(this.observer);
                n0Var = n0.f34904a;
            }
            if (n0Var == null) {
                this.restoredTagsAwaitingAttach.add(gVar.g());
            }
        }
        this.fragmentManager.k(new d0() { // from class: x4.a
            @Override // androidx.fragment.app.d0
            public final void a(androidx.fragment.app.z zVar, androidx.fragment.app.f fVar) {
                c.q(c.this, zVar, fVar);
            }
        });
    }

    @Override // v4.z
    public void j(v4.g popUpTo, boolean z10) {
        List B0;
        t.g(popUpTo, "popUpTo");
        if (this.fragmentManager.T0()) {
            Log.i("DialogFragmentNavigator", "Ignoring popBackStack() call: FragmentManager has already saved its state");
            return;
        }
        List list = (List) b().b().getValue();
        B0 = c0.B0(list.subList(list.indexOf(popUpTo), list.size()));
        Iterator it = B0.iterator();
        while (it.hasNext()) {
            androidx.fragment.app.f l02 = this.fragmentManager.l0(((v4.g) it.next()).g());
            if (l02 != null) {
                l02.getLifecycle().d(this.observer);
                ((androidx.fragment.app.e) l02).dismiss();
            }
        }
        b().g(popUpTo, z10);
    }

    @Override // v4.z
    /* renamed from: n, reason: merged with bridge method [inline-methods] */
    public b a() {
        return new b(this);
    }
}
