package androidx.navigation.fragment;

import android.app.Dialog;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import androidx.activity.q;
import androidx.fragment.app.FragmentContainerView;
import androidx.fragment.app.e;
import androidx.fragment.app.f;
import androidx.fragment.app.z;
import androidx.lifecycle.d1;
import kotlin.Metadata;
import kotlin.jvm.internal.k;
import kotlin.jvm.internal.t;
import rm.n0;
import v4.a0;
import v4.e0;
import v4.j;
import v4.r;
import v4.y;
import x4.c;
import x4.g;

@Metadata(d1 = {"\u0000f\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\u0018\u0002\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\u0002\n\u0002\u0010\u000b\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\r\n\u0002\u0010\b\n\u0002\b\u0010\b\u0016\u0018\u0000 :2\u00020\u00012\u00020\u0002:\u0001;B\u0007¢\u0006\u0004\b8\u00109J\u0010\u0010\u0006\u001a\u00020\u00052\u0006\u0010\u0004\u001a\u00020\u0003H\u0017J\u0012\u0010\t\u001a\u00020\u00052\b\u0010\b\u001a\u0004\u0018\u00010\u0007H\u0017J\u0010\u0010\f\u001a\u00020\u00052\u0006\u0010\u000b\u001a\u00020\nH\u0015J\u0010\u0010\u000f\u001a\u00020\u00052\u0006\u0010\u000e\u001a\u00020\rH\u0015J\u0010\u0010\u0012\u001a\u00020\u00052\u0006\u0010\u0011\u001a\u00020\u0010H\u0017J\u0010\u0010\u0015\u001a\n\u0012\u0006\b\u0001\u0012\u00020\u00140\u0013H\u0015J&\u0010\u001b\u001a\u0004\u0018\u00010\u001a2\u0006\u0010\u0017\u001a\u00020\u00162\b\u0010\u0019\u001a\u0004\u0018\u00010\u00182\b\u0010\b\u001a\u0004\u0018\u00010\u0007H\u0016J\u001a\u0010\u001d\u001a\u00020\u00052\u0006\u0010\u001c\u001a\u00020\u001a2\b\u0010\b\u001a\u0004\u0018\u00010\u0007H\u0016J\"\u0010 \u001a\u00020\u00052\u0006\u0010\u0004\u001a\u00020\u00032\u0006\u0010\u001f\u001a\u00020\u001e2\b\u0010\b\u001a\u0004\u0018\u00010\u0007H\u0017J\u0010\u0010\"\u001a\u00020\u00052\u0006\u0010!\u001a\u00020\u0007H\u0017J\b\u0010#\u001a\u00020\u0005H\u0016R\u0018\u0010\u000b\u001a\u0004\u0018\u00010\n8\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b$\u0010%R\u0018\u0010(\u001a\u0004\u0018\u00010\u00108\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b&\u0010'R\u0018\u0010+\u001a\u0004\u0018\u00010\u001a8\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b)\u0010*R\u0016\u0010/\u001a\u00020,8\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b-\u0010.R\u0016\u00102\u001a\u00020\u00108\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b0\u00101R\u0014\u00105\u001a\u00020,8BX\u0082\u0004¢\u0006\u0006\u001a\u0004\b3\u00104R\u0011\u0010\u000e\u001a\u00020\r8F¢\u0006\u0006\u001a\u0004\b6\u00107¨\u0006<"}, d2 = {"Landroidx/navigation/fragment/NavHostFragment;", "Landroidx/fragment/app/f;", "", "Landroid/content/Context;", "context", "Lrm/n0;", "onAttach", "Landroid/os/Bundle;", "savedInstanceState", "onCreate", "Lv4/r;", "navHostController", "C", "Lv4/j;", "navController", "B", "", "isPrimaryNavigationFragment", "onPrimaryNavigationFragmentChanged", "Lv4/z;", "Lx4/e$b;", "y", "Landroid/view/LayoutInflater;", "inflater", "Landroid/view/ViewGroup;", "container", "Landroid/view/View;", "onCreateView", "view", "onViewCreated", "Landroid/util/AttributeSet;", "attrs", "onInflate", "outState", "onSaveInstanceState", "onDestroyView", "p", "Lv4/r;", "q", "Ljava/lang/Boolean;", "isPrimaryBeforeOnCreate", "r", "Landroid/view/View;", "viewParent", "", "s", "I", "graphId", "t", "Z", "defaultNavHost", "z", "()I", "containerId", "A", "()Lv4/j;", "<init>", "()V", "u", "a", "navigation-fragment_release"}, k = 1, mv = {1, 6, 0})
/* loaded from: classes.dex */
public class NavHostFragment extends f {

