package androidx.fragment.app;

import android.util.Log;
import androidx.fragment.app.k0;
import androidx.fragment.app.z;
import androidx.lifecycle.n;
import java.io.PrintWriter;
import java.util.ArrayList;

/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes.dex */
public final class a extends k0 implements z.o {

    /* renamed from: t, reason: collision with root package name */
    final z f4402t;

    /* renamed from: u, reason: collision with root package name */
    boolean f4403u;

    /* renamed from: v, reason: collision with root package name */
    int f4404v;

    /* renamed from: w, reason: collision with root package name */
    boolean f4405w;

    /* JADX INFO: Access modifiers changed from: package-private */
    public a(z zVar) {
        super(zVar.x0(), zVar.A0() != null ? zVar.A0().f().getClassLoader() : null);
        this.f4404v = -1;
        this.f4405w = false;
        this.f4402t = zVar;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void A() {
        int size = this.f4568c.size() - 1;
        while (size >= 0) {
            k0.a aVar = (k0.a) this.f4568c.get(size);
            if (aVar.f4587c) {
                if (aVar.f4585a == 8) {
                    aVar.f4587c = false;
                    this.f4568c.remove(size - 1);
                    size--;
                } else {
                    int i10 = aVar.f4586b.mContainerId;
                    aVar.f4585a = 2;
                    aVar.f4587c = false;
                    for (int i11 = size - 1; i11 >= 0; i11--) {
                        k0.a aVar2 = (k0.a) this.f4568c.get(i11);
                        if (aVar2.f4587c && aVar2.f4586b.mContainerId == i10) {
                            this.f4568c.remove(i11);
                            size--;
                        }
                    }
                }
            }
            size--;
        }
    }

    int B(boolean z10) {
        if (this.f4403u) {
            throw new IllegalStateException("commit already called");
        }
        if (z.N0(2)) {
            Log.v("FragmentManager", "Commit: " + this);
            PrintWriter printWriter = new PrintWriter(new q0("FragmentManager"));
            C("  ", printWriter);
            printWriter.close();
        }
        this.f4403u = true;
        if (this.f4574i) {
            this.f4404v = this.f4402t.m();
        } else {
            this.f4404v = -1;
        }
        this.f4402t.b0(this, z10);
        return this.f4404v;
    }

    public void C(String str, PrintWriter printWriter) {
        D(str, printWriter, true);
    }

    public void D(String str, PrintWriter printWriter, boolean z10) {
        String str2;
        if (z10) {
            printWriter.print(str);
            printWriter.print("mName=");
            printWriter.print(this.f4576k);
            printWriter.print(" mIndex=");
            printWriter.print(this.f4404v);
            printWriter.print(" mCommitted=");
            printWriter.println(this.f4403u);
            if (this.f4573h != 0) {
                printWriter.print(str);
                printWriter.print("mTransition=#");
                printWriter.print(Integer.toHexString(this.f4573h));
            }
            if (this.f4569d != 0 || this.f4570e != 0) {
                printWriter.print(str);
                printWriter.print("mEnterAnim=#");
                printWriter.print(Integer.toHexString(this.f4569d));
                printWriter.print(" mExitAnim=#");
                printWriter.println(Integer.toHexString(this.f4570e));
            }
            if (this.f4571f != 0 || this.f4572g != 0) {
                printWriter.print(str);
                printWriter.print("mPopEnterAnim=#");
                printWriter.print(Integer.toHexString(this.f4571f));
                printWriter.print(" mPopExitAnim=#");
                printWriter.println(Integer.toHexString(this.f4572g));
            }
            if (this.f4577l != 0 || this.f4578m != null) {
                printWriter.print(str);
                printWriter.print("mBreadCrumbTitleRes=#");
                printWriter.print(Integer.toHexString(this.f4577l));
                printWriter.print(" mBreadCrumbTitleText=");
                printWriter.println(this.f4578m);
            }
            if (this.f4579n != 0 || this.f4580o != null) {
                printWriter.print(str);
                printWriter.print("mBreadCrumbShortTitleRes=#");
                printWriter.print(Integer.toHexString(this.f4579n));
                printWriter.print(" mBreadCrumbShortTitleText=");
                printWriter.println(this.f4580o);
            }
        }
        if (this.f4568c.isEmpty()) {
            return;
        }
        printWriter.print(str);
        printWriter.println("Operations:");
        int size = this.f4568c.size();
        for (int i10 = 0; i10 < size; i10++) {
            k0.a aVar = (k0.a) this.f4568c.get(i10);
            switch (aVar.f4585a) {
                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 9:
                    str2 = "UNSET_PRIMARY_NAV";
                    break;
                case 10:
                    str2 = "OP_SET_MAX_LIFECYCLE";
                    break;
                default:
                    str2 = "cmd=" + aVar.f4585a;
                    break;
            }
            printWriter.print(str);
            printWriter.print("  Op #");
            printWriter.print(i10);
            printWriter.print(": ");
            printWriter.print(str2);
            printWriter.print(" ");
            printWriter.println(aVar.f4586b);
            if (z10) {
                if (aVar.f4588d != 0 || aVar.f4589e != 0) {
                    printWriter.print(str);
                    printWriter.print("enterAnim=#");
                    printWriter.print(Integer.toHexString(aVar.f4588d));
                    printWriter.print(" exitAnim=#");
                    printWriter.println(Integer.toHexString(aVar.f4589e));
                }
                if (aVar.f4590f != 0 || aVar.f4591g != 0) {
                    printWriter.print(str);
                    printWriter.print("popEnterAnim=#");
                    printWriter.print(Integer.toHexString(aVar.f4590f));
                    printWriter.print(" popExitAnim=#");
                    printWriter.println(Integer.toHexString(aVar.f4591g));
                }
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void E() {
        int size = this.f4568c.size();
        for (int i10 = 0; i10 < size; i10++) {
            k0.a aVar = (k0.a) this.f4568c.get(i10);
            f fVar = aVar.f4586b;
            if (fVar != null) {
                fVar.mBeingSaved = this.f4405w;
                fVar.setPopDirection(false);
                fVar.setNextTransition(this.f4573h);
                fVar.setSharedElementNames(this.f4581p, this.f4582q);
            }
            switch (aVar.f4585a) {
                case 1:
                    fVar.setAnimations(aVar.f4588d, aVar.f4589e, aVar.f4590f, aVar.f4591g);
                    this.f4402t.C1(fVar, false);
                    this.f4402t.j(fVar);
                    break;
                case 2:
                default:
                    throw new IllegalArgumentException("Unknown cmd: " + aVar.f4585a);
                case 3:
                    fVar.setAnimations(aVar.f4588d, aVar.f4589e, aVar.f4590f, aVar.f4591g);
                    this.f4402t.p1(fVar);
                    break;
                case 4:
                    fVar.setAnimations(aVar.f4588d, aVar.f4589e, aVar.f4590f, aVar.f4591g);
                    this.f4402t.K0(fVar);
                    break;
                case 5:
                    fVar.setAnimations(aVar.f4588d, aVar.f4589e, aVar.f4590f, aVar.f4591g);
                    this.f4402t.C1(fVar, false);
                    this.f4402t.I1(fVar);
                    break;
                case 6:
                    fVar.setAnimations(aVar.f4588d, aVar.f4589e, aVar.f4590f, aVar.f4591g);
                    this.f4402t.z(fVar);
                    break;
                case 7:
                    fVar.setAnimations(aVar.f4588d, aVar.f4589e, aVar.f4590f, aVar.f4591g);
                    this.f4402t.C1(fVar, false);
                    this.f4402t.o(fVar);
                    break;
                case 8:
                    this.f4402t.G1(fVar);
                    break;
                case 9:
                    this.f4402t.G1(null);
                    break;
                case 10:
                    this.f4402t.F1(fVar, aVar.f4593i);
                    break;
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void F() {
        for (int size = this.f4568c.size() - 1; size >= 0; size--) {
            k0.a aVar = (k0.a) this.f4568c.get(size);
            f fVar = aVar.f4586b;
            if (fVar != null) {
                fVar.mBeingSaved = this.f4405w;
                fVar.setPopDirection(true);
                fVar.setNextTransition(z.w1(this.f4573h));
                fVar.setSharedElementNames(this.f4582q, this.f4581p);
            }
            switch (aVar.f4585a) {
                case 1:
                    fVar.setAnimations(aVar.f4588d, aVar.f4589e, aVar.f4590f, aVar.f4591g);
                    this.f4402t.C1(fVar, true);
                    this.f4402t.p1(fVar);
                    break;
                case 2:
                default:
                    throw new IllegalArgumentException("Unknown cmd: " + aVar.f4585a);
                case 3:
                    fVar.setAnimations(aVar.f4588d, aVar.f4589e, aVar.f4590f, aVar.f4591g);
                    this.f4402t.j(fVar);
                    break;
                case 4:
                    fVar.setAnimations(aVar.f4588d, aVar.f4589e, aVar.f4590f, aVar.f4591g);
                    this.f4402t.I1(fVar);
                    break;
                case 5:
                    fVar.setAnimations(aVar.f4588d, aVar.f4589e, aVar.f4590f, aVar.f4591g);
                    this.f4402t.C1(fVar, true);
                    this.f4402t.K0(fVar);
                    break;
                case 6:
                    fVar.setAnimations(aVar.f4588d, aVar.f4589e, aVar.f4590f, aVar.f4591g);
                    this.f4402t.o(fVar);
                    break;
                case 7:
                    fVar.setAnimations(aVar.f4588d, aVar.f4589e, aVar.f4590f, aVar.f4591g);
                    this.f4402t.C1(fVar, true);
                    this.f4402t.z(fVar);
                    break;
                case 8:
                    this.f4402t.G1(null);
                    break;
                case 9:
                    this.f4402t.G1(fVar);
                    break;
                case 10:
                    this.f4402t.F1(fVar, aVar.f4592h);
                    break;
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public f G(ArrayList arrayList, f fVar) {
        f fVar2 = fVar;
        int i10 = 0;
        while (i10 < this.f4568c.size()) {
            k0.a aVar = (k0.a) this.f4568c.get(i10);
            int i11 = aVar.f4585a;
            if (i11 != 1) {
                if (i11 == 2) {
                    f fVar3 = aVar.f4586b;
                    int i12 = fVar3.mContainerId;
                    boolean z10 = false;
                    for (int size = arrayList.size() - 1; size >= 0; size--) {
                        f fVar4 = (f) arrayList.get(size);
                        if (fVar4.mContainerId == i12) {
                            if (fVar4 == fVar3) {
                                z10 = true;
                            } else {
                                if (fVar4 == fVar2) {
                                    this.f4568c.add(i10, new k0.a(9, fVar4, true));
                                    i10++;
                                    fVar2 = null;
                                }
                                k0.a aVar2 = new k0.a(3, fVar4, true);
                                aVar2.f4588d = aVar.f4588d;
                                aVar2.f4590f = aVar.f4590f;
                                aVar2.f4589e = aVar.f4589e;
                                aVar2.f4591g = aVar.f4591g;
                                this.f4568c.add(i10, aVar2);
                                arrayList.remove(fVar4);
                                i10++;
                            }
                        }
                    }
                    if (z10) {
                        this.f4568c.remove(i10);
                        i10--;
                    } else {
                        aVar.f4585a = 1;
                        aVar.f4587c = true;
                        arrayList.add(fVar3);
                    }
                } else if (i11 == 3 || i11 == 6) {
                    arrayList.remove(aVar.f4586b);
                    f fVar5 = aVar.f4586b;
                    if (fVar5 == fVar2) {
                        this.f4568c.add(i10, new k0.a(9, fVar5));
                        i10++;
                        fVar2 = null;
                    }
                } else if (i11 != 7) {
                    if (i11 == 8) {
                        this.f4568c.add(i10, new k0.a(9, fVar2, true));
                        aVar.f4587c = true;
                        i10++;
                        fVar2 = aVar.f4586b;
                    }
                }
                i10++;
            }
            arrayList.add(aVar.f4586b);
            i10++;
        }
        return fVar2;
    }

    public String H() {
        return this.f4576k;
    }

    public void I() {
        if (this.f4584s != null) {
            for (int i10 = 0; i10 < this.f4584s.size(); i10++) {
                ((Runnable) this.f4584s.get(i10)).run();
            }
            this.f4584s = null;
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public f J(ArrayList arrayList, f fVar) {
        for (int size = this.f4568c.size() - 1; size >= 0; size--) {
            k0.a aVar = (k0.a) this.f4568c.get(size);
            int i10 = aVar.f4585a;
            if (i10 != 1) {
                if (i10 != 3) {
                    switch (i10) {
                        case 8:
                            fVar = null;
                            break;
                        case 9:
                            fVar = aVar.f4586b;
                            break;
                        case 10:
                            aVar.f4593i = aVar.f4592h;
                            break;
                    }
                }
                arrayList.add(aVar.f4586b);
            }
            arrayList.remove(aVar.f4586b);
        }
        return fVar;
    }

    @Override // androidx.fragment.app.z.o
    public boolean a(ArrayList arrayList, ArrayList arrayList2) {
        if (z.N0(2)) {
            Log.v("FragmentManager", "Run: " + this);
        }
        arrayList.add(this);
        arrayList2.add(Boolean.FALSE);
        if (!this.f4574i) {
            return true;
        }
        this.f4402t.i(this);
        return true;
    }

    @Override // androidx.fragment.app.k0
    public int i() {
        return B(false);
    }

    @Override // androidx.fragment.app.k0
    public int j() {
        return B(true);
    }

    @Override // androidx.fragment.app.k0
    public void k() {
        n();
        this.f4402t.e0(this, false);
    }

    @Override // androidx.fragment.app.k0
    public void l() {
        n();
        this.f4402t.e0(this, true);
    }

    @Override // androidx.fragment.app.k0
    public k0 m(f fVar) {
        z zVar = fVar.mFragmentManager;
        if (zVar == null || zVar == this.f4402t) {
            return super.m(fVar);
        }
        throw new IllegalStateException("Cannot detach Fragment attached to a different FragmentManager. Fragment " + fVar.toString() + " is already attached to a FragmentManager.");
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    @Override // androidx.fragment.app.k0
    public void o(int i10, f fVar, String str, int i11) {
        super.o(i10, fVar, str, i11);
        fVar.mFragmentManager = this.f4402t;
    }

    @Override // androidx.fragment.app.k0
    public k0 p(f fVar) {
        z zVar = fVar.mFragmentManager;
        if (zVar == null || zVar == this.f4402t) {
            return super.p(fVar);
        }
        throw new IllegalStateException("Cannot hide Fragment attached to a different FragmentManager. Fragment " + fVar.toString() + " is already attached to a FragmentManager.");
    }

    @Override // androidx.fragment.app.k0
    public boolean q() {
        return this.f4568c.isEmpty();
    }

    @Override // androidx.fragment.app.k0
    public k0 r(f fVar) {
        z zVar = fVar.mFragmentManager;
        if (zVar == null || zVar == this.f4402t) {
            return super.r(fVar);
        }
        throw new IllegalStateException("Cannot remove Fragment attached to a different FragmentManager. Fragment " + fVar.toString() + " is already attached to a FragmentManager.");
    }

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

    @Override // androidx.fragment.app.k0
    public k0 v(f fVar, n.b bVar) {
        if (fVar.mFragmentManager != this.f4402t) {
            throw new IllegalArgumentException("Cannot setMaxLifecycle for Fragment not attached to FragmentManager " + this.f4402t);
        }
        if (bVar == n.b.INITIALIZED && fVar.mState > -1) {
            throw new IllegalArgumentException("Cannot set maximum Lifecycle to " + bVar + " after the Fragment has been created");
        }
        if (bVar != n.b.DESTROYED) {
            return super.v(fVar, bVar);
        }
        throw new IllegalArgumentException("Cannot set maximum Lifecycle to " + bVar + ". Use remove() to remove the fragment from the FragmentManager and trigger its destruction.");
    }

    @Override // androidx.fragment.app.k0
    public k0 w(f fVar) {
        z zVar;
        if (fVar == null || (zVar = fVar.mFragmentManager) == null || zVar == this.f4402t) {
            return super.w(fVar);
        }
        throw new IllegalStateException("Cannot setPrimaryNavigation for Fragment attached to a different FragmentManager. Fragment " + fVar.toString() + " is already attached to a FragmentManager.");
    }

    @Override // androidx.fragment.app.k0
    public k0 y(f fVar) {
        z zVar = fVar.mFragmentManager;
        if (zVar == null || zVar == this.f4402t) {
            return super.y(fVar);
        }
        throw new IllegalStateException("Cannot show Fragment attached to a different FragmentManager. Fragment " + fVar.toString() + " is already attached to a FragmentManager.");
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void z(int i10) {
        if (this.f4574i) {
            if (z.N0(2)) {
                Log.v("FragmentManager", "Bump nesting in " + this + " by " + i10);
            }
            int size = this.f4568c.size();
            for (int i11 = 0; i11 < size; i11++) {
                k0.a aVar = (k0.a) this.f4568c.get(i11);
                f fVar = aVar.f4586b;
                if (fVar != null) {
                    fVar.mBackStackNesting += i10;
                    if (z.N0(2)) {
                        Log.v("FragmentManager", "Bump nesting of " + aVar.f4586b + " to " + aVar.f4586b.mBackStackNesting);
                    }
                }
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public a(a aVar) {
        super(aVar.f4402t.x0(), aVar.f4402t.A0() != null ? aVar.f4402t.A0().f().getClassLoader() : null, aVar);
        this.f4404v = -1;
        this.f4405w = false;
        this.f4402t = aVar.f4402t;
        this.f4403u = aVar.f4403u;
        this.f4404v = aVar.f4404v;
        this.f4405w = aVar.f4405w;
    }
}
