package androidx.compose.ui.platform;

import android.content.ContentResolver;
import android.content.Context;
import android.database.ContentObserver;
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
import android.provider.Settings;
import android.view.View;
import android.view.ViewParent;
import androidx.lifecycle.n;
import java.util.LinkedHashMap;
import java.util.Map;
import tp.u1;
import wp.d0;

/* loaded from: classes.dex */
public abstract class m3 {

    /* renamed from: a, reason: collision with root package name */
    private static final Map f2541a = new LinkedHashMap();

    /* loaded from: classes.dex */
    public static final class a implements View.OnAttachStateChangeListener {

        /* renamed from: p, reason: collision with root package name */
        final /* synthetic */ View f2542p;

        /* renamed from: q, reason: collision with root package name */
        final /* synthetic */ y0.n2 f2543q;

        a(View view, y0.n2 n2Var) {
            this.f2542p = view;
            this.f2543q = n2Var;
        }

        @Override // android.view.View.OnAttachStateChangeListener
        public void onViewAttachedToWindow(View view) {
        }

        @Override // android.view.View.OnAttachStateChangeListener
        public void onViewDetachedFromWindow(View view) {
            this.f2542p.removeOnAttachStateChangeListener(this);
            this.f2543q.Y();
        }
    }

    /* loaded from: classes.dex */
    public static final class b implements androidx.lifecycle.r {

        /* renamed from: p, reason: collision with root package name */
        final /* synthetic */ tp.m0 f2544p;

        /* renamed from: q, reason: collision with root package name */
        final /* synthetic */ y0.y1 f2545q;

        /* renamed from: r, reason: collision with root package name */
        final /* synthetic */ y0.n2 f2546r;

        /* renamed from: s, reason: collision with root package name */
        final /* synthetic */ kotlin.jvm.internal.o0 f2547s;

        /* renamed from: t, reason: collision with root package name */
        final /* synthetic */ View f2548t;

        /* loaded from: classes.dex */
        public /* synthetic */ class a {

            /* renamed from: a, reason: collision with root package name */
            public static final /* synthetic */ int[] f2549a;

            static {
                int[] iArr = new int[n.a.values().length];
                try {
                    iArr[n.a.ON_CREATE.ordinal()] = 1;
                } catch (NoSuchFieldError unused) {
                }
                try {
                    iArr[n.a.ON_START.ordinal()] = 2;
                } catch (NoSuchFieldError unused2) {
                }
                try {
                    iArr[n.a.ON_STOP.ordinal()] = 3;
                } catch (NoSuchFieldError unused3) {
                }
                try {
                    iArr[n.a.ON_DESTROY.ordinal()] = 4;
                } catch (NoSuchFieldError unused4) {
                }
                try {
                    iArr[n.a.ON_PAUSE.ordinal()] = 5;
                } catch (NoSuchFieldError unused5) {
                }
                try {
                    iArr[n.a.ON_RESUME.ordinal()] = 6;
                } catch (NoSuchFieldError unused6) {
                }
                try {
                    iArr[n.a.ON_ANY.ordinal()] = 7;
                } catch (NoSuchFieldError unused7) {
                }
                f2549a = iArr;
            }
        }

        /* renamed from: androidx.compose.ui.platform.m3$b$b, reason: collision with other inner class name */
        /* loaded from: classes.dex */
        static final class C0066b extends kotlin.coroutines.jvm.internal.l implements dn.p {

            /* renamed from: p, reason: collision with root package name */
            int f2550p;

            /* renamed from: q, reason: collision with root package name */
            private /* synthetic */ Object f2551q;

            /* renamed from: r, reason: collision with root package name */
            final /* synthetic */ kotlin.jvm.internal.o0 f2552r;

            /* renamed from: s, reason: collision with root package name */
            final /* synthetic */ y0.n2 f2553s;

            /* renamed from: t, reason: collision with root package name */
            final /* synthetic */ androidx.lifecycle.u f2554t;

            /* renamed from: u, reason: collision with root package name */
            final /* synthetic */ b f2555u;

            /* renamed from: v, reason: collision with root package name */
            final /* synthetic */ View f2556v;