    /* renamed from: u, reason: collision with root package name and from kotlin metadata */
    public static final Companion INSTANCE = new Companion(null);

    /* renamed from: p, reason: collision with root package name and from kotlin metadata */
    private r navHostController;

    /* renamed from: q, reason: collision with root package name and from kotlin metadata */
    private Boolean isPrimaryBeforeOnCreate;

    /* renamed from: r, reason: collision with root package name and from kotlin metadata */
    private View viewParent;

    /* renamed from: s, reason: collision with root package name and from kotlin metadata */
    private int graphId;

    /* renamed from: t, reason: collision with root package name and from kotlin metadata */
    private boolean defaultNavHost;

    /* renamed from: androidx.navigation.fragment.NavHostFragment$a, reason: from kotlin metadata */
    /* loaded from: classes.dex */
    public static final class Companion {
        private Companion() {
        }

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

        public final j a(f fragment) {
            Dialog dialog;
            Window window;
            t.g(fragment, "fragment");
            for (f fVar = fragment; fVar != null; fVar = fVar.getParentFragment()) {
                if (fVar instanceof NavHostFragment) {
                    r rVar = ((NavHostFragment) fVar).navHostController;
                    if (rVar != null) {
                        return rVar;
                    }
                    throw new NullPointerException("null cannot be cast to non-null type androidx.navigation.NavController");
                }
                f E0 = fVar.getParentFragmentManager().E0();
                if (E0 instanceof NavHostFragment) {
                    r rVar2 = ((NavHostFragment) E0).navHostController;
                    if (rVar2 != null) {
                        return rVar2;
                    }
                    throw new NullPointerException("null cannot be cast to non-null type androidx.navigation.NavController");
                }
            }
            View view = fragment.getView();
            if (view != null) {
                return y.c(view);
            }
            View view2 = null;
            e eVar = fragment instanceof e ? (e) fragment : null;
            if (eVar != null && (dialog = eVar.getDialog()) != null && (window = dialog.getWindow()) != null) {
                view2 = window.getDecorView();
            }
            if (view2 != null) {
                return y.c(view2);
            }
            throw new IllegalStateException("Fragment " + fragment + " does not have a NavController set");
        }
    }

    private final int z() {
        int id2 = getId();
        return (id2 == 0 || id2 == -1) ? x4.f.f50480a : id2;
    }

    public final j A() {
        r rVar = this.navHostController;
        if (rVar == null) {
            throw new IllegalStateException("NavController is not available before onCreate()".toString());
        }
        if (rVar != null) {
            return rVar;
        }
        throw new NullPointerException("null cannot be cast to non-null type androidx.navigation.NavHostController");
    }

    protected void B(j navController) {
        t.g(navController, "navController");
        a0 G = navController.G();
        Context requireContext = requireContext();
        t.f(requireContext, "requireContext()");
        z childFragmentManager = getChildFragmentManager();
        t.f(childFragmentManager, "childFragmentManager");
        G.c(new c(requireContext, childFragmentManager));
        navController.G().c(y());
    }

    protected void C(r navHostController) {
        t.g(navHostController, "navHostController");
        B(navHostController);
    }

