package androidx.fragment.app;

import F1.AbstractC0193w;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.Log;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import androidx.lifecycle.EnumC1108q;
import com.debridstream.tv.R;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Iterator;
import m1.AbstractC2464a;

/* JADX INFO: loaded from: classes.dex */
public final class o0 {

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final p0 f11683b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final G f11684c;

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

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public int f11686e = -1;

    public o0(M m6, p0 p0Var, G g6) {
        this.f11682a = m6;
        this.f11683b = p0Var;
        this.f11684c = g6;
    }

    public final void a() {
        boolean zH = AbstractC1050g0.H(3);
        G g6 = this.f11684c;
        if (zH) {
            Log.d("FragmentManager", "moveto ACTIVITY_CREATED: " + g6);
        }
        Bundle bundle = g6.mSavedFragmentState;
        g6.performActivityCreated(bundle != null ? bundle.getBundle("savedInstanceState") : null);
        this.f11682a.a(false);
    }

    public final void b() {
        G g6;
        View view;
        View view2;
        int iIndexOfChild = -1;
        G g7 = this.f11684c;
        View view3 = g7.mContainer;
        while (true) {
            g6 = null;
            if (view3 == null) {
                break;
            }
            Object tag = view3.getTag(R.id.fragment_container_view_tag);
            G g8 = tag instanceof G ? (G) tag : null;
            if (g8 != null) {
                g6 = g8;
                break;
            } else {
                Object parent = view3.getParent();
                view3 = parent instanceof View ? (View) parent : null;
            }
        }
        G parentFragment = g7.getParentFragment();
        if (g6 != null && !g6.equals(parentFragment)) {
            int i6 = g7.mContainerId;
            X1.c cVar = X1.d.f8547a;
            StringBuilder sb = new StringBuilder("Attempting to nest fragment ");
            sb.append(g7);
            sb.append(" within the view of parent fragment ");
            sb.append(g6);
            sb.append(" via container with ID ");
            X1.d.b(new X1.a(g7, Z0.o.q(sb, i6, " without using parent's childFragmentManager")));
            X1.d.a(g7).getClass();
        }
        p0 p0Var = this.f11683b;
        p0Var.getClass();
        ViewGroup viewGroup = g7.mContainer;
        if (viewGroup != null) {
            ArrayList arrayList = p0Var.f11689a;
            int iIndexOf = arrayList.indexOf(g7);
            int i7 = iIndexOf - 1;
            while (true) {
                if (i7 < 0) {
                    while (true) {
                        iIndexOf++;
                        if (iIndexOf >= arrayList.size()) {
                            break;
                        }
                        G g9 = (G) arrayList.get(iIndexOf);
                        if (g9.mContainer == viewGroup && (view = g9.mView) != null) {
                            iIndexOfChild = viewGroup.indexOfChild(view);
                            break;
                        }
                    }
                } else {
                    G g10 = (G) arrayList.get(i7);
                    if (g10.mContainer == viewGroup && (view2 = g10.mView) != null) {
                        iIndexOfChild = viewGroup.indexOfChild(view2) + 1;
                        break;
                    }
                    i7--;
                }
            }
        }
        g7.mContainer.addView(g7.mView, iIndexOfChild);
    }

    public final void c() {
        boolean zH = AbstractC1050g0.H(3);
        G g6 = this.f11684c;
        if (zH) {
            Log.d("FragmentManager", "moveto ATTACHED: " + g6);
        }
        G g7 = g6.mTarget;
        o0 o0Var = null;
        p0 p0Var = this.f11683b;
        if (g7 != null) {
            o0 o0Var2 = (o0) p0Var.f11690b.get(g7.mWho);
            if (o0Var2 == null) {
                throw new IllegalStateException("Fragment " + g6 + " declared target fragment " + g6.mTarget + " that does not belong to this FragmentManager!");
            }
            g6.mTargetWho = g6.mTarget.mWho;
            g6.mTarget = null;
            o0Var = o0Var2;
        } else {
            String str = g6.mTargetWho;
            if (str != null && (o0Var = (o0) p0Var.f11690b.get(str)) == null) {
                StringBuilder sb = new StringBuilder("Fragment ");
                sb.append(g6);
                sb.append(" declared target fragment ");
                throw new IllegalStateException(com.google.android.recaptcha.internal.a.n(sb, g6.mTargetWho, " that does not belong to this FragmentManager!"));
            }
        }
        if (o0Var != null) {
            o0Var.k();
        }
        AbstractC1050g0 abstractC1050g0 = g6.mFragmentManager;
        g6.mHost = abstractC1050g0.f11623u;
        g6.mParentFragment = abstractC1050g0.f11625w;
        M m6 = this.f11682a;
        m6.g(false);
        g6.performAttach();
        m6.b(false);
    }

