package defpackage;

import defpackage.cd1;
import java.util.ArrayList;
import java.util.Iterator;

/* JADX INFO: loaded from: classes.dex */
public class du0 extends ypa {
    public final ArrayList k;
    public int l;

    public du0(cd1 cd1Var, int i) {
        cd1 cd1Var2;
        super(cd1Var);
        ArrayList<ypa> arrayList = new ArrayList();
        this.k = arrayList;
        this.f = i;
        cd1 cd1Var3 = this.b;
        cd1 cd1VarN = cd1Var3.n(i);
        while (true) {
            cd1Var2 = cd1Var3;
            cd1Var3 = cd1VarN;
            if (cd1Var3 == null) {
                break;
            } else {
                cd1VarN = cd1Var3.n(this.f);
            }
        }
        this.b = cd1Var2;
        int i2 = this.f;
        arrayList.add(i2 == 0 ? cd1Var2.d : i2 == 1 ? cd1Var2.e : null);
        cd1 cd1VarM = cd1Var2.m(this.f);
        while (cd1VarM != null) {
            int i3 = this.f;
            arrayList.add(i3 == 0 ? cd1VarM.d : i3 == 1 ? cd1VarM.e : null);
            cd1VarM = cd1VarM.m(this.f);
        }
        for (ypa ypaVar : arrayList) {
            int i4 = this.f;
            if (i4 == 0) {
                ypaVar.b.b = this;
            } else if (i4 == 1) {
                ypaVar.b.c = this;
            }
        }
        if (this.f == 0 && ((dd1) this.b.av).bw && arrayList.size() > 1) {
            this.b = ((ypa) arrayList.get(arrayList.size() - 1)).b;
        }
        this.l = this.f == 0 ? this.b.bk : this.b.bl;
    }