            /* JADX INFO: Access modifiers changed from: package-private */
            /* renamed from: androidx.compose.ui.platform.m3$b$b$a */
            /* loaded from: classes.dex */
            public static final class a extends kotlin.coroutines.jvm.internal.l implements dn.p {

                /* renamed from: p, reason: collision with root package name */
                int f2557p;

                /* renamed from: q, reason: collision with root package name */
                final /* synthetic */ wp.h0 f2558q;

                /* renamed from: r, reason: collision with root package name */
                final /* synthetic */ y1 f2559r;

                /* JADX INFO: Access modifiers changed from: package-private */
                /* renamed from: androidx.compose.ui.platform.m3$b$b$a$a, reason: collision with other inner class name */
                /* loaded from: classes.dex */
                public static final class C0067a implements wp.f {

                    /* renamed from: p, reason: collision with root package name */
                    final /* synthetic */ y1 f2560p;

                    C0067a(y1 y1Var) {
                        this.f2560p = y1Var;
                    }

                    public final Object b(float f10, vm.d dVar) {
                        this.f2560p.e(f10);
                        return rm.n0.f34904a;
                    }

                    @Override // wp.f
                    public /* bridge */ /* synthetic */ Object emit(Object obj, vm.d dVar) {
                        return b(((Number) obj).floatValue(), dVar);
                    }
                }

                /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
                a(wp.h0 h0Var, y1 y1Var, vm.d dVar) {
                    super(2, dVar);
                    this.f2558q = h0Var;
                    this.f2559r = y1Var;
                }

                @Override // kotlin.coroutines.jvm.internal.a
                public final vm.d create(Object obj, vm.d dVar) {
                    return new a(this.f2558q, this.f2559r, dVar);
                }

                @Override // kotlin.coroutines.jvm.internal.a
                public final Object invokeSuspend(Object obj) {
                    Object f10;
                    f10 = wm.d.f();
                    int i10 = this.f2557p;
                    if (i10 == 0) {
                        rm.y.b(obj);
                        wp.h0 h0Var = this.f2558q;
                        C0067a c0067a = new C0067a(this.f2559r);
                        this.f2557p = 1;
                        if (h0Var.collect(c0067a, this) == f10) {
                            return f10;
                        }
                    } else {
                        if (i10 != 1) {
                            throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                        }
                        rm.y.b(obj);
                    }
                    throw new rm.k();
                }

                @Override // dn.p
                public final Object invoke(tp.m0 m0Var, vm.d dVar) {
                    return ((a) create(m0Var, dVar)).invokeSuspend(rm.n0.f34904a);
                }
            }

            /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
            C0066b(kotlin.jvm.internal.o0 o0Var, y0.n2 n2Var, androidx.lifecycle.u uVar, b bVar, View view, vm.d dVar) {
                super(2, dVar);
                this.f2552r = o0Var;
                this.f2553s = n2Var;
                this.f2554t = uVar;
                this.f2555u = bVar;
                this.f2556v = view;
            }

            @Override // kotlin.coroutines.jvm.internal.a
            public final vm.d create(Object obj, vm.d dVar) {
                C0066b c0066b = new C0066b(this.f2552r, this.f2553s, this.f2554t, this.f2555u, this.f2556v, dVar);
                c0066b.f2551q = obj;
                return c0066b;
            }

