package com.bytedance.adsdk.ugeno.core;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import com.bytedance.adsdk.ugeno.core.wsy;
import com.bytedance.adsdk.ugeno.ro.fm;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import org.json.JSONObject;

/* JADX INFO: loaded from: classes.dex */
public class duv {
    private gof ajl;
    private ku duv;

    /* JADX INFO: renamed from: ef, reason: collision with root package name */
    private com.bytedance.adsdk.ugeno.yz.dsz f6308ef;
    private com.bytedance.adsdk.ugeno.yz.fm.fm fhx;
    private Context fm;
    private List<String> gof;
    private jnr gqi;
    private boolean irt;
    private fhx jnr;
    private String ku;

    /* JADX INFO: renamed from: lb, reason: collision with root package name */
    private com.bytedance.adsdk.ugeno.ro.lb<View> f6309lb;
    private ef maa;
    private boolean qhl;
    private JSONObject ro;
    private float sds;
    private wsy vt;
    private float wey;
    private irt wsy;
    private com.bytedance.adsdk.ugeno.yz.onz wu;
    private wu yz;
    private boolean dsz = true;
    private boolean onz = false;

    public duv(Context context) {
        this.fm = context;
    }

    public void fm(irt irtVar) {
        this.wsy = irtVar;
    }

    public List<String> ro() {
        return this.gof;
    }

    public void fm(jnr jnrVar) {
        this.gqi = jnrVar;
    }

    public com.bytedance.adsdk.ugeno.ro.lb<View> ro(wsy.fm fmVar, com.bytedance.adsdk.ugeno.ro.lb<View> lbVar) {
        List<wsy.fm> listLb;
        fm.C0019fm c0019fmVt = null;
        if (!wsy.yz(fmVar)) {
            return null;
        }
        String strYz = fmVar.yz();
        ro roVarFm = yz.fm(strYz);
        if (roVarFm == null) {
            "not found component ".concat(String.valueOf(strYz));
            this.irt = true;
            if (this.gof == null) {
                this.gof = new ArrayList();
            }
            this.gof.add(strYz);
            return null;
        }
        com.bytedance.adsdk.ugeno.ro.lb lbVarFm = roVarFm.fm(this.fm);
        if (lbVarFm == null) {
            return null;
        }
        lbVarFm.ef(com.bytedance.adsdk.ugeno.lb.ro.fm(fmVar.fm(), this.ro));
        lbVarFm.vt(strYz);
        lbVarFm.lb(fmVar.jnr());
        lbVarFm.fm(fmVar);
        lbVarFm.fm(this.duv);
        if (lbVar instanceof com.bytedance.adsdk.ugeno.ro.fm) {
            com.bytedance.adsdk.ugeno.ro.fm fmVar2 = (com.bytedance.adsdk.ugeno.ro.fm) lbVar;
            lbVarFm.fm(fmVar2);
            c0019fmVt = fmVar2.vt();
        }
        Iterator<String> itKeys = fmVar.jnr().keys();
        while (itKeys.hasNext()) {
            String next = itKeys.next();
            String strFm = com.bytedance.adsdk.ugeno.lb.ro.fm(fmVar.jnr().optString(next), this.ro);
            lbVarFm.fm(next, strFm);
            if (c0019fmVt != null) {
                c0019fmVt.fm(this.fm, next, strFm);
            }
        }
        if (lbVarFm instanceof com.bytedance.adsdk.ugeno.ro.fm) {
            List<wsy.fm> listAjl = fmVar.ajl();
            if (listAjl == null || listAjl.size() <= 0) {
                if (TextUtils.equals(lbVarFm.hxv(), "RecyclerLayout") && (listLb = this.vt.lb()) != null && listLb.size() > 0) {
                    Iterator<wsy.fm> it = listLb.iterator();
                    while (it.hasNext()) {
                        com.bytedance.adsdk.ugeno.ro.lb<View> lbVarRo = ro(it.next(), (com.bytedance.adsdk.ugeno.ro.lb<View>) lbVarFm);
                        if (lbVarRo != null && lbVarRo.mon()) {
                            ((com.bytedance.adsdk.ugeno.ro.fm) lbVarFm).fm(lbVarRo);
                        }
                    }
                }
                return lbVarFm;
            }
            if (TextUtils.equals(lbVarFm.hxv(), "Swiper")) {
                listAjl.size();
            }
            Iterator<wsy.fm> it2 = listAjl.iterator();
            while (it2.hasNext()) {
                com.bytedance.adsdk.ugeno.ro.lb<View> lbVarRo2 = ro(it2.next(), (com.bytedance.adsdk.ugeno.ro.lb<View>) lbVarFm);
                if (lbVarRo2 != null && lbVarRo2.mon()) {
                    ((com.bytedance.adsdk.ugeno.ro.fm) lbVarFm).fm(lbVarRo2);
                }
            }
        }
        if (c0019fmVt != null) {
            lbVarFm.fm(c0019fmVt.fm());
        }
        this.f6309lb = lbVarFm;
        return lbVarFm;
    }

