package androidx.fragment.app;

import com.google.android.gms.common.ConnectionResult;
import java.io.PrintWriter;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Objects;
import o.AbstractC1843mC;
import o.AbstractC2033oC;
import o.C1938nC;
import o.InterfaceC1080eC;
import o.KM;
import o.WB;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public final class a extends AbstractC2033oC implements InterfaceC1080eC {
    public final s p;
    public boolean q;
    public int r;

    public a(s sVar) {
        sVar.D();
        WB wb = sVar.t;
        if (wb != null) {
            wb.m.getClassLoader();
        }
        this.a = new ArrayList();
        this.f660o = false;
        this.r = -1;
        this.p = sVar;
    }

    @Override // o.InterfaceC1080eC
    public final boolean a(ArrayList arrayList, ArrayList arrayList2) {
        if (s.F(2)) {
            toString();
        }
        arrayList.add(this);
        arrayList2.add(Boolean.FALSE);
        if (!this.g) {
            return true;
        }
        s sVar = this.p;
        if (sVar.d == null) {
            sVar.d = new ArrayList();
        }
        sVar.d.add(this);
        return true;
    }

    @Override // o.AbstractC2033oC
    public final void c(int i, l lVar, String str, int i2) {
        String str2 = lVar.mPreviousWho;
        if (str2 != null) {
            AbstractC1843mC.c(lVar, str2);
        }
        Class<?> cls = lVar.getClass();
        int modifiers = cls.getModifiers();
        if (cls.isAnonymousClass() || !Modifier.isPublic(modifiers) || (cls.isMemberClass() && !Modifier.isStatic(modifiers))) {
            throw new IllegalStateException("Fragment " + cls.getCanonicalName() + " must be a public static class to be  properly recreated from instance state.");
        }
        if (str != null) {
            String str3 = lVar.mTag;
            if (str3 != null && !str.equals(str3)) {
                throw new IllegalStateException("Can't change tag of fragment " + lVar + ": was " + lVar.mTag + " now " + str);
            }
            lVar.mTag = str;
        }
        if (i != 0) {
            if (i == -1) {
                throw new IllegalArgumentException("Can't add fragment " + lVar + " with tag " + str + " to container view with no id");
            }
            int i3 = lVar.mFragmentId;
            if (i3 != 0 && i3 != i) {
                throw new IllegalStateException("Can't change container ID of fragment " + lVar + ": was " + lVar.mFragmentId + " now " + i);
            }
            lVar.mFragmentId = i;
            lVar.mContainerId = i;
        }
        b(new C1938nC(lVar, i2));
        lVar.mFragmentManager = this.p;
    }

    public final void d(int i) {
        ArrayList arrayList = this.a;
        if (this.g) {
            if (s.F(2)) {
                toString();
            }
            int size = arrayList.size();
            for (int i2 = 0; i2 < size; i2++) {
                C1938nC c1938nC = (C1938nC) arrayList.get(i2);
                l lVar = c1938nC.b;
                if (lVar != null) {
                    lVar.mBackStackNesting += i;
                    if (s.F(2)) {
                        Objects.toString(c1938nC.b);
                        int i3 = c1938nC.b.mBackStackNesting;
                    }
                }
            }
        }
    }

    public final int e(boolean z) {
        if (this.q) {
            throw new IllegalStateException("commit already called");
        }
        if (s.F(2)) {
            toString();
            PrintWriter printWriter = new PrintWriter(new KM());
            f("  ", printWriter, true);
            printWriter.close();
        }
        this.q = true;
        boolean z2 = this.g;
        s sVar = this.p;
        if (z2) {
            this.r = sVar.i.getAndIncrement();
        } else {
            this.r = -1;
        }
        sVar.v(this, z);
        return this.r;
    }

    public final void f(String str, PrintWriter printWriter, boolean z) {
        String str2;
        ArrayList arrayList = this.a;
        if (z) {
            printWriter.print(str);
            printWriter.print("mName=");
            printWriter.print(this.h);
            printWriter.print(" mIndex=");
            printWriter.print(this.r);
            printWriter.print(" mCommitted=");
            printWriter.println(this.q);
            if (this.f != 0) {
                printWriter.print(str);
                printWriter.print("mTransition=#");
                printWriter.print(Integer.toHexString(this.f));
            }
            if (this.b != 0 || this.c != 0) {
                printWriter.print(str);
                printWriter.print("mEnterAnim=#");
                printWriter.print(Integer.toHexString(this.b));
                printWriter.print(" mExitAnim=#");
                printWriter.println(Integer.toHexString(this.c));
            }
            if (this.d != 0 || this.e != 0) {
                printWriter.print(str);
                printWriter.print("mPopEnterAnim=#");
                printWriter.print(Integer.toHexString(this.d));
                printWriter.print(" mPopExitAnim=#");
                printWriter.println(Integer.toHexString(this.e));
            }
            if (this.i != 0 || this.j != null) {
                printWriter.print(str);
                printWriter.print("mBreadCrumbTitleRes=#");
                printWriter.print(Integer.toHexString(this.i));
                printWriter.print(" mBreadCrumbTitleText=");
                printWriter.println(this.j);
            }
            if (this.k != 0 || this.l != null) {
                printWriter.print(str);
                printWriter.print("mBreadCrumbShortTitleRes=#");
                printWriter.print(Integer.toHexString(this.k));
                printWriter.print(" mBreadCrumbShortTitleText=");
                printWriter.println(this.l);
            }
        }
        if (arrayList.isEmpty()) {
            return;
        }
        printWriter.print(str);
        printWriter.println("Operations:");
        int size = arrayList.size();
        for (int i = 0; i < size; i++) {
            C1938nC c1938nC = (C1938nC) arrayList.get(i);
            switch (c1938nC.a) {
                case 0:
                    str2 = "NULL";
                    break;
                case 1:
                    str2 = "ADD";
                    break;
                case 2:
                    str2 = "REPLACE";
                    break;
                case 3:
                    str2 = "REMOVE";
                    break;
                case 4:
                    str2 = "HIDE";
                    break;
                case 5:
                    str2 = "SHOW";
                    break;
                case 6:
                    str2 = "DETACH";
                    break;
                case 7:
                    str2 = "ATTACH";
                    break;
                case 8:
                    str2 = "SET_PRIMARY_NAV";
                    break;
                case ConnectionResult.SERVICE_INVALID /* 9 */:
                    str2 = "UNSET_PRIMARY_NAV";
                    break;
                case 10:
                    str2 = "OP_SET_MAX_LIFECYCLE";
                    break;
                default:
                    str2 = "cmd=" + c1938nC.a;
                    break;
            }
            printWriter.print(str);
            printWriter.print("  Op #");
            printWriter.print(i);
            printWriter.print(": ");
            printWriter.print(str2);
            printWriter.print(" ");
            printWriter.println(c1938nC.b);
            if (z) {
                if (c1938nC.d != 0 || c1938nC.e != 0) {
                    printWriter.print(str);
                    printWriter.print("enterAnim=#");
                    printWriter.print(Integer.toHexString(c1938nC.d));
                    printWriter.print(" exitAnim=#");
                    printWriter.println(Integer.toHexString(c1938nC.e));
                }
                if (c1938nC.f != 0 || c1938nC.g != 0) {
                    printWriter.print(str);
                    printWriter.print("popEnterAnim=#");
                    printWriter.print(Integer.toHexString(c1938nC.f));
                    printWriter.print(" popExitAnim=#");
                    printWriter.println(Integer.toHexString(c1938nC.g));
                }
            }
        }
    }

    public final String toString() {
        StringBuilder sb = new StringBuilder(128);
        sb.append("BackStackEntry{");
        sb.append(Integer.toHexString(System.identityHashCode(this)));
        if (this.r >= 0) {
            sb.append(" #");
            sb.append(this.r);
        }
        if (this.h != null) {
            sb.append(" ");
            sb.append(this.h);
        }
        sb.append("}");
        return sb.toString();
    }
}
