package com.bytedance.sdk.component.adexpress.dynamic.jnr;

import android.text.TextUtils;
import androidx.media3.common.MimeTypes;
import com.bytedance.sdk.component.adexpress.dynamic.jnr.jnr;
import com.bytedance.sdk.component.adexpress.ro.dsz;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import tv.danmaku.ijk.media.player.IjkMediaMeta;
import u.a;
import xyz.stream.download.config.InnerConstant;

/* JADX INFO: loaded from: classes.dex */
public class ajl {
    private static HashMap<String, String> wsy;
    private com.bytedance.sdk.component.adexpress.dynamic.yz.yz ajl;
    private JSONObject fm;
    private lb jnr;

    /* JADX INFO: renamed from: lb, reason: collision with root package name */
    private com.bytedance.sdk.component.adexpress.dynamic.yz.lb f6476lb;
    private JSONObject ro;
    private fm yz;

    public static class fm {
        float fm;

        /* JADX INFO: renamed from: lb, reason: collision with root package name */
        boolean f6477lb;
        float ro;

        public static fm fm(JSONObject jSONObject) {
            fm fmVar = new fm();
            if (jSONObject != null) {
                fmVar.fm = (float) jSONObject.optDouble("width");
                fmVar.ro = (float) jSONObject.optDouble("height");
                fmVar.f6477lb = jSONObject.optBoolean("isLandscape");
            }
            return fmVar;
        }
    }

    static {
        HashMap<String, String> map = new HashMap<>();
        wsy = map;
        map.put("subtitle", "description");
        wsy.put("source", "source|app.app_name");
        wsy.put("screenshot", "dynamic_creative.screenshot");
    }

    public ajl(JSONObject jSONObject, JSONObject jSONObject2, JSONObject jSONObject3, JSONObject jSONObject4) {
        this.fm = jSONObject;
        this.ro = jSONObject2;
        this.f6476lb = new com.bytedance.sdk.component.adexpress.dynamic.yz.lb(jSONObject2);
        this.yz = fm.fm(jSONObject3);
        this.ajl = com.bytedance.sdk.component.adexpress.dynamic.yz.yz.fm(jSONObject4);
    }

    private void ro(com.bytedance.sdk.component.adexpress.dynamic.yz.wu wuVar) {
        com.bytedance.sdk.component.adexpress.dynamic.yz.lb lbVar;
        Object objFm;
        Object objFm2;
        Object objFm3;
        Object objFm4;
        if (wuVar == null || (lbVar = this.f6476lb) == null || (objFm = lbVar.fm("image.0.url")) == null) {
            return;
        }
        String strValueOf = String.valueOf(objFm);
        if (TextUtils.isEmpty(strValueOf) || (objFm2 = this.f6476lb.fm(IjkMediaMeta.IJKM_KEY_TITLE)) == null) {
            return;
        }
        String strValueOf2 = String.valueOf(objFm2);
        if (TextUtils.isEmpty(strValueOf2) || (objFm3 = this.f6476lb.fm("description")) == null) {
            return;
        }
        String strValueOf3 = String.valueOf(objFm3);
        if (TextUtils.isEmpty(strValueOf3) || (objFm4 = this.f6476lb.fm("icon")) == null) {
            return;
        }
        String strValueOf4 = String.valueOf(objFm4);
        if (TextUtils.isEmpty(strValueOf4)) {
            return;
        }
        Object objFm5 = this.f6476lb.fm("app.app_name");
        Object objFm6 = this.f6476lb.fm("source");
        if (objFm5 == null && objFm6 == null) {
            return;
        }
        if (objFm5 == null) {
            objFm5 = objFm6;
        }
        String strValueOf5 = String.valueOf(objFm5);
        if (TextUtils.isEmpty(strValueOf5)) {
            return;
        }
        wuVar.fm("imageUrl", strValueOf);
        wuVar.fm(IjkMediaMeta.IJKM_KEY_TITLE, strValueOf2);
        wuVar.fm("description", strValueOf3);
        wuVar.fm("icon", strValueOf4);
        wuVar.fm("app_name", strValueOf5);
        wuVar.fm(true);
    }

