package com.bytedance.sdk.openadsdk.core.dsz.ajl;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;
import com.bytedance.adsdk.ugeno.core.dsz;
import com.bytedance.sdk.component.utils.gof;
import com.bytedance.sdk.component.utils.wey;
import com.bytedance.sdk.openadsdk.core.gqi;
import com.bytedance.sdk.openadsdk.core.model.lse;
import com.bytedance.sdk.openadsdk.utils.bx;
import java.util.Iterator;
import org.json.JSONArray;
import org.json.JSONObject;
import tv.danmaku.ijk.media.player.IjkMediaPlayer;

/* JADX INFO: loaded from: classes2.dex */
public class jnr {
    private boolean dsz;
    private final JSONObject duv;

    /* JADX INFO: renamed from: ef, reason: collision with root package name */
    private final String f7027ef;
    private boolean fhx;
    private JSONArray irt;
    private com.bytedance.adsdk.ugeno.ro.lb jnr;
    private JSONObject ku;

    /* JADX INFO: renamed from: lb, reason: collision with root package name */
    private com.bytedance.adsdk.ugeno.ro.lb f7028lb;
    private boolean onz;
    private com.bytedance.sdk.openadsdk.core.widget.jnr vt;
    private final Context wsy;
    private final lse wu;
    private com.bytedance.adsdk.ugeno.ro.lb yz;
    private int fm = -1;
    private int ro = -1;
    private final String ajl = "UGenSwiperEvent";

    public jnr(Context context, lse lseVar, String str, JSONObject jSONObject) {
        this.wsy = context;
        this.wu = lseVar;
        this.f7027ef = str;
        this.duv = jSONObject;
    }

    public void fm(com.bytedance.sdk.openadsdk.core.widget.jnr jnrVar) {
        this.vt = jnrVar;
    }

    public JSONObject yz() {
        return this.ku;
    }

    public void lb() {
        int i10;
        com.bytedance.adsdk.ugeno.ro.lb lbVar = this.jnr;
        if (!(lbVar instanceof com.bytedance.adsdk.ugeno.lb) || (i10 = this.fm) == -1) {
            return;
        }
        ((com.bytedance.adsdk.ugeno.lb) lbVar).fm(i10 + 1);
    }

    public void ro() {
        int i10;
        com.bytedance.adsdk.ugeno.ro.lb lbVar = this.jnr;
        if (!(lbVar instanceof com.bytedance.adsdk.ugeno.lb) || (i10 = this.fm) == -1) {
            return;
        }
        ((com.bytedance.adsdk.ugeno.lb) lbVar).fm(i10 - 1);
    }

    public void fm(com.bytedance.adsdk.ugeno.ro.lb<View> lbVar) {
        com.bytedance.adsdk.ugeno.ro.lb<T> lbVarJnr = lbVar.jnr("swiperLayout");
        this.jnr = lbVarJnr;
        if (lbVarJnr instanceof com.bytedance.adsdk.ugeno.lb) {
            this.irt = this.duv.optJSONArray("dpa_data");
            this.f7028lb = lbVar.jnr("swiperLeftArrow");
            this.yz = lbVar.jnr("swiperRightArrow");
            ((com.bytedance.adsdk.ugeno.lb) this.jnr).fm(new com.bytedance.adsdk.ugeno.ajl.lb() { // from class: com.bytedance.sdk.openadsdk.core.dsz.ajl.jnr.1
                @Override // com.bytedance.adsdk.ugeno.ajl.lb
                public void fm(boolean z10, int i10) {
                }

                @Override // com.bytedance.adsdk.ugeno.ajl.lb
                public void fm(boolean z10, int i10, float f10, int i11) {
                }

                @Override // com.bytedance.adsdk.ugeno.ajl.lb
                public void fm(boolean z10, int i10, int i11, boolean z11, boolean z12) {
                    jnr.this.ro = i10;
                    jnr.this.fm = i11;
                    jnr.this.dsz = z10;
                    jnr.this.onz = z11;
                    jnr.this.fhx = z12;
                    jnr.this.fm(z10, z11, z12);
                    jnr.this.fm(i10);
                }
            });
        }
    }

