package D;

import B.AbstractC0057e;
import B.H0;
import B.InterfaceC0063h;
import B.InterfaceC0067j;
import B.V;
import F.AbstractC0158l;
import F.C0167v;
import G0.C0;
import G0.InterfaceC0247b0;
import androidx.compose.runtime.snapshots.Snapshot;
import h1.C2069a;
import i0.C2245i;
import i0.C2246j;
import java.util.ArrayList;
import java.util.List;
import n.AbstractC2586m;
import p0.InterfaceC2684B;
import v.AbstractC3058z;
import x.EnumC3207z0;
import x4.AbstractC3250p;
import x4.AbstractC3251q;
import x4.AbstractC3252r;
import x4.C3249o;

/* JADX INFO: loaded from: classes.dex */
public final class u implements F.F {

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

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

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final /* synthetic */ Q4.i f880d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final /* synthetic */ InterfaceC0067j f881e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final /* synthetic */ InterfaceC0063h f882f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final /* synthetic */ V4.C f883g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final /* synthetic */ F.J f884h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public final /* synthetic */ C2245i f885i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final /* synthetic */ C2246j f886j;

    public u(H h5, boolean z6, H0 h0, Q4.i iVar, InterfaceC0067j interfaceC0067j, InterfaceC0063h interfaceC0063h, V4.C c6, InterfaceC2684B interfaceC2684B, F.J j4, C2245i c2245i, C2246j c2246j) {
        this.f877a = h5;
        this.f878b = z6;
        this.f879c = h0;
        this.f880d = iVar;
        this.f881e = interfaceC0067j;
        this.f882f = interfaceC0063h;
        this.f883g = c6;
        this.f884h = j4;
        this.f885i = c2245i;
        this.f886j = c2246j;
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:309:0x06f5  */
    /* JADX WARN: Removed duplicated region for block: B:314:0x0708  */
    /* JADX WARN: Removed duplicated region for block: B:317:0x0717  */
    /* JADX WARN: Removed duplicated region for block: B:318:0x071a  */
    /* JADX WARN: Removed duplicated region for block: B:327:0x075c  */
    /* JADX WARN: Removed duplicated region for block: B:328:0x0761  */
    /* JADX WARN: Removed duplicated region for block: B:330:0x0764  */
    /* JADX WARN: Removed duplicated region for block: B:331:0x0769  */
    /* JADX WARN: Removed duplicated region for block: B:334:0x0770  */
    /* JADX WARN: Removed duplicated region for block: B:336:0x0777  */
    @Override // F.F
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final InterfaceC0247b0 a(F.G g6, long j4) throws Throwable {
        float fA;
        int i6;
        long j6;
        int i7;
        int i8;
        int i9;
        int i10;
        int i11;
        float f6;
        float f7;
        int i12;
        List arrayList;
        int i13;
        int i14;
        ArrayList arrayList2;
        x xVar;
        int i15;
        long j7;
        o oVar;
        int i16;
        Integer numValueOf;
        Integer numValueOf2;
        w wVar;
        C0 c02;
        int i17;
        int i18;
        H h5 = this.f877a;
        h5.f784s.getValue();
        boolean z6 = h5.f768b;
        boolean z7 = true;
        C0 c03 = g6.f1200b;
        boolean z8 = z6 || c03.U();
        boolean z9 = this.f878b;
        AbstractC3058z.k(j4, z9 ? EnumC3207z0.f25984a : EnumC3207z0.f25985b);
        H0 h0 = this.f879c;
        int iG0 = z9 ? c03.g0(h0.b(c03.getLayoutDirection())) : c03.g0(AbstractC0057e.m(h0, c03.getLayoutDirection()));
        int iG02 = z9 ? c03.g0(h0.d(c03.getLayoutDirection())) : c03.g0(AbstractC0057e.l(h0, c03.getLayoutDirection()));
        int iG03 = c03.g0(h0.c());
        int iG04 = c03.g0(h0.a()) + iG03;
        int i19 = iG0 + iG02;
        int i20 = z9 ? iG04 : i19;
        int i21 = z9 ? iG03 : !z9 ? iG0 : iG02;
        int i22 = i20 - i21;
        long jI = h1.b.i(-i19, -iG04, j4);
        o oVar2 = (o) this.f880d.invoke();
        C0134e c0134e = oVar2.f842c;
        int iH = C2069a.h(jI);
        int iG = C2069a.g(jI);
        c0134e.f816a.setIntValue(iH);
        c0134e.f817b.setIntValue(iG);
        InterfaceC0063h interfaceC0063h = this.f882f;
        InterfaceC0067j interfaceC0067j = this.f881e;
        if (z9) {
            if (interfaceC0067j == null) {
                A.b.b("null verticalArrangement when isVertical == true");
                throw new E3.v();
            }
            fA = interfaceC0067j.a();
        } else {
            if (interfaceC0063h == null) {
                A.b.b("null horizontalAlignment when isVertical == false");
                throw new E3.v();
            }
            fA = interfaceC0063h.a();
        }
        int iG05 = c03.g0(fA);
        int i23 = oVar2.f841b.n().f1279b;
        int iG2 = z9 ? C2069a.g(j4) - iG04 : C2069a.h(j4) - i19;
        int i24 = i21;
        t tVar = new t(jI, this.f878b, oVar2, g6, i23, iG05, this.f885i, this.f886j, i24, i22, (((long) iG0) << 32) | (((long) iG03) & 4294967295L), this.f877a);
        Snapshot.Companion companion = Snapshot.Companion;
        Snapshot currentThreadSnapshot = companion.getCurrentThreadSnapshot();
        J4.c readObserver = currentThreadSnapshot != null ? currentThreadSnapshot.getReadObserver() : null;
        Snapshot snapshotMakeCurrentNonObservable = companion.makeCurrentNonObservable(currentThreadSnapshot);
        try {
            int iG3 = h5.g();
            B b5 = h5.f771e;
            int iL = AbstractC0158l.l(oVar2, b5.f750e, iG3);
            if (iG3 != iL) {
                i6 = i22;
                b5.f747b.setIntValue(iL);
                b5.f751f.b(iG3);
            } else {
                i6 = i22;
            }
            int iH2 = h5.h();
            companion.restoreNonObservable(currentThreadSnapshot, snapshotMakeCurrentNonObservable, readObserver);
            List listJ = AbstractC0158l.j(oVar2, h5.f783r, h5.f780o);
            float fFloatValue = (c03.U() || !z8) ? h5.f774h : ((Number) h5.f788w.f1229b.f23390b.getValue()).floatValue();
            boolean zU = c03.U();
            if (i24 < 0) {
                A.b.a("invalid beforeContentPadding");
            }
            if (i6 < 0) {
                A.b.a("invalid afterContentPadding");
            }
            x4.y yVar = x4.y.f26065a;
            x4.z zVar = x4.z.f26066a;
            C0167v c0167v = h5.f779n;
            o oVar3 = tVar.f865b;
            int i25 = i23;
            V4.C c6 = this.f883g;
            if (i25 <= 0) {
                int iJ = C2069a.j(jI);
                int i26 = C2069a.i(jI);
                c0167v.c(iJ, i26, new ArrayList(), oVar3.f843d, tVar, zU, 1, z8, 0, 0);
                if (!zU) {
                    c0167v.b();
                    if (!h1.l.a(0L, 0L)) {
                        iJ = h1.b.g((int) 0, jI);
                        i26 = h1.b.f((int) 0, jI);
                    }
                }
                c02 = c03;
                wVar = new w(null, 0, false, 0.0f, c03.e(h1.b.g(iJ + i19, j4), h1.b.f(i26 + iG04, j4), zVar, new q.H0(8)), 0.0f, false, c6, g6, tVar.f867d, yVar, -i24, iG2 + i6, 0, z9 ? EnumC3207z0.f25984a : EnumC3207z0.f25985b, i6, iG05);
            } else {
                float f8 = fFloatValue;
                int i27 = iH2;
                int i28 = iG2;
                int i29 = i6;
                if (iL >= i25) {
                    iL = i25 - 1;
                    i27 = 0;
                }
                int iRound = Math.round(f8);
                int i30 = i27 - iRound;
                if (iL == 0 && i30 < 0) {
                    iRound += i30;
                    i30 = 0;
                }
                C3249o c3249o = new C3249o();
                int i31 = -i24;
                int i32 = iL;
                int i33 = i31 + (iG05 < 0 ? iG05 : 0);
                int i34 = i30 + i33;
                int iMax = 0;
                while (true) {
                    j6 = tVar.f867d;
                    if (i34 >= 0 || i32 <= 0) {
                        break;
                    }
                    H h6 = h5;
                    int i35 = i32 - 1;
                    x xVarN = tVar.n(i35, j6);
                    c3249o.add(0, xVarN);
                    iMax = Math.max(iMax, xVarN.f920o);
                    i34 += xVarN.f919n;
                    i32 = i35;
                    h5 = h6;
                }
                H h7 = h5;
                if (i34 < i33) {
                    iRound -= i33 - i34;
                    i34 = i33;
                }
                int i36 = iRound;
                int i37 = i34 - i33;
                int i38 = i28 + i29;
                int i39 = i38 >= 0 ? i38 : 0;
                int i40 = iMax;
                int i41 = i32;
                boolean z10 = false;
                int i42 = -i37;
                int i43 = 0;
                while (i43 < c3249o.size()) {
                    if (i42 >= i39) {
                        c3249o.remove(i43);
                        z10 = true;
                    } else {
                        i41++;
                        i42 += ((x) c3249o.get(i43)).f919n;
                        i43++;
                    }
                }
                int iMax2 = i40;
                int i44 = i37;
                boolean z11 = z10;
                int i45 = i41;
                while (i45 < i25 && (i42 < i39 || i42 <= 0 || c3249o.isEmpty())) {
                    int i46 = i39;
                    x xVarN2 = tVar.n(i45, j6);
                    int i47 = i25;
                    int i48 = xVarN2.f919n;
                    i42 += i48;
                    if (i42 <= i33) {
                        i18 = i33;
                        if (i45 != i47 - 1) {
                            i32 = i45 + 1;
                            i44 -= i48;
                            z11 = true;
                        }
                        i45++;
                        i39 = i46;
                        i25 = i47;
                        i33 = i18;
                    } else {
                        i18 = i33;
                    }
                    iMax2 = Math.max(iMax2, xVarN2.f920o);
                    c3249o.addLast(xVarN2);
                    i45++;
                    i39 = i46;
                    i25 = i47;
                    i33 = i18;
                }
                int i49 = i25;
                if (i42 < i28) {
                    int i50 = i28 - i42;
                    i42 += i50;
                    int i51 = i44 - i50;
                    while (i51 < i24 && i32 > 0) {
                        int i52 = i32 - 1;
                        int i53 = i50;
                        x xVarN3 = tVar.n(i52, j6);
                        c3249o.add(0, xVarN3);
                        iMax2 = Math.max(iMax2, xVarN3.f920o);
                        i51 += xVarN3.f919n;
                        i32 = i52;
                        i50 = i53;
                    }
                    int i54 = i50;
                    int i55 = i51;
                    i7 = i36;
                    int i56 = i7 + i54;
                    if (i55 < 0) {
                        i42 += i55;
                        i9 = i32;
                        i10 = i56 + i55;
                        i8 = 0;
                    } else {
                        i8 = i55;
                        i9 = i32;
                        i10 = i56;
                    }
                } else {
                    i7 = i36;
                    i8 = i44;
                    i9 = i32;
                    i10 = i7;
                }
                int i57 = iMax2;
                int i58 = i45;
                if (Integer.signum(Math.round(f8)) != Integer.signum(i10) || Math.abs(Math.round(f8)) < Math.abs(i10)) {
                    i11 = i10;
                    f6 = f8;
                } else {
                    i11 = i10;
                    f6 = i11;
                }
                float f9 = f8 - f6;
                float f10 = 0.0f;
                if (zU && i11 > i7 && f9 <= 0.0f) {
                    f10 = (i11 - i7) + f9;
                }
                float f11 = f10;
                if (i8 < 0) {
                    A.b.a("negative currentFirstItemScrollOffset");
                }
                int i59 = -i8;
                x xVar2 = (x) c3249o.first();
                if (i24 > 0 || iG05 < 0) {
                    f7 = f11;
                    int size = c3249o.size();
                    x xVar3 = xVar2;
                    int i60 = 0;
                    while (i60 < size) {
                        int i61 = size;
                        int i62 = ((x) c3249o.get(i60)).f919n;
                        if (i8 == 0 || i62 > i8 || i60 == AbstractC3252r.A(c3249o)) {
                            break;
                        }
                        i8 -= i62;
                        i60++;
                        xVar3 = (x) c3249o.get(i60);
                        size = i61;
                    }
                    xVar2 = xVar3;
                } else {
                    f7 = f11;
                }
                int i63 = i8;
                x xVar4 = xVar2;
                int iMax3 = Math.max(0, i9);
                int i64 = i9 - 1;
                if (iMax3 <= i64) {
                    arrayList = null;
                    while (true) {
                        if (arrayList == null) {
                            arrayList = new ArrayList();
                        }
                        i12 = i59;
                        arrayList.add(tVar.n(i64, j6));
                        if (i64 == iMax3) {
                            break;
                        }
                        i64--;
                        i59 = i12;
                    }
                } else {
                    i12 = i59;
                    arrayList = null;
                }
                int size2 = listJ.size() - 1;
                if (size2 >= 0) {
                    while (true) {
                        int i65 = size2 - 1;
                        int iIntValue = ((Number) listJ.get(size2)).intValue();
                        if (iIntValue < iMax3) {
                            if (arrayList == null) {
                                arrayList = new ArrayList();
                            }
                            arrayList.add(tVar.n(iIntValue, j6));
                        }
                        if (i65 < 0) {
                            break;
                        }
                        size2 = i65;
                    }
                }
                if (arrayList == null) {
                    arrayList = yVar;
                }
                int iMax4 = i57;
                int i66 = 0;
                for (int size3 = arrayList.size(); i66 < size3; size3 = size3) {
                    iMax4 = Math.max(iMax4, ((x) arrayList.get(i66)).f920o);
                    i66++;
                }
                int iMin = Math.min(((x) AbstractC3251q.n0(c3249o)).f907a, i49 - 1);
                int i67 = ((x) AbstractC3251q.n0(c3249o)).f907a + 1;
                if (i67 <= iMin) {
                    ArrayList arrayList3 = null;
                    while (true) {
                        if (arrayList3 == null) {
                            arrayList3 = new ArrayList();
                        }
                        i13 = iMax4;
                        i14 = i24;
                        arrayList2 = arrayList3;
                        arrayList2.add(tVar.n(i67, j6));
                        if (i67 == iMin) {
                            break;
                        }
                        i67++;
                        arrayList3 = arrayList2;
                        iMax4 = i13;
                        i24 = i14;
                    }
                } else {
                    i13 = iMax4;
                    i14 = i24;
                    arrayList2 = null;
                }
                if (arrayList2 != null && ((x) AbstractC3251q.n0(arrayList2)).f907a > iMin) {
                    iMin = ((x) AbstractC3251q.n0(arrayList2)).f907a;
                }
                int size4 = listJ.size();
                List arrayList4 = arrayList2;
                int i68 = 0;
                while (i68 < size4) {
                    int i69 = i68;
                    int iIntValue2 = ((Number) listJ.get(i68)).intValue();
                    if (iIntValue2 > iMin) {
                        if (arrayList4 == null) {
                            arrayList4 = new ArrayList();
                        }
                        arrayList4.add(tVar.n(iIntValue2, j6));
                    }
                    i68 = i69 + 1;
                }
                if (arrayList4 == null) {
                    arrayList4 = yVar;
                }
                int size5 = arrayList4.size();
                int iMax5 = i13;
                for (int i70 = 0; i70 < size5; i70++) {
                    iMax5 = Math.max(iMax5, ((x) arrayList4.get(i70)).f920o);
                }
                boolean z12 = kotlin.jvm.internal.o.c(xVar4, c3249o.first()) && arrayList.isEmpty() && arrayList4.isEmpty();
                int iG4 = h1.b.g(z9 ? iMax5 : i42, jI);
                if (z9) {
                    iMax5 = i42;
                }
                int iF = h1.b.f(iMax5, jI);
                int i71 = z9 ? iF : iG4;
                boolean z13 = i42 < Math.min(i71, i28);
                if (z13 && i12 != 0) {
                    A.b.c("non-zero itemsScrollOffset");
                }
                boolean z14 = z12;
                ArrayList arrayList5 = new ArrayList(arrayList4.size() + arrayList.size() + c3249o.size());
                if (z13) {
                    if (!arrayList.isEmpty() || !arrayList4.isEmpty()) {
                        A.b.a("no extra items");
                    }
                    int size6 = c3249o.size();
                    int[] iArr = new int[size6];
                    for (int i72 = 0; i72 < size6; i72++) {
                        iArr[i72] = ((x) c3249o.get(i72)).f918m;
                    }
                    int[] iArr2 = new int[size6];
                    if (z9) {
                        if (interfaceC0067j == null) {
                            A.b.b("null verticalArrangement when isVertical == true");
                            throw new E3.v();
                        }
                        interfaceC0067j.b(g6, i71, iArr, iArr2);
                        xVar = xVar4;
                        i17 = i28;
                        i15 = i49;
                        j7 = jI;
                        oVar = oVar3;
                        i16 = i58;
                    } else {
                        if (interfaceC0063h == null) {
                            A.b.b("null horizontalArrangement when isVertical == false");
                            throw new E3.v();
                        }
                        xVar = xVar4;
                        i17 = i28;
                        i15 = i49;
                        j7 = jI;
                        oVar = oVar3;
                        i16 = i58;
                        interfaceC0063h.c(g6, i71, iArr, h1.m.f16628a, iArr2);
                    }
                    P4.g gVarM = AbstractC3250p.M(iArr2);
                    int i73 = gVarM.f5676a;
                    int i74 = gVarM.f5677b;
                    int i75 = gVarM.f5678c;
                    if ((i75 > 0 && i73 <= i74) || (i75 < 0 && i74 <= i73)) {
                        while (true) {
                            int i76 = iArr2[i73];
                            x xVar5 = (x) c3249o.get(i73);
                            xVar5.k(i76, iG4, iF);
                            arrayList5.add(xVar5);
                            if (i73 == i74) {
                                break;
                            }
                            i73 += i75;
                        }
                    }
                    i28 = i17;
                } else {
                    xVar = xVar4;
                    i15 = i49;
                    j7 = jI;
                    oVar = oVar3;
                    i16 = i58;
                    int i77 = i12;
                    int i78 = 0;
                    for (int size7 = arrayList.size(); i78 < size7; size7 = size7) {
                        x xVar6 = (x) arrayList.get(i78);
                        i77 -= xVar6.f919n;
                        xVar6.k(i77, iG4, iF);
                        arrayList5.add(xVar6);
                        i78++;
                    }
                    int size8 = c3249o.size();
                    int i79 = i12;
                    for (int i80 = 0; i80 < size8; i80++) {
                        x xVar7 = (x) c3249o.get(i80);
                        xVar7.k(i79, iG4, iF);
                        arrayList5.add(xVar7);
                        i79 += xVar7.f919n;
                    }
                    int size9 = arrayList4.size();
                    for (int i81 = 0; i81 < size9; i81++) {
                        x xVar8 = (x) arrayList4.get(i81);
                        xVar8.k(i79, iG4, iF);
                        arrayList5.add(xVar8);
                        i79 += xVar8.f919n;
                    }
                }
                c0167v.c(iG4, iF, arrayList5, oVar.f843d, tVar, zU, 1, z8, i63, i42);
                if (!zU) {
                    c0167v.b();
                    if (!h1.l.a(0L, 0L)) {
                        int i82 = z9 ? iF : iG4;
                        long j8 = j7;
                        iG4 = h1.b.g(Math.max(iG4, (int) 0), j8);
                        iF = h1.b.f(Math.max(iF, (int) 0), j8);
                        int i83 = z9 ? iF : iG4;
                        if (i83 != i82) {
                            int size10 = arrayList5.size();
                            for (int i84 = 0; i84 < size10; i84++) {
                                ((x) arrayList5.get(i84)).f922q = i83;
                            }
                        }
                    }
                }
                int i85 = iF;
                x xVar9 = (x) c3249o.j();
                int i86 = xVar9 != null ? xVar9.f907a : 0;
                x xVar10 = (x) c3249o.l();
                int i87 = xVar10 != null ? xVar10.f907a : 0;
                oVar.f841b.getClass();
                int i88 = i14;
                int i89 = iG4;
                List listI = AbstractC0158l.i(this.f884h, i86, i87, arrayList5, AbstractC2586m.f21455a, i88, i89, i85, new V(tVar, 3));
                if (z14) {
                    x xVar11 = (x) AbstractC3251q.g0(arrayList5);
                    numValueOf = xVar11 != null ? Integer.valueOf(xVar11.f907a) : null;
                    if (z14) {
                        x xVar12 = (x) c3249o.l();
                        if (xVar12 != null) {
                            numValueOf2 = Integer.valueOf(xVar12.f907a);
                        }
                        if (i16 >= i15) {
                            z7 = false;
                        }
                        int i90 = i15;
                        c02 = c03;
                        h5 = h7;
                        wVar = new w(xVar, i63, z7, f6, c03.e(h1.b.g(i89 + i19, j4), h1.b.f(i85 + iG04, j4), zVar, new v(h7.f787v, arrayList5, listI, zU, 0)), f7, z11, c6, g6, tVar.f867d, AbstractC0158l.r(numValueOf == null ? numValueOf.intValue() : 0, numValueOf2 == null ? numValueOf2.intValue() : 0, arrayList5, listI), i31, i38, i90, !z9 ? EnumC3207z0.f25984a : EnumC3207z0.f25985b, i29, iG05);
                    } else {
                        x xVar13 = (x) AbstractC3251q.o0(arrayList5);
                        numValueOf2 = xVar13 != null ? Integer.valueOf(xVar13.f907a) : null;
                        if (i16 >= i15 && i42 <= i28) {
                            z7 = false;
                        }
                        int i902 = i15;
                        c02 = c03;
                        h5 = h7;
                        wVar = new w(xVar, i63, z7, f6, c03.e(h1.b.g(i89 + i19, j4), h1.b.f(i85 + iG04, j4), zVar, new v(h7.f787v, arrayList5, listI, zU, 0)), f7, z11, c6, g6, tVar.f867d, AbstractC0158l.r(numValueOf == null ? numValueOf.intValue() : 0, numValueOf2 == null ? numValueOf2.intValue() : 0, arrayList5, listI), i31, i38, i902, !z9 ? EnumC3207z0.f25984a : EnumC3207z0.f25985b, i29, iG05);
                    }
                } else {
                    x xVar14 = (x) c3249o.j();
                    if (xVar14 != null) {
                        numValueOf = Integer.valueOf(xVar14.f907a);
                    }
                    if (z14) {
                    }
                }
            }
            h5.f(wVar, c02.U(), false);
            C0130a c0130a = h5.f767a;
            return wVar;
        } catch (Throwable th) {
            companion.restoreNonObservable(currentThreadSnapshot, snapshotMakeCurrentNonObservable, readObserver);
            throw th;
        }
    }
}