    public void fm(com.bytedance.adsdk.ugeno.yz.onz onzVar) {
        this.wu = onzVar;
    }

    public boolean fm() {
        return this.irt;
    }

    public void fm(String str, ku kuVar) {
        this.duv = kuVar;
        this.ku = str;
        if (kuVar != null) {
            this.ro = kuVar.fm();
        }
    }

    public com.bytedance.adsdk.ugeno.ro.lb<View> fm(JSONObject jSONObject, JSONObject jSONObject2, JSONObject jSONObject3) {
        this.ro = jSONObject2;
        gof gofVar = this.ajl;
        if (gofVar != null) {
            gofVar.fm();
        }
        wsy wsyVar = new wsy(jSONObject, jSONObject2, jSONObject3);
        this.vt = wsyVar;
        wsyVar.fm(this.wey, this.sds);
        this.fhx = new com.bytedance.adsdk.ugeno.yz.fm.fm();
        if (!(this.jnr instanceof com.bytedance.adsdk.ugeno.core.fm.ro)) {
            this.f6309lb = fm(this.vt.fm(), (com.bytedance.adsdk.ugeno.ro.lb<View>) null);
            if (this.maa == null) {
                gof gofVar2 = this.ajl;
                if (gofVar2 != null) {
                    gofVar2.ro();
                    this.f6309lb.fm(this.ajl);
                    this.ajl.lb();
                }
                fm(this.f6309lb);
                if (this.ajl != null) {
                    qhl qhlVar = new qhl();
                    qhlVar.fm(0);
                    qhlVar.fm(this.f6309lb);
                    this.ajl.fm(qhlVar);
                }
                return this.f6309lb;
            }
            throw null;
        }
        this.vt.ro();
        throw null;
    }

    public com.bytedance.adsdk.ugeno.ro.lb<View> fm(wsy.fm fmVar, JSONObject jSONObject, JSONObject jSONObject2) {
        this.ro = jSONObject;
        gof gofVar = this.ajl;
        if (gofVar != null) {
            gofVar.fm();
        }
        this.fhx = new com.bytedance.adsdk.ugeno.yz.fm.fm();
        if (!(this.jnr instanceof com.bytedance.adsdk.ugeno.core.fm.ro)) {
            this.f6309lb = fm(fmVar, (com.bytedance.adsdk.ugeno.ro.lb<View>) null);
            gof gofVar2 = this.ajl;
            if (gofVar2 != null) {
                gofVar2.ro();
                this.f6309lb.fm(this.ajl);
            }
            fm(this.f6309lb);
            return this.f6309lb;
        }
        throw null;
    }