    /* JADX WARN: Removed duplicated region for block: B:62:0x00d1  */
    /* JADX WARN: Removed duplicated region for block: B:66:0x00e2  */
    @Override // defpackage.ypa, defpackage.w42
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void a(w42 w42Var) {
        int i;
        int i2;
        cd1.b bVar;
        boolean z;
        float f;
        int i3;
        int i4;
        int i5;
        int i6;
        float f2;
        int i7;
        int i8;
        int i9;
        int i10;
        int i11;
        int i12;
        int i13;
        int i14;
        boolean z2;
        int i15;
        int i16;
        d52 d52Var = this.h;
        if (d52Var.j) {
            d52 d52Var2 = this.i;
            if (d52Var2.j) {
                cd1 cd1Var = this.b.av;
                boolean z3 = cd1Var instanceof dd1 ? ((dd1) cd1Var).bw : false;
                int i17 = d52Var2.g - d52Var.g;
                ArrayList arrayList = this.k;
                int size = arrayList.size();
                int i18 = 0;
                while (true) {
                    i = -1;
                    i2 = 8;
                    if (i18 >= size) {
                        i18 = -1;
                        break;
                    } else if (((ypa) arrayList.get(i18)).b.bi != 8) {
                        break;
                    } else {
                        i18++;
                    }
                }
                int i19 = size - 1;
                int i20 = i19;
                while (true) {
                    if (i20 < 0) {
                        break;
                    }
                    if (((ypa) arrayList.get(i20)).b.bi != 8) {
                        i = i20;
                        break;
                    }
                    i20--;
                }
                int i21 = 0;
                while (true) {
                    bVar = cd1.b.c;
                    if (i21 >= 2) {
                        z = z3;
                        f = 0.0f;
                        i3 = 0;
                        i4 = 0;
                        i5 = 0;
                        break;
                    }
                    f = 0.0f;
                    int i22 = 0;
                    i5 = 0;
                    i13 = 0;
                    i14 = 0;
                    while (i22 < size) {
                        ypa ypaVar = (ypa) arrayList.get(i22);
                        boolean z4 = z3;
                        cd1 cd1Var2 = ypaVar.b;
                        int i23 = i21;
                        if (cd1Var2.bi != i2) {
                            i14++;
                            if (i22 > 0 && i22 >= i18) {
                                i5 += ypaVar.h.f;
                            }
                            ra2 ra2Var = ypaVar.e;
                            int i24 = ra2Var.g;
                            boolean z5 = ypaVar.d != bVar;
                            if (z5) {
                                int i25 = this.f;
                                z2 = z5;
                                if (i25 == 0 && !cd1Var2.d.e.j) {
                                    return;
                                }
                                if (i25 == 1 && !cd1Var2.e.e.j) {
                                    return;
                                } else {
                                    i15 = i5;
                                }
                            } else {
                                z2 = z5;
                                i15 = i5;
                                if (ypaVar.a == 1 && i23 == 0) {
                                    i16 = ra2Var.m;
                                    i13++;
                                } else if (ra2Var.j) {
                                    i16 = i24;
                                }
                                z2 = true;
                                if (z2) {
                                    i13++;
                                    float f3 = cd1Var2.bm[this.f];
                                    if (f3 >= 0.0f) {
                                        f += f3;
                                    }
                                    i5 = i15;
                                } else {
                                    i5 = i15 + i16;
                                }
                                if (i22 >= i19 && i22 < i) {
                                    i5 += -ypaVar.i.f;
                                }
                            }
                            i16 = i24;
                            if (z2) {
                            }
                            if (i22 >= i19) {
                            }
                        }
                        i22++;
                        z3 = z4;
                        i21 = i23;
                        i2 = 8;
                    }
                    z = z3;
                    int i26 = i21;
                    if (i5 < i17 || i13 == 0) {
                        break;
                    }
                    i21 = i26 + 1;
                    z3 = z;
                    i2 = 8;
                }
                i3 = i13;
                i4 = i14;
                int i27 = d52Var.g;
                if (z) {
                    i27 = d52Var2.g;
                }
                float f4 = 0.5f;
                if (i5 > i17) {
                    i27 = z ? i27 + ((int) (((i5 - i17) / 2.0f) + 0.5f)) : i27 - ((int) (((i5 - i17) / 2.0f) + 0.5f));
                }
                if (i3 > 0) {
                    float f5 = i17 - i5;
                    int i28 = (int) ((f5 / i3) + 0.5f);
                    int i29 = 0;
                    int i30 = 0;
                    while (i29 < size) {
                        float f6 = f4;
                        ypa ypaVar2 = (ypa) arrayList.get(i29);
                        int i31 = i27;
                        cd1 cd1Var3 = ypaVar2.b;
                        int i32 = i3;
                        ra2 ra2Var2 = ypaVar2.e;
                        float f7 = f5;
                        int i33 = i28;
                        if (cd1Var3.bi == 8 || ypaVar2.d != bVar || ra2Var2.j) {
                            i12 = i29;
                        } else {
                            int i34 = f > 0.0f ? (int) (((cd1Var3.bm[this.f] * f7) / f) + f6) : i33;
                            if (this.f == 0) {
                                i10 = cd1Var3.v;
                                i11 = cd1Var3.u;
                            } else {
                                i10 = cd1Var3.y;
                                i11 = cd1Var3.x;
                            }
                            i12 = i29;
                            int iMax = Math.max(i11, ypaVar2.a == 1 ? Math.min(i34, ra2Var2.m) : i34);
                            if (i10 > 0) {
                                iMax = Math.min(i10, iMax);
                            }
                            if (iMax != i34) {
                                i30++;
                                i34 = iMax;
                            }
                            ra2Var2.d(i34);
                        }
                        i29 = i12 + 1;
                        i27 = i31;
                        f4 = f6;
                        i3 = i32;
                        f5 = f7;
                        i28 = i33;
                    }
                    i6 = i27;
                    f2 = f4;
                    int i35 = i3;
                    if (i30 > 0) {
                        i3 = i35 - i30;
                        i5 = 0;
                        for (int i36 = 0; i36 < size; i36++) {
                            ypa ypaVar3 = (ypa) arrayList.get(i36);
                            if (ypaVar3.b.bi != 8) {
                                if (i36 > 0 && i36 >= i18) {
                                    i5 += ypaVar3.h.f;
                                }
                                i5 += ypaVar3.e.g;
                                if (i36 < i19 && i36 < i) {
                                    i5 += -ypaVar3.i.f;
                                }
                            }
                        }
                    } else {
                        i3 = i35;
                    }
                    i8 = 2;
                    if (this.l == 2 && i30 == 0) {
                        i7 = 0;
                        this.l = 0;
                    } else {
                        i7 = 0;
                    }
                } else {
                    i6 = i27;
                    f2 = 0.5f;
                    i7 = 0;
                    i8 = 2;
                }
                if (i5 > i17) {
                    this.l = i8;
                }
                if (i4 > 0 && i3 == 0 && i18 == i) {
                    this.l = i8;
                }
                int i37 = this.l;
                if (i37 == 1) {
                    int i38 = i4 > 1 ? (i17 - i5) / (i4 - 1) : i4 == 1 ? (i17 - i5) / 2 : i7;
                    if (i3 > 0) {
                        i38 = i7;
                    }
                    int i39 = i6;
                    for (int i40 = i7; i40 < size; i40++) {
                        ypa ypaVar4 = (ypa) arrayList.get(z ? size - (i40 + 1) : i40);
                        cd1 cd1Var4 = ypaVar4.b;
                        d52 d52Var3 = ypaVar4.i;
                        d52 d52Var4 = ypaVar4.h;
                        if (cd1Var4.bi == 8) {
                            d52Var4.d(i39);
                            d52Var3.d(i39);
                        } else {
                            if (i40 > 0) {
                                i39 = z ? i39 - i38 : i39 + i38;
                            }
                            if (i40 > 0 && i40 >= i18) {
                                i39 = z ? i39 - d52Var4.f : i39 + d52Var4.f;
                            }
                            if (z) {
                                d52Var3.d(i39);
                            } else {
                                d52Var4.d(i39);
                            }
                            ra2 ra2Var3 = ypaVar4.e;
                            int i41 = ra2Var3.g;
                            if (ypaVar4.d == bVar) {
                                i9 = i39;
                                if (ypaVar4.a == 1) {
                                    i41 = ra2Var3.m;
                                }
                            } else {
                                i9 = i39;
                            }
                            i39 = z ? i9 - i41 : i9 + i41;
                            if (z) {
                                d52Var4.d(i39);
                            } else {
                                d52Var3.d(i39);
                            }
                            ypaVar4.g = true;
                            if (i40 < i19 && i40 < i) {
                                i39 = z ? i39 - (-d52Var3.f) : i39 + (-d52Var3.f);
                            }
                        }
                    }
                    return;
                }
                if (i37 == 0) {
                    int i42 = (i17 - i5) / (i4 + 1);
                    if (i3 > 0) {
                        i42 = i7;
                    }
                    int i43 = i6;
                    for (int i44 = i7; i44 < size; i44++) {
                        ypa ypaVar5 = (ypa) arrayList.get(z ? size - (i44 + 1) : i44);
                        cd1 cd1Var5 = ypaVar5.b;
                        d52 d52Var5 = ypaVar5.i;
                        d52 d52Var6 = ypaVar5.h;
                        if (cd1Var5.bi == 8) {
                            d52Var6.d(i43);
                            d52Var5.d(i43);
                        } else {
                            int i45 = z ? i43 - i42 : i43 + i42;
                            if (i44 > 0 && i44 >= i18) {
                                i45 = z ? i45 - d52Var6.f : i45 + d52Var6.f;
                            }
                            if (z) {
                                d52Var5.d(i45);
                            } else {
                                d52Var6.d(i45);
                            }
                            ra2 ra2Var4 = ypaVar5.e;
                            int iMin = ra2Var4.g;
                            if (ypaVar5.d == bVar && ypaVar5.a == 1) {
                                iMin = Math.min(iMin, ra2Var4.m);
                            }
                            i43 = z ? i45 - iMin : i45 + iMin;
                            if (z) {
                                d52Var6.d(i43);
                            } else {
                                d52Var5.d(i43);
                            }
                            if (i44 < i19 && i44 < i) {
                                i43 = z ? i43 - (-d52Var5.f) : i43 + (-d52Var5.f);
                            }
                        }
                    }
                    return;
                }
                if (i37 == 2) {
                    float f8 = this.f == 0 ? this.b.bf : this.b.bg;
                    if (z) {
                        f8 = 1.0f - f8;
                    }
                    int i46 = (int) (((i17 - i5) * f8) + f2);
                    if (i46 < 0 || i3 > 0) {
                        i46 = i7;
                    }
                    int i47 = z ? i6 - i46 : i6 + i46;
                    for (int i48 = i7; i48 < size; i48++) {
                        ypa ypaVar6 = (ypa) arrayList.get(z ? size - (i48 + 1) : i48);
                        cd1 cd1Var6 = ypaVar6.b;
                        d52 d52Var7 = ypaVar6.i;
                        d52 d52Var8 = ypaVar6.h;
                        if (cd1Var6.bi == 8) {
                            d52Var8.d(i47);
                            d52Var7.d(i47);
                        } else {
                            if (i48 > 0 && i48 >= i18) {
                                i47 = z ? i47 - d52Var8.f : i47 + d52Var8.f;
                            }
                            if (z) {
                                d52Var7.d(i47);
                            } else {
                                d52Var8.d(i47);
                            }
                            ra2 ra2Var5 = ypaVar6.e;
                            int i49 = ra2Var5.g;
                            if (ypaVar6.d == bVar && ypaVar6.a == 1) {
                                i49 = ra2Var5.m;
                            }
                            i47 = z ? i47 - i49 : i47 + i49;
                            if (z) {
                                d52Var8.d(i47);
                            } else {
                                d52Var7.d(i47);
                            }
                            if (i48 < i19 && i48 < i) {
                                i47 = z ? i47 - (-d52Var7.f) : i47 + (-d52Var7.f);
                            }
                        }
                    }
                }
            }
        }
    }

