package com.google.android.gms.internal.ads;

import android.content.Context;
import android.graphics.Point;
import android.graphics.Rect;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import androidx.annotation.Nullable;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.Executor;
import org.json.JSONObject;

/* JADX INFO: loaded from: classes2.dex */
public final class lm0 extends mc0 {
    public static final zzguf H;
    public final tg A;
    public final q7.a B;
    public final Context C;
    public final nm0 D;
    public final e11 E;
    public final HashMap F;
    public final ArrayList G;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public final Executor f13761k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public final pm0 f13762l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public final sm0 f13763m;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public final cn0 f13764n;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public final rm0 f13765o;

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    public final um0 f13766p;

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public final gg2 f13767q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public final gg2 f13768r;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public final gg2 f13769s;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public final gg2 f13770t;

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public final gg2 f13771u;

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    public boolean f13772v;

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    public boolean f13773w;

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    public boolean f13774x;

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    public boolean f13775y;

    /* JADX INFO: renamed from: z, reason: collision with root package name */
    public final w10 f13776z;

    @Nullable
    private pn0 zzo;

    static {
        bs1 bs1Var = zzguf.f19771b;
        Object[] objArr = {"3010", "3008", "1005", "1009", "2011", "2007"};
        ih1.t(6, objArr);
        H = zzguf.u(6, objArr);
    }

    public lm0(lc0 lc0Var, Executor executor, pm0 pm0Var, sm0 sm0Var, cn0 cn0Var, rm0 rm0Var, um0 um0Var, gg2 gg2Var, gg2 gg2Var2, gg2 gg2Var3, gg2 gg2Var4, gg2 gg2Var5, w10 w10Var, tg tgVar, q7.a aVar, Context context, nm0 nm0Var, e11 e11Var) {
        super(lc0Var);
        this.f13761k = executor;
        this.f13762l = pm0Var;
        this.f13763m = sm0Var;
        this.f13764n = cn0Var;
        this.f13765o = rm0Var;
        this.f13766p = um0Var;
        this.f13767q = gg2Var;
        this.f13768r = gg2Var2;
        this.f13769s = gg2Var3;
        this.f13770t = gg2Var4;
        this.f13771u = gg2Var5;
        this.f13776z = w10Var;
        this.A = tgVar;
        this.B = aVar;
        this.C = context;
        this.D = nm0Var;
        this.E = e11Var;
        this.F = new HashMap();
        this.G = new ArrayList();
    }

    public static boolean d(View view) {
        if (!((Boolean) n7.y.f31093e.f31096c.b(ao.Pb)).booleanValue()) {
            return view.isShown() && view.getGlobalVisibleRect(new Rect(), new Point());
        }
        p7.r0 r0Var = m7.n.C.f30464c;
        long jA = p7.r0.a(view);
        if (view.isShown() && view.getGlobalVisibleRect(new Rect(), new Point())) {
            if (jA >= ((Integer) r1.f31096c.b(ao.Qb)).intValue()) {
                return true;
            }
        }
        return false;
    }

    @Nullable
    private final synchronized View zzag(Map map) {
        if (map != null) {
            zzguf zzgufVar = H;
            int i10 = ((zzgwa) zzgufVar).f19788d;
            int i11 = 0;
            while (i11 < i10) {
                WeakReference weakReference = (WeakReference) map.get((String) ((zzgwa) zzgufVar).get(i11));
                i11++;
                if (weakReference != null) {
                    return (View) weakReference.get();
                }
            }
        }
        return null;
    }