    public com.bytedance.sdk.component.adexpress.dynamic.yz.wu fm(double d10, int i10, double d11, String str, dsz dszVar) {
        JSONObject jSONObject;
        this.f6476lb.fm();
        try {
            jSONObject = new JSONObject(this.ajl.ro);
        } catch (JSONException unused) {
            jSONObject = null;
        }
        com.bytedance.sdk.component.adexpress.dynamic.yz.wu wuVarFm = fm(yz.fm(this.fm, jSONObject), (com.bytedance.sdk.component.adexpress.dynamic.yz.wu) null);
        fm(wuVarFm);
        jnr jnrVar = new jnr(d10, i10, d11, str, dszVar);
        jnr.fm fmVar = new jnr.fm();
        fm fmVar2 = this.yz;
        fmVar.fm = fmVar2.fm;
        fmVar.ro = fmVar2.ro;
        fmVar.f6479lb = 0.0f;
        jnrVar.fm(fmVar);
        jnrVar.fm(wuVarFm, 0.0f, 0.0f);
        jnrVar.fm();
        com.bytedance.sdk.component.adexpress.dynamic.yz.ro roVar = jnrVar.fm;
        if (roVar.yz == 65536.0f) {
            return null;
        }
        return roVar.ajl;
    }

    private void fm(com.bytedance.sdk.component.adexpress.dynamic.yz.wu wuVar) {
        int iFm;
        if (wuVar == null) {
            return;
        }
        if (com.bytedance.sdk.component.adexpress.fm.fm.fm.fm().lb() != null) {
            iFm = com.bytedance.sdk.component.adexpress.fm.fm.fm.fm().lb().irt();
        } else {
            iFm = com.bytedance.sdk.component.adexpress.yz.wsy.fm(com.bytedance.sdk.component.adexpress.yz.fm());
        }
        int iRo = com.bytedance.sdk.component.adexpress.yz.wsy.ro(com.bytedance.sdk.component.adexpress.yz.fm(), iFm);
        fm fmVar = this.yz;
        float fMin = fmVar.f6477lb ? fmVar.fm : Math.min(fmVar.fm, iRo);
        if (this.yz.ro == 0.0f) {
            wuVar.jnr(fMin);
            wuVar.vt().jnr().vt("auto");
            wuVar.ajl(0.0f);
        } else {
            wuVar.jnr(fMin);
            int iRo2 = com.bytedance.sdk.component.adexpress.yz.wsy.ro(com.bytedance.sdk.component.adexpress.yz.fm(), com.bytedance.sdk.component.adexpress.yz.wsy.ro(com.bytedance.sdk.component.adexpress.yz.fm()));
            fm fmVar2 = this.yz;
            wuVar.ajl(fmVar2.f6477lb ? fmVar2.ro : Math.min(fmVar2.ro, iRo2));
            wuVar.vt().jnr().vt("fixed");
        }
    }

    public com.bytedance.sdk.component.adexpress.dynamic.yz.wu fm(JSONObject jSONObject, com.bytedance.sdk.component.adexpress.dynamic.yz.wu wuVar) {
        int length;
        if (jSONObject == null) {
            return null;
        }
        String strOptString = jSONObject.optString("type");
        if (TextUtils.equals(strOptString, "custom-component-vessel")) {
            int iOptInt = jSONObject.optInt("componentId");
            if (this.ajl != null) {
                lb lbVar = new lb();
                this.jnr = lbVar;
                JSONObject jSONObjectFm = lbVar.fm(this.ajl.fm, iOptInt, jSONObject);
                if (jSONObjectFm != null) {
                    jSONObject = jSONObjectFm;
                }
            }
        }
        com.bytedance.sdk.component.adexpress.dynamic.yz.wu wuVarFm = fm(jSONObject);
        wuVarFm.fm(wuVar);
        JSONArray jSONArrayOptJSONArray = jSONObject.optJSONArray("children");
        if (jSONArrayOptJSONArray == null) {
            wuVarFm.fm((List<com.bytedance.sdk.component.adexpress.dynamic.yz.wu>) null);
            return wuVarFm;
        }
        ArrayList arrayList = new ArrayList();
        ArrayList arrayList2 = new ArrayList();
        for (int i10 = 0; i10 < jSONArrayOptJSONArray.length(); i10++) {
            JSONArray jSONArrayOptJSONArray2 = jSONArrayOptJSONArray.optJSONArray(i10);
            if (jSONArrayOptJSONArray2 != null) {
                ArrayList arrayList3 = new ArrayList();
                if (TextUtils.equals(strOptString, "tag-group")) {
                    length = wuVarFm.vt().jnr().jm();
                } else {
                    length = jSONArrayOptJSONArray2.length();
                }
                for (int i11 = 0; i11 < length; i11++) {
                    com.bytedance.sdk.component.adexpress.dynamic.yz.wu wuVarFm2 = fm(jSONArrayOptJSONArray2.optJSONObject(i11), wuVarFm);
                    if (com.bytedance.sdk.component.adexpress.yz.ro() && "skip-with-time".equals(wuVarFm.vt().ro()) && !"transparent".equals(wuVarFm.lse()) && !TextUtils.isEmpty(wuVarFm.lse())) {
                        wuVarFm2.lb(wuVarFm.lse());
                    }
                    arrayList.add(wuVarFm2);
                    arrayList3.add(wuVarFm2);
                }
                arrayList2.add(arrayList3);
            }
        }
        if (arrayList.size() > 0) {
            wuVarFm.fm(arrayList);
        }
        if (arrayList2.size() > 0) {
            wuVarFm.ro(arrayList2);
        }
        return wuVarFm;
    }