    @Override // defpackage.ypa
    public final void d() {
        ArrayList arrayList = this.k;
        Iterator it = arrayList.iterator();
        while (it.hasNext()) {
            ((ypa) it.next()).d();
        }
        int size = arrayList.size();
        if (size < 1) {
            return;
        }
        cd1 cd1Var = ((ypa) arrayList.get(0)).b;
        cd1 cd1Var2 = ((ypa) arrayList.get(size - 1)).b;
        int i = this.f;
        d52 d52Var = this.i;
        d52 d52Var2 = this.h;
        if (i == 0) {
            sc1 sc1Var = cd1Var.aj;
            sc1 sc1Var2 = cd1Var2.al;
            d52 d52VarI = ypa.i(sc1Var, 0);
            int iE = sc1Var.e();
            cd1 cd1VarM = m();
            if (cd1VarM != null) {
                iE = cd1VarM.aj.e();
            }
            if (d52VarI != null) {
                ypa.b(d52Var2, d52VarI, iE);
            }
            d52 d52VarI2 = ypa.i(sc1Var2, 0);
            int iE2 = sc1Var2.e();
            cd1 cd1VarN = n();
            if (cd1VarN != null) {
                iE2 = cd1VarN.al.e();
            }
            if (d52VarI2 != null) {
                ypa.b(d52Var, d52VarI2, -iE2);
            }
        } else {
            sc1 sc1Var3 = cd1Var.ak;
            sc1 sc1Var4 = cd1Var2.am;
            d52 d52VarI3 = ypa.i(sc1Var3, 1);
            int iE3 = sc1Var3.e();
            cd1 cd1VarM2 = m();
            if (cd1VarM2 != null) {
                iE3 = cd1VarM2.ak.e();
            }
            if (d52VarI3 != null) {
                ypa.b(d52Var2, d52VarI3, iE3);
            }
            d52 d52VarI4 = ypa.i(sc1Var4, 1);
            int iE4 = sc1Var4.e();
            cd1 cd1VarN2 = n();
            if (cd1VarN2 != null) {
                iE4 = cd1VarN2.am.e();
            }
            if (d52VarI4 != null) {
                ypa.b(d52Var, d52VarI4, -iE4);
            }
        }
        d52Var2.a = this;
        d52Var.a = this;
    }

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