    @Nullable
    private final synchronized ImageView.ScaleType zzah() {
        pn0 pn0Var = this.zzo;
        if (pn0Var == null) {
            q7.j.a("Ad should be associated with an ad view before calling getMediaviewScaleType()");
            return null;
        }
        k8.a aVarZzo = pn0Var.zzo();
        if (aVarZzo != null) {
            return (ImageView.ScaleType) k8.b.O(aVarZzo);
        }
        return cn0.f9989i;
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX INFO: renamed from: zzaj, reason: merged with bridge method [inline-methods] */
    public final void h(View view, @Nullable sw0 sw0Var) {
        x50 x50VarZzW = this.f13762l.zzW();
        if (!this.f13765o.c() || sw0Var == null || x50VarZzW == null || view == null) {
            return;
        }
        m7.n.C.f30485x.c(sw0Var.f16602a, view);
    }

    @Override // com.google.android.gms.internal.ads.mc0
    public final void a() {
        hm0 hm0Var = new hm0(this, 1);
        Executor executor = this.f13761k;
        executor.execute(hm0Var);
        if (this.f13762l.r() != 7) {
            sm0 sm0Var = this.f13763m;
            Objects.requireNonNull(sm0Var);
            executor.execute(new z80(sm0Var, 10));
        }
        super.a();
    }

    public final synchronized void c() {
        pn0 pn0Var = this.zzo;
        if (pn0Var == null) {
            q7.j.a("Ad should be associated with an ad view before calling recordCustomClickGesture()");
        } else {
            this.f13761k.execute(new n5.q(4, this, pn0Var instanceof an0));
        }
    }

    public final void e(View view) {
        boolean zBooleanValue = ((Boolean) n7.y.f31093e.f31096c.b(ao.h6)).booleanValue();
        pm0 pm0Var = this.f13762l;
        if (!zBooleanValue || pm0Var.r() == 3) {
            h(view, pm0Var.zzZ());
            return;
        }
        e30 e30VarZzY = pm0Var.zzY();
        if (e30VarZzY == null) {
            return;
        }
        ih1.z1(e30VarZzY, new zv1(this, view), this.f13761k);
    }

    public final /* synthetic */ void f(boolean z10) {
        pn0 pn0Var = this.zzo;
        if (pn0Var == null) {
            q7.j.a("Ad should be associated with an ad view before calling recordCustomClickGesture()");
        } else {
            this.f13763m.zzf(null, pn0Var.zzdE(), this.zzo.zzj(), this.zzo.zzk(), z10, zzah(), 0);
        }
    }

    public final /* synthetic */ void g(View view, int i10, boolean z10) {
        pn0 pn0Var = this.zzo;
        if (pn0Var == null) {
            q7.j.a("Ad should be associated with an ad view before calling performClickForCustomGesture()");
        } else {
            this.f13763m.zzf(view, pn0Var.zzdE(), this.zzo.zzj(), this.zzo.zzk(), z10, zzah(), i10);
        }
    }

    public final /* synthetic */ pn0 i() {
        return this.zzo;
    }

    public final synchronized void j(pn0 pn0Var) {
        Iterator<String> itKeys;
        View view;
        qg qgVar;
        try {
            if (!this.f13772v) {
                this.zzo = pn0Var;
                cn0 cn0Var = this.f13764n;
                cn0Var.getClass();
                cn0Var.f9994e.execute(new bv(cn0Var, pn0Var, 25));
                this.f13763m.zza(pn0Var.zzdE(), pn0Var.zzk(), pn0Var.zzl(), pn0Var, pn0Var);
                tn tnVar = ao.f8882h3;
                n7.y yVar = n7.y.f31093e;
                if (((Boolean) yVar.f31096c.b(tnVar)).booleanValue() && (qgVar = this.A.f16877b) != null) {
                    qgVar.zzh(pn0Var.zzdE());
                }
                if (((Boolean) yVar.f31096c.b(ao.f8881h2)).booleanValue()) {
                    wa1 wa1Var = this.f14057b;
                    if (wa1Var.f17982f0 && (itKeys = wa1Var.f17980e0.keys()) != null) {
                        while (itKeys.hasNext()) {
                            String next = itKeys.next();
                            pn0 pn0Var2 = this.zzo;
                            WeakReference weakReference = pn0Var2 == null ? null : (WeakReference) pn0Var2.zzj().get(next);
                            this.F.put(next, Boolean.FALSE);
                            if (weakReference != null && (view = (View) weakReference.get()) != null) {
                                lj ljVar = new lj(this.C, view);
                                this.G.add(ljVar);
                                ljVar.f13728k.add(new gm0(this, next));
                                ljVar.d(3);
                            }
                        }
                    }
                }
                if (pn0Var.zzh() != null) {
                    lj ljVarZzh = pn0Var.zzh();
                    ljVarZzh.f13728k.add(this.f13776z);
                    ljVarZzh.d(3);
                }
            }
        } catch (Throwable th) {
            throw th;
        }
    }

    public final void k(pn0 pn0Var) {
        this.f13763m.zzb(pn0Var.zzdE(), pn0Var.zzj());
        if (pn0Var.zzdA() != null) {
            pn0Var.zzdA().setClickable(false);
            pn0Var.zzdA().removeAllViews();
        }
        if (pn0Var.zzh() != null) {
            pn0Var.zzh().f13728k.remove(this.f13776z);
        }
        this.zzo = null;
    }

    public final synchronized void l(View view, Map map, Map map2) {
        this.f13764n.zzc(this.zzo);
        this.f13763m.zzw(view, map, map2, zzah());
        this.f13773w = true;
    }

    public final synchronized void m(View view, Map map, Map map2) {
        View viewZzag;
        if (!this.f13774x && (viewZzag = zzag(map)) != null) {
            tn tnVar = ao.Qe;
            n7.y yVar = n7.y.f31093e;
            if (((Boolean) yVar.f31096c.b(tnVar)).booleanValue()) {
                Rect rect = new Rect();
                if (viewZzag.getGlobalVisibleRect(rect, new Point()) && viewZzag.getHeight() == rect.height() && viewZzag.getWidth() == rect.width()) {
                    this.f13763m.zzx(view, map, map2, zzah());
                    this.f13774x = true;
                }
            } else if (!((Boolean) yVar.f31096c.b(ao.Re)).booleanValue()) {
                tn tnVar2 = ao.Se;
                if (((Float) yVar.f31096c.b(tnVar2)).floatValue() > 0.0d) {
                    double dFloatValue = ((Float) yVar.f31096c.b(tnVar2)).floatValue();
                    if (viewZzag.getGlobalVisibleRect(new Rect(), new Point())) {
                        if (r4.height() * r4.width() >= ((double) (viewZzag.getHeight() * viewZzag.getWidth())) * (dFloatValue / 100.0d)) {
                            this.f13763m.zzx(view, map, map2, zzah());
                            this.f13774x = true;
                        }
                    }
                }
            } else if (d(viewZzag)) {
                this.f13763m.zzx(view, map, map2, zzah());
                this.f13774x = true;
            }
        }
    }

    public final void n() {
        if (!((Boolean) n7.y.f31093e.f31096c.b(ao.h6)).booleanValue()) {
            zzL("Google", true);
            return;
        }
        com.google.common.util.concurrent.w wVarZzX = this.f13762l.zzX();
        if (wVarZzX == null) {
            return;
        }
        ih1.z1(wVarZzX, new zv1(this), this.f13761k);
    }

    public final synchronized void o() {
        this.f13772v = true;
        this.f13761k.execute(new hm0(this, 0));
        this.f14058c.zzc(null);
    }

    public final synchronized boolean p(Bundle bundle) {
        if (this.f13773w) {
            return true;
        }
        boolean zH = this.f13763m.h(bundle);
        this.f13773w = zH;
        return zH;
    }

    public final synchronized void q(pn0 pn0Var) {
        if (((Boolean) n7.y.f31093e.f31096c.b(ao.f8848f2)).booleanValue()) {
            p7.r0.f31763l.post(new im0(this, pn0Var, 0));
        } else {
            j(pn0Var);
        }
    }

    public final synchronized void r(pn0 pn0Var) {
        if (((Boolean) n7.y.f31093e.f31096c.b(ao.f8848f2)).booleanValue()) {
            p7.r0.f31763l.post(new im0(this, pn0Var, 1));
        } else {
            k(pn0Var);
        }
    }

    public final synchronized void s(View view, View view2, Map map, Map map2, boolean z10) {
        x50 x50VarZzT;
        this.f13764n.zzb(this.zzo);
        this.f13763m.zzc(view, view2, map, map2, z10, zzah());
        if (this.f13775y) {
            pm0 pm0Var = this.f13762l;
            if (pm0Var.zzT() != null && (x50VarZzT = pm0Var.zzT()) != null) {
                x50VarZzT.d("onSdkAdUserInteractionClick", new androidx.collection.f());
            }
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:21:0x004a A[Catch: all -> 0x000a, TryCatch #0 {, blocks: (B:3:0x0001, B:5:0x0005, B:10:0x000d, B:12:0x001f, B:14:0x0025, B:15:0x002f, B:17:0x0035, B:21:0x004a, B:24:0x005e, B:25:0x0066, B:27:0x006c, B:29:0x0080, B:31:0x0086, B:36:0x008d), top: B:41:0x0001 }] */
    /* JADX WARN: Removed duplicated region for block: B:36:0x008d A[Catch: all -> 0x000a, TRY_ENTER, TRY_LEAVE, TryCatch #0 {, blocks: (B:3:0x0001, B:5:0x0005, B:10:0x000d, B:12:0x001f, B:14:0x0025, B:15:0x002f, B:17:0x0035, B:21:0x004a, B:24:0x005e, B:25:0x0066, B:27:0x006c, B:29:0x0080, B:31:0x0086, B:36:0x008d), top: B:41:0x0001 }] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final synchronized void t(View view, Map map, Map map2, boolean z10) {
        if (this.f13773w) {
            m(view, map, map2);
            return;
        }
        if (((Boolean) n7.y.f31093e.f31096c.b(ao.f8881h2)).booleanValue() && this.f14057b.f17982f0) {
            HashMap map3 = this.F;
            Iterator it = map3.keySet().iterator();
            while (it.hasNext()) {
                if (!((Boolean) map3.get((String) it.next())).booleanValue()) {
                    break;
                }
            }
            if (!z10) {
            }
        } else {
            if (!z10) {
                l(view, map, map2);
                m(view, map, map2);
                return;
            }
            if (((Boolean) n7.y.f31093e.f31096c.b(ao.C4)).booleanValue() && map != null) {
                Iterator it2 = map.entrySet().iterator();
                while (it2.hasNext()) {
                    View view2 = (View) ((WeakReference) ((Map.Entry) it2.next()).getValue()).get();
                    if (view2 != null && d(view2)) {
                        l(view, map, map2);
                        return;
                    }
                }
            }
        }
    }

    public final synchronized JSONObject u(FrameLayout frameLayout, Map map, Map map2) {
        return this.f13763m.zzl(frameLayout, map, map2, zzah());
    }

    public final synchronized JSONObject v(View view, Map map, Map map2) {
        return this.f13763m.zzm(view, map, map2, zzah());
    }

    public final synchronized void zzA(@Nullable n7.x1 x1Var) {
        this.f13763m.zzr(x1Var);
    }

    public final synchronized void zzE(@Nullable View view, int i10) {
        if (((Boolean) n7.y.f31093e.f31096c.b(ao.Lc)).booleanValue()) {
            pn0 pn0Var = this.zzo;
            if (pn0Var == null) {
                q7.j.a("Ad should be associated with an ad view before calling performClickForCustomGesture()");
            } else {
                this.f13761k.execute(new jm0(this, view, pn0Var instanceof an0, i10));
            }
        }
    }

    @Nullable
    public final sw0 zzL(String str, boolean z10) {
        boolean z11;
        boolean z12;
        String str2;
        zzejx zzejxVar;
        zzejy zzejyVar;
        rm0 rm0Var = this.f13765o;
        if (rm0Var.c() && !TextUtils.isEmpty(str)) {
            pm0 pm0Var = this.f13762l;
            x50 x50VarZzW = pm0Var.zzW();
            x50 x50VarZzT = pm0Var.zzT();
            if (x50VarZzW == null && x50VarZzT == null) {
                q7.j.d("Omid display and video webview are null. Skipping initialization.");
                return null;
            }
            rm0Var.f();
            int iA = rm0Var.f().a();
            int i10 = iA - 1;
            if (i10 != 0) {
                if (i10 != 1) {
                    String str3 = iA != 1 ? iA != 2 ? "UNKNOWN" : "DISPLAY" : "VIDEO";
                    StringBuilder sb = new StringBuilder(str3.length() + 49);
                    sb.append("Unknown omid media type: ");
                    sb.append(str3);
                    sb.append(". Not initializing Omid.");
                    q7.j.d(sb.toString());
                    return null;
                }
                if (x50VarZzW == null) {
                    q7.j.d("Omid media type was display but there was no display webview.");
                    return null;
                }
                z12 = false;
                z11 = true;
            } else if (x50VarZzT != null) {
                z11 = false;
                z12 = true;
            } else {
                q7.j.d("Omid media type was video but there was no video webview.");
            }
            if (z11) {
                str2 = null;
            } else {
                str2 = "javascript";
                x50VarZzW = x50VarZzT;
            }
            if (x50VarZzW == null) {
                q7.j.d("Webview is null in InternalNativeAd");
                return null;
            }
            m7.n nVar = m7.n.C;
            if (!nVar.f30485x.a(this.C)) {
                q7.j.d("Failed to initialize omid in InternalNativeAd");
                return null;
            }
            q7.a aVar = this.B;
            int i11 = aVar.f32213b;
            int iB = com.google.android.gms.measurement.internal.u1.b(i11, 1);
            int i12 = aVar.f32214c;
            StringBuilder sb2 = new StringBuilder(iB + String.valueOf(i12).length());
            sb2.append(i11);
            sb2.append(".");
            sb2.append(i12);
            String string = sb2.toString();
            if (z12) {
                zzejxVar = zzejx.VIDEO;
                zzejyVar = zzejy.DEFINED_BY_JAVASCRIPT;
            } else {
                zzejxVar = zzejx.NATIVE_DISPLAY;
                zzejyVar = pm0Var.r() == 3 ? zzejy.UNSPECIFIED : zzejy.ONE_PIXEL;
            }
            sw0 sw0VarZzd = nVar.f30485x.zzd(string, x50VarZzW.c(), "", "javascript", str2, str, zzejyVar, zzejxVar, this.f14057b.zzal);
            if (sw0VarZzd == null) {
                q7.j.d("Failed to create omid session in InternalNativeAd");
                return null;
            }
            pm0Var.p(sw0VarZzd);
            x50VarZzW.I(sw0VarZzd);
            pw0 pw0Var = nVar.f30485x;
            sf1 sf1Var = sw0VarZzd.f16602a;
            if (z12) {
                if (x50VarZzT != null) {
                    pw0Var.c(sf1Var, x50VarZzT.o());
                }
                this.f13775y = true;
            }
            if (z10) {
                pw0Var.b(sf1Var);
                x50VarZzW.d("onSdkLoaded", new androidx.collection.f(0));
            }
            return sw0VarZzd;
        }
        return null;
    }
}