    public com.bytedance.sdk.component.adexpress.dynamic.yz.wu fm(JSONObject jSONObject) {
        String strFm;
        JSONObject jSONObject2;
        String strOptString = jSONObject.optString("type");
        String strOptString2 = jSONObject.optString(InnerConstant.Db.f36069id);
        JSONObject jSONObjectOptJSONObject = jSONObject.optJSONObject("values");
        ef.fm(strOptString, jSONObjectOptJSONObject);
        JSONObject jSONObjectFm = ef.fm(strOptString, ef.fm(jSONObject.optJSONArray("sceneValues")), jSONObjectOptJSONObject);
        com.bytedance.sdk.component.adexpress.dynamic.yz.wu wuVar = new com.bytedance.sdk.component.adexpress.dynamic.yz.wu();
        if (TextUtils.isEmpty(strOptString2)) {
            wuVar.ro(String.valueOf(wuVar.hashCode()));
        } else {
            wuVar.ro(strOptString2);
        }
        if (jSONObjectOptJSONObject != null) {
            ro(wuVar);
            wuVar.lb((float) jSONObjectOptJSONObject.optDouble("x"));
            wuVar.yz((float) jSONObjectOptJSONObject.optDouble("y"));
            wuVar.jnr((float) jSONObjectOptJSONObject.optDouble("width"));
            wuVar.ajl((float) jSONObjectOptJSONObject.optDouble("height"));
            wuVar.wsy(jSONObjectOptJSONObject.optInt("remainWidth"));
            com.bytedance.sdk.component.adexpress.dynamic.yz.jnr jnrVar = new com.bytedance.sdk.component.adexpress.dynamic.yz.jnr();
            jnrVar.fm(strOptString);
            jnrVar.ro(jSONObjectOptJSONObject.optString("data"));
            jnrVar.lb(jSONObjectOptJSONObject.optString("dataExtraInfo"));
            com.bytedance.sdk.component.adexpress.dynamic.yz.ajl ajlVarFm = com.bytedance.sdk.component.adexpress.dynamic.yz.ajl.fm(jSONObjectOptJSONObject);
            jnrVar.fm(ajlVarFm);
            com.bytedance.sdk.component.adexpress.dynamic.yz.ajl ajlVarFm2 = com.bytedance.sdk.component.adexpress.dynamic.yz.ajl.fm(jSONObjectFm);
            if (ajlVarFm2 == null) {
                jnrVar.ro(ajlVarFm);
            } else {
                jnrVar.ro(ajlVarFm2);
            }
            fm(ajlVarFm);
            fm(ajlVarFm2);
            if (TextUtils.equals(strOptString, "video-image-budget") && (jSONObject2 = this.ro) != null) {
                fm(jnrVar, jSONObject2.optInt("image_mode"));
            }
            String strRo = jnrVar.ro();
            com.bytedance.sdk.component.adexpress.dynamic.yz.ajl ajlVarJnr = jnrVar.jnr();
            if (wsy.containsKey(strRo) && !ajlVarJnr.mpp()) {
                ajlVarJnr.wey(wsy.get(strRo));
            }
            if (ajlVarJnr.mpp()) {
                strFm = jnrVar.lb();
            } else {
                strFm = fm(jnrVar.lb());
            }
            if (com.bytedance.sdk.component.adexpress.yz.ro()) {
                if (TextUtils.equals(strRo, "star") || TextUtils.equals(strRo, "text_star")) {
                    strFm = fm("dynamic_creative.score_exact_i18n|");
                }
                if (TextUtils.equals(strRo, "score-count") || TextUtils.equals(strRo, "score-count-type-1") || TextUtils.equals(strRo, "score-count-type-2")) {
                    strFm = fm("dynamic_creative.comment_num_i18n|");
                }
                if ("root".equals(strRo) && ajlVarFm.oy()) {
                    strFm = fm("image.0.url");
                }
            }
            if (!TextUtils.isEmpty(fm()) && (TextUtils.equals("logo-union", strOptString) || TextUtils.equals("logo", strOptString))) {
                StringBuilder sbD = a.d(strFm, "adx:");
                sbD.append(fm());
                jnrVar.ro(sbD.toString());
            } else {
                jnrVar.ro(strFm);
            }
            wuVar.fm(jnrVar);
        }
        return wuVar;
    }

