package androidx.fragment.app;

import android.graphics.Rect;
import android.os.Build;
import android.os.CancellationSignal;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import kotlin.Pair;
import kotlin.jvm.internal.Ref$ObjectRef;

/* JADX INFO: loaded from: classes.dex */
public final class n extends d2 {

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final f2 f2517d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final f2 f2518e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final z1 f2519f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final Object f2520g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final ArrayList f2521h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public final ArrayList f2522i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final androidx.collection.f f2523j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public final ArrayList f2524k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public final ArrayList f2525l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public final androidx.collection.f f2526m;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public final androidx.collection.f f2527n;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public final m0.e f2528o = new m0.e();

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    public Object f2529p;

    public n(ArrayList arrayList, f2 f2Var, f2 f2Var2, z1 z1Var, Object obj, ArrayList arrayList2, ArrayList arrayList3, androidx.collection.f fVar, ArrayList arrayList4, ArrayList arrayList5, androidx.collection.f fVar2, androidx.collection.f fVar3, boolean z10) {
        this.f2516c = arrayList;
        this.f2517d = f2Var;
        this.f2518e = f2Var2;
        this.f2519f = z1Var;
        this.f2520g = obj;
        this.f2521h = arrayList2;
        this.f2522i = arrayList3;
        this.f2523j = fVar;
        this.f2524k = arrayList4;
        this.f2525l = arrayList5;
        this.f2526m = fVar2;
        this.f2527n = fVar3;
    }

    public static void f(ArrayList arrayList, View view) {
        if (!(view instanceof ViewGroup)) {
            if (arrayList.contains(view)) {
                return;
            }
            arrayList.add(view);
            return;
        }
        ViewGroup viewGroup = (ViewGroup) view;
        if (viewGroup.isTransitionGroup()) {
            if (arrayList.contains(view)) {
                return;
            }
            arrayList.add(view);
            return;
        }
        int childCount = viewGroup.getChildCount();
        for (int i10 = 0; i10 < childCount; i10++) {
            View childAt = viewGroup.getChildAt(i10);
            if (childAt.getVisibility() == 0) {
                f(arrayList, childAt);
            }
        }
    }

    @Override // androidx.fragment.app.d2
    public final boolean a() {
        Object obj;
        Object obj2;
        z1 z1Var = this.f2519f;
        if (z1Var.i()) {
            List<o> list = this.f2516c;
            if ((list instanceof Collection) && list.isEmpty()) {
                obj2 = this.f2520g;
                if (obj2 != null) {
                }
                return true;
            }
            for (o oVar : list) {
                if (Build.VERSION.SDK_INT < 34 || (obj = oVar.f2535b) == null || !z1Var.j(obj)) {
                    break;
                }
            }
            obj2 = this.f2520g;
            if (obj2 != null || z1Var.j(obj2)) {
                return true;
            }
        }
        return false;
    }

    @Override // androidx.fragment.app.d2
    public final void b(ViewGroup viewGroup) {
        nb.g.i(viewGroup, "container");
        m0.e eVar = this.f2528o;
        synchronized (eVar) {
            try {
                if (eVar.f30279a) {
                    return;
                }
                eVar.f30279a = true;
                eVar.f30282d = true;
                m0.d dVar = eVar.f30280b;
                CancellationSignal cancellationSignal = eVar.f30281c;
                if (dVar != null) {
                    try {
                        androidx.media3.exoplayer.hls.b bVar = (androidx.media3.exoplayer.hls.b) dVar;
                        Runnable runnable = (Runnable) bVar.f3022c;
                        r3.z zVar = (r3.z) bVar.f3021b;
                        Runnable runnable2 = (Runnable) bVar.f3023d;
                        if (runnable == null) {
                            zVar.cancel();
                            runnable2.run();
                        } else {
                            runnable.run();
                        }
                    } catch (Throwable th) {
                        synchronized (eVar) {
                            eVar.f30282d = false;
                            eVar.notifyAll();
                            throw th;
                        }
                    }
                }
                if (cancellationSignal != null) {
                    cancellationSignal.cancel();
                }
                synchronized (eVar) {
                    eVar.f30282d = false;
                    eVar.notifyAll();
                }
            } finally {
            }
        }
    }

