package androidx.navigation.fragment;

import B6.b;
import B6.i;
import B6.w;
import E1.C0103j;
import E1.C0105l;
import E1.C0106m;
import E1.C0110q;
import E1.F;
import E1.G;
import E1.S;
import E1.T;
import E1.U;
import G1.e;
import G1.f;
import P6.g;
import P6.p;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.fragment.app.FragmentContainerView;
import androidx.lifecycle.C0518x;
import androidx.lifecycle.Z;
import com.martsnew.tv.R;
import d.c;
import d.x;
import d.y;
import d5.AbstractC0844a;
import h0.C1001a;
import h0.ComponentCallbacksC1023x;
import h0.P;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import s7.l;

/* JADX INFO: loaded from: classes.dex */
public class NavHostFragment extends ComponentCallbacksC1023x {

    /* JADX INFO: renamed from: o0, reason: collision with root package name */
    public F f8979o0;

    /* JADX INFO: renamed from: p0, reason: collision with root package name */
    public Boolean f8980p0;
    public View q0;

    /* JADX INFO: renamed from: r0, reason: collision with root package name */
    public int f8981r0;

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

    @Override // h0.ComponentCallbacksC1023x
    public final void E(Context context) {
        g.e(context, "context");
        super.E(context);
        if (this.f8982s0) {
            C1001a c1001a = new C1001a(q());
            c1001a.k(this);
            c1001a.f();
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r0v0, types: [android.content.Context] */
    /* JADX WARN: Type inference failed for: r0v1 */
    /* JADX WARN: Type inference failed for: r0v14, types: [android.content.Context, java.lang.Object] */
    @Override // h0.ComponentCallbacksC1023x
    public final void F(Bundle bundle) throws IllegalAccessException, Z6.F, InvocationTargetException {
        Bundle bundle2;
        C0518x c0518x;
        ?? Z7 = Z();
        F f3 = new F(Z7);
        this.f8979o0 = f3;
        if (!equals(f3.f2008m)) {
            NavHostFragment navHostFragment = f3.f2008m;
            C0106m c0106m = f3.f2013r;
            if (navHostFragment != null && (c0518x = navHostFragment.f13285f0) != null) {
                c0518x.y(c0106m);
            }
            f3.f2008m = this;
            this.f13285f0.f(c0106m);
        }
        while (true) {
            if (!(Z7 instanceof ContextWrapper)) {
                break;
            }
            if (Z7 instanceof y) {
                F f7 = this.f8979o0;
                g.b(f7);
                x xVarG = ((y) Z7).g();
                g.d(xVarG, "context as OnBackPressed…).onBackPressedDispatcher");
                if (!xVarG.equals(f7.f2009n)) {
                    NavHostFragment navHostFragment2 = f7.f2008m;
                    if (navHostFragment2 == null) {
                        throw new IllegalStateException("You must call setLifecycleOwner() before calling setOnBackPressedDispatcher()");
                    }
                    C0110q c0110q = f7.f2014s;
                    Iterator it = c0110q.f11308b.iterator();
                    while (it.hasNext()) {
                        ((c) it.next()).cancel();
                    }
                    f7.f2009n = xVarG;
                    xVarG.a(navHostFragment2, c0110q);
                    C0518x c0518x2 = navHostFragment2.f13285f0;
                    C0106m c0106m2 = f7.f2013r;
                    c0518x2.y(c0106m2);
                    c0518x2.f(c0106m2);
                }
            } else {
                Z7 = ((ContextWrapper) Z7).getBaseContext();
                g.d(Z7, "context.baseContext");
            }
        }
        F f8 = this.f8979o0;
        g.b(f8);
        Boolean bool = this.f8980p0;
        f8.f2015t = bool != null && bool.booleanValue();
        f8.u();
        this.f8980p0 = null;
        F f9 = this.f8979o0;
        g.b(f9);
        Z zR = r();
        if (!g.a(f9.f2010o, l.o(zR))) {
            if (!f9.f2003g.isEmpty()) {
                throw new IllegalStateException("ViewModelStore should be set before setGraph call");
            }
            f9.f2010o = l.o(zR);
        }
        F f10 = this.f8979o0;
        g.b(f10);
        Context contextZ = Z();
        P pN = n();
        g.d(pN, "childFragmentManager");
        G1.c cVar = new G1.c(contextZ, pN);
        T t6 = f10.f2016u;
        t6.a(cVar);
        t6.a(f0());
        if (bundle != null) {
            bundle2 = bundle.getBundle("android-support-nav:fragment:navControllerState");
            if (bundle.getBoolean("android-support-nav:fragment:defaultHost", false)) {
                this.f8982s0 = true;
                C1001a c1001a = new C1001a(q());
                c1001a.k(this);
                c1001a.f();
            }
            this.f8981r0 = bundle.getInt("android-support-nav:fragment:graphId");
        } else {
            bundle2 = null;
        }
        if (bundle2 != null) {
            F f11 = this.f8979o0;
            g.b(f11);
            bundle2.setClassLoader(f11.f1997a.getClassLoader());
            f11.f2000d = bundle2.getBundle("android-support-nav:controller:navigatorState");
            f11.f2001e = bundle2.getParcelableArray("android-support-nav:controller:backStack");
            LinkedHashMap linkedHashMap = f11.f2007l;
            linkedHashMap.clear();
            int[] intArray = bundle2.getIntArray("android-support-nav:controller:backStackDestIds");
            ArrayList<String> stringArrayList = bundle2.getStringArrayList("android-support-nav:controller:backStackIds");
            if (intArray != null && stringArrayList != null) {
                int length = intArray.length;
                int i = 0;
                int i5 = 0;
                while (i < length) {
                    f11.f2006k.put(Integer.valueOf(intArray[i]), stringArrayList.get(i5));
                    i++;
                    i5++;
                }
            }
            ArrayList<String> stringArrayList2 = bundle2.getStringArrayList("android-support-nav:controller:backStackStates");
            if (stringArrayList2 != null) {
                int size = stringArrayList2.size();
                int i8 = 0;
                while (i8 < size) {
                    String str = stringArrayList2.get(i8);
                    i8++;
                    String str2 = str;
                    Parcelable[] parcelableArray = bundle2.getParcelableArray("android-support-nav:controller:backStackStates:" + str2);
                    if (parcelableArray != null) {
                        g.d(str2, "id");
                        i iVar = new i(parcelableArray.length);
                        b bVarD = p.d(parcelableArray);
                        while (bVarD.hasNext()) {
                            Parcelable parcelable = (Parcelable) bVarD.next();
                            if (parcelable == null) {
                                throw new NullPointerException("null cannot be cast to non-null type androidx.navigation.NavBackStackEntryState");
                            }
                            iVar.addLast((C0105l) parcelable);
                        }
                        linkedHashMap.put(str2, iVar);
                    }
                }
            }
            f11.f2002f = bundle2.getBoolean("android-support-nav:controller:deepLinkHandled");
        }
        if (this.f8981r0 != 0) {
            F f12 = this.f8979o0;
            g.b(f12);
            f12.r(((G) f12.f1995B.getValue()).b(this.f8981r0), null);
        } else {
            Bundle bundle3 = this.f13298v;
            int i9 = bundle3 != null ? bundle3.getInt("android-support-nav:fragment:graphId") : 0;
            Bundle bundle4 = bundle3 != null ? bundle3.getBundle("android-support-nav:fragment:startDestinationArgs") : null;
            if (i9 != 0) {
                F f13 = this.f8979o0;
                g.b(f13);
                f13.r(((G) f13.f1995B.getValue()).b(i9), bundle4);
            }
        }
        super.F(bundle);
    }

    @Override // h0.ComponentCallbacksC1023x
    public final View G(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        g.e(layoutInflater, "inflater");
        Context context = layoutInflater.getContext();
        g.d(context, "inflater.context");
        FragmentContainerView fragmentContainerView = new FragmentContainerView(context);
        int i = this.f13269O;
        if (i == 0 || i == -1) {
            i = R.id.nav_host_fragment_container;
        }
        fragmentContainerView.setId(i);
        return fragmentContainerView;
    }

    @Override // h0.ComponentCallbacksC1023x
    public final void J() {
        this.f13276V = true;
        View view = this.q0;
        if (view != null && W3.b.m(view) == this.f8979o0) {
            view.setTag(R.id.nav_controller_view_tag, null);
        }
        this.q0 = null;
    }

    @Override // h0.ComponentCallbacksC1023x
    public final void N(Context context, AttributeSet attributeSet, Bundle bundle) {
        g.e(context, "context");
        g.e(attributeSet, "attrs");
        super.N(context, attributeSet, bundle);
        TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(attributeSet, U.f2059b);
        g.d(typedArrayObtainStyledAttributes, "context.obtainStyledAttr…yleable.NavHost\n        )");
        int resourceId = typedArrayObtainStyledAttributes.getResourceId(0, 0);
        if (resourceId != 0) {
            this.f8981r0 = resourceId;
        }
        typedArrayObtainStyledAttributes.recycle();
        TypedArray typedArrayObtainStyledAttributes2 = context.obtainStyledAttributes(attributeSet, f.f2927c);
        g.d(typedArrayObtainStyledAttributes2, "context.obtainStyledAttr…tyleable.NavHostFragment)");
        if (typedArrayObtainStyledAttributes2.getBoolean(0, false)) {
            this.f8982s0 = true;
        }
        typedArrayObtainStyledAttributes2.recycle();
    }

    @Override // h0.ComponentCallbacksC1023x
    public final void P(boolean z8) {
        F f3 = this.f8979o0;
        if (f3 == null) {
            this.f8980p0 = Boolean.valueOf(z8);
        } else {
            f3.f2015t = z8;
            f3.u();
        }
    }

    @Override // h0.ComponentCallbacksC1023x
    public final void R(Bundle bundle) {
        Bundle bundle2;
        F f3 = this.f8979o0;
        g.b(f3);
        ArrayList<String> arrayList = new ArrayList<>();
        Bundle bundle3 = new Bundle();
        for (Map.Entry entry : w.p0(f3.f2016u.f2057a).entrySet()) {
            String str = (String) entry.getKey();
            Bundle bundleH = ((S) entry.getValue()).h();
            if (bundleH != null) {
                arrayList.add(str);
                bundle3.putBundle(str, bundleH);
            }
        }
        if (arrayList.isEmpty()) {
            bundle2 = null;
        } else {
            bundle2 = new Bundle();
            bundle3.putStringArrayList("android-support-nav:controller:navigatorState:names", arrayList);
            bundle2.putBundle("android-support-nav:controller:navigatorState", bundle3);
        }
        i iVar = f3.f2003g;
        if (!iVar.isEmpty()) {
            if (bundle2 == null) {
                bundle2 = new Bundle();
            }
            Parcelable[] parcelableArr = new Parcelable[iVar.f1028s];
            Iterator<E> it = iVar.iterator();
            int i = 0;
            while (it.hasNext()) {
                parcelableArr[i] = new C0105l((C0103j) it.next());
                i++;
            }
            bundle2.putParcelableArray("android-support-nav:controller:backStack", parcelableArr);
        }
        LinkedHashMap linkedHashMap = f3.f2006k;
        if (!linkedHashMap.isEmpty()) {
            if (bundle2 == null) {
                bundle2 = new Bundle();
            }
            int[] iArr = new int[linkedHashMap.size()];
            ArrayList<String> arrayList2 = new ArrayList<>();
            int i5 = 0;
            for (Map.Entry entry2 : linkedHashMap.entrySet()) {
                int iIntValue = ((Number) entry2.getKey()).intValue();
                String str2 = (String) entry2.getValue();
                iArr[i5] = iIntValue;
                arrayList2.add(str2);
                i5++;
            }
            bundle2.putIntArray("android-support-nav:controller:backStackDestIds", iArr);
            bundle2.putStringArrayList("android-support-nav:controller:backStackIds", arrayList2);
        }
        LinkedHashMap linkedHashMap2 = f3.f2007l;
        if (!linkedHashMap2.isEmpty()) {
            if (bundle2 == null) {
                bundle2 = new Bundle();
            }
            ArrayList<String> arrayList3 = new ArrayList<>();
            for (Map.Entry entry3 : linkedHashMap2.entrySet()) {
                String str3 = (String) entry3.getKey();
                i iVar2 = (i) entry3.getValue();
                arrayList3.add(str3);
                Parcelable[] parcelableArr2 = new Parcelable[iVar2.f1028s];
                int i8 = 0;
                for (Object obj : iVar2) {
                    int i9 = i8 + 1;
                    if (i8 < 0) {
                        B6.l.Z();
                        throw null;
                    }
                    parcelableArr2[i8] = (C0105l) obj;
                    i8 = i9;
                }
                bundle2.putParcelableArray(AbstractC0844a.x("android-support-nav:controller:backStackStates:", str3), parcelableArr2);
            }
            bundle2.putStringArrayList("android-support-nav:controller:backStackStates", arrayList3);
        }
        if (f3.f2002f) {
            if (bundle2 == null) {
                bundle2 = new Bundle();
            }
            bundle2.putBoolean("android-support-nav:controller:deepLinkHandled", f3.f2002f);
        }
        if (bundle2 != null) {
            bundle.putBundle("android-support-nav:fragment:navControllerState", bundle2);
        }
        if (this.f8982s0) {
            bundle.putBoolean("android-support-nav:fragment:defaultHost", true);
        }
        int i10 = this.f8981r0;
        if (i10 != 0) {
            bundle.putInt("android-support-nav:fragment:graphId", i10);
        }
    }

    @Override // h0.ComponentCallbacksC1023x
    public final void U(View view, Bundle bundle) {
        g.e(view, "view");
        if (!(view instanceof ViewGroup)) {
            throw new IllegalStateException(("created host view " + view + " is not a ViewGroup").toString());
        }
        view.setTag(R.id.nav_controller_view_tag, this.f8979o0);
        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.q0 = view2;
            if (view2.getId() == this.f13269O) {
                View view3 = this.q0;
                g.b(view3);
                view3.setTag(R.id.nav_controller_view_tag, this.f8979o0);
            }
        }
    }

    public S f0() {
        Context contextZ = Z();
        P pN = n();
        g.d(pN, "childFragmentManager");
        int i = this.f13269O;
        if (i == 0 || i == -1) {
            i = R.id.nav_host_fragment_container;
        }
        return new e(contextZ, pN, i);
    }
}
