package androidx.fragment.app;

import android.content.res.Resources;
import android.os.BadParcelableException;
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 androidx.lifecycle.EnumC0308o;
import com.riyaz.zvytour.R;
import g0.C0611a;
import java.lang.reflect.Field;
import java.util.ArrayList;
import p0.AbstractC0928a;

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

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

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

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

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

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

    public p0(O o5, q0 q0Var, I i) {
        this.f4349a = o5;
        this.f4350b = q0Var;
        this.f4351c = i;
    }

    public final void a() {
        boolean zJ = h0.J(3);
        I i = this.f4351c;
        if (zJ) {
            Log.d("FragmentManager", "moveto ACTIVITY_CREATED: " + i);
        }
        Bundle bundle = i.mSavedFragmentState;
        i.performActivityCreated(bundle != null ? bundle.getBundle("savedInstanceState") : null);
        this.f4349a.a(i, false);
    }

    public final void b() {
        I i;
        View view;
        View view2;
        int iIndexOfChild = -1;
        I i5 = this.f4351c;
        View view3 = i5.mContainer;
        while (true) {
            i = null;
            if (view3 == null) {
                break;
            }
            Object tag = view3.getTag(R.id.fragment_container_view_tag);
            I i6 = tag instanceof I ? (I) tag : null;
            if (i6 != null) {
                i = i6;
                break;
            } else {
                Object parent = view3.getParent();
                view3 = parent instanceof View ? (View) parent : null;
            }
        }
        I parentFragment = i5.getParentFragment();
        if (i != null && !i.equals(parentFragment)) {
            int i7 = i5.mContainerId;
            g0.c cVar = g0.d.f6417a;
            StringBuilder sb = new StringBuilder("Attempting to nest fragment ");
            sb.append(i5);
            sb.append(" within the view of parent fragment ");
            sb.append(i);
            sb.append(" via container with ID ");
            g0.d.b(new C0611a(i5, s0.c.d(sb, i7, " without using parent's childFragmentManager")));
            g0.d.a(i5).getClass();
        }
        q0 q0Var = this.f4350b;
        q0Var.getClass();
        ViewGroup viewGroup = i5.mContainer;
        if (viewGroup != null) {
            ArrayList arrayList = q0Var.f4359a;
            int iIndexOf = arrayList.indexOf(i5);
            int i8 = iIndexOf - 1;
            while (true) {
                if (i8 < 0) {
                    while (true) {
                        iIndexOf++;
                        if (iIndexOf >= arrayList.size()) {
                            break;
                        }
                        I i9 = (I) arrayList.get(iIndexOf);
                        if (i9.mContainer == viewGroup && (view = i9.mView) != null) {
                            iIndexOfChild = viewGroup.indexOfChild(view);
                            break;
                        }
                    }
                } else {
                    I i10 = (I) arrayList.get(i8);
                    if (i10.mContainer == viewGroup && (view2 = i10.mView) != null) {
                        iIndexOfChild = viewGroup.indexOfChild(view2) + 1;
                        break;
                    }
                    i8--;
                }
            }
        }
        i5.mContainer.addView(i5.mView, iIndexOfChild);
    }

    public final void c() {
        boolean zJ = h0.J(3);
        I i = this.f4351c;
        if (zJ) {
            Log.d("FragmentManager", "moveto ATTACHED: " + i);
        }
        I i5 = i.mTarget;
        p0 p0Var = null;
        q0 q0Var = this.f4350b;
        if (i5 != null) {
            p0 p0Var2 = (p0) q0Var.f4360b.get(i5.mWho);
            if (p0Var2 == null) {
                throw new IllegalStateException("Fragment " + i + " declared target fragment " + i.mTarget + " that does not belong to this FragmentManager!");
            }
            i.mTargetWho = i.mTarget.mWho;
            i.mTarget = null;
            p0Var = p0Var2;
        } else {
            String str = i.mTargetWho;
            if (str != null && (p0Var = (p0) q0Var.f4360b.get(str)) == null) {
                StringBuilder sb = new StringBuilder("Fragment ");
                sb.append(i);
                sb.append(" declared target fragment ");
                throw new IllegalStateException(s0.c.e(sb, i.mTargetWho, " that does not belong to this FragmentManager!"));
            }
        }
        if (p0Var != null) {
            p0Var.k();
        }
        h0 h0Var = i.mFragmentManager;
        i.mHost = h0Var.f4293v;
        i.mParentFragment = h0Var.f4295x;
        O o5 = this.f4349a;
        o5.g(i, false);
        i.performAttach();
        o5.b(i, false);
    }

    public final int d() {
        I i = this.f4351c;
        if (i.mFragmentManager == null) {
            return i.mState;
        }
        int iMin = this.f4353e;
        int iOrdinal = i.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 (i.mFromLayout) {
            if (i.mInLayout) {
                iMin = Math.max(this.f4353e, 2);
                View view = i.mView;
                if (view != null && view.getParent() == null) {
                    iMin = Math.min(iMin, 2);
                }
            } else {
                iMin = this.f4353e < 4 ? Math.min(iMin, i.mState) : Math.min(iMin, 1);
            }
        }
        if (!i.mAdded) {
            iMin = Math.min(iMin, 1);
        }
        ViewGroup viewGroup = i.mContainer;
        if (viewGroup != null) {
            C0285q c0285qJ = C0285q.j(viewGroup, i.getParentFragmentManager());
            c0285qJ.getClass();
            E0 e0G = c0285qJ.g(i);
            int i5 = e0G != null ? e0G.f4149b : 0;
            E0 e0H = c0285qJ.h(i);
            i = e0H != null ? e0H.f4149b : 0;
            int i6 = i5 == 0 ? -1 : F0.f4175a[u.e.c(i5)];
            if (i6 != -1 && i6 != 1) {
                i = i5;
            }
        }
        if (i == 2) {
            iMin = Math.min(iMin, 6);
        } else if (i == 3) {
            iMin = Math.max(iMin, 3);
        } else if (i.mRemoving) {
            iMin = i.isInBackStack() ? Math.min(iMin, 1) : Math.min(iMin, -1);
        }
        if (i.mDeferStart && i.mState < 5) {
            iMin = Math.min(iMin, 4);
        }
        if (i.mTransitioning && i.mContainer != null) {
            iMin = Math.max(iMin, 3);
        }
        if (h0.J(2)) {
            Log.v("FragmentManager", "computeExpectedState() of " + iMin + " for " + i);
        }
        return iMin;
    }

    public final void e() {
        boolean zJ = h0.J(3);
        I i = this.f4351c;
        if (zJ) {
            Log.d("FragmentManager", "moveto CREATED: " + i);
        }
        Bundle bundle = i.mSavedFragmentState;
        Bundle bundle2 = bundle != null ? bundle.getBundle("savedInstanceState") : null;
        if (i.mIsCreated) {
            i.mState = 1;
            i.restoreChildFragmentState();
        } else {
            O o5 = this.f4349a;
            o5.h(i, false);
            i.performCreate(bundle2);
            o5.c(i, false);
        }
    }

    public final void f() {
        String resourceName;
        I i = this.f4351c;
        if (i.mFromLayout) {
            return;
        }
        if (h0.J(3)) {
            Log.d("FragmentManager", "moveto CREATE_VIEW: " + i);
        }
        Bundle bundle = i.mSavedFragmentState;
        ViewGroup viewGroup = null;
        Bundle bundle2 = bundle != null ? bundle.getBundle("savedInstanceState") : null;
        LayoutInflater layoutInflaterPerformGetLayoutInflater = i.performGetLayoutInflater(bundle2);
        ViewGroup viewGroup2 = i.mContainer;
        if (viewGroup2 != null) {
            viewGroup = viewGroup2;
        } else {
            int i5 = i.mContainerId;
            if (i5 != 0) {
                if (i5 == -1) {
                    throw new IllegalArgumentException(AbstractC0928a.k("Cannot create fragment ", i, " for a container view with no id"));
                }
                viewGroup = (ViewGroup) i.mFragmentManager.f4294w.b(i5);
                if (viewGroup == null) {
                    if (!i.mRestored) {
                        try {
                            resourceName = i.getResources().getResourceName(i.mContainerId);
                        } catch (Resources.NotFoundException unused) {
                            resourceName = "unknown";
                        }
                        throw new IllegalArgumentException("No view found for id 0x" + Integer.toHexString(i.mContainerId) + " (" + resourceName + ") for fragment " + i);
                    }
                } else if (!(viewGroup instanceof FragmentContainerView)) {
                    g0.c cVar = g0.d.f6417a;
                    g0.d.b(new C0611a(i, "Attempting to add fragment " + i + " to container " + viewGroup + " which is not a FragmentContainerView"));
                    g0.d.a(i).getClass();
                }
            }
        }
        i.mContainer = viewGroup;
        i.performCreateView(layoutInflaterPerformGetLayoutInflater, viewGroup, bundle2);
        if (i.mView != null) {
            if (h0.J(3)) {
                Log.d("FragmentManager", "moveto VIEW_CREATED: " + i);
            }
            i.mView.setSaveFromParentEnabled(false);
            i.mView.setTag(R.id.fragment_container_view_tag, i);
            if (viewGroup != null) {
                b();
            }
            if (i.mHidden) {
                i.mView.setVisibility(8);
            }
            if (i.mView.isAttachedToWindow()) {
                View view = i.mView;
                Field field = P.Q.f2392a;
                P.G.c(view);
            } else {
                View view2 = i.mView;
                view2.addOnAttachStateChangeListener(new o0(view2));
            }
            i.performViewCreated();
            this.f4349a.m(i, i.mView, false);
            int visibility = i.mView.getVisibility();
            i.setPostOnViewCreatedAlpha(i.mView.getAlpha());
            if (i.mContainer != null && visibility == 0) {
                View viewFindFocus = i.mView.findFocus();
                if (viewFindFocus != null) {
                    i.setFocusedView(viewFindFocus);
                    if (h0.J(2)) {
                        Log.v("FragmentManager", "requestFocus: Saved focused view " + viewFindFocus + " for Fragment " + i);
                    }
                }
                i.mView.setAlpha(0.0f);
            }
        }
        i.mState = 2;
    }

    public final void g() {
        I iB;
        boolean zJ = h0.J(3);
        I i = this.f4351c;
        if (zJ) {
            Log.d("FragmentManager", "movefrom CREATED: " + i);
        }
        boolean zIsChangingConfigurations = true;
        boolean z5 = i.mRemoving && !i.isInBackStack();
        q0 q0Var = this.f4350b;
        if (z5 && !i.mBeingSaved) {
            q0Var.i(null, i.mWho);
        }
        if (!z5) {
            l0 l0Var = q0Var.f4362d;
            if (!((l0Var.f4311d.containsKey(i.mWho) && l0Var.f4314g) ? l0Var.f4315h : true)) {
                String str = i.mTargetWho;
                if (str != null && (iB = q0Var.b(str)) != null && iB.mRetainInstance) {
                    i.mTarget = iB;
                }
                i.mState = 0;
                return;
            }
        }
        T t4 = i.mHost;
        if (t4 instanceof androidx.lifecycle.d0) {
            zIsChangingConfigurations = q0Var.f4362d.f4315h;
        } else {
            N n5 = t4.f4196l;
            if (n5 != null) {
                zIsChangingConfigurations = true ^ n5.isChangingConfigurations();
            }
        }
        if ((z5 && !i.mBeingSaved) || zIsChangingConfigurations) {
            q0Var.f4362d.d(i, false);
        }
        i.performDestroy();
        this.f4349a.d(i, false);
        for (p0 p0Var : q0Var.d()) {
            if (p0Var != null) {
                String str2 = i.mWho;
                I i5 = p0Var.f4351c;
                if (str2.equals(i5.mTargetWho)) {
                    i5.mTarget = i;
                    i5.mTargetWho = null;
                }
            }
        }
        String str3 = i.mTargetWho;
        if (str3 != null) {
            i.mTarget = q0Var.b(str3);
        }
        q0Var.h(this);
    }

    public final void h() {
        View view;
        boolean zJ = h0.J(3);
        I i = this.f4351c;
        if (zJ) {
            Log.d("FragmentManager", "movefrom CREATE_VIEW: " + i);
        }
        ViewGroup viewGroup = i.mContainer;
        if (viewGroup != null && (view = i.mView) != null) {
            viewGroup.removeView(view);
        }
        i.performDestroyView();
        this.f4349a.n(i, false);
        i.mContainer = null;
        i.mView = null;
        i.mViewLifecycleOwner = null;
        i.mViewLifecycleOwnerLiveData.setValue(null);
        i.mInLayout = false;
    }

    public final void i() {
        boolean zJ = h0.J(3);
        I i = this.f4351c;
        if (zJ) {
            Log.d("FragmentManager", "movefrom ATTACHED: " + i);
        }
        i.performDetach();
        this.f4349a.e(i, false);
        i.mState = -1;
        i.mHost = null;
        i.mParentFragment = null;
        i.mFragmentManager = null;
        if (!i.mRemoving || i.isInBackStack()) {
            l0 l0Var = this.f4350b.f4362d;
            if (!((l0Var.f4311d.containsKey(i.mWho) && l0Var.f4314g) ? l0Var.f4315h : true)) {
                return;
            }
        }
        if (h0.J(3)) {
            Log.d("FragmentManager", "initState called for fragment: " + i);
        }
        i.initState();
    }

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

    /* JADX WARN: Code restructure failed: missing block: B:155:0x01b4, code lost:
    
        continue;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public final void k() {
        /*
            Method dump skipped, instruction units count: 678
            To view this dump change 'Code comments level' option to 'DEBUG'
        */
        throw new UnsupportedOperationException("Method not decompiled: androidx.fragment.app.p0.k():void");
    }

    public final void l(ClassLoader classLoader) {
        I i = this.f4351c;
        Bundle bundle = i.mSavedFragmentState;
        if (bundle == null) {
            return;
        }
        bundle.setClassLoader(classLoader);
        if (i.mSavedFragmentState.getBundle("savedInstanceState") == null) {
            i.mSavedFragmentState.putBundle("savedInstanceState", new Bundle());
        }
        try {
            i.mSavedViewState = i.mSavedFragmentState.getSparseParcelableArray("viewState");
            i.mSavedViewRegistryState = i.mSavedFragmentState.getBundle("viewRegistryState");
            n0 n0Var = (n0) i.mSavedFragmentState.getParcelable("state");
            if (n0Var != null) {
                i.mTargetWho = n0Var.f4340v;
                i.mTargetRequestCode = n0Var.f4341w;
                Boolean bool = i.mSavedUserVisibleHint;
                if (bool != null) {
                    i.mUserVisibleHint = bool.booleanValue();
                    i.mSavedUserVisibleHint = null;
                } else {
                    i.mUserVisibleHint = n0Var.f4342x;
                }
            }
            if (i.mUserVisibleHint) {
                return;
            }
            i.mDeferStart = true;
        } catch (BadParcelableException e2) {
            throw new IllegalStateException("Failed to restore view hierarchy state for fragment " + i, e2);
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:16:0x003c  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public final void m() {
        /*
            r6 = this;
            r0 = 3
            boolean r0 = androidx.fragment.app.h0.J(r0)
            java.lang.String r1 = "FragmentManager"
            androidx.fragment.app.I r2 = r6.f4351c
            if (r0 == 0) goto L1c
            java.lang.StringBuilder r0 = new java.lang.StringBuilder
            java.lang.String r3 = "moveto RESUMED: "
            r0.<init>(r3)
            r0.append(r2)
            java.lang.String r0 = r0.toString()
            android.util.Log.d(r1, r0)
        L1c:
            android.view.View r0 = r2.getFocusedView()
            if (r0 == 0) goto L78
            android.view.View r3 = r2.mView
            if (r0 != r3) goto L27
            goto L31
        L27:
            android.view.ViewParent r3 = r0.getParent()
        L2b:
            if (r3 == 0) goto L78
            android.view.View r4 = r2.mView
            if (r3 != r4) goto L73
        L31:
            boolean r3 = r0.requestFocus()
            r4 = 2
            boolean r4 = androidx.fragment.app.h0.J(r4)
            if (r4 == 0) goto L78
            java.lang.StringBuilder r4 = new java.lang.StringBuilder
            java.lang.String r5 = "requestFocus: Restoring focused view "
            r4.<init>(r5)
            r4.append(r0)
            java.lang.String r0 = " "
            r4.append(r0)
            if (r3 == 0) goto L50
            java.lang.String r0 = "succeeded"
            goto L52
        L50:
            java.lang.String r0 = "failed"
        L52:
            r4.append(r0)
            java.lang.String r0 = " on Fragment "
            r4.append(r0)
            r4.append(r2)
            java.lang.String r0 = " resulting in focused view "
            r4.append(r0)
            android.view.View r0 = r2.mView
            android.view.View r0 = r0.findFocus()
            r4.append(r0)
            java.lang.String r0 = r4.toString()
            android.util.Log.v(r1, r0)
            goto L78
        L73:
            android.view.ViewParent r3 = r3.getParent()
            goto L2b
        L78:
            r0 = 0
            r2.setFocusedView(r0)
            r2.performResume()
            androidx.fragment.app.O r1 = r6.f4349a
            r3 = 0
            r1.i(r2, r3)
            androidx.fragment.app.q0 r1 = r6.f4350b
            java.lang.String r3 = r2.mWho
            r1.i(r0, r3)
            r2.mSavedFragmentState = r0
            r2.mSavedViewState = r0
            r2.mSavedViewRegistryState = r0
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: androidx.fragment.app.p0.m():void");
    }

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

    public final void o() {
        I i = this.f4351c;
        if (i.mView == null) {
            return;
        }
        if (h0.J(2)) {
            Log.v("FragmentManager", "Saving view state for fragment " + i + " with view " + i.mView);
        }
        SparseArray<Parcelable> sparseArray = new SparseArray<>();
        i.mView.saveHierarchyState(sparseArray);
        if (sparseArray.size() > 0) {
            i.mSavedViewState = sparseArray;
        }
        Bundle bundle = new Bundle();
        i.mViewLifecycleOwner.f4131o.c(bundle);
        if (bundle.isEmpty()) {
            return;
        }
        i.mSavedViewRegistryState = bundle;
    }

    public p0(O o5, q0 q0Var, ClassLoader classLoader, C0263a0 c0263a0, Bundle bundle) {
        this.f4349a = o5;
        this.f4350b = q0Var;
        n0 n0Var = (n0) bundle.getParcelable("state");
        I iInstantiate = I.instantiate(c0263a0.f4224a.f4293v.f4196l, n0Var.f4331k, null);
        iInstantiate.mWho = n0Var.f4332l;
        iInstantiate.mFromLayout = n0Var.f4333m;
        iInstantiate.mRestored = true;
        iInstantiate.mFragmentId = n0Var.f4334n;
        iInstantiate.mContainerId = n0Var.f4335o;
        iInstantiate.mTag = n0Var.p;
        iInstantiate.mRetainInstance = n0Var.q;
        iInstantiate.mRemoving = n0Var.f4336r;
        iInstantiate.mDetached = n0Var.f4337s;
        iInstantiate.mHidden = n0Var.f4338t;
        iInstantiate.mMaxState = EnumC0308o.values()[n0Var.f4339u];
        iInstantiate.mTargetWho = n0Var.f4340v;
        iInstantiate.mTargetRequestCode = n0Var.f4341w;
        iInstantiate.mUserVisibleHint = n0Var.f4342x;
        this.f4351c = iInstantiate;
        iInstantiate.mSavedFragmentState = bundle;
        Bundle bundle2 = bundle.getBundle("arguments");
        if (bundle2 != null) {
            bundle2.setClassLoader(classLoader);
        }
        iInstantiate.setArguments(bundle2);
        if (h0.J(2)) {
            Log.v("FragmentManager", "Instantiated fragment " + iInstantiate);
        }
    }

    public p0(O o5, q0 q0Var, I i, Bundle bundle) {
        this.f4349a = o5;
        this.f4350b = q0Var;
        this.f4351c = i;
        i.mSavedViewState = null;
        i.mSavedViewRegistryState = null;
        i.mBackStackNesting = 0;
        i.mInLayout = false;
        i.mAdded = false;
        I i5 = i.mTarget;
        i.mTargetWho = i5 != null ? i5.mWho : null;
        i.mTarget = null;
        i.mSavedFragmentState = bundle;
        i.mArguments = bundle.getBundle("arguments");
    }
}