    public final int d() {
        Object next;
        G g6 = this.f11684c;
        if (g6.mFragmentManager == null) {
            return g6.mState;
        }
        int iMin = this.f11686e;
        int iOrdinal = g6.mMaxState.ordinal();
        if (iOrdinal == 1) {
            iMin = Math.min(iMin, 0);
        } else if (iOrdinal == 2) {
            iMin = Math.min(iMin, 1);
        } else if (iOrdinal == 3) {
            iMin = Math.min(iMin, 5);
        } else if (iOrdinal != 4) {
            iMin = Math.min(iMin, -1);
        }
        if (g6.mFromLayout) {
            if (g6.mInLayout) {
                iMin = Math.max(this.f11686e, 2);
                View view = g6.mView;
                if (view != null && view.getParent() == null) {
                    iMin = Math.min(iMin, 2);
                }
            } else {
                iMin = this.f11686e < 4 ? Math.min(iMin, g6.mState) : Math.min(iMin, 1);
            }
        }
        if (!g6.mAdded) {
            iMin = Math.min(iMin, 1);
        }
        ViewGroup viewGroup = g6.mContainer;
        if (viewGroup != null) {
            C1058o c1058oH = C1058o.h(viewGroup, g6.getParentFragmentManager());
            c1058oH.getClass();
            D0 d0F = c1058oH.f(g6);
            int i6 = d0F != null ? d0F.f11511b : 0;
            Iterator it = c1058oH.f11679c.iterator();
            while (true) {
                if (!it.hasNext()) {
                    next = null;
                    break;
                }
                next = it.next();
                D0 d02 = (D0) next;
                if (kotlin.jvm.internal.o.c(d02.f11512c, g6) && !d02.f11515f) {
                    break;
                }
            }
            D0 d03 = (D0) next;
            i = d03 != null ? d03.f11511b : 0;
            int i7 = i6 == 0 ? -1 : F0.f11520a[AbstractC2464a.c(i6)];
            if (i7 != -1 && i7 != 1) {
                i = i6;
            }
        }
        if (i == 2) {
            iMin = Math.min(iMin, 6);
        } else if (i == 3) {
            iMin = Math.max(iMin, 3);
        } else if (g6.mRemoving) {
            iMin = g6.isInBackStack() ? Math.min(iMin, 1) : Math.min(iMin, -1);
        }
        if (g6.mDeferStart && g6.mState < 5) {
            iMin = Math.min(iMin, 4);
        }
        if (AbstractC1050g0.H(2)) {
            Log.v("FragmentManager", "computeExpectedState() of " + iMin + " for " + g6);
        }
        return iMin;
    }

    public final void e() {
        boolean zH = AbstractC1050g0.H(3);
        G g6 = this.f11684c;
        if (zH) {
            Log.d("FragmentManager", "moveto CREATED: " + g6);
        }
        Bundle bundle = g6.mSavedFragmentState;
        Bundle bundle2 = bundle != null ? bundle.getBundle("savedInstanceState") : null;
        if (g6.mIsCreated) {
            g6.mState = 1;
            g6.restoreChildFragmentState();
        } else {
            M m6 = this.f11682a;
            m6.h(false);
            g6.performCreate(bundle2);
            m6.c(false);
        }
    }