    @Override // androidx.fragment.app.f
    public void onAttach(Context context) {
        t.g(context, "context");
        super.onAttach(context);
        if (this.defaultNavHost) {
            getParentFragmentManager().p().w(this).i();
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:17:0x007f  */
    /* JADX WARN: Removed duplicated region for block: B:22:0x00a8  */
    /* JADX WARN: Removed duplicated region for block: B:25:0x00b4  */
    /* JADX WARN: Removed duplicated region for block: B:29:0x00bf  */
    /* JADX WARN: Removed duplicated region for block: B:36:0x00a5  */
    @Override // androidx.fragment.app.f
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public void onCreate(Bundle bundle) {
        boolean z10;
        Bundle bundle2;
        Context requireContext = requireContext();
        t.f(requireContext, "requireContext()");
        r rVar = new r(requireContext);
        this.navHostController = rVar;
        t.d(rVar);
        rVar.m0(this);
        Object obj = requireContext;
        while (true) {
            if (!(obj instanceof ContextWrapper)) {
                break;
            }
            if (obj instanceof androidx.activity.t) {
                r rVar2 = this.navHostController;
                t.d(rVar2);
                q onBackPressedDispatcher = ((androidx.activity.t) obj).getOnBackPressedDispatcher();
                t.f(onBackPressedDispatcher, "context as OnBackPressed…).onBackPressedDispatcher");
                rVar2.n0(onBackPressedDispatcher);
                break;
            }
            Context baseContext = ((ContextWrapper) obj).getBaseContext();
            t.f(baseContext, "context.baseContext");
            obj = baseContext;
        }
        r rVar3 = this.navHostController;
        t.d(rVar3);
        Boolean bool = this.isPrimaryBeforeOnCreate;
        if (bool != null) {
            if (bool == null) {
                throw new NullPointerException("null cannot be cast to non-null type kotlin.Boolean");
            }
            if (bool.booleanValue()) {
                z10 = true;
                rVar3.t(z10);
                this.isPrimaryBeforeOnCreate = null;
                r rVar4 = this.navHostController;
                t.d(rVar4);
                d1 viewModelStore = getViewModelStore();
                t.f(viewModelStore, "viewModelStore");
                rVar4.o0(viewModelStore);
                r rVar5 = this.navHostController;
                t.d(rVar5);
                C(rVar5);
                if (bundle == null) {
                    bundle2 = bundle.getBundle("android-support-nav:fragment:navControllerState");
                    if (bundle.getBoolean("android-support-nav:fragment:defaultHost", false)) {
                        this.defaultNavHost = true;
                        getParentFragmentManager().p().w(this).i();
                    }
                    this.graphId = bundle.getInt("android-support-nav:fragment:graphId");
                } else {
                    bundle2 = null;
                }
                if (bundle2 != null) {
                    r rVar6 = this.navHostController;
                    t.d(rVar6);
                    rVar6.f0(bundle2);
                }
                if (this.graphId == 0) {
                    r rVar7 = this.navHostController;
                    t.d(rVar7);
                    rVar7.i0(this.graphId);
                } else {
                    Bundle arguments = getArguments();
                    int i10 = arguments != null ? arguments.getInt("android-support-nav:fragment:graphId") : 0;
                    Bundle bundle3 = arguments != null ? arguments.getBundle("android-support-nav:fragment:startDestinationArgs") : null;
                    if (i10 != 0) {
                        r rVar8 = this.navHostController;
                        t.d(rVar8);
                        rVar8.j0(i10, bundle3);
                    }
                }
                super.onCreate(bundle);
            }
        }
        z10 = false;
        rVar3.t(z10);
        this.isPrimaryBeforeOnCreate = null;
        r rVar42 = this.navHostController;
        t.d(rVar42);
        d1 viewModelStore2 = getViewModelStore();
        t.f(viewModelStore2, "viewModelStore");
        rVar42.o0(viewModelStore2);
        r rVar52 = this.navHostController;
        t.d(rVar52);
        C(rVar52);
        if (bundle == null) {
        }
        if (bundle2 != null) {
        }
        if (this.graphId == 0) {
        }
        super.onCreate(bundle);
    }

    @Override // androidx.fragment.app.f
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        t.g(inflater, "inflater");
        Context context = inflater.getContext();
        t.f(context, "inflater.context");
        FragmentContainerView fragmentContainerView = new FragmentContainerView(context);
        fragmentContainerView.setId(z());
        return fragmentContainerView;
    }

    @Override // androidx.fragment.app.f
    public void onDestroyView() {
        super.onDestroyView();
        View view = this.viewParent;
        if (view != null && y.c(view) == this.navHostController) {
            y.f(view, null);
        }
        this.viewParent = null;
    }

    @Override // androidx.fragment.app.f
    public void onInflate(Context context, AttributeSet attrs, Bundle bundle) {
        t.g(context, "context");
        t.g(attrs, "attrs");
        super.onInflate(context, attrs, bundle);
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attrs, e0.f39046g);
        t.f(obtainStyledAttributes, "context.obtainStyledAttr…yleable.NavHost\n        )");
        int resourceId = obtainStyledAttributes.getResourceId(e0.f39047h, 0);
        if (resourceId != 0) {
            this.graphId = resourceId;
        }
        n0 n0Var = n0.f34904a;
        obtainStyledAttributes.recycle();
        TypedArray obtainStyledAttributes2 = context.obtainStyledAttributes(attrs, g.f50485e);
        t.f(obtainStyledAttributes2, "context.obtainStyledAttr…tyleable.NavHostFragment)");
        if (obtainStyledAttributes2.getBoolean(g.f50486f, false)) {
            this.defaultNavHost = true;
        }
        obtainStyledAttributes2.recycle();
    }