    @Override // defpackage.ypa
    public final void f() {
        this.c = null;
        Iterator it = this.k.iterator();
        while (it.hasNext()) {
            ((ypa) it.next()).f();
        }
    }

    @Override // defpackage.ypa
    public final long j() {
        ArrayList arrayList = this.k;
        int size = arrayList.size();
        long j = 0;
        for (int i = 0; i < size; i++) {
            ypa ypaVar = (ypa) arrayList.get(i);
            j = ((long) ypaVar.i.f) + ypaVar.j() + j + ((long) ypaVar.h.f);
        }
        return j;
    }

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

    public final cd1 m() {
        int i = 0;
        while (true) {
            ArrayList arrayList = this.k;
            if (i >= arrayList.size()) {
                return null;
            }
            cd1 cd1Var = ((ypa) arrayList.get(i)).b;
            if (cd1Var.bi != 8) {
                return cd1Var;
            }
            i++;
        }
    }

    public final cd1 n() {
        ArrayList arrayList = this.k;
        for (int size = arrayList.size() - 1; size >= 0; size--) {
            cd1 cd1Var = ((ypa) arrayList.get(size)).b;
            if (cd1Var.bi != 8) {
                return cd1Var;
            }
        }
        return null;
    }

    public final String toString() {
        StringBuilder sb = new StringBuilder("ChainRun ");
        sb.append(this.f == 0 ? "horizontal : " : "vertical : ");
        for (ypa ypaVar : this.k) {
            sb.append("<");
            sb.append(ypaVar);
            sb.append("> ");
        }
        return sb.toString();
    }
}