    public final void f() {
        String resourceName;
        G g6 = this.f11684c;
        if (g6.mFromLayout) {
            return;
        }
        if (AbstractC1050g0.H(3)) {
            Log.d("FragmentManager", "moveto CREATE_VIEW: " + g6);
        }
        Bundle bundle = g6.mSavedFragmentState;
        ViewGroup viewGroup = null;
        Bundle bundle2 = bundle != null ? bundle.getBundle("savedInstanceState") : null;
        LayoutInflater layoutInflaterPerformGetLayoutInflater = g6.performGetLayoutInflater(bundle2);
        ViewGroup viewGroup2 = g6.mContainer;
        if (viewGroup2 != null) {
            viewGroup = viewGroup2;
        } else {
            int i6 = g6.mContainerId;
            if (i6 != 0) {
                if (i6 == -1) {
                    throw new IllegalArgumentException(Z0.o.m("Cannot create fragment ", g6, " for a container view with no id"));
                }
                viewGroup = (ViewGroup) g6.mFragmentManager.f11624v.b(i6);
                if (viewGroup == null) {
                    if (!g6.mRestored) {
                        try {
                            resourceName = g6.getResources().getResourceName(g6.mContainerId);
                        } catch (Resources.NotFoundException unused) {
                            resourceName = "unknown";
                        }
                        throw new IllegalArgumentException("No view found for id 0x" + Integer.toHexString(g6.mContainerId) + " (" + resourceName + ") for fragment " + g6);
                    }
                } else if (!(viewGroup instanceof P)) {
                    X1.c cVar = X1.d.f8547a;
                    X1.d.b(new X1.a(g6, "Attempting to add fragment " + g6 + " to container " + viewGroup + " which is not a FragmentContainerView"));
                    X1.d.a(g6).getClass();
                }
            }
        }
        g6.mContainer = viewGroup;
        g6.performCreateView(layoutInflaterPerformGetLayoutInflater, viewGroup, bundle2);
        if (g6.mView != null) {
            if (AbstractC1050g0.H(3)) {
                Log.d("FragmentManager", "moveto VIEW_CREATED: " + g6);
            }
            g6.mView.setSaveFromParentEnabled(false);
            g6.mView.setTag(R.id.fragment_container_view_tag, g6);
            if (viewGroup != null) {
                b();
            }
            if (g6.mHidden) {
                g6.mView.setVisibility(8);
            }
            View view = g6.mView;
            Field field = F1.F.f1367a;
            if (view.isAttachedToWindow()) {
                AbstractC0193w.c(g6.mView);
            } else {
                View view2 = g6.mView;
                view2.addOnAttachStateChangeListener(new n0(view2));
            }
            g6.performViewCreated();
            this.f11682a.m(false);
            int visibility = g6.mView.getVisibility();
            g6.setPostOnViewCreatedAlpha(g6.mView.getAlpha());
            if (g6.mContainer != null && visibility == 0) {
                View viewFindFocus = g6.mView.findFocus();
                if (viewFindFocus != null) {
                    g6.setFocusedView(viewFindFocus);
                    if (AbstractC1050g0.H(2)) {
                        Log.v("FragmentManager", "requestFocus: Saved focused view " + viewFindFocus + " for Fragment " + g6);
                    }
                }
                g6.mView.setAlpha(0.0f);
            }
        }
        g6.mState = 2;
    }

    public final void g() {
        G gB;
        boolean zH = AbstractC1050g0.H(3);
        G g6 = this.f11684c;
        if (zH) {
            Log.d("FragmentManager", "movefrom CREATED: " + g6);
        }
        boolean zIsChangingConfigurations = true;
        boolean z6 = g6.mRemoving && !g6.isInBackStack();
        p0 p0Var = this.f11683b;
        if (z6 && !g6.mBeingSaved) {
            p0Var.i(null, g6.mWho);
        }
        if (!z6 && !p0Var.f11692d.shouldDestroy(g6)) {
            String str = g6.mTargetWho;
            if (str != null && (gB = p0Var.b(str)) != null && gB.mRetainInstance) {
                g6.mTarget = gB;
            }
            g6.mState = 0;
            return;
        }
        S s6 = g6.mHost;
        if (s6 instanceof androidx.lifecycle.j0) {
            zIsChangingConfigurations = p0Var.f11692d.isCleared();
        } else {
            L l = s6.f11540b;
            if (l != null) {
                zIsChangingConfigurations = true ^ l.isChangingConfigurations();
            }
        }
        if ((z6 && !g6.mBeingSaved) || zIsChangingConfigurations) {
            p0Var.f11692d.clearNonConfigState(g6);
        }
        g6.performDestroy();
        this.f11682a.d(false);
        for (o0 o0Var : p0Var.d()) {
            if (o0Var != null) {
                String str2 = g6.mWho;
                G g7 = o0Var.f11684c;
                if (str2.equals(g7.mTargetWho)) {
                    g7.mTarget = g6;
                    g7.mTargetWho = null;
                }
            }
        }
        String str3 = g6.mTargetWho;
        if (str3 != null) {
            g6.mTarget = p0Var.b(str3);
        }
        p0Var.h(this);
    }

