package Z;

import C0.D;
import D.C0135f;
import I0.AbstractC0303l;
import I0.InterfaceC0297i;
import I0.InterfaceC0305n;
import I0.InterfaceC0314x;
import T.p;
import V4.E;
import a0.C0881a0;
import a0.Z;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import androidx.compose.ui.platform.AndroidCompositionLocals_androidKt;
import i0.AbstractC2254r;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import n.J;
import n2.AbstractC2613d;
import o0.C2631b;
import p0.AbstractC2697c;
import p0.C2714u;
import p0.InterfaceC2712s;
import q.AbstractC2761L;
import q.C2769d;
import r0.C2863b;
import r0.InterfaceC2864c;
import r0.InterfaceC2866e;
import x4.AbstractC3252r;
import z.k;
import z.n;
import z.o;
import z.q;

/* JADX INFO: loaded from: classes.dex */
public final class a extends AbstractC2254r implements InterfaceC0297i, InterfaceC0305n, InterfaceC0314x {

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

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

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

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

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

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public D f9014f;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public float f9015j;
    public boolean l;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public d f9018n;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public e f9019o;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public long f9016k = 0;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public final J f9017m = new J();

    public a(k kVar, boolean z6, float f6, C0881a0 c0881a0, Z z7) {
        this.f9009a = kVar;
        this.f9010b = z6;
        this.f9011c = f6;
        this.f9012d = c0881a0;
        this.f9013e = z7;
    }

    @Override // I0.InterfaceC0305n
    public final void draw(InterfaceC2864c interfaceC2864c) throws Throwable {
        o4.f fVar;
        long j4;
        I0.J j6 = (I0.J) interfaceC2864c;
        j6.b();
        D d6 = this.f9014f;
        C2863b c2863b = j6.f2210a;
        if (d6 != null) {
            float f6 = this.f9015j;
            long jA = this.f9012d.a();
            float fFloatValue = ((Number) ((C2769d) d6.f520c).d()).floatValue();
            if (fFloatValue > 0.0f) {
                long jC = C2714u.c(fFloatValue, jA);
                if (d6.f518a) {
                    float fD = o0.e.d(c2863b.c());
                    float fB = o0.e.b(c2863b.c());
                    o4.f fVar2 = c2863b.f23803b;
                    long jF = fVar2.f();
                    fVar2.c().f();
                    try {
                        ((o4.f) ((l2.c) fVar2.f21850c).f20267b).c().o(0.0f, 0.0f, fD, fB, 1);
                        j4 = jF;
                        fVar = fVar2;
                    } catch (Throwable th) {
                        th = th;
                        fVar = fVar2;
                        j4 = jF;
                    }
                    try {
                        InterfaceC2866e.u(j6, jC, f6, 0L, 124);
                        AbstractC2761L.o(fVar, j4);
                    } catch (Throwable th2) {
                        th = th2;
                        AbstractC2761L.o(fVar, j4);
                        throw th;
                    }
                } else {
                    InterfaceC2866e.u(j6, jC, f6, 0L, 124);
                }
            }
        }
        InterfaceC2712s interfaceC2712sC = c2863b.f23803b.c();
        e eVar = this.f9019o;
        if (eVar != null) {
            long j7 = this.f9016k;
            int iD0 = L4.a.d0(this.f9015j);
            long jA2 = this.f9012d.a();
            this.f9013e.invoke();
            eVar.e(iD0, j7, jA2);
            eVar.draw(AbstractC2697c.a(interfaceC2712sC));
        }
    }

    @Override // i0.AbstractC2254r
    public final boolean getShouldAutoInvalidate() {
        return false;
    }

    @Override // I0.InterfaceC0314x
    public final void m(long j4) {
        float fY;
        this.l = true;
        h1.c cVar = AbstractC0303l.t(this).f2155C;
        this.f9016k = W0.e.K(j4);
        float f6 = this.f9011c;
        if (Float.isNaN(f6)) {
            long j6 = this.f9016k;
            float f7 = c.f9020a;
            fY = C2631b.c(AbstractC2613d.a(o0.e.d(j6), o0.e.b(j6))) / 2.0f;
            if (this.f9010b) {
                fY += cVar.Y(c.f9020a);
            }
        } else {
            fY = cVar.Y(f6);
        }
        this.f9015j = fY;
        J j7 = this.f9017m;
        Object[] objArr = j7.f21376a;
        int i6 = j7.f21377b;
        for (int i7 = 0; i7 < i6; i7++) {
            t0((q) objArr[i7]);
        }
        j7.j();
    }

