package h0;

import android.os.Bundle;
import d5.AbstractC0844a;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import n4.u0;

/* JADX INFO: loaded from: classes.dex */
public final class O implements L {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final /* synthetic */ int f13050a;

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final /* synthetic */ P f13052c;

    public /* synthetic */ O(P p3, String str, int i) {
        this.f13050a = i;
        this.f13052c = p3;
        this.f13051b = str;
    }

    /* JADX WARN: Code restructure failed: missing block: B:116:0x0323, code lost:
    
        r5.add(r10);
     */
    /* JADX WARN: Removed duplicated region for block: B:37:0x00c0  */
    @Override // h0.L
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final boolean a(ArrayList arrayList, ArrayList arrayList2) throws Throwable {
        int i;
        ArrayList arrayList3;
        int i5;
        switch (this.f13050a) {
            case u0.f15495q /* 0 */:
                P p3 = this.f13052c;
                C1003c c1003c = (C1003c) p3.f13077l.remove(this.f13051b);
                if (c1003c == null) {
                    return false;
                }
                HashMap map = new HashMap();
                int size = arrayList.size();
                int i8 = 0;
                while (i8 < size) {
                    Object obj = arrayList.get(i8);
                    i8++;
                    C1001a c1001a = (C1001a) obj;
                    if (c1001a.f13163u) {
                        ArrayList arrayList4 = c1001a.f13144a;
                        int size2 = arrayList4.size();
                        int i9 = 0;
                        while (i9 < size2) {
                            Object obj2 = arrayList4.get(i9);
                            i9++;
                            ComponentCallbacksC1023x componentCallbacksC1023x = ((X) obj2).f13129b;
                            if (componentCallbacksC1023x != null) {
                                map.put(componentCallbacksC1023x.f13297u, componentCallbacksC1023x);
                            }
                        }
                    }
                }
                ArrayList arrayList5 = c1003c.f13190q;
                HashMap map2 = new HashMap(arrayList5.size());
                int size3 = arrayList5.size();
                int i10 = 0;
                while (i10 < size3) {
                    Object obj3 = arrayList5.get(i10);
                    i10++;
                    String str = (String) obj3;
                    ComponentCallbacksC1023x componentCallbacksC1023x2 = (ComponentCallbacksC1023x) map.get(str);
                    if (componentCallbacksC1023x2 != null) {
                        map2.put(componentCallbacksC1023x2.f13297u, componentCallbacksC1023x2);
                    } else {
                        Bundle bundleL = p3.f13069c.L(str, null);
                        if (bundleL != null) {
                            ClassLoader classLoader = p3.f13088w.f13306u.getClassLoader();
                            ComponentCallbacksC1023x componentCallbacksC1023xA = ((U) bundleL.getParcelable("state")).a(p3.I());
                            componentCallbacksC1023xA.f13294r = bundleL;
                            if (bundleL.getBundle("savedInstanceState") == null) {
                                componentCallbacksC1023xA.f13294r.putBundle("savedInstanceState", new Bundle());
                            }
                            Bundle bundle = bundleL.getBundle("arguments");
                            if (bundle != null) {
                                bundle.setClassLoader(classLoader);
                            }
                            componentCallbacksC1023xA.d0(bundle);
                            map2.put(componentCallbacksC1023xA.f13297u, componentCallbacksC1023xA);
                        }
                    }
                }
                ArrayList arrayList6 = new ArrayList();
                ArrayList arrayList7 = c1003c.f13191r;
                int size4 = arrayList7.size();
                int i11 = 0;
                while (i11 < size4) {
                    Object obj4 = arrayList7.get(i11);
                    i11++;
                    C1002b c1002b = (C1002b) obj4;
                    c1002b.getClass();
                    C1001a c1001a2 = new C1001a(p3);
                    c1002b.a(c1001a2);
                    int i12 = 0;
                    while (true) {
                        ArrayList arrayList8 = c1002b.f13170r;
                        if (i12 < arrayList8.size()) {
                            String str2 = (String) arrayList8.get(i12);
                            if (str2 != null) {
                                ComponentCallbacksC1023x componentCallbacksC1023x3 = (ComponentCallbacksC1023x) map2.get(str2);
                                if (componentCallbacksC1023x3 == null) {
                                    throw new IllegalStateException("Restoring FragmentTransaction " + c1002b.f13174v + " failed due to missing saved state for Fragment (" + str2 + ")");
                                }
                                ((X) c1001a2.f13144a.get(i12)).f13129b = componentCallbacksC1023x3;
                            }
                            i12++;
                        }
                    }
                }
                int size5 = arrayList6.size();
                int i13 = 0;
                boolean z8 = false;
                while (i13 < size5) {
                    Object obj5 = arrayList6.get(i13);
                    i13++;
                    ((C1001a) obj5).a(arrayList, arrayList2);
                    z8 = true;
                }
                return z8;
            default:
                P p4 = this.f13052c;
                String str3 = this.f13051b;
                int iB = p4.B(-1, str3, true);
                if (iB < 0) {
                    return false;
                }
                int i14 = iB;
                while (true) {
                    Throwable th = null;
                    if (i14 >= p4.f13070d.size()) {
                        HashSet hashSet = new HashSet();
                        int i15 = iB;
                        while (i15 < p4.f13070d.size()) {
                            C1001a c1001a3 = (C1001a) p4.f13070d.get(i15);
                            HashSet hashSet2 = new HashSet();
                            HashSet hashSet3 = new HashSet();
                            ArrayList arrayList9 = c1001a3.f13144a;
                            int size6 = arrayList9.size();
                            Throwable th2 = th;
                            int i16 = 0;
                            while (i16 < size6) {
                                Object obj6 = arrayList9.get(i16);
                                i16++;
                                X x8 = (X) obj6;
                                int i17 = size6;
                                ComponentCallbacksC1023x componentCallbacksC1023x4 = x8.f13129b;
                                if (componentCallbacksC1023x4 == null) {
                                    size6 = i17;
                                } else {
                                    int i18 = i15;
                                    if (x8.f13130c) {
                                        i = i16;
                                        int i19 = x8.f13128a;
                                        arrayList3 = arrayList9;
                                        if (i19 == 1 || i19 == 2 || i19 == 8) {
                                        }
                                        i5 = x8.f13128a;
                                        if (i5 != 1 || i5 == 2) {
                                            hashSet3.add(componentCallbacksC1023x4);
                                        }
                                        size6 = i17;
                                        i15 = i18;
                                        i16 = i;
                                        arrayList9 = arrayList3;
                                    } else {
                                        i = i16;
                                        arrayList3 = arrayList9;
                                    }
                                    hashSet.add(componentCallbacksC1023x4);
                                    hashSet2.add(componentCallbacksC1023x4);
                                    i5 = x8.f13128a;
                                    if (i5 != 1) {
                                        hashSet3.add(componentCallbacksC1023x4);
                                        size6 = i17;
                                        i15 = i18;
                                        i16 = i;
                                        arrayList9 = arrayList3;
                                    }
                                }
                            }
                            int i20 = i15;
                            hashSet2.removeAll(hashSet3);
                            if (!hashSet2.isEmpty()) {
                                StringBuilder sbP = AbstractC0844a.p("saveBackStack(\"", str3, "\") must be self contained and not reference fragments from non-saved FragmentTransactions. Found reference to fragment");
                                sbP.append(hashSet2.size() == 1 ? " " + hashSet2.iterator().next() : "s " + hashSet2);
                                sbP.append(" in ");
                                sbP.append(c1001a3);
                                sbP.append(" that were previously added to the FragmentManager through a separate FragmentTransaction.");
                                p4.h0(new IllegalArgumentException(sbP.toString()));
                                throw th2;
                            }
                            i15 = i20 + 1;
                            th = th2;
                        }
                        Throwable th3 = th;
                        ArrayDeque arrayDeque = new ArrayDeque(hashSet);
                        while (!arrayDeque.isEmpty()) {
                            ComponentCallbacksC1023x componentCallbacksC1023x5 = (ComponentCallbacksC1023x) arrayDeque.removeFirst();
                            if (componentCallbacksC1023x5.f13274T) {
                                StringBuilder sbP2 = AbstractC0844a.p("saveBackStack(\"", str3, "\") must not contain retained fragments. Found ");
                                sbP2.append(hashSet.contains(componentCallbacksC1023x5) ? "direct reference to retained " : "retained child ");
                                sbP2.append("fragment ");
                                sbP2.append(componentCallbacksC1023x5);
                                p4.h0(new IllegalArgumentException(sbP2.toString()));
                                throw th3;
                            }
                            ArrayList arrayListR = componentCallbacksC1023x5.f13267M.f13069c.r();
                            int size7 = arrayListR.size();
                            int i21 = 0;
                            while (i21 < size7) {
                                Object obj7 = arrayListR.get(i21);
                                i21++;
                                ComponentCallbacksC1023x componentCallbacksC1023x6 = (ComponentCallbacksC1023x) obj7;
                                if (componentCallbacksC1023x6 != null) {
                                    arrayDeque.addLast(componentCallbacksC1023x6);
                                }
                            }
                        }
                        ArrayList arrayList10 = new ArrayList();
                        Iterator it = hashSet.iterator();
                        while (it.hasNext()) {
                            arrayList10.add(((ComponentCallbacksC1023x) it.next()).f13297u);
                        }
                        ArrayList arrayList11 = new ArrayList(p4.f13070d.size() - iB);
                        for (int i22 = iB; i22 < p4.f13070d.size(); i22++) {
                            arrayList11.add(th3);
                        }
                        C1003c c1003c2 = new C1003c(arrayList10, arrayList11);
                        for (int size8 = p4.f13070d.size() - 1; size8 >= iB; size8--) {
                            C1001a c1001a4 = (C1001a) p4.f13070d.remove(size8);
                            C1001a c1001a5 = new C1001a(c1001a4);
                            c1001a5.e();
                            arrayList11.set(size8 - iB, new C1002b(c1001a5));
                            c1001a4.f13163u = true;
                            arrayList.add(c1001a4);
                            arrayList2.add(Boolean.TRUE);
                        }
                        p4.f13077l.put(str3, c1003c2);
                        return true;
                    }
                    C1001a c1001a6 = (C1001a) p4.f13070d.get(i14);
                    if (!c1001a6.f13158p) {
                        p4.h0(new IllegalArgumentException("saveBackStack(\"" + str3 + "\") included FragmentTransactions must use setReorderingAllowed(true) to ensure that the back stack can be restored as an atomic operation. Found " + c1001a6 + " that did not use setReorderingAllowed(true)."));
                        throw null;
                    }
                    i14++;
                }
                break;
        }
    }
}