    public void fm() {
        fm(this.dsz, this.onz, this.fhx);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void fm(boolean z10, boolean z11, boolean z12) {
        com.bytedance.adsdk.ugeno.ro.lb lbVar = this.f7028lb;
        if (lbVar == null || this.yz == null) {
            return;
        }
        View viewKu = lbVar.ku();
        View viewKu2 = this.yz.ku();
        JSONArray jSONArray = this.irt;
        if (jSONArray != null && jSONArray.length() == 1) {
            viewKu.setVisibility(8);
            viewKu2.setVisibility(8);
            return;
        }
        if (z10) {
            return;
        }
        if (z11) {
            if (viewKu instanceof TextView) {
                fm((TextView) viewKu, 90);
            }
            if (viewKu2 instanceof TextView) {
                fm((TextView) viewKu2, 255);
                return;
            }
            return;
        }
        if (z12) {
            if (viewKu instanceof TextView) {
                fm((TextView) viewKu, 255);
            }
            if (viewKu2 instanceof TextView) {
                fm((TextView) viewKu2, 90);
                return;
            }
            return;
        }
        if (viewKu instanceof TextView) {
            fm((TextView) viewKu, 255);
        }
        if (viewKu2 instanceof TextView) {
            fm((TextView) viewKu2, 255);
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void fm(int i10) {
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.put("index", i10);
        } catch (Throwable unused) {
        }
        com.bytedance.sdk.openadsdk.yz.lb.ro(this.wu, this.f7027ef, "carousel_show", jSONObject);
    }

    private void fm(TextView textView, int i10) {
        int currentTextColor = textView.getCurrentTextColor();
        textView.setTextColor(Color.argb(i10, Color.red(currentTextColor), Color.green(currentTextColor), Color.blue(currentTextColor)));
    }

    public boolean fm(dsz dszVar) {
        JSONObject jSONObjectOptJSONObject;
        this.ku = null;
        int i10 = this.ro;
        if (i10 != -1 && i10 != 0) {
            try {
                JSONObject jSONObjectLb = dszVar.lb();
                if (jSONObjectLb != null && (jSONObjectOptJSONObject = jSONObjectLb.optJSONObject("related_dpa_click")) != null) {
                    boolean zOptBoolean = jSONObjectOptJSONObject.optBoolean("enableOpenExternalUrl");
                    int iOptInt = jSONObjectOptJSONObject.optInt("landingStyle");
                    if (zOptBoolean && iOptInt != -1) {
                        if (this.irt != null) {
                            String strFm = com.bytedance.adsdk.ugeno.lb.ro.fm(jSONObjectOptJSONObject.optString(IjkMediaPlayer.OnNativeInvokeListener.ARG_URL), this.irt.optJSONObject(this.ro));
                            String strFm2 = com.bytedance.adsdk.ugeno.lb.ro.fm(jSONObjectOptJSONObject.optString("fallback_url"), this.irt.optJSONObject(this.ro));
                            jSONObjectOptJSONObject.put(IjkMediaPlayer.OnNativeInvokeListener.ARG_URL, strFm);
                            jSONObjectOptJSONObject.put("fallback_url", strFm2);
                            fm(jSONObjectOptJSONObject, this.irt.optJSONObject(this.ro));
                        }
                        fm(jSONObjectOptJSONObject, dszVar.fm().ku());
                        return true;
                    }
                    return false;
                }
            } catch (Throwable th) {
                wey.lb("UGenSwiperEvent", th.getMessage());
            }
        }
        return false;
    }

    private void fm(JSONObject jSONObject, JSONObject jSONObject2) {
        if (jSONObject == null || jSONObject2 == null) {
            return;
        }
        JSONObject jSONObjectOptJSONObject = jSONObject.optJSONObject("clickInfo");
        this.ku = jSONObjectOptJSONObject;
        if (jSONObjectOptJSONObject != null) {
            Iterator<String> itKeys = jSONObjectOptJSONObject.keys();
            while (itKeys.hasNext()) {
                String next = itKeys.next();
                try {
                    this.ku.putOpt(next, com.bytedance.adsdk.ugeno.lb.ro.fm((String) this.ku.opt(next), jSONObject2));
                } catch (Throwable unused) {
                }
            }
            try {
                jSONObject.putOpt("clickInfo", this.ku);
            } catch (Throwable unused2) {
            }
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:17:0x001f  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    private boolean fm(int i10, String str, String str2) {
        if (i10 == 1) {
            if (!gof.fm(str)) {
                return false;
            }
        } else if (i10 != 2) {
            if (i10 == 3) {
            }
        } else if ((TextUtils.isEmpty(str) && TextUtils.isEmpty(str2)) || !gof.fm(str2)) {
            return false;
        }
        return true;
    }

    private void fm(JSONObject jSONObject, View view) {
        if (fm(jSONObject.optInt("landingStyle"), jSONObject.optString(IjkMediaPlayer.OnNativeInvokeListener.ARG_URL), jSONObject.optString("fallback_url"))) {
            gqi.fm(fm(view), this.wsy instanceof Activity, jSONObject, this.wu, this.f7027ef, bx.fm(this.f7027ef), null, this.vt);
        }
    }

    private Context fm(View view) {
        Activity activityFm = view != null ? com.bytedance.sdk.component.utils.ro.fm(view) : null;
        return activityFm == null ? this.wsy : activityFm;
    }
}