    public com.bytedance.adsdk.ugeno.ro.lb<View> fm(wsy.fm fmVar, com.bytedance.adsdk.ugeno.ro.lb<View> lbVar) {
        fm.C0019fm c0019fmVt;
        List<wsy.fm> listLb;
        if (!wsy.yz(fmVar)) {
            return null;
        }
        String strYz = fmVar.yz();
        ro roVarFm = yz.fm(strYz);
        ro roVar = roVarFm;
        if (roVarFm == null) {
            this.irt = true;
            if (this.gof == null) {
                this.gof = new ArrayList();
            }
            this.gof.add(strYz);
            strYz = "View";
            fmVar.fm("View");
            ro roVarFm2 = yz.fm("View");
            roVar = roVarFm2;
            if (roVarFm2 == null) {
                "not found component ".concat("View");
                return null;
            }
        }
        com.bytedance.adsdk.ugeno.ro.lb lbVarFm = roVar.fm(this.fm);
        if (lbVarFm == null) {
            return null;
        }
        JSONObject jSONObjectJnr = fmVar.jnr();
        lbVarFm.ef(com.bytedance.adsdk.ugeno.lb.ro.fm(fmVar.fm(), this.ro));
        lbVarFm.vt(strYz);
        lbVarFm.lb(jSONObjectJnr);
        lbVarFm.fm(fmVar);
        lbVarFm.ro(this.ro);
        wsy wsyVar = this.vt;
        if (wsyVar == null) {
            lbVarFm.fm(true);
        } else {
            lbVarFm.fm(wsyVar.yz());
        }
        lbVarFm.fm(this.duv);
        lbVarFm.fm(this.fhx);
        Iterator<String> itKeys = jSONObjectJnr.keys();
        if (lbVar instanceof com.bytedance.adsdk.ugeno.ro.fm) {
            com.bytedance.adsdk.ugeno.ro.fm fmVar2 = (com.bytedance.adsdk.ugeno.ro.fm) lbVar;
            c0019fmVt = fmVar2.vt();
            lbVarFm.fm(fmVar2);
        } else {
            c0019fmVt = null;
        }
        while (itKeys.hasNext()) {
            String next = itKeys.next();
            String strFm = com.bytedance.adsdk.ugeno.lb.ro.fm(jSONObjectJnr.optString(next), this.ro);
            lbVarFm.fm(next, strFm);
            if (this.maa != null) {
                throw null;
            }
            if (c0019fmVt != null) {
                c0019fmVt.fm(this.fm, next, strFm);
            }
        }
        if (c0019fmVt != null) {
            lbVarFm.fm(c0019fmVt.fm());
        }
        if (lbVar != null && TextUtils.equals("virtualNode", lbVar.pkk()) && lbVarFm.bkb()) {
            this.qhl = true;
        }
        if (lbVarFm instanceof com.bytedance.adsdk.ugeno.ro.fm) {
            List<wsy.fm> listAjl = fmVar.ajl();
            if (listAjl != null && listAjl.size() > 0) {
                if (TextUtils.equals(lbVarFm.hxv(), "Swiper")) {
                    listAjl.size();
                }
                try {
                    Collections.sort(listAjl, new Comparator<wsy.fm>() { // from class: com.bytedance.adsdk.ugeno.core.duv.1
                        @Override // java.util.Comparator
                        /* JADX INFO: renamed from: fm, reason: merged with bridge method [inline-methods] */
                        public int compare(wsy.fm fmVar3, wsy.fm fmVar4) {
                            return fmVar3.jnr().optInt("order", 0) - fmVar4.jnr().optInt("order", 0);
                        }
                    });
                } catch (Throwable unused) {
                }
                Iterator<wsy.fm> it = listAjl.iterator();
                while (it.hasNext()) {
                    com.bytedance.adsdk.ugeno.ro.lb<View> lbVarFm2 = fm(it.next(), (com.bytedance.adsdk.ugeno.ro.lb<View>) lbVarFm);
                    if (lbVarFm2 != null && !lbVarFm2.bkb()) {
                        ((com.bytedance.adsdk.ugeno.ro.fm) lbVarFm).fm(lbVarFm2, lbVarFm2.ai());
                    }
                }
            } else {
                if (TextUtils.equals(lbVarFm.hxv(), "RecyclerLayout") && (listLb = this.vt.lb()) != null && listLb.size() > 0) {
                    Iterator<wsy.fm> it2 = listLb.iterator();
                    while (it2.hasNext()) {
                        com.bytedance.adsdk.ugeno.ro.lb<View> lbVarFm3 = fm(it2.next(), (com.bytedance.adsdk.ugeno.ro.lb<View>) lbVarFm);
                        if (lbVarFm3 != null && lbVarFm3.mon()) {
                            ((com.bytedance.adsdk.ugeno.ro.fm) lbVarFm).fm(lbVarFm3);
                        }
                    }
                }
                return lbVarFm;
            }
        }
        this.f6309lb = lbVarFm;
        return lbVarFm;
    }

