package d2;

import android.os.SystemClock;
import android.view.MotionEvent;
import java.util.List;

/* loaded from: classes.dex */
public final class i0 implements f0 {

    /* renamed from: b, reason: collision with root package name */
    public dn.l f15805b;

    /* renamed from: c, reason: collision with root package name */
    private p0 f15806c;

    /* renamed from: d, reason: collision with root package name */
    private boolean f15807d;

    /* renamed from: e, reason: collision with root package name */
    private final e0 f15808e = new b();

    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: classes.dex */
    public enum a {
        Unknown,
        Dispatching,
        NotDispatching
    }

    /* loaded from: classes.dex */
    public static final class b extends e0 {

        /* renamed from: b, reason: collision with root package name */
        private a f15809b = a.Unknown;

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

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

            /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
            a(i0 i0Var) {
                super(1);
                this.f15811p = i0Var;
            }

            public final void a(MotionEvent motionEvent) {
                this.f15811p.j().invoke(motionEvent);
            }

            @Override // dn.l
            public /* bridge */ /* synthetic */ Object invoke(Object obj) {
                a((MotionEvent) obj);
                return rm.n0.f34904a;
            }
        }

        /* JADX INFO: Access modifiers changed from: package-private */
        /* renamed from: d2.i0$b$b, reason: collision with other inner class name */
        /* loaded from: classes.dex */
        public static final class C0347b extends kotlin.jvm.internal.v implements dn.l {

            /* renamed from: q, reason: collision with root package name */
            final /* synthetic */ i0 f15813q;

            /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
            C0347b(i0 i0Var) {
                super(1);
                this.f15813q = i0Var;
            }

            public final void a(MotionEvent motionEvent) {
                if (motionEvent.getActionMasked() != 0) {
                    this.f15813q.j().invoke(motionEvent);
                } else {
                    b.this.f15809b = ((Boolean) this.f15813q.j().invoke(motionEvent)).booleanValue() ? a.Dispatching : a.NotDispatching;
                }
            }

            @Override // dn.l
            public /* bridge */ /* synthetic */ Object invoke(Object obj) {
                a((MotionEvent) obj);
                return rm.n0.f34904a;
            }
        }

        /* loaded from: classes.dex */
        static final class c extends kotlin.jvm.internal.v implements dn.l {

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

            /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
            c(i0 i0Var) {
                super(1);
                this.f15814p = i0Var;
            }

            public final void a(MotionEvent motionEvent) {
                this.f15814p.j().invoke(motionEvent);
            }

            @Override // dn.l
            public /* bridge */ /* synthetic */ Object invoke(Object obj) {
                a((MotionEvent) obj);
                return rm.n0.f34904a;
            }
        }

        b() {
        }

        private final void h(m mVar) {
            boolean z10;
            List c10 = mVar.c();
            int size = c10.size();
            int i10 = 0;
            while (true) {
                if (i10 >= size) {
                    z10 = false;
                    break;
                } else {
                    if (((y) c10.get(i10)).p()) {
                        z10 = true;
                        break;
                    }
                    i10++;
                }
            }
            if (z10) {
                if (this.f15809b == a.Dispatching) {
                    h2.s b10 = b();
                    if (b10 == null) {
                        throw new IllegalStateException("layoutCoordinates not set".toString());
                    }
                    k0.b(mVar, b10.r0(r1.g.f34318b.c()), new a(i0.this));
                }
                this.f15809b = a.NotDispatching;
                return;
            }
            h2.s b11 = b();
            if (b11 == null) {
                throw new IllegalStateException("layoutCoordinates not set".toString());
            }
            k0.c(mVar, b11.r0(r1.g.f34318b.c()), new C0347b(i0.this));
            if (this.f15809b == a.Dispatching) {
                int size2 = c10.size();
                for (int i11 = 0; i11 < size2; i11++) {
                    ((y) c10.get(i11)).a();
                }
                g d10 = mVar.d();
                if (d10 == null) {
                    return;
                }
                d10.e(!i0.this.c());
            }
        }

        private final void i() {
            this.f15809b = a.Unknown;
            i0.this.k(false);
        }

        @Override // d2.e0
        public boolean c() {
            return true;
        }

        @Override // d2.e0
        public void d() {
            if (this.f15809b == a.Dispatching) {
                k0.a(SystemClock.uptimeMillis(), new c(i0.this));
                i();
            }
        }

        /* JADX WARN: Removed duplicated region for block: B:18:0x003f  */
        /* JADX WARN: Removed duplicated region for block: B:28:0x0055  */
        /* JADX WARN: Removed duplicated region for block: B:41:? A[RETURN, SYNTHETIC] */
        @Override // d2.e0
        /*
            Code decompiled incorrectly, please refer to instructions dump.
        */
        public void e(m mVar, o oVar, long j10) {
            boolean z10;
            boolean z11;
            List c10 = mVar.c();
            boolean z12 = false;
            if (!i0.this.c()) {
                int size = c10.size();
                int i10 = 0;
                while (true) {
                    if (i10 >= size) {
                        z11 = false;
                        break;
                    }
                    y yVar = (y) c10.get(i10);
                    if (n.b(yVar) || n.d(yVar)) {
                        z11 = true;
                        break;
                    }
                    i10++;
                }
                if (!z11) {
                    z10 = false;
                    if (this.f15809b != a.NotDispatching) {
                        if (oVar == o.Initial && z10) {
                            h(mVar);
                        }
                        if (oVar == o.Final && !z10) {
                            h(mVar);
                        }
                    }
                    if (oVar != o.Final) {
                        int size2 = c10.size();
                        int i11 = 0;
                        while (true) {
                            if (i11 >= size2) {
                                z12 = true;
                                break;
                            } else if (!n.d((y) c10.get(i11))) {
                                break;
                            } else {
                                i11++;
                            }
                        }
                        if (z12) {
                            i();
                            return;
                        }
                        return;
                    }
                    return;
                }
            }
            z10 = true;
            if (this.f15809b != a.NotDispatching) {
            }
            if (oVar != o.Final) {
            }
        }
    }

    public final boolean c() {
        return this.f15807d;
    }

    @Override // d2.f0
    public e0 e() {
        return this.f15808e;
    }

    public final dn.l j() {
        dn.l lVar = this.f15805b;
        if (lVar != null) {
            return lVar;
        }
        kotlin.jvm.internal.t.y("onTouchEvent");
        return null;
    }

    public final void k(boolean z10) {
        this.f15807d = z10;
    }

    public final void l(dn.l lVar) {
        this.f15805b = lVar;
    }

    public final void m(p0 p0Var) {
        p0 p0Var2 = this.f15806c;
        if (p0Var2 != null) {
            p0Var2.b(null);
        }
        this.f15806c = p0Var;
        if (p0Var == null) {
            return;
        }
        p0Var.b(this);
    }
}
