package p052r;

import java.util.ArrayList;
import java.util.Iterator;
import p049q.C1544a;
import p049q.C1547d;
import p049q.C1550e;
import p049q.C1553f;
import p049q.C1554g;
import p049q.C1557i;
import p052r.C1571b;

/* renamed from: r.i */
/* loaded from: classes.dex */
public class C1581i {
    /* renamed from: a */
    public static C1589o m847a(C1550e c1550e, int i, ArrayList<C1589o> arrayList, C1589o c1589o) {
        C1547d c1547d;
        int m897p1;
        int i2 = i == 0 ? c1550e.f3496I0 : c1550e.f3498J0;
        if (i2 != -1 && (c1589o == null || i2 != c1589o.f3702b)) {
            int i3 = 0;
            while (true) {
                if (i3 >= arrayList.size()) {
                    break;
                }
                C1589o c1589o2 = arrayList.get(i3);
                if (c1589o2.m832c() == i2) {
                    if (c1589o != null) {
                        c1589o.m828g(i, c1589o2);
                        arrayList.remove(c1589o);
                    }
                    c1589o = c1589o2;
                } else {
                    i3++;
                }
            }
        } else if (i2 != -1) {
            return c1589o;
        }
        if (c1589o == null) {
            if ((c1550e instanceof C1557i) && (m897p1 = ((C1557i) c1550e).m897p1(i)) != -1) {
                int i4 = 0;
                while (true) {
                    if (i4 >= arrayList.size()) {
                        break;
                    }
                    C1589o c1589o3 = arrayList.get(i4);
                    if (c1589o3.m832c() == m897p1) {
                        c1589o = c1589o3;
                        break;
                    }
                    i4++;
                }
            }
            if (c1589o == null) {
                c1589o = new C1589o(i);
            }
            arrayList.add(c1589o);
        }
        if (c1589o.m834a(c1550e)) {
            if (c1550e instanceof C1554g) {
                C1554g c1554g = (C1554g) c1550e;
                c1554g.m910o1().m1072b(c1554g.m909p1() == 0 ? 1 : 0, arrayList, c1589o);
            }
            int m832c = c1589o.m832c();
            if (i == 0) {
                c1550e.f3496I0 = m832c;
                c1550e.f3503O.m1072b(i, arrayList, c1589o);
                c1547d = c1550e.f3505Q;
            } else {
                c1550e.f3498J0 = m832c;
                c1550e.f3504P.m1072b(i, arrayList, c1589o);
                c1550e.f3507S.m1072b(i, arrayList, c1589o);
                c1547d = c1550e.f3506R;
            }
            c1547d.m1072b(i, arrayList, c1589o);
            c1550e.f3510V.m1072b(i, arrayList, c1589o);
        }
        return c1589o;
    }

    /* renamed from: b */
    public static C1589o m846b(ArrayList<C1589o> arrayList, int i) {
        int size = arrayList.size();
        for (int i2 = 0; i2 < size; i2++) {
            C1589o c1589o = arrayList.get(i2);
            if (i == c1589o.f3702b) {
                return c1589o;
            }
        }
        return null;
    }