    public void ro(JSONObject jSONObject) {
        gof gofVar = this.ajl;
        if (gofVar != null) {
            gofVar.lb();
        }
        this.ro = jSONObject;
        fm(this.f6309lb, jSONObject);
        fm(this.f6309lb);
        if (this.ajl != null) {
            qhl qhlVar = new qhl();
            qhlVar.fm(0);
            qhlVar.fm(this.f6309lb);
            this.ajl.fm(qhlVar);
        }
    }

    private void ro(com.bytedance.adsdk.ugeno.ro.lb lbVar) {
        try {
            if (!lbVar.wbw() || lbVar.ol() == null || lbVar.ol().wsy() == null) {
                return;
            }
            JSONObject jSONObject = new JSONObject();
            jSONObject.put("i18n", lbVar.ol().wsy());
            this.ro.put("xNode", jSONObject);
        } catch (Exception unused) {
        }
    }

    private void ro(JSONObject jSONObject, com.bytedance.adsdk.ugeno.ro.lb lbVar) {
        List<com.bytedance.adsdk.ugeno.ro.lb<View>> listEf;
        if (lbVar == null) {
            return;
        }
        this.ro = jSONObject;
        lbVar.ro(jSONObject);
        lbVar.fm(this.duv);
        fm.C0019fm c0019fmVt = lbVar.ha() instanceof com.bytedance.adsdk.ugeno.ro.fm ? lbVar.ha().vt() : null;
        Iterator<String> itKeys = lbVar.nt().keys();
        while (itKeys.hasNext()) {
            String next = itKeys.next();
            String strFm = com.bytedance.adsdk.ugeno.lb.ro.fm(lbVar.nt().optString(next), jSONObject);
            lbVar.fm(next, strFm);
            if (c0019fmVt != null) {
                c0019fmVt.fm(this.fm, next, strFm);
            }
        }
        if ((lbVar instanceof com.bytedance.adsdk.ugeno.ro.fm) && (listEf = ((com.bytedance.adsdk.ugeno.ro.fm) lbVar).ef()) != null && !listEf.isEmpty()) {
            Iterator<com.bytedance.adsdk.ugeno.ro.lb<View>> it = listEf.iterator();
            while (it.hasNext()) {
                ro(jSONObject, it.next());
            }
        }
        if (c0019fmVt != null) {
            lbVar.fm(c0019fmVt.fm());
        }
    }

    public com.bytedance.adsdk.ugeno.ro.lb<View> fm(JSONObject jSONObject) {
        gof gofVar = this.ajl;
        if (gofVar != null) {
            gofVar.fm();
        }
        wsy wsyVar = new wsy(jSONObject, this.ro);
        this.vt = wsyVar;
        if (!(this.jnr instanceof com.bytedance.adsdk.ugeno.core.fm.ro)) {
            this.f6309lb = ro(wsyVar.fm(), (com.bytedance.adsdk.ugeno.ro.lb<View>) null);
            gof gofVar2 = this.ajl;
            if (gofVar2 != null) {
                gofVar2.ro();
                this.f6309lb.fm(this.ajl);
            }
            return this.f6309lb;
        }
        wsyVar.ro();
        throw null;
    }