    public final void h() {
        View view;
        boolean zH = AbstractC1050g0.H(3);
        G g6 = this.f11684c;
        if (zH) {
            Log.d("FragmentManager", "movefrom CREATE_VIEW: " + g6);
        }
        ViewGroup viewGroup = g6.mContainer;
        if (viewGroup != null && (view = g6.mView) != null) {
            viewGroup.removeView(view);
        }
        g6.performDestroyView();
        this.f11682a.n(false);
        g6.mContainer = null;
        g6.mView = null;
        g6.mViewLifecycleOwner = null;
        g6.mViewLifecycleOwnerLiveData.h(null);
        g6.mInLayout = false;
    }

    public final void i() {
        boolean zH = AbstractC1050g0.H(3);
        G g6 = this.f11684c;
        if (zH) {
            Log.d("FragmentManager", "movefrom ATTACHED: " + g6);
        }
        g6.performDetach();
        this.f11682a.e(false);
        g6.mState = -1;
        g6.mHost = null;
        g6.mParentFragment = null;
        g6.mFragmentManager = null;
        if ((!g6.mRemoving || g6.isInBackStack()) && !this.f11683b.f11692d.shouldDestroy(g6)) {
            return;
        }
        if (AbstractC1050g0.H(3)) {
            Log.d("FragmentManager", "initState called for fragment: " + g6);
        }
        g6.initState();
    }

    public final void j() {
        G g6 = this.f11684c;
        if (g6.mFromLayout && g6.mInLayout && !g6.mPerformedCreateView) {
            if (AbstractC1050g0.H(3)) {
                Log.d("FragmentManager", "moveto CREATE_VIEW: " + g6);
            }
            Bundle bundle = g6.mSavedFragmentState;
            Bundle bundle2 = bundle != null ? bundle.getBundle("savedInstanceState") : null;
            g6.performCreateView(g6.performGetLayoutInflater(bundle2), null, bundle2);
            View view = g6.mView;
            if (view != null) {
                view.setSaveFromParentEnabled(false);
                g6.mView.setTag(R.id.fragment_container_view_tag, g6);
                if (g6.mHidden) {
                    g6.mView.setVisibility(8);
                }
                g6.performViewCreated();
                this.f11682a.m(false);
                g6.mState = 2;
            }
        }
    }