    @Override // androidx.fragment.app.d2
    public final void c(final ViewGroup viewGroup) {
        nb.g.i(viewGroup, "container");
        boolean zIsLaidOut = viewGroup.isLaidOut();
        List<o> list = this.f2516c;
        if (!zIsLaidOut) {
            for (o oVar : list) {
                f2 f2Var = (f2) oVar.f31277a;
                if (Log.isLoggable("FragmentManager", 2)) {
                    viewGroup.toString();
                    Objects.toString(f2Var);
                }
                ((f2) oVar.f31277a).c(this);
            }
            return;
        }
        Object obj = this.f2529p;
        z1 z1Var = this.f2519f;
        f2 f2Var2 = this.f2518e;
        f2 f2Var3 = this.f2517d;
        if (obj != null) {
            z1Var.c(obj);
            if (Log.isLoggable("FragmentManager", 2)) {
                Objects.toString(f2Var3);
                Objects.toString(f2Var2);
                return;
            }
            return;
        }
        Pair pairG = g(viewGroup, f2Var2, f2Var3);
        ArrayList arrayList = (ArrayList) pairG.getFirst();
        final Object second = pairG.getSecond();
        List list2 = list;
        ArrayList<f2> arrayList2 = new ArrayList(kotlin.collections.i.Z0(10, list2));
        Iterator it = list2.iterator();
        while (it.hasNext()) {
            arrayList2.add((f2) ((o) it.next()).f31277a);
        }
        for (f2 f2Var4 : arrayList2) {
            z1Var.n(f2Var4.f2442c, second, this.f2528o, new l(f2Var4, this, 0));
        }
        i(arrayList, viewGroup, new sd.a() { // from class: androidx.fragment.app.DefaultSpecialEffectsController$TransitionEffect$onCommit$4
            /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
            {
                super(0);
            }

            @Override // sd.a
            public final Object invoke() {
                this.this$0.f2519f.beginDelayedTransition(viewGroup, second);
                return kd.e.f29109a;
            }
        });
        if (Log.isLoggable("FragmentManager", 2)) {
            Objects.toString(f2Var3);
            Objects.toString(f2Var2);
        }
    }

    @Override // androidx.fragment.app.d2
    public final void d(androidx.activity.b bVar, ViewGroup viewGroup) {
        nb.g.i(bVar, "backEvent");
        nb.g.i(viewGroup, "container");
        Object obj = this.f2529p;
        if (obj != null) {
            this.f2519f.l(obj, bVar.f468c);
        }
    }

