package com.bytedance.sdk.openadsdk.core.YoT;

import com.bytedance.sdk.openadsdk.core.YoT.Sg.tN;
import com.bytedance.sdk.openadsdk.core.YoT.tN.YFl;
import com.bytedance.sdk.openadsdk.core.model.Wwa;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
/* loaded from: classes2.dex */
public class tN {
    protected YFl.Sg AlY;
    protected List<com.bytedance.sdk.openadsdk.core.YoT.Sg.tN> DSW;
    protected int Sg;
    protected int YFl;
    private Wwa YoT;
    private String nc;
    protected String qsH;
    protected YFl.EnumC0146YFl tN;
    protected List<com.bytedance.sdk.openadsdk.core.YoT.Sg.tN> vc;
    protected String wN;
    private final AtomicBoolean eT = new AtomicBoolean(false);
    protected String NjR = "endcard_click";

    public int Sg() {
        return this.YFl;
    }

    public void YFl(Wwa wwa) {
        this.YoT = wwa;
    }

    public void YFl(String str) {
        this.nc = str;
    }

    public int tN() {
        return this.Sg;
    }

    public String vc() {
        return this.wN;
    }

    public tN(int i, int i2, YFl.EnumC0146YFl enumC0146YFl, YFl.Sg sg, String str, List<com.bytedance.sdk.openadsdk.core.YoT.Sg.tN> list, List<com.bytedance.sdk.openadsdk.core.YoT.Sg.tN> list2, String str2) {
        this.vc = new ArrayList();
        this.DSW = new ArrayList();
        this.YFl = i;
        this.Sg = i2;
        this.tN = enumC0146YFl;
        this.AlY = sg;
        this.wN = str;
        this.vc = list;
        this.DSW = list2;
        this.qsH = str2;
    }

    public void YFl(long j) {
        com.bytedance.sdk.openadsdk.core.YoT.Sg.tN.YFl(this.vc, null, j, this.nc, new tN.Sg(this.NjR, this.YoT));
    }

    public void Sg(long j) {
        if (this.eT.compareAndSet(false, true)) {
            com.bytedance.sdk.openadsdk.core.YoT.Sg.tN.Sg(this.DSW, null, j, this.nc);
        }
    }

    public static float YFl(int i, int i2, int i3, int i4, YFl.Sg sg, YFl.EnumC0146YFl enumC0146YFl) {
        if (i2 == 0 || i4 == 0) {
            return 0.0f;
        }
        float f = i;
        float f2 = i3;
        return YFl(sg, enumC0146YFl) / ((Math.abs((f / i2) - (f2 / i4)) + Math.abs((f - f2) / f)) + 1.0f);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* renamed from: com.bytedance.sdk.openadsdk.core.YoT.tN$1  reason: invalid class name */
    /* loaded from: classes2.dex */
    public static /* synthetic */ class AnonymousClass1 {
        static final /* synthetic */ int[] YFl;

        static {
            int[] iArr = new int[YFl.Sg.values().length];
            YFl = iArr;
            try {
                iArr[YFl.Sg.STATIC_RESOURCE.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                YFl[YFl.Sg.HTML_RESOURCE.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                YFl[YFl.Sg.IFRAME_RESOURCE.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
        }
    }

    private static float YFl(YFl.Sg sg, YFl.EnumC0146YFl enumC0146YFl) {
        int i = AnonymousClass1.YFl[sg.ordinal()];
        if (i != 1) {
            if (i != 2) {
                return i != 3 ? 0.0f : 1.0f;
            }
            return 1.2f;
        } else if (YFl.EnumC0146YFl.JAVASCRIPT.equals(enumC0146YFl)) {
            return 1.0f;
        } else {
            return YFl.EnumC0146YFl.IMAGE.equals(enumC0146YFl) ? 0.8f : 0.0f;
        }
    }

    public String AlY() {
        int i = AnonymousClass1.YFl[this.AlY.ordinal()];
        if (i != 1) {
            if (i != 2) {
                if (i != 3) {
                    return null;
                }
                return "<iframe frameborder=\"0\" scrolling=\"no\" marginheight=\"0\" marginwidth=\"0\" style=\"border: 0px; margin: 0px;\" width=\"" + this.YFl + "\" height=\"" + this.Sg + "\" src=\"" + this.wN + "\"></iframe>";
            }
            return this.wN;
        } else if (this.tN == YFl.EnumC0146YFl.IMAGE) {
            return "<html><head></head><body style=\"margin:0;padding:0\"><img src=\"" + this.wN + "\" width=\"100%\" style=\"max-width:100%;max-height:100%;\" /></body></html>";
        } else {
            if (this.tN == YFl.EnumC0146YFl.JAVASCRIPT) {
                return "<script src=\"" + this.wN + "\"></script>";
            }
            return null;
        }
    }

    public String wN() {
        if (this.AlY == YFl.Sg.STATIC_RESOURCE && this.tN == YFl.EnumC0146YFl.IMAGE) {
            return this.wN;
        }
        return null;
    }

    public static tN Sg(JSONObject jSONObject) {
        if (jSONObject == null) {
            return null;
        }
        int optInt = jSONObject.optInt("width");
        int optInt2 = jSONObject.optInt("height");
        String optString = jSONObject.optString("creativeType", YFl.EnumC0146YFl.NONE.toString());
        String optString2 = jSONObject.optString("resourceType", YFl.Sg.HTML_RESOURCE.toString());
        String optString3 = jSONObject.optString("contentUrl");
        String optString4 = jSONObject.optString("clickThroughUri");
        JSONArray optJSONArray = jSONObject.optJSONArray("clickTrackers");
        JSONArray optJSONArray2 = jSONObject.optJSONArray("creativeViewTrackers");
        ArrayList arrayList = new ArrayList();
        for (int i = 0; i < optJSONArray.length(); i++) {
            arrayList.add(new tN.YFl(optJSONArray.optString(i)).YFl());
        }
        ArrayList arrayList2 = new ArrayList();
        for (int i2 = 0; i2 < optJSONArray2.length(); i2++) {
            arrayList2.add(new tN.YFl(optJSONArray2.optString(i2)).YFl());
        }
        return new tN(optInt, optInt2, YFl.EnumC0146YFl.valueOf(optString), YFl.Sg.valueOf(optString2), optString3, arrayList, arrayList2, optString4);
    }

    public JSONObject YFl() throws JSONException {
        JSONObject jSONObject = new JSONObject();
        jSONObject.put("width", this.YFl);
        jSONObject.put("height", this.Sg);
        jSONObject.put("creativeType", this.tN.toString());
        jSONObject.put("resourceType", this.AlY.toString());
        jSONObject.put("contentUrl", this.wN);
        jSONObject.put("clickThroughUri", this.qsH);
        jSONObject.put("clickTrackers", com.bytedance.sdk.openadsdk.core.YoT.Sg.tN.YFl(this.vc));
        jSONObject.put("creativeViewTrackers", com.bytedance.sdk.openadsdk.core.YoT.Sg.tN.YFl(this.DSW));
        return jSONObject;
    }
}