    @Override // i0.AbstractC2254r
    public final void onAttach() {
        E.y(getCoroutineScope(), null, null, new g(this, null), 3);
    }

    @Override // i0.AbstractC2254r
    public final void onDetach() throws Throwable {
        d dVar = this.f9018n;
        if (dVar != null) {
            this.f9019o = null;
            AbstractC0303l.k(this);
            p pVar = dVar.f9024d;
            e eVar = (e) ((LinkedHashMap) pVar.f6345b).get(this);
            if (eVar != null) {
                eVar.c();
                LinkedHashMap linkedHashMap = (LinkedHashMap) pVar.f6345b;
                e eVar2 = (e) linkedHashMap.get(this);
                if (eVar2 != null) {
                }
                linkedHashMap.remove(this);
                dVar.f9023c.add(eVar);
            }
        }
    }

    public final void t0(q qVar) {
        if (!(qVar instanceof o)) {
            if (qVar instanceof z.p) {
                o oVar = ((z.p) qVar).f26253a;
                e eVar = this.f9019o;
                if (eVar != null) {
                    eVar.d();
                    return;
                }
                return;
            }
            if (qVar instanceof n) {
                o oVar2 = ((n) qVar).f26251a;
                e eVar2 = this.f9019o;
                if (eVar2 != null) {
                    eVar2.d();
                    return;
                }
                return;
            }
            return;
        }
        o oVar3 = (o) qVar;
        long j4 = this.f9016k;
        float f6 = this.f9015j;
        d dVar = this.f9018n;
        if (dVar == null) {
            Object obj = (View) AbstractC0303l.h(this, AndroidCompositionLocals_androidKt.f11158f);
            while (!(obj instanceof ViewGroup)) {
                ViewParent parent = ((View) obj).getParent();
                if (!(parent instanceof View)) {
                    throw new IllegalArgumentException(("Couldn't find a valid parent for " + obj + ". Are you overriding LocalView and providing a View that is not attached to the view hierarchy?").toString());
                }
                obj = parent;
            }
            ViewGroup viewGroup = (ViewGroup) obj;
            int childCount = viewGroup.getChildCount();
            int i6 = 0;
            while (true) {
                if (i6 >= childCount) {
                    d dVar2 = new d(viewGroup.getContext());
                    viewGroup.addView(dVar2);
                    dVar = dVar2;
                    break;
                } else {
                    View childAt = viewGroup.getChildAt(i6);
                    if (childAt instanceof d) {
                        dVar = (d) childAt;
                        break;
                    }
                    i6++;
                }
            }
            this.f9018n = dVar;
            kotlin.jvm.internal.o.e(dVar);
        }
        p pVar = dVar.f9024d;
        e eVar3 = (e) ((LinkedHashMap) pVar.f6345b).get(this);
        if (eVar3 == null) {
            ArrayList arrayList = dVar.f9023c;
            kotlin.jvm.internal.o.h(arrayList, "<this>");
            eVar3 = (e) (arrayList.isEmpty() ? null : arrayList.remove(0));
            LinkedHashMap linkedHashMap = (LinkedHashMap) pVar.f6346c;
            LinkedHashMap linkedHashMap2 = (LinkedHashMap) pVar.f6345b;
            if (eVar3 == null) {
                int i7 = dVar.f9025e;
                ArrayList arrayList2 = dVar.f9022b;
                if (i7 > AbstractC3252r.A(arrayList2)) {
                    eVar3 = new e(dVar.getContext());
                    dVar.addView(eVar3);
                    arrayList2.add(eVar3);
                } else {
                    eVar3 = (e) arrayList2.get(dVar.f9025e);
                    a aVar = (a) linkedHashMap.get(eVar3);
                    if (aVar != null) {
                        aVar.f9019o = null;
                        AbstractC0303l.k(aVar);
                        e eVar4 = (e) linkedHashMap2.get(aVar);
                        if (eVar4 != null) {
                        }
                        linkedHashMap2.remove(aVar);
                        eVar3.c();
                    }
                }
                int i8 = dVar.f9025e;
                if (i8 < dVar.f9021a - 1) {
                    dVar.f9025e = i8 + 1;
                } else {
                    dVar.f9025e = 0;
                }
            }
            linkedHashMap2.put(this, eVar3);
            linkedHashMap.put(eVar3, this);
        }
        e eVar5 = eVar3;
        int iD0 = L4.a.d0(f6);
        long jA = this.f9012d.a();
        this.f9013e.invoke();
        eVar5.b(oVar3, this.f9010b, j4, iD0, jA, new C0135f(this, 18));
        this.f9019o = eVar5;
        AbstractC0303l.k(this);
    }
}