    /* JADX WARN: Code restructure failed: missing block: B:155:0x01b4, code lost:
    
        continue;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void k() {
        ViewGroup viewGroup;
        ViewGroup viewGroup2;
        ViewGroup viewGroup3;
        boolean z6 = this.f11685d;
        G g6 = this.f11684c;
        if (z6) {
            if (AbstractC1050g0.H(2)) {
                Log.v("FragmentManager", "Ignoring re-entrant call to moveToExpectedState() for " + g6);
                return;
            }
            return;
        }
        try {
            this.f11685d = true;
            boolean z7 = false;
            while (true) {
                int iD = d();
                int i6 = g6.mState;
                int i7 = 3;
                p0 p0Var = this.f11683b;
                if (iD == i6) {
                    if (!z7 && i6 == -1 && g6.mRemoving && !g6.isInBackStack() && !g6.mBeingSaved) {
                        if (AbstractC1050g0.H(3)) {
                            Log.d("FragmentManager", "Cleaning up state of never attached fragment: " + g6);
                        }
                        p0Var.f11692d.clearNonConfigState(g6);
                        p0Var.h(this);
                        if (AbstractC1050g0.H(3)) {
                            Log.d("FragmentManager", "initState called for fragment: " + g6);
                        }
                        g6.initState();
                    }
                    if (g6.mHiddenChanged) {
                        if (g6.mView != null && (viewGroup = g6.mContainer) != null) {
                            C1058o c1058oH = C1058o.h(viewGroup, g6.getParentFragmentManager());
                            if (g6.mHidden) {
                                c1058oH.getClass();
                                if (AbstractC1050g0.H(2)) {
                                    Log.v("FragmentManager", "SpecialEffectsController: Enqueuing hide operation for fragment " + g6);
                                }
                                c1058oH.b(3, 1, this);
                            } else {
                                c1058oH.getClass();
                                if (AbstractC1050g0.H(2)) {
                                    Log.v("FragmentManager", "SpecialEffectsController: Enqueuing show operation for fragment " + g6);
                                }
                                c1058oH.b(2, 1, this);
                            }
                        }
                        AbstractC1050g0 abstractC1050g0 = g6.mFragmentManager;
                        if (abstractC1050g0 != null && g6.mAdded && AbstractC1050g0.I(g6)) {
                            abstractC1050g0.f11594E = true;
                        }
                        g6.mHiddenChanged = false;
                        g6.onHiddenChanged(g6.mHidden);
                        g6.mChildFragmentManager.n();
                    }
                    this.f11685d = false;
                    return;
                }
                M m6 = this.f11682a;
                if (iD <= i6) {
                    switch (i6 - 1) {
                        case -1:
                            i();
                            break;
                        case 0:
                            if (g6.mBeingSaved) {
                                if (((Bundle) p0Var.f11691c.get(g6.mWho)) == null) {
                                    p0Var.i(n(), g6.mWho);
                                }
                            }
                            g();
                            break;
                        case 1:
                            h();
                            g6.mState = 1;
                            break;
                        case 2:
                            g6.mInLayout = false;
                            g6.mState = 2;
                            break;
                        case 3:
                            if (AbstractC1050g0.H(3)) {
                                Log.d("FragmentManager", "movefrom ACTIVITY_CREATED: " + g6);
                            }
                            if (g6.mBeingSaved) {
                                p0Var.i(n(), g6.mWho);
                            } else if (g6.mView != null && g6.mSavedViewState == null) {
                                o();
                            }
                            if (g6.mView != null && (viewGroup2 = g6.mContainer) != null) {
                                C1058o c1058oH2 = C1058o.h(viewGroup2, g6.getParentFragmentManager());
                                c1058oH2.getClass();
                                if (AbstractC1050g0.H(2)) {
                                    Log.v("FragmentManager", "SpecialEffectsController: Enqueuing remove operation for fragment " + g6);
                                }
                                c1058oH2.b(1, 3, this);
                            }
                            g6.mState = 3;
                            break;
                        case 4:
                            if (AbstractC1050g0.H(3)) {
                                Log.d("FragmentManager", "movefrom STARTED: " + g6);
                            }
                            g6.performStop();
                            m6.l(false);
                            break;
                        case 5:
                            g6.mState = 5;
                            break;
                        case 6:
                            if (AbstractC1050g0.H(3)) {
                                Log.d("FragmentManager", "movefrom RESUMED: " + g6);
                            }
                            g6.performPause();
                            m6.f(false);
                            break;
                    }
                } else {
                    switch (i6 + 1) {
                        case 0:
                            c();
                            break;
                        case 1:
                            e();
                            break;
                        case 2:
                            j();
                            f();
                            break;
                        case 3:
                            a();
                            break;
                        case 4:
                            if (g6.mView != null && (viewGroup3 = g6.mContainer) != null) {
                                C1058o c1058oH3 = C1058o.h(viewGroup3, g6.getParentFragmentManager());
                                int visibility = g6.mView.getVisibility();
                                if (visibility == 0) {
                                    i7 = 2;
                                } else if (visibility == 4) {
                                    i7 = 4;
                                } else if (visibility != 8) {
                                    throw new IllegalArgumentException("Unknown visibility " + visibility);
                                }
                                c1058oH3.getClass();
                                com.google.android.recaptcha.internal.a.t(i7, "finalState");
                                if (AbstractC1050g0.H(2)) {
                                    Log.v("FragmentManager", "SpecialEffectsController: Enqueuing add operation for fragment " + g6);
                                }
                                c1058oH3.b(i7, 2, this);
                            }
                            g6.mState = 4;
                            break;
                        case 5:
                            if (AbstractC1050g0.H(3)) {
                                Log.d("FragmentManager", "moveto STARTED: " + g6);
                            }
                            g6.performStart();
                            m6.k(false);
                            break;
                        case 6:
                            g6.mState = 6;
                            break;
                        case 7:
                            m();
                            break;
                    }
                }
                z7 = true;
            }
        } catch (Throwable th) {
            this.f11685d = false;
            throw th;
        }
    }

    public final void l(ClassLoader classLoader) {
        G g6 = this.f11684c;
        Bundle bundle = g6.mSavedFragmentState;
        if (bundle == null) {
            return;
        }
        bundle.setClassLoader(classLoader);
        if (g6.mSavedFragmentState.getBundle("savedInstanceState") == null) {
            g6.mSavedFragmentState.putBundle("savedInstanceState", new Bundle());
        }
        g6.mSavedViewState = g6.mSavedFragmentState.getSparseParcelableArray("viewState");
        g6.mSavedViewRegistryState = g6.mSavedFragmentState.getBundle("viewRegistryState");
        m0 m0Var = (m0) g6.mSavedFragmentState.getParcelable("state");
        if (m0Var != null) {
            g6.mTargetWho = m0Var.f11669o;
            g6.mTargetRequestCode = m0Var.f11670p;
            Boolean bool = g6.mSavedUserVisibleHint;
            if (bool != null) {
                g6.mUserVisibleHint = bool.booleanValue();
                g6.mSavedUserVisibleHint = null;
            } else {
                g6.mUserVisibleHint = m0Var.f11671q;
            }
        }
        if (g6.mUserVisibleHint) {
            return;
        }
        g6.mDeferStart = true;
    }

    /* JADX WARN: Removed duplicated region for block: B:16:0x003c  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void m() {
        boolean zH = AbstractC1050g0.H(3);
        G g6 = this.f11684c;
        if (zH) {
            Log.d("FragmentManager", "moveto RESUMED: " + g6);
        }
        View focusedView = g6.getFocusedView();
        if (focusedView != null) {
            if (focusedView == g6.mView) {
                boolean zRequestFocus = focusedView.requestFocus();
                if (AbstractC1050g0.H(2)) {
                    StringBuilder sb = new StringBuilder("requestFocus: Restoring focused view ");
                    sb.append(focusedView);
                    sb.append(" ");
                    sb.append(zRequestFocus ? "succeeded" : "failed");
                    sb.append(" on Fragment ");
                    sb.append(g6);
                    sb.append(" resulting in focused view ");
                    sb.append(g6.mView.findFocus());
                    Log.v("FragmentManager", sb.toString());
                }
            } else {
                for (ViewParent parent = focusedView.getParent(); parent != null; parent = parent.getParent()) {
                    if (parent == g6.mView) {
                        boolean zRequestFocus2 = focusedView.requestFocus();
                        if (AbstractC1050g0.H(2)) {
                        }
                    }
                }
            }
        }
        g6.setFocusedView(null);
        g6.performResume();
        this.f11682a.i(false);
        this.f11683b.i(null, g6.mWho);
        g6.mSavedFragmentState = null;
        g6.mSavedViewState = null;
        g6.mSavedViewRegistryState = null;
    }

    public final Bundle n() {
        Bundle bundle;
        Bundle bundle2 = new Bundle();
        G g6 = this.f11684c;
        if (g6.mState == -1 && (bundle = g6.mSavedFragmentState) != null) {
            bundle2.putAll(bundle);
        }
        bundle2.putParcelable("state", new m0(g6));
        if (g6.mState > -1) {
            Bundle bundle3 = new Bundle();
            g6.performSaveInstanceState(bundle3);
            if (!bundle3.isEmpty()) {
                bundle2.putBundle("savedInstanceState", bundle3);
            }
            this.f11682a.j(false);
            Bundle bundle4 = new Bundle();
            g6.mSavedStateRegistryController.c(bundle4);
            if (!bundle4.isEmpty()) {
                bundle2.putBundle("registryState", bundle4);
            }
            Bundle bundleT = g6.mChildFragmentManager.T();
            if (!bundleT.isEmpty()) {
                bundle2.putBundle("childFragmentManager", bundleT);
            }
            if (g6.mView != null) {
                o();
            }
            SparseArray<Parcelable> sparseArray = g6.mSavedViewState;
            if (sparseArray != null) {
                bundle2.putSparseParcelableArray("viewState", sparseArray);
            }
            Bundle bundle5 = g6.mSavedViewRegistryState;
            if (bundle5 != null) {
                bundle2.putBundle("viewRegistryState", bundle5);
            }
        }
        Bundle bundle6 = g6.mArguments;
        if (bundle6 != null) {
            bundle2.putBundle("arguments", bundle6);
        }
        return bundle2;
    }

    public final void o() {
        G g6 = this.f11684c;
        if (g6.mView == null) {
            return;
        }
        if (AbstractC1050g0.H(2)) {
            Log.v("FragmentManager", "Saving view state for fragment " + g6 + " with view " + g6.mView);
        }
        SparseArray<Parcelable> sparseArray = new SparseArray<>();
        g6.mView.saveHierarchyState(sparseArray);
        if (sparseArray.size() > 0) {
            g6.mSavedViewState = sparseArray;
        }
        Bundle bundle = new Bundle();
        g6.mViewLifecycleOwner.f11481f.c(bundle);
        if (bundle.isEmpty()) {
            return;
        }
        g6.mSavedViewRegistryState = bundle;
    }

    public o0(M m6, p0 p0Var, ClassLoader classLoader, Z z6, Bundle bundle) {
        this.f11682a = m6;
        this.f11683b = p0Var;
        m0 m0Var = (m0) bundle.getParcelable("state");
        G gInstantiate = G.instantiate(z6.f11554a.f11623u.f11540b, m0Var.f11659a, null);
        gInstantiate.mWho = m0Var.f11660b;
        gInstantiate.mFromLayout = m0Var.f11661c;
        gInstantiate.mRestored = true;
        gInstantiate.mFragmentId = m0Var.f11662d;
        gInstantiate.mContainerId = m0Var.f11663e;
        gInstantiate.mTag = m0Var.f11664f;
        gInstantiate.mRetainInstance = m0Var.f11665j;
        gInstantiate.mRemoving = m0Var.f11666k;
        gInstantiate.mDetached = m0Var.l;
        gInstantiate.mHidden = m0Var.f11667m;
        gInstantiate.mMaxState = EnumC1108q.values()[m0Var.f11668n];
        gInstantiate.mTargetWho = m0Var.f11669o;
        gInstantiate.mTargetRequestCode = m0Var.f11670p;
        gInstantiate.mUserVisibleHint = m0Var.f11671q;
        this.f11684c = gInstantiate;
        gInstantiate.mSavedFragmentState = bundle;
        Bundle bundle2 = bundle.getBundle("arguments");
        if (bundle2 != null) {
            bundle2.setClassLoader(classLoader);
        }
        gInstantiate.setArguments(bundle2);
        if (AbstractC1050g0.H(2)) {
            Log.v("FragmentManager", "Instantiated fragment " + gInstantiate);
        }
    }

    public o0(M m6, p0 p0Var, G g6, Bundle bundle) {
        this.f11682a = m6;
        this.f11683b = p0Var;
        this.f11684c = g6;
        g6.mSavedViewState = null;
        g6.mSavedViewRegistryState = null;
        g6.mBackStackNesting = 0;
        g6.mInLayout = false;
        g6.mAdded = false;
        G g7 = g6.mTarget;
        g6.mTargetWho = g7 != null ? g7.mWho : null;
        g6.mTarget = null;
        g6.mSavedFragmentState = bundle;
        g6.mArguments = bundle.getBundle("arguments");
    }
}