    public void fm(com.bytedance.adsdk.ugeno.ro.lb lbVar, JSONObject jSONObject) {
        if (lbVar == null) {
            return;
        }
        if (lbVar instanceof com.bytedance.adsdk.ugeno.ro.fm) {
            lbVar.fm(jSONObject);
            List<com.bytedance.adsdk.ugeno.ro.lb<View>> listEf = ((com.bytedance.adsdk.ugeno.ro.fm) lbVar).ef();
            if (listEf == null || listEf.size() <= 0) {
                return;
            }
            Iterator<com.bytedance.adsdk.ugeno.ro.lb<View>> it = listEf.iterator();
            while (it.hasNext()) {
                fm(it.next(), jSONObject);
            }
            return;
        }
        lbVar.fm(jSONObject);
    }

    private void fm(com.bytedance.adsdk.ugeno.ro.lb<View> lbVar) {
        List<com.bytedance.adsdk.ugeno.ro.lb<View>> listEf;
        if (lbVar == null) {
            return;
        }
        JSONObject jSONObjectNt = lbVar.nt();
        Iterator<String> itKeys = jSONObjectNt.keys();
        com.bytedance.adsdk.ugeno.ro.fm fmVarHa = lbVar.ha();
        fm.C0019fm c0019fmVt = fmVarHa != null ? fmVarHa.vt() : null;
        ro(lbVar);
        while (itKeys.hasNext()) {
            String next = itKeys.next();
            String strFm = com.bytedance.adsdk.ugeno.lb.ro.fm(jSONObjectNt.optString(next), this.ro);
            lbVar.fm(next, strFm);
            if (c0019fmVt != null) {
                c0019fmVt.fm(this.fm, next, strFm);
            }
        }
        lbVar.fm(this.yz);
        lbVar.fm(this.jnr);
        lbVar.fm(this.wsy);
        ef efVar = this.maa;
        if (efVar != null) {
            lbVar.fm(efVar);
        }
        jnr jnrVar = this.gqi;
        if (jnrVar != null) {
            lbVar.fm(jnrVar);
        }
        com.bytedance.adsdk.ugeno.yz.onz onzVar = this.wu;
        if (onzVar != null) {
            lbVar.fm(onzVar);
        }
        com.bytedance.adsdk.ugeno.yz.dsz dszVar = this.f6308ef;
        if (dszVar != null) {
            lbVar.fm(dszVar);
        }
        if ((lbVar instanceof com.bytedance.adsdk.ugeno.ro.fm) && (listEf = ((com.bytedance.adsdk.ugeno.ro.fm) lbVar).ef()) != null && listEf.size() > 0) {
            Iterator<com.bytedance.adsdk.ugeno.ro.lb<View>> it = listEf.iterator();
            while (it.hasNext()) {
                fm(it.next());
            }
        }
        if (c0019fmVt != null) {
            lbVar.fm(c0019fmVt.fm());
        }
        lbVar.ro();
    }

    public void fm(fhx fhxVar) {
        com.bytedance.adsdk.ugeno.core.fm.fm fmVarJnr = com.bytedance.adsdk.ugeno.jnr.fm().jnr();
        if (fmVarJnr == null) {
            this.jnr = fhxVar;
        } else {
            if (fmVarJnr.fm(fhxVar) != null) {
                throw null;
            }
            this.jnr = fhxVar;
        }
    }

    public void fm(com.bytedance.adsdk.ugeno.ro.lb lbVar, String str, Object... objArr) {
        List<com.bytedance.adsdk.ugeno.ro.lb<View>> listEf;
        if (lbVar == null) {
            return;
        }
        lbVar.fm(str, objArr);
        if (!(lbVar instanceof com.bytedance.adsdk.ugeno.ro.fm) || (listEf = ((com.bytedance.adsdk.ugeno.ro.fm) lbVar).ef()) == null || listEf.isEmpty()) {
            return;
        }
        Iterator<com.bytedance.adsdk.ugeno.ro.lb<View>> it = listEf.iterator();
        while (it.hasNext()) {
            fm(it.next(), str, objArr);
        }
    }

    public void fm(JSONObject jSONObject, com.bytedance.adsdk.ugeno.ro.lb lbVar) {
        ro(jSONObject, lbVar);
        fm((com.bytedance.adsdk.ugeno.ro.lb<View>) lbVar);
    }
}