            /* JADX WARN: Removed duplicated region for block: B:15:0x0083  */
            @Override // kotlin.coroutines.jvm.internal.a
            /*
                Code decompiled incorrectly, please refer to instructions dump.
            */
            public final Object invokeSuspend(Object obj) {
                Object f10;
                tp.u1 u1Var;
                tp.u1 u1Var2;
                f10 = wm.d.f();
                int i10 = this.f2550p;
                if (i10 == 0) {
                    rm.y.b(obj);
                    tp.m0 m0Var = (tp.m0) this.f2551q;
                    try {
                        y1 y1Var = (y1) this.f2552r.f26199p;
                        if (y1Var != null) {
                            wp.h0 e10 = m3.e(this.f2556v.getContext().getApplicationContext());
                            y1Var.e(((Number) e10.getValue()).floatValue());
                            u1Var2 = tp.i.d(m0Var, null, null, new a(e10, y1Var, null), 3, null);
                        } else {
                            u1Var2 = null;
                        }
                        try {
                            y0.n2 n2Var = this.f2553s;
                            this.f2551q = u1Var2;
                            this.f2550p = 1;
                            if (n2Var.z0(this) == f10) {
                                return f10;
                            }
                            u1Var = u1Var2;
                        } catch (Throwable th2) {
                            u1Var = u1Var2;
                            th = th2;
                            if (u1Var != null) {
                            }
                            this.f2554t.getLifecycle().d(this.f2555u);
                            throw th;
                        }
                    } catch (Throwable th3) {
                        th = th3;
                        u1Var = null;
                    }
                } else {
                    if (i10 != 1) {
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                    }
                    u1Var = (tp.u1) this.f2551q;
                    try {
                        rm.y.b(obj);
                    } catch (Throwable th4) {
                        th = th4;
                        if (u1Var != null) {
                            u1.a.a(u1Var, null, 1, null);
                        }
                        this.f2554t.getLifecycle().d(this.f2555u);
                        throw th;
                    }
                }
                if (u1Var != null) {
                    u1.a.a(u1Var, null, 1, null);
                }
                this.f2554t.getLifecycle().d(this.f2555u);
                return rm.n0.f34904a;
            }

            @Override // dn.p
            public final Object invoke(tp.m0 m0Var, vm.d dVar) {
                return ((C0066b) create(m0Var, dVar)).invokeSuspend(rm.n0.f34904a);
            }
        }

        b(tp.m0 m0Var, y0.y1 y1Var, y0.n2 n2Var, kotlin.jvm.internal.o0 o0Var, View view) {
            this.f2544p = m0Var;
            this.f2545q = y1Var;
            this.f2546r = n2Var;
            this.f2547s = o0Var;
            this.f2548t = view;
        }