    /* JADX WARN: Removed duplicated region for block: B:175:0x034c  */
    /* JADX WARN: Removed duplicated region for block: B:187:0x0388  */
    /* JADX WARN: Removed duplicated region for block: B:190:0x038d A[ADDED_TO_REGION] */
    /* renamed from: c */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static boolean m845c(C1553f c1553f, C1571b.InterfaceC1573b interfaceC1573b) {
        C1589o c1589o;
        C1589o c1589o2;
        C1544a c1544a;
        ArrayList<C1550e> m889o1 = c1553f.m889o1();
        int size = m889o1.size();
        int i = 0;
        for (int i2 = 0; i2 < size; i2++) {
            C1550e c1550e = m889o1.get(i2);
            if (!m844d(c1553f.m953y(), c1553f.m1021R(), c1550e.m953y(), c1550e.m1021R())) {
                return false;
            }
        }
        int i3 = 0;
        ArrayList arrayList = null;
        ArrayList arrayList2 = null;
        ArrayList arrayList3 = null;
        ArrayList arrayList4 = null;
        ArrayList arrayList5 = null;
        ArrayList arrayList6 = null;
        while (i3 < size) {
            C1550e c1550e2 = m889o1.get(i3);
            if (!m844d(c1553f.m953y(), c1553f.m1021R(), c1550e2.m953y(), c1550e2.m1021R())) {
                C1553f.m934O1(i, c1550e2, interfaceC1573b, c1553f.f3603p1, C1571b.C1572a.f3638k);
            }
            boolean z = c1550e2 instanceof C1554g;
            if (z) {
                C1554g c1554g = (C1554g) c1550e2;
                if (c1554g.m909p1() == 0) {
                    if (arrayList3 == null) {
                        arrayList3 = new ArrayList();
                    }
                    arrayList3.add(c1554g);
                }
                if (c1554g.m909p1() == 1) {
                    if (arrayList == null) {
                        arrayList = new ArrayList();
                    }
                    arrayList.add(c1554g);
                }
            }
            if (c1550e2 instanceof C1557i) {
                if (c1550e2 instanceof C1544a) {
                    C1544a c1544a2 = (C1544a) c1550e2;
                    if (c1544a2.m1083u1() == 0) {
                        if (arrayList2 == null) {
                            arrayList2 = new ArrayList();
                        }
                        arrayList2.add(c1544a2);
                    }
                    int m1083u1 = c1544a2.m1083u1();
                    c1544a = c1544a2;
                    if (m1083u1 == 1) {
                        if (arrayList4 == null) {
                            arrayList4 = new ArrayList();
                            c1544a = c1544a2;
                        }
                    }
                } else {
                    C1557i c1557i = (C1557i) c1550e2;
                    if (arrayList2 == null) {
                        arrayList2 = new ArrayList();
                    }
                    arrayList2.add(c1557i);
                    c1544a = c1557i;
                    if (arrayList4 == null) {
                        arrayList4 = new ArrayList();
                        c1544a = c1557i;
                    }
                }
                arrayList4.add(c1544a);
            }
            if (c1550e2.f3503O.f3463f == null && c1550e2.f3505Q.f3463f == null && !z && !(c1550e2 instanceof C1544a)) {
                if (arrayList5 == null) {
                    arrayList5 = new ArrayList();
                }
                arrayList5.add(c1550e2);
            }
            if (c1550e2.f3504P.f3463f == null && c1550e2.f3506R.f3463f == null && c1550e2.f3507S.f3463f == null && !z && !(c1550e2 instanceof C1544a)) {
                if (arrayList6 == null) {
                    arrayList6 = new ArrayList();
                }
                arrayList6.add(c1550e2);
            }
            i3++;
            i = 0;
        }
        ArrayList<C1589o> arrayList7 = new ArrayList<>();
        if (arrayList != null) {
            Iterator it = arrayList.iterator();
            while (it.hasNext()) {
                m847a((C1554g) it.next(), 0, arrayList7, null);
            }
        }
        C1589o c1589o3 = null;
        int i4 = 0;
        if (arrayList2 != null) {
            Iterator it2 = arrayList2.iterator();
            while (it2.hasNext()) {
                C1557i c1557i2 = (C1557i) it2.next();
                C1589o m847a = m847a(c1557i2, i4, arrayList7, c1589o3);
                c1557i2.m898o1(arrayList7, i4, m847a);
                m847a.m833b(arrayList7);
                c1589o3 = null;
                i4 = 0;
            }
        }
        C1547d mo913m = c1553f.mo913m(C1547d.EnumC1549b.LEFT);
        if (mo913m.m1071c() != null) {
            Iterator<C1547d> it3 = mo913m.m1071c().iterator();
            while (it3.hasNext()) {
                m847a(it3.next().f3461d, 0, arrayList7, null);
            }
        }
        C1547d mo913m2 = c1553f.mo913m(C1547d.EnumC1549b.RIGHT);
        if (mo913m2.m1071c() != null) {
            Iterator<C1547d> it4 = mo913m2.m1071c().iterator();
            while (it4.hasNext()) {
                m847a(it4.next().f3461d, 0, arrayList7, null);
            }
        }
        C1547d mo913m3 = c1553f.mo913m(C1547d.EnumC1549b.CENTER);
        if (mo913m3.m1071c() != null) {
            Iterator<C1547d> it5 = mo913m3.m1071c().iterator();
            while (it5.hasNext()) {
                m847a(it5.next().f3461d, 0, arrayList7, null);
            }
        }
        C1589o c1589o4 = null;
        if (arrayList5 != null) {
            Iterator it6 = arrayList5.iterator();
            while (it6.hasNext()) {
                m847a((C1550e) it6.next(), 0, arrayList7, null);
            }
        }
        if (arrayList3 != null) {
            Iterator it7 = arrayList3.iterator();
            while (it7.hasNext()) {
                m847a((C1554g) it7.next(), 1, arrayList7, null);
            }
        }
        int i5 = 1;
        if (arrayList4 != null) {
            Iterator it8 = arrayList4.iterator();
            while (it8.hasNext()) {
                C1557i c1557i3 = (C1557i) it8.next();
                C1589o m847a2 = m847a(c1557i3, i5, arrayList7, c1589o4);
                c1557i3.m898o1(arrayList7, i5, m847a2);
                m847a2.m833b(arrayList7);
                c1589o4 = null;
                i5 = 1;
            }
        }
        C1547d mo913m4 = c1553f.mo913m(C1547d.EnumC1549b.TOP);
        if (mo913m4.m1071c() != null) {
            Iterator<C1547d> it9 = mo913m4.m1071c().iterator();
            while (it9.hasNext()) {
                m847a(it9.next().f3461d, 1, arrayList7, null);
            }
        }
        C1547d mo913m5 = c1553f.mo913m(C1547d.EnumC1549b.BASELINE);
        if (mo913m5.m1071c() != null) {
            Iterator<C1547d> it10 = mo913m5.m1071c().iterator();
            while (it10.hasNext()) {
                m847a(it10.next().f3461d, 1, arrayList7, null);
            }
        }
        C1547d mo913m6 = c1553f.mo913m(C1547d.EnumC1549b.BOTTOM);
        if (mo913m6.m1071c() != null) {
            Iterator<C1547d> it11 = mo913m6.m1071c().iterator();
            while (it11.hasNext()) {
                m847a(it11.next().f3461d, 1, arrayList7, null);
            }
        }
        C1547d mo913m7 = c1553f.mo913m(C1547d.EnumC1549b.CENTER);
        if (mo913m7.m1071c() != null) {
            Iterator<C1547d> it12 = mo913m7.m1071c().iterator();
            while (it12.hasNext()) {
                m847a(it12.next().f3461d, 1, arrayList7, null);
            }
        }
        if (arrayList6 != null) {
            Iterator it13 = arrayList6.iterator();
            while (it13.hasNext()) {
                m847a((C1550e) it13.next(), 1, arrayList7, null);
            }
        }
        for (int i6 = 0; i6 < size; i6++) {
            C1550e c1550e3 = m889o1.get(i6);
            if (c1550e3.m966q0()) {
                C1589o m846b = m846b(arrayList7, c1550e3.f3496I0);
                C1589o m846b2 = m846b(arrayList7, c1550e3.f3498J0);
                if (m846b != null && m846b2 != null) {
                    m846b.m828g(0, m846b2);
                    m846b2.m826i(2);
                    arrayList7.remove(m846b);
                }
            }
        }
        if (arrayList7.size() <= 1) {
            return false;
        }
        if (c1553f.m953y() == C1550e.EnumC1552b.WRAP_CONTENT) {
            Iterator<C1589o> it14 = arrayList7.iterator();
            c1589o = null;
            int i7 = 0;
            while (it14.hasNext()) {
                C1589o next = it14.next();
                if (next.m831d() != 1) {
                    next.m827h(false);
                    int m829f = next.m829f(c1553f.m942H1(), 0);
                    if (m829f > i7) {
                        c1589o = next;
                        i7 = m829f;
                    }
                }
            }
            if (c1589o != null) {
                c1553f.m1030M0(C1550e.EnumC1552b.FIXED);
                c1553f.m985h1(i7);
                c1589o.m827h(true);
                if (c1553f.m1021R() != C1550e.EnumC1552b.WRAP_CONTENT) {
                    Iterator<C1589o> it15 = arrayList7.iterator();
                    C1589o c1589o5 = null;
                    int i8 = 0;
                    while (it15.hasNext()) {
                        C1589o next2 = it15.next();
                        if (next2.m831d() != 0) {
                            next2.m827h(false);
                            int m829f2 = next2.m829f(c1553f.m942H1(), 1);
                            if (m829f2 > i8) {
                                c1589o5 = next2;
                                i8 = m829f2;
                            }
                        }
                    }
                    if (c1589o5 != null) {
                        c1553f.m995d1(C1550e.EnumC1552b.FIXED);
                        c1553f.m1037I0(i8);
                        c1589o5.m827h(true);
                        c1589o2 = c1589o5;
                        return c1589o == null || c1589o2 != null;
                    }
                }
                c1589o2 = null;
                if (c1589o == null) {
                }
            }
        }
        c1589o = null;
        if (c1553f.m1021R() != C1550e.EnumC1552b.WRAP_CONTENT) {
        }
        c1589o2 = null;
        if (c1589o == null) {
        }
    }

    /* renamed from: d */
    public static boolean m844d(C1550e.EnumC1552b enumC1552b, C1550e.EnumC1552b enumC1552b2, C1550e.EnumC1552b enumC1552b3, C1550e.EnumC1552b enumC1552b4) {
        C1550e.EnumC1552b enumC1552b5;
        C1550e.EnumC1552b enumC1552b6;
        C1550e.EnumC1552b enumC1552b7 = C1550e.EnumC1552b.FIXED;
        return (enumC1552b3 == enumC1552b7 || enumC1552b3 == (enumC1552b6 = C1550e.EnumC1552b.WRAP_CONTENT) || (enumC1552b3 == C1550e.EnumC1552b.MATCH_PARENT && enumC1552b != enumC1552b6)) || (enumC1552b4 == enumC1552b7 || enumC1552b4 == (enumC1552b5 = C1550e.EnumC1552b.WRAP_CONTENT) || (enumC1552b4 == C1550e.EnumC1552b.MATCH_PARENT && enumC1552b2 != enumC1552b5));
    }
}