package w;

import d5.AbstractC0844a;
import java.util.ArrayList;

/* JADX INFO: renamed from: w.c, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C1685c extends AbstractC1694l {

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

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public int f18137l;

    public C1685c(v.d dVar, int i) {
        v.d dVar2;
        super(dVar);
        this.f18136k = new ArrayList();
        this.f18160f = i;
        v.d dVar3 = this.f18156b;
        v.d dVarK = dVar3.k(i);
        while (true) {
            v.d dVar4 = dVarK;
            dVar2 = dVar3;
            dVar3 = dVar4;
            if (dVar3 == null) {
                break;
            } else {
                dVarK = dVar3.k(this.f18160f);
            }
        }
        this.f18156b = dVar2;
        int i5 = this.f18160f;
        AbstractC1694l abstractC1694l = i5 == 0 ? dVar2.f17903d : i5 == 1 ? dVar2.f17904e : null;
        ArrayList arrayList = this.f18136k;
        arrayList.add(abstractC1694l);
        v.d dVarJ = dVar2.j(this.f18160f);
        while (dVarJ != null) {
            int i8 = this.f18160f;
            arrayList.add(i8 == 0 ? dVarJ.f17903d : i8 == 1 ? dVarJ.f17904e : null);
            dVarJ = dVarJ.j(this.f18160f);
        }
        int size = arrayList.size();
        int i9 = 0;
        while (i9 < size) {
            Object obj = arrayList.get(i9);
            i9++;
            AbstractC1694l abstractC1694l2 = (AbstractC1694l) obj;
            int i10 = this.f18160f;
            if (i10 == 0) {
                abstractC1694l2.f18156b.f17899b = this;
            } else if (i10 == 1) {
                abstractC1694l2.f18156b.f17901c = this;
            }
        }
        if (this.f18160f == 0 && ((v.e) this.f18156b.f17880I).f17929h0 && arrayList.size() > 1) {
            this.f18156b = ((AbstractC1694l) arrayList.get(arrayList.size() - 1)).f18156b;
        }
        this.f18137l = this.f18160f == 0 ? this.f18156b.X : this.f18156b.f17895Y;
    }

    /* JADX WARN: Removed duplicated region for block: B:121:0x01c1 A[PHI: r1 r26
      0x01c1: PHI (r1v57 int) = (r1v55 int), (r1v60 int) binds: [B:120:0x01bf, B:111:0x019f] A[DONT_GENERATE, DONT_INLINE]
      0x01c1: PHI (r26v1 int) = (r26v0 int), (r26v3 int) binds: [B:120:0x01bf, B:111:0x019f] A[DONT_GENERATE, DONT_INLINE]] */
    /* JADX WARN: Removed duplicated region for block: B:64:0x00d0  */
    /* JADX WARN: Removed duplicated region for block: B:67:0x00df  */
    /* JADX WARN: Removed duplicated region for block: B:93:0x0154  */
    @Override // w.InterfaceC1686d
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void a(InterfaceC1686d interfaceC1686d) {
        int i;
        int i5;
        boolean z8;
        float f3;
        int i8;
        int i9;
        int i10;
        int i11;
        float f7;
        int i12;
        int i13;
        int i14;
        int i15;
        int i16;
        int iMax;
        int i17;
        boolean z9;
        int i18;
        C1687e c1687e = this.f18162h;
        if (c1687e.f18146j) {
            C1687e c1687e2 = this.i;
            if (c1687e2.f18146j) {
                v.d dVar = this.f18156b.f17880I;
                boolean z10 = (dVar == null || !(dVar instanceof v.e)) ? false : ((v.e) dVar).f17929h0;
                int i19 = c1687e2.f18144g - c1687e.f18144g;
                ArrayList arrayList = this.f18136k;
                int size = arrayList.size();
                int i20 = 0;
                while (true) {
                    i = -1;
                    i5 = 8;
                    if (i20 >= size) {
                        i20 = -1;
                        break;
                    } else if (((AbstractC1694l) arrayList.get(i20)).f18156b.f17893V != 8) {
                        break;
                    } else {
                        i20++;
                    }
                }
                int i21 = size - 1;
                int i22 = i21;
                while (true) {
                    if (i22 < 0) {
                        break;
                    }
                    if (((AbstractC1694l) arrayList.get(i22)).f18156b.f17893V != 8) {
                        i = i22;
                        break;
                    }
                    i22--;
                }
                int i23 = 0;
                while (i23 < 2) {
                    f3 = 0.0f;
                    int i24 = 0;
                    i10 = 0;
                    int i25 = 0;
                    int i26 = 0;
                    while (i24 < size) {
                        AbstractC1694l abstractC1694l = (AbstractC1694l) arrayList.get(i24);
                        v.d dVar2 = abstractC1694l.f18156b;
                        boolean z11 = z10;
                        if (dVar2.f17893V == i5) {
                            i17 = i23;
                        } else {
                            i26++;
                            if (i24 > 0 && i24 >= i20) {
                                i10 += abstractC1694l.f18162h.f18143f;
                            }
                            C1688f c1688f = abstractC1694l.f18159e;
                            int i27 = c1688f.f18144g;
                            i17 = i23;
                            boolean z12 = abstractC1694l.f18158d != 3;
                            if (z12) {
                                int i28 = this.f18160f;
                                if (i28 == 0 && !dVar2.f17903d.f18159e.f18146j) {
                                    return;
                                }
                                if (i28 == 1 && !dVar2.f17904e.f18159e.f18146j) {
                                    return;
                                } else {
                                    z9 = z12;
                                }
                            } else {
                                z9 = z12;
                                if (abstractC1694l.f18155a == 1 && i17 == 0) {
                                    i18 = c1688f.f18149m;
                                    i25++;
                                } else if (c1688f.f18146j) {
                                    i18 = i27;
                                }
                                z9 = true;
                                if (z9) {
                                    i25++;
                                    float f8 = dVar2.f17896Z[this.f18160f];
                                    if (f8 >= 0.0f) {
                                        f3 += f8;
                                    }
                                } else {
                                    i10 += i18;
                                }
                                if (i24 >= i21 && i24 < i) {
                                    i10 += -abstractC1694l.i.f18143f;
                                }
                            }
                            i18 = i27;
                            if (z9) {
                            }
                            if (i24 >= i21) {
                            }
                        }
                        i24++;
                        z10 = z11;
                        i23 = i17;
                        i5 = 8;
                    }
                    z8 = z10;
                    int i29 = i23;
                    if (i10 < i19 || i25 == 0) {
                        i8 = i25;
                        i9 = i26;
                        break;
                    } else {
                        i23 = i29 + 1;
                        z10 = z8;
                        i5 = 8;
                    }
                }
                z8 = z10;
                f3 = 0.0f;
                i8 = 0;
                i9 = 0;
                i10 = 0;
                int i30 = c1687e.f18144g;
                if (z8) {
                    i30 = c1687e2.f18144g;
                }
                float f9 = 0.5f;
                if (i10 > i19) {
                    i30 = z8 ? i30 + ((int) (((i10 - i19) / 2.0f) + 0.5f)) : i30 - ((int) (((i10 - i19) / 2.0f) + 0.5f));
                }
                if (i8 > 0) {
                    float f10 = i19 - i10;
                    int i31 = (int) ((f10 / i8) + 0.5f);
                    int i32 = 0;
                    int i33 = 0;
                    while (i32 < size) {
                        float f11 = f9;
                        AbstractC1694l abstractC1694l2 = (AbstractC1694l) arrayList.get(i32);
                        int i34 = i30;
                        v.d dVar3 = abstractC1694l2.f18156b;
                        int i35 = i8;
                        float f12 = f10;
                        if (dVar3.f17893V != 8 && abstractC1694l2.f18158d == 3) {
                            C1688f c1688f2 = abstractC1694l2.f18159e;
                            if (c1688f2.f18146j) {
                                i15 = i31;
                                i16 = i32;
                            } else {
                                if (f3 > 0.0f) {
                                    i14 = (int) (((dVar3.f17896Z[this.f18160f] * f12) / f3) + f11);
                                    i15 = i31;
                                } else {
                                    i14 = i31;
                                    i15 = i14;
                                }
                                if (this.f18160f == 0) {
                                    int i36 = dVar3.f17912n;
                                    i16 = i32;
                                    iMax = Math.max(dVar3.f17911m, abstractC1694l2.f18155a == 1 ? Math.min(i14, c1688f2.f18149m) : i14);
                                    if (i36 > 0) {
                                        iMax = Math.min(i36, iMax);
                                    }
                                    if (iMax != i14) {
                                        i33++;
                                        i14 = iMax;
                                    }
                                    c1688f2.d(i14);
                                } else {
                                    i16 = i32;
                                    int i37 = dVar3.f17915q;
                                    iMax = Math.max(dVar3.f17914p, abstractC1694l2.f18155a == 1 ? Math.min(i14, c1688f2.f18149m) : i14);
                                    if (i37 > 0) {
                                        iMax = Math.min(i37, iMax);
                                    }
                                    if (iMax != i14) {
                                    }
                                    c1688f2.d(i14);
                                }
                            }
                        }
                        i32 = i16 + 1;
                        i30 = i34;
                        f9 = f11;
                        i8 = i35;
                        f10 = f12;
                        i31 = i15;
                    }
                    i11 = i30;
                    f7 = f9;
                    int i38 = i8;
                    if (i33 > 0) {
                        i8 = i38 - i33;
                        i10 = 0;
                        for (int i39 = 0; i39 < size; i39++) {
                            AbstractC1694l abstractC1694l3 = (AbstractC1694l) arrayList.get(i39);
                            if (abstractC1694l3.f18156b.f17893V != 8) {
                                if (i39 > 0 && i39 >= i20) {
                                    i10 += abstractC1694l3.f18162h.f18143f;
                                }
                                i10 += abstractC1694l3.f18159e.f18144g;
                                if (i39 < i21 && i39 < i) {
                                    i10 += -abstractC1694l3.i.f18143f;
                                }
                            }
                        }
                    } else {
                        i8 = i38;
                    }
                    i13 = 2;
                    if (this.f18137l == 2 && i33 == 0) {
                        i12 = 0;
                        this.f18137l = 0;
                    } else {
                        i12 = 0;
                    }
                } else {
                    i11 = i30;
                    f7 = 0.5f;
                    i12 = 0;
                    i13 = 2;
                }
                if (i10 > i19) {
                    this.f18137l = i13;
                }
                if (i9 > 0 && i8 == 0 && i20 == i) {
                    this.f18137l = i13;
                }
                int i40 = this.f18137l;
                if (i40 == 1) {
                    int i41 = i9 > 1 ? (i19 - i10) / (i9 - 1) : i9 == 1 ? (i19 - i10) / 2 : i12;
                    if (i8 > 0) {
                        i41 = i12;
                    }
                    int i42 = i11;
                    for (int i43 = i12; i43 < size; i43++) {
                        AbstractC1694l abstractC1694l4 = (AbstractC1694l) arrayList.get(z8 ? size - (i43 + 1) : i43);
                        int i44 = abstractC1694l4.f18156b.f17893V;
                        C1687e c1687e3 = abstractC1694l4.i;
                        C1687e c1687e4 = abstractC1694l4.f18162h;
                        if (i44 == 8) {
                            c1687e4.d(i42);
                            c1687e3.d(i42);
                        } else {
                            if (i43 > 0) {
                                i42 = z8 ? i42 - i41 : i42 + i41;
                            }
                            if (i43 > 0 && i43 >= i20) {
                                i42 = z8 ? i42 - c1687e4.f18143f : i42 + c1687e4.f18143f;
                            }
                            if (z8) {
                                c1687e3.d(i42);
                            } else {
                                c1687e4.d(i42);
                            }
                            C1688f c1688f3 = abstractC1694l4.f18159e;
                            int i45 = c1688f3.f18144g;
                            if (abstractC1694l4.f18158d == 3 && abstractC1694l4.f18155a == 1) {
                                i45 = c1688f3.f18149m;
                            }
                            i42 = z8 ? i42 - i45 : i42 + i45;
                            if (z8) {
                                c1687e4.d(i42);
                            } else {
                                c1687e3.d(i42);
                            }
                            abstractC1694l4.f18161g = true;
                            if (i43 < i21 && i43 < i) {
                                i42 = z8 ? i42 - (-c1687e3.f18143f) : i42 + (-c1687e3.f18143f);
                            }
                        }
                    }
                    return;
                }
                if (i40 == 0) {
                    int i46 = (i19 - i10) / (i9 + 1);
                    if (i8 > 0) {
                        i46 = i12;
                    }
                    int i47 = i11;
                    for (int i48 = i12; i48 < size; i48++) {
                        AbstractC1694l abstractC1694l5 = (AbstractC1694l) arrayList.get(z8 ? size - (i48 + 1) : i48);
                        int i49 = abstractC1694l5.f18156b.f17893V;
                        C1687e c1687e5 = abstractC1694l5.i;
                        C1687e c1687e6 = abstractC1694l5.f18162h;
                        if (i49 == 8) {
                            c1687e6.d(i47);
                            c1687e5.d(i47);
                        } else {
                            int i50 = z8 ? i47 - i46 : i47 + i46;
                            if (i48 > 0 && i48 >= i20) {
                                i50 = z8 ? i50 - c1687e6.f18143f : i50 + c1687e6.f18143f;
                            }
                            if (z8) {
                                c1687e5.d(i50);
                            } else {
                                c1687e6.d(i50);
                            }
                            C1688f c1688f4 = abstractC1694l5.f18159e;
                            int iMin = c1688f4.f18144g;
                            if (abstractC1694l5.f18158d == 3 && abstractC1694l5.f18155a == 1) {
                                iMin = Math.min(iMin, c1688f4.f18149m);
                            }
                            i47 = z8 ? i50 - iMin : i50 + iMin;
                            if (z8) {
                                c1687e6.d(i47);
                            } else {
                                c1687e5.d(i47);
                            }
                            if (i48 < i21 && i48 < i) {
                                i47 = z8 ? i47 - (-c1687e5.f18143f) : i47 + (-c1687e5.f18143f);
                            }
                        }
                    }
                    return;
                }
                if (i40 == 2) {
                    float f13 = this.f18160f == 0 ? this.f18156b.f17890S : this.f18156b.f17891T;
                    if (z8) {
                        f13 = 1.0f - f13;
                    }
                    int i51 = (int) (((i19 - i10) * f13) + f7);
                    if (i51 < 0 || i8 > 0) {
                        i51 = i12;
                    }
                    int i52 = z8 ? i11 - i51 : i11 + i51;
                    for (int i53 = i12; i53 < size; i53++) {
                        AbstractC1694l abstractC1694l6 = (AbstractC1694l) arrayList.get(z8 ? size - (i53 + 1) : i53);
                        int i54 = abstractC1694l6.f18156b.f17893V;
                        C1687e c1687e7 = abstractC1694l6.i;
                        C1687e c1687e8 = abstractC1694l6.f18162h;
                        if (i54 == 8) {
                            c1687e8.d(i52);
                            c1687e7.d(i52);
                        } else {
                            if (i53 > 0 && i53 >= i20) {
                                i52 = z8 ? i52 - c1687e8.f18143f : i52 + c1687e8.f18143f;
                            }
                            if (z8) {
                                c1687e7.d(i52);
                            } else {
                                c1687e8.d(i52);
                            }
                            C1688f c1688f5 = abstractC1694l6.f18159e;
                            int i55 = c1688f5.f18144g;
                            if (abstractC1694l6.f18158d == 3 && abstractC1694l6.f18155a == 1) {
                                i55 = c1688f5.f18149m;
                            }
                            i52 = z8 ? i52 - i55 : i52 + i55;
                            if (z8) {
                                c1687e8.d(i52);
                            } else {
                                c1687e7.d(i52);
                            }
                            if (i53 < i21 && i53 < i) {
                                i52 = z8 ? i52 - (-c1687e7.f18143f) : i52 + (-c1687e7.f18143f);
                            }
                        }
                    }
                }
            }
        }
    }

    @Override // w.AbstractC1694l
    public final void d() {
        ArrayList arrayList = this.f18136k;
        int size = arrayList.size();
        int i = 0;
        while (i < size) {
            Object obj = arrayList.get(i);
            i++;
            ((AbstractC1694l) obj).d();
        }
        int size2 = arrayList.size();
        if (size2 < 1) {
            return;
        }
        v.d dVar = ((AbstractC1694l) arrayList.get(0)).f18156b;
        v.d dVar2 = ((AbstractC1694l) arrayList.get(size2 - 1)).f18156b;
        int i5 = this.f18160f;
        C1687e c1687e = this.i;
        C1687e c1687e2 = this.f18162h;
        if (i5 == 0) {
            v.c cVar = dVar.f17922x;
            v.c cVar2 = dVar2.f17924z;
            C1687e c1687eI = AbstractC1694l.i(cVar, 0);
            int iC = cVar.c();
            v.d dVarM = m();
            if (dVarM != null) {
                iC = dVarM.f17922x.c();
            }
            if (c1687eI != null) {
                AbstractC1694l.b(c1687e2, c1687eI, iC);
            }
            C1687e c1687eI2 = AbstractC1694l.i(cVar2, 0);
            int iC2 = cVar2.c();
            v.d dVarN = n();
            if (dVarN != null) {
                iC2 = dVarN.f17924z.c();
            }
            if (c1687eI2 != null) {
                AbstractC1694l.b(c1687e, c1687eI2, -iC2);
            }
        } else {
            v.c cVar3 = dVar.f17923y;
            v.c cVar4 = dVar2.f17874A;
            C1687e c1687eI3 = AbstractC1694l.i(cVar3, 1);
            int iC3 = cVar3.c();
            v.d dVarM2 = m();
            if (dVarM2 != null) {
                iC3 = dVarM2.f17923y.c();
            }
            if (c1687eI3 != null) {
                AbstractC1694l.b(c1687e2, c1687eI3, iC3);
            }
            C1687e c1687eI4 = AbstractC1694l.i(cVar4, 1);
            int iC4 = cVar4.c();
            v.d dVarN2 = n();
            if (dVarN2 != null) {
                iC4 = dVarN2.f17874A.c();
            }
            if (c1687eI4 != null) {
                AbstractC1694l.b(c1687e, c1687eI4, -iC4);
            }
        }
        c1687e2.f18138a = this;
        c1687e.f18138a = this;
    }

    @Override // w.AbstractC1694l
    public final void e() {
        int i = 0;
        while (true) {
            ArrayList arrayList = this.f18136k;
            if (i >= arrayList.size()) {
                return;
            }
            ((AbstractC1694l) arrayList.get(i)).e();
            i++;
        }
    }

    @Override // w.AbstractC1694l
    public final void f() {
        this.f18157c = null;
        ArrayList arrayList = this.f18136k;
        int size = arrayList.size();
        int i = 0;
        while (i < size) {
            Object obj = arrayList.get(i);
            i++;
            ((AbstractC1694l) obj).f();
        }
    }

    @Override // w.AbstractC1694l
    public final long j() {
        ArrayList arrayList = this.f18136k;
        int size = arrayList.size();
        long j8 = 0;
        for (int i = 0; i < size; i++) {
            AbstractC1694l abstractC1694l = (AbstractC1694l) arrayList.get(i);
            j8 = ((long) abstractC1694l.i.f18143f) + abstractC1694l.j() + j8 + ((long) abstractC1694l.f18162h.f18143f);
        }
        return j8;
    }

    @Override // w.AbstractC1694l
    public final boolean k() {
        ArrayList arrayList = this.f18136k;
        int size = arrayList.size();
        for (int i = 0; i < size; i++) {
            if (!((AbstractC1694l) arrayList.get(i)).k()) {
                return false;
            }
        }
        return true;
    }

    public final v.d m() {
        int i = 0;
        while (true) {
            ArrayList arrayList = this.f18136k;
            if (i >= arrayList.size()) {
                return null;
            }
            v.d dVar = ((AbstractC1694l) arrayList.get(i)).f18156b;
            if (dVar.f17893V != 8) {
                return dVar;
            }
            i++;
        }
    }

    public final v.d n() {
        ArrayList arrayList = this.f18136k;
        for (int size = arrayList.size() - 1; size >= 0; size--) {
            v.d dVar = ((AbstractC1694l) arrayList.get(size)).f18156b;
            if (dVar.f17893V != 8) {
                return dVar;
            }
        }
        return null;
    }

    public final String toString() {
        String strConcat = "ChainRun ".concat(this.f18160f == 0 ? "horizontal : " : "vertical : ");
        ArrayList arrayList = this.f18136k;
        int size = arrayList.size();
        int i = 0;
        while (i < size) {
            Object obj = arrayList.get(i);
            i++;
            strConcat = AbstractC0844a.l(AbstractC0844a.l(strConcat, "<") + ((AbstractC1694l) obj), "> ");
        }
        return strConcat;
    }
}