        @Override // androidx.lifecycle.r
        public void f(androidx.lifecycle.u uVar, n.a aVar) {
            int i10 = a.f2549a[aVar.ordinal()];
            if (i10 == 1) {
                tp.i.d(this.f2544p, null, tp.o0.UNDISPATCHED, new C0066b(this.f2547s, this.f2546r, uVar, this, this.f2548t, null), 1, null);
                return;
            }
            if (i10 == 2) {
                y0.y1 y1Var = this.f2545q;
                if (y1Var != null) {
                    y1Var.g();
                }
                this.f2546r.y0();
                return;
            }
            if (i10 == 3) {
                this.f2546r.l0();
            } else {
                if (i10 != 4) {
                    return;
                }
                this.f2546r.Y();
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public static final class c extends kotlin.coroutines.jvm.internal.l implements dn.p {

        /* renamed from: p, reason: collision with root package name */
        Object f2561p;

        /* renamed from: q, reason: collision with root package name */
        int f2562q;

        /* renamed from: r, reason: collision with root package name */
        private /* synthetic */ Object f2563r;

        /* renamed from: s, reason: collision with root package name */
        final /* synthetic */ ContentResolver f2564s;

        /* renamed from: t, reason: collision with root package name */
        final /* synthetic */ Uri f2565t;

        /* renamed from: u, reason: collision with root package name */
        final /* synthetic */ d f2566u;

        /* renamed from: v, reason: collision with root package name */
        final /* synthetic */ vp.d f2567v;

        /* renamed from: w, reason: collision with root package name */
        final /* synthetic */ Context f2568w;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        c(ContentResolver contentResolver, Uri uri, d dVar, vp.d dVar2, Context context, vm.d dVar3) {
            super(2, dVar3);
            this.f2564s = contentResolver;
            this.f2565t = uri;
            this.f2566u = dVar;
            this.f2567v = dVar2;
            this.f2568w = context;
        }

        @Override // dn.p
        /* renamed from: b, reason: merged with bridge method [inline-methods] */
        public final Object invoke(wp.f fVar, vm.d dVar) {
            return ((c) create(fVar, dVar)).invokeSuspend(rm.n0.f34904a);
        }

        @Override // kotlin.coroutines.jvm.internal.a
        public final vm.d create(Object obj, vm.d dVar) {
            c cVar = new c(this.f2564s, this.f2565t, this.f2566u, this.f2567v, this.f2568w, dVar);
            cVar.f2563r = obj;
            return cVar;
        }

        /* JADX WARN: Removed duplicated region for block: B:11:0x0052 A[RETURN] */
        /* JADX WARN: Removed duplicated region for block: B:13:0x0053  */
        /* JADX WARN: Removed duplicated region for block: B:16:0x005e A[Catch: all -> 0x008a, TRY_LEAVE, TryCatch #0 {all -> 0x008a, blocks: (B:7:0x0016, B:9:0x0046, B:14:0x0056, B:16:0x005e, B:25:0x002b, B:27:0x0040), top: B:2:0x0008 }] */
        /* JADX WARN: Removed duplicated region for block: B:19:0x0080  */
        /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:17:0x007d -> B:8:0x0019). Please report as a decompilation issue!!! */
        @Override // kotlin.coroutines.jvm.internal.a
        /*
            Code decompiled incorrectly, please refer to instructions dump.
        */
        public final Object invokeSuspend(Object obj) {
            Object f10;
            wp.f fVar;
            vp.f it;
            wp.f fVar2;
            Object b10;
            f10 = wm.d.f();
            int i10 = this.f2562q;
            try {
                if (i10 == 0) {
                    rm.y.b(obj);
                    fVar = (wp.f) this.f2563r;
                    this.f2564s.registerContentObserver(this.f2565t, false, this.f2566u);
                    it = this.f2567v.iterator();
                    this.f2563r = fVar;
                    this.f2561p = it;
                    this.f2562q = 1;
                    b10 = it.b(this);
                    if (b10 == f10) {
                    }
                } else if (i10 == 1) {
                    it = (vp.f) this.f2561p;
                    fVar2 = (wp.f) this.f2563r;
                    rm.y.b(obj);
                    if (((Boolean) obj).booleanValue()) {
                    }
                } else {
                    if (i10 != 2) {
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                    }
                    it = (vp.f) this.f2561p;
                    fVar2 = (wp.f) this.f2563r;
                    rm.y.b(obj);
                    fVar = fVar2;
                    this.f2563r = fVar;
                    this.f2561p = it;
                    this.f2562q = 1;
                    b10 = it.b(this);
                    if (b10 == f10) {
                        return f10;
                    }
                    fVar2 = fVar;
                    obj = b10;
                    if (((Boolean) obj).booleanValue()) {
                        this.f2564s.unregisterContentObserver(this.f2566u);
                        return rm.n0.f34904a;
                    }
                    it.next();
                    Float b11 = kotlin.coroutines.jvm.internal.b.b(Settings.Global.getFloat(this.f2568w.getContentResolver(), "animator_duration_scale", 1.0f));
                    this.f2563r = fVar2;
                    this.f2561p = it;
                    this.f2562q = 2;
                    if (fVar2.emit(b11, this) == f10) {
                        return f10;
                    }
                    fVar = fVar2;
                    this.f2563r = fVar;
                    this.f2561p = it;
                    this.f2562q = 1;
                    b10 = it.b(this);
                    if (b10 == f10) {
                    }
                }
            } catch (Throwable th2) {
                this.f2564s.unregisterContentObserver(this.f2566u);
                throw th2;
            }
        }
    }

    /* loaded from: classes.dex */
    public static final class d extends ContentObserver {

        /* renamed from: a, reason: collision with root package name */
        final /* synthetic */ vp.d f2569a;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        d(vp.d dVar, Handler handler) {
            super(handler);
            this.f2569a = dVar;
        }

        @Override // android.database.ContentObserver
        public void onChange(boolean z10, Uri uri) {
            this.f2569a.n(rm.n0.f34904a);
        }
    }

    public static final y0.n2 b(View view, vm.g gVar, androidx.lifecycle.n nVar) {
        y0.y1 y1Var;
        if (gVar.d(vm.e.INSTANCE) == null || gVar.d(y0.g1.f51542o) == null) {
            gVar = o0.B.a().h(gVar);
        }
        y0.g1 g1Var = (y0.g1) gVar.d(y0.g1.f51542o);
        if (g1Var != null) {
            y0.y1 y1Var2 = new y0.y1(g1Var);
            y1Var2.e();
            y1Var = y1Var2;
        } else {
            y1Var = null;
        }
        kotlin.jvm.internal.o0 o0Var = new kotlin.jvm.internal.o0();
        vm.g gVar2 = (l1.l) gVar.d(l1.l.f27376g);
        if (gVar2 == null) {
            gVar2 = new y1();
            o0Var.f26199p = gVar2;
        }
        vm.g h10 = gVar.h(y1Var != null ? y1Var : vm.h.f40193p).h(gVar2);
        y0.n2 n2Var = new y0.n2(h10);
        n2Var.l0();
        tp.m0 a10 = tp.n0.a(h10);
        if (nVar == null) {
            androidx.lifecycle.u a11 = androidx.lifecycle.f1.a(view);
            nVar = a11 != null ? a11.getLifecycle() : null;
        }
        if (nVar != null) {
            view.addOnAttachStateChangeListener(new a(view, n2Var));
            nVar.a(new b(a10, y1Var, n2Var, o0Var, view));
            return n2Var;
        }
        g2.a.c("ViewTreeLifecycleOwner not found from " + view);
        throw new rm.k();
    }

    public static /* synthetic */ y0.n2 c(View view, vm.g gVar, androidx.lifecycle.n nVar, int i10, Object obj) {
        if ((i10 & 1) != 0) {
            gVar = vm.h.f40193p;
        }
        if ((i10 & 2) != 0) {
            nVar = null;
        }
        return b(view, gVar, nVar);
    }

    public static final y0.r d(View view) {
        y0.r f10 = f(view);
        if (f10 != null) {
            return f10;
        }
        for (ViewParent parent = view.getParent(); f10 == null && (parent instanceof View); parent = parent.getParent()) {
            f10 = f((View) parent);
        }
        return f10;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final wp.h0 e(Context context) {
        wp.h0 h0Var;
        Map map = f2541a;
        synchronized (map) {
            Object obj = map.get(context);
            if (obj == null) {
                ContentResolver contentResolver = context.getContentResolver();
                Uri uriFor = Settings.Global.getUriFor("animator_duration_scale");
                vp.d b10 = vp.g.b(-1, null, null, 6, null);
                obj = wp.g.t(wp.g.q(new c(contentResolver, uriFor, new d(b10, androidx.core.os.g.a(Looper.getMainLooper())), b10, context, null)), tp.n0.b(), d0.a.b(wp.d0.f49579a, 0L, 0L, 3, null), Float.valueOf(Settings.Global.getFloat(context.getContentResolver(), "animator_duration_scale", 1.0f)));
                map.put(context, obj);
            }
            h0Var = (wp.h0) obj;
        }
        return h0Var;
    }

    public static final y0.r f(View view) {
        Object tag = view.getTag(l1.m.G);
        if (tag instanceof y0.r) {
            return (y0.r) tag;
        }
        return null;
    }

    private static final View g(View view) {
        Object parent = view.getParent();
        while (parent instanceof View) {
            View view2 = (View) parent;
            if (view2.getId() == 16908290) {
                return view;
            }
            parent = view2.getParent();
            view = view2;
        }
        return view;
    }

    public static final y0.n2 h(View view) {
        if (!view.isAttachedToWindow()) {
            g2.a.b("Cannot locate windowRecomposer; View " + view + " is not attached to a window");
        }
        View g10 = g(view);
        y0.r f10 = f(g10);
        if (f10 == null) {
            return l3.f2504a.a(g10);
        }
        if (f10 instanceof y0.n2) {
            return (y0.n2) f10;
        }
        throw new IllegalStateException("root viewTreeParentCompositionContext is not a Recomposer".toString());
    }

    public static final void i(View view, y0.r rVar) {
        view.setTag(l1.m.G, rVar);
    }
}