    private void fm(com.bytedance.sdk.component.adexpress.dynamic.yz.jnr jnrVar, int i10) {
        int iLastIndexOf;
        if (i10 != 5 && i10 != 15 && i10 != 50 && i10 != 154) {
            jnrVar.fm(MimeTypes.BASE_TYPE_IMAGE);
            String strFm = ef.fm(MimeTypes.BASE_TYPE_IMAGE);
            com.bytedance.sdk.component.adexpress.dynamic.yz.ajl ajlVarJnr = jnrVar.jnr();
            ajlVarJnr.wey(strFm);
            jnrVar.wsy().wey(strFm);
            String strFm2 = ef.fm(MimeTypes.BASE_TYPE_IMAGE, "clickArea");
            if (!TextUtils.isEmpty(strFm2)) {
                ajlVarJnr.fhx(strFm2);
                jnrVar.wsy().fhx(strFm2);
            }
            JSONObject jSONObjectPyj = ajlVarJnr.pyj();
            if (jSONObjectPyj != null) {
                ajlVarJnr.lse(jSONObjectPyj.optString("imageLottieTosPath"));
                ajlVarJnr.duv(jSONObjectPyj.optBoolean("animationsLoop"));
                ajlVarJnr.nt(jSONObjectPyj.optInt("lottieAppNameMaxLength"));
                ajlVarJnr.gzf(jSONObjectPyj.optInt("lottieAdDescMaxLength"));
                ajlVarJnr.mq(jSONObjectPyj.optInt("lottieAdTitleMaxLength"));
            }
            jnrVar.ro(strFm);
            if (strFm != null && (iLastIndexOf = strFm.lastIndexOf(".")) > 0) {
                String strSubstring = strFm.substring(0, iLastIndexOf);
                JSONObject jSONObject = new JSONObject();
                try {
                    jSONObject.put("width", fm(strSubstring + ".width"));
                    jSONObject.put("height", fm(strSubstring + ".height"));
                } catch (JSONException unused) {
                }
                jnrVar.lb(jSONObject.toString());
            }
            ajlVarJnr.vj();
            return;
        }
        jnrVar.fm("video");
        String strFm3 = ef.fm("video");
        jnrVar.jnr().wey(strFm3);
        String strFm4 = ef.fm("video", "clickArea");
        if (!TextUtils.isEmpty(strFm4)) {
            jnrVar.jnr().fhx(strFm4);
            jnrVar.wsy().fhx(strFm4);
        }
        jnrVar.wsy().wey(strFm3);
        jnrVar.ro(strFm3);
        jnrVar.jnr().hou();
    }

    private String fm(String str) {
        if (TextUtils.isEmpty(str)) {
            return "";
        }
        for (String str2 : str.split("\\|")) {
            if (this.f6476lb.ro(str2)) {
                String strValueOf = String.valueOf(this.f6476lb.fm(str2));
                if (!TextUtils.isEmpty(strValueOf)) {
                    return strValueOf;
                }
            }
        }
        return "";
    }

    private String fm() {
        Object objFm;
        com.bytedance.sdk.component.adexpress.dynamic.yz.lb lbVar = this.f6476lb;
        return (lbVar == null || (objFm = lbVar.fm("adx_name")) == null) ? "" : String.valueOf(objFm);
    }

    private void fm(com.bytedance.sdk.component.adexpress.dynamic.yz.ajl ajlVar) {
        if (ajlVar == null) {
            return;
        }
        String strAi = ajlVar.ai();
        if (com.bytedance.sdk.component.adexpress.yz.ro()) {
            String strLb = com.bytedance.sdk.component.adexpress.yz.wsy.lb(com.bytedance.sdk.component.adexpress.yz.fm());
            if ("zh".equals(strLb)) {
                strLb = "cn";
            }
            if (!TextUtils.isEmpty(strLb) && ajlVar.ajl() != null) {
                String strOptString = ajlVar.ajl().optString(strLb);
                if (!TextUtils.isEmpty(strOptString)) {
                    strAi = strOptString;
                }
            }
        }
        if (TextUtils.isEmpty(strAi)) {
            return;
        }
        int iIndexOf = strAi.indexOf("{{");
        int iIndexOf2 = strAi.indexOf("}}");
        if (iIndexOf >= 0 && iIndexOf2 >= 0 && iIndexOf2 >= iIndexOf) {
            String strFm = fm(strAi.substring(iIndexOf + 2, iIndexOf2));
            StringBuilder sb = new StringBuilder(strAi.substring(0, iIndexOf));
            if (!TextUtils.isEmpty(strFm)) {
                sb.append(strFm);
            }
            sb.append(strAi.substring(iIndexOf2 + 2));
            ajlVar.duv(sb.toString());
            return;
        }
        ajlVar.duv(strAi);
    }
}