    @Override // androidx.fragment.app.d2
    public final void e(final ViewGroup viewGroup) {
        Object obj;
        boolean zIsLaidOut = viewGroup.isLaidOut();
        List list = this.f2516c;
        if (!zIsLaidOut) {
            Iterator it = list.iterator();
            while (it.hasNext()) {
                f2 f2Var = (f2) ((o) it.next()).f31277a;
                if (Log.isLoggable("FragmentManager", 2)) {
                    viewGroup.toString();
                    Objects.toString(f2Var);
                }
            }
            return;
        }
        boolean zH = h();
        f2 f2Var2 = this.f2518e;
        f2 f2Var3 = this.f2517d;
        if (zH && (obj = this.f2520g) != null && !a()) {
            Objects.toString(obj);
            Objects.toString(f2Var3);
            Objects.toString(f2Var2);
        }
        if (a() && h()) {
            final Ref$ObjectRef ref$ObjectRef = new Ref$ObjectRef();
            Pair pairG = g(viewGroup, f2Var2, f2Var3);
            ArrayList arrayList = (ArrayList) pairG.getFirst();
            final Object second = pairG.getSecond();
            List list2 = list;
            ArrayList<f2> arrayList2 = new ArrayList(kotlin.collections.i.Z0(10, list2));
            Iterator it2 = list2.iterator();
            while (it2.hasNext()) {
                arrayList2.add((f2) ((o) it2.next()).f31277a);
            }
            for (f2 f2Var4 : arrayList2) {
                this.f2519f.setListenerForTransitionEnd(f2Var4.f2442c, second, this.f2528o, new y.a(ref$ObjectRef, 2), new l(f2Var4, this, 1));
            }
            i(arrayList, viewGroup, new sd.a() { // from class: androidx.fragment.app.DefaultSpecialEffectsController$TransitionEffect$onStart$4
                /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
                {
                    super(0);
                }

                /* JADX WARN: Type inference failed for: r2v2, types: [T, androidx.fragment.app.DefaultSpecialEffectsController$TransitionEffect$onStart$4$2] */
                @Override // sd.a
                public final Object invoke() {
                    n nVar = this.this$0;
                    nVar.f2529p = nVar.f2519f.controlDelayedTransition(viewGroup, second);
                    final n nVar2 = this.this$0;
                    boolean z10 = nVar2.f2529p != null;
                    Object obj2 = second;
                    final ViewGroup viewGroup2 = viewGroup;
                    if (z10) {
                        ref$ObjectRef.element = new sd.a() { // from class: androidx.fragment.app.DefaultSpecialEffectsController$TransitionEffect$onStart$4.2
                            /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
                            {
                                super(0);
                            }

                            @Override // sd.a
                            public final Object invoke() {
                                n nVar3 = nVar2;
                                z1 z1Var = nVar3.f2519f;
                                Object obj3 = nVar3.f2529p;
                                nb.g.f(obj3);
                                z1Var.d(obj3, new m(nVar2, viewGroup2, 0));
                                return kd.e.f29109a;
                            }
                        };
                        if (Log.isLoggable("FragmentManager", 2)) {
                            Objects.toString(this.this$0.f2517d);
                            Objects.toString(this.this$0.f2518e);
                        }
                        return kd.e.f29109a;
                    }
                    throw new IllegalStateException(("Unable to start transition " + obj2 + " for container " + viewGroup2 + '.').toString());
                }
            });
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:44:0x0191  */
    /* JADX WARN: Removed duplicated region for block: B:55:0x01c5  */
    /* JADX WARN: Removed duplicated region for block: B:76:0x0206 A[SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:77:0x01f3 A[SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Pair g(ViewGroup viewGroup, f2 f2Var, f2 f2Var2) {
        ArrayList arrayList;
        ArrayList arrayList2;
        Object obj;
        z1 z1Var;
        Object obj2;
        View view;
        Iterator it;
        n nVar = this;
        View view2 = new View(viewGroup.getContext());
        Rect rect = new Rect();
        List list = nVar.f2516c;
        Iterator it2 = list.iterator();
        View view3 = null;
        boolean z10 = false;
        while (true) {
            boolean zHasNext = it2.hasNext();
            arrayList = nVar.f2522i;
            arrayList2 = nVar.f2521h;
            obj = nVar.f2520g;
            z1Var = nVar.f2519f;
            if (!zHasNext) {
                break;
            }
            if (((o) it2.next()).f2537d == null || f2Var2 == null || f2Var == null || !(!nVar.f2523j.isEmpty()) || obj == null) {
                it = it2;
            } else {
                x1 x1Var = s1.f2581a;
                nb.g.i(f2Var.f2442c, "inFragment");
                nb.g.i(f2Var2.f2442c, "outFragment");
                androidx.collection.f fVar = nVar.f2526m;
                nb.g.i(fVar, "sharedElements");
                it = it2;
                androidx.core.view.o0.a(viewGroup, new androidx.emoji2.text.v(f2Var, f2Var2, nVar, 2));
                arrayList2.addAll(fVar.values());
                ArrayList arrayList3 = nVar.f2525l;
                if (!arrayList3.isEmpty()) {
                    Object obj3 = arrayList3.get(0);
                    nb.g.h(obj3, "exitingNames[0]");
                    View view4 = (View) fVar.get((String) obj3);
                    z1Var.setEpicenter(obj, view4);
                    view3 = view4;
                }
                androidx.collection.f fVar2 = nVar.f2527n;
                arrayList.addAll(fVar2.values());
                ArrayList arrayList4 = nVar.f2524k;
                if (!arrayList4.isEmpty()) {
                    Object obj4 = arrayList4.get(0);
                    nb.g.h(obj4, "enteringNames[0]");
                    View view5 = (View) fVar2.get((String) obj4);
                    if (view5 != null) {
                        androidx.core.view.o0.a(viewGroup, new androidx.emoji2.text.v(z1Var, view5, rect, 3));
                        z10 = true;
                    }
                }
                z1Var.o(obj, view2, arrayList2);
                z1 z1Var2 = nVar.f2519f;
                Object obj5 = nVar.f2520g;
                z1Var2.scheduleRemoveTargets(obj5, null, null, null, null, obj5, nVar.f2522i);
            }
            it2 = it;
        }
        ArrayList arrayList5 = new ArrayList();
        Iterator it3 = list.iterator();
        Object obj6 = null;
        Object objMergeTransitionsTogether = null;
        while (true) {
            obj2 = objMergeTransitionsTogether;
            if (!it3.hasNext()) {
                break;
            }
            Iterator it4 = it3;
            o oVar = (o) it3.next();
            Object obj7 = obj6;
            f2 f2Var3 = (f2) oVar.f31277a;
            View view6 = view3;
            Object objCloneTransition = z1Var.cloneTransition(oVar.f2535b);
            if (objCloneTransition != null) {
                ArrayList<View> arrayList6 = new ArrayList<>();
                View view7 = f2Var3.f2442c.f2419k0;
                Rect rect2 = rect;
                nb.g.h(view7, "operation.fragment.mView");
                f(arrayList6, view7);
                if (obj != null && (f2Var3 == f2Var2 || f2Var3 == f2Var)) {
                    if (f2Var3 == f2Var2) {
                        arrayList6.removeAll(kotlin.collections.n.t1(arrayList2));
                    } else {
                        arrayList6.removeAll(kotlin.collections.n.t1(arrayList));
                    }
                }
                if (arrayList6.isEmpty()) {
                    z1Var.a(view2, objCloneTransition);
                } else {
                    z1Var.b(objCloneTransition, arrayList6);
                    nVar.f2519f.scheduleRemoveTargets(objCloneTransition, objCloneTransition, arrayList6, null, null, null, null);
                    if (f2Var3.f2440a == SpecialEffectsController$Operation$State.f2307c) {
                        f2Var3.f2448i = false;
                        ArrayList arrayList7 = new ArrayList(arrayList6);
                        e0 e0Var = f2Var3.f2442c;
                        arrayList7.remove(e0Var.f2419k0);
                        z1Var.k(objCloneTransition, e0Var.f2419k0, arrayList7);
                        androidx.core.view.o0.a(viewGroup, new y.a(arrayList6, 3));
                    }
                    if (f2Var3.f2440a != SpecialEffectsController$Operation$State.f2306b) {
                        arrayList5.addAll(arrayList6);
                        if (z10) {
                            z1Var.m(objCloneTransition, rect2);
                        }
                        if (Log.isLoggable("FragmentManager", 2)) {
                            objCloneTransition.toString();
                            for (View view8 : arrayList6) {
                                nb.g.h(view8, "transitioningViews");
                                view8.toString();
                            }
                        }
                        rect2 = rect2;
                        view = view6;
                    } else {
                        view = view6;
                        z1Var.setEpicenter(objCloneTransition, view);
                        if (Log.isLoggable("FragmentManager", 2)) {
                            objCloneTransition.toString();
                            for (View view9 : arrayList6) {
                                nb.g.h(view9, "transitioningViews");
                                view9.toString();
                            }
                        }
                    }
                    if (oVar.f2536c) {
                        objMergeTransitionsTogether = z1Var.mergeTransitionsTogether(obj2, objCloneTransition, null);
                        nVar = this;
                        view3 = view;
                        rect = rect2;
                        obj6 = obj7;
                        it3 = it4;
                    } else {
                        Object objMergeTransitionsTogether2 = z1Var.mergeTransitionsTogether(obj7, objCloneTransition, null);
                        nVar = this;
                        view3 = view;
                        objMergeTransitionsTogether = obj2;
                        it3 = it4;
                        obj6 = objMergeTransitionsTogether2;
                        rect = rect2;
                    }
                }
                if (f2Var3.f2440a != SpecialEffectsController$Operation$State.f2306b) {
                }
                if (oVar.f2536c) {
                }
            } else {
                objMergeTransitionsTogether = obj2;
                nVar = this;
                obj6 = obj7;
                it3 = it4;
                view3 = view6;
            }
        }
        Object objMergeTransitionsInSequence = z1Var.mergeTransitionsInSequence(obj6, obj2, obj);
        if (Log.isLoggable("FragmentManager", 2)) {
            Objects.toString(objMergeTransitionsInSequence);
        }
        return new Pair(arrayList5, objMergeTransitionsInSequence);
    }

    public final boolean h() {
        List list = this.f2516c;
        if ((list instanceof Collection) && list.isEmpty()) {
            return true;
        }
        Iterator it = list.iterator();
        while (it.hasNext()) {
            if (!((f2) ((o) it.next()).f31277a).f2442c.f2422m) {
                return false;
            }
        }
        return true;
    }

    public final void i(ArrayList arrayList, ViewGroup viewGroup, sd.a aVar) {
        s1.a(4, arrayList);
        z1 z1Var = this.f2519f;
        z1Var.getClass();
        ArrayList arrayList2 = new ArrayList();
        ArrayList<View> arrayList3 = this.f2522i;
        int size = arrayList3.size();
        for (int i10 = 0; i10 < size; i10++) {
            View view = arrayList3.get(i10);
            arrayList2.add(androidx.core.view.s1.getTransitionName(view));
            androidx.core.view.s1.setTransitionName(view, null);
        }
        boolean zIsLoggable = Log.isLoggable("FragmentManager", 2);
        ArrayList<View> arrayList4 = this.f2521h;
        if (zIsLoggable) {
            for (View view2 : arrayList4) {
                nb.g.h(view2, "sharedElementFirstOutViews");
                View view3 = view2;
                view3.toString();
                androidx.core.view.s1.getTransitionName(view3);
            }
            for (View view4 : arrayList3) {
                nb.g.h(view4, "sharedElementLastInViews");
                View view5 = view4;
                view5.toString();
                androidx.core.view.s1.getTransitionName(view5);
            }
        }
        aVar.invoke();
        ArrayList arrayList5 = this.f2521h;
        int size2 = arrayList3.size();
        ArrayList arrayList6 = new ArrayList();
        for (int i11 = 0; i11 < size2; i11++) {
            View view6 = (View) arrayList5.get(i11);
            String transitionName = androidx.core.view.s1.getTransitionName(view6);
            arrayList6.add(transitionName);
            if (transitionName != null) {
                androidx.core.view.s1.setTransitionName(view6, null);
                String str = (String) this.f2523j.get(transitionName);
                int i12 = 0;
                while (true) {
                    if (i12 >= size2) {
                        break;
                    }
                    if (str.equals(arrayList2.get(i12))) {
                        androidx.core.view.s1.setTransitionName(arrayList3.get(i12), transitionName);
                        break;
                    }
                    i12++;
                }
            }
        }
        androidx.core.view.o0.a(viewGroup, new y1(z1Var, size2, arrayList3, arrayList2, arrayList5, arrayList6, 0));
        s1.a(0, arrayList);
        z1Var.swapSharedElementTargets(this.f2520g, arrayList4, arrayList3);
    }
}