    @Override // androidx.fragment.app.f
    public void onPrimaryNavigationFragmentChanged(boolean z10) {
        r rVar = this.navHostController;
        if (rVar == null) {
            this.isPrimaryBeforeOnCreate = Boolean.valueOf(z10);
        } else {
            if (rVar == null) {
                return;
            }
            rVar.t(z10);
        }
    }

    @Override // androidx.fragment.app.f
    public void onSaveInstanceState(Bundle outState) {
        t.g(outState, "outState");
        super.onSaveInstanceState(outState);
        r rVar = this.navHostController;
        t.d(rVar);
        Bundle h02 = rVar.h0();
        if (h02 != null) {
            outState.putBundle("android-support-nav:fragment:navControllerState", h02);
        }
        if (this.defaultNavHost) {
            outState.putBoolean("android-support-nav:fragment:defaultHost", true);
        }
        int i10 = this.graphId;
        if (i10 != 0) {
            outState.putInt("android-support-nav:fragment:graphId", i10);
        }
    }

    @Override // androidx.fragment.app.f
    public void onViewCreated(View view, Bundle bundle) {
        t.g(view, "view");
        super.onViewCreated(view, bundle);
        if (!(view instanceof ViewGroup)) {
            throw new IllegalStateException(("created host view " + view + " is not a ViewGroup").toString());
        }
        y.f(view, this.navHostController);
        if (view.getParent() != null) {
            Object parent = view.getParent();
            if (parent == null) {
                throw new NullPointerException("null cannot be cast to non-null type android.view.View");
            }
            View view2 = (View) parent;
            this.viewParent = view2;
            t.d(view2);
            if (view2.getId() == getId()) {
                View view3 = this.viewParent;
                t.d(view3);
                y.f(view3, this.navHostController);
            }
        }
    }

    protected v4.z y() {
        Context requireContext = requireContext();
        t.f(requireContext, "requireContext()");
        z childFragmentManager = getChildFragmentManager();
        t.f(childFragmentManager, "childFragmentManager");
        return new x4.e(requireContext, childFragmentManager, z());
    }
}
