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

import android.os.Bundle;
import androidx.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.json.JSONException;
import org.json.JSONObject;

/* JADX INFO: loaded from: classes2.dex */
public final class zw0 {

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final String f19408c;

    @Nullable
    private za1 zzd = null;

    @Nullable
    private wa1 zze = null;

    @Nullable
    private n7.h4 zzf = null;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final Map f19407b = Collections.synchronizedMap(new HashMap());

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final List f19406a = Collections.synchronizedList(new ArrayList());

    public zw0(String str) {
        this.f19408c = str;
    }

    public static String e(wa1 wa1Var) {
        return ((Boolean) n7.y.f31093e.f31096c.b(ao.f8964m4)).booleanValue() ? wa1Var.f17990j0 : wa1Var.f18011u;
    }

    private final void zzk(wa1 wa1Var, long j10, @Nullable n7.l2 l2Var, boolean z10) {
        String strE = e(wa1Var);
        Map map = this.f19407b;
        if (map.containsKey(strE)) {
            if (this.zze == null) {
                this.zze = wa1Var;
            }
            n7.h4 h4Var = (n7.h4) map.get(strE);
            h4Var.f30968b = j10;
            h4Var.zzc = l2Var;
            if (((Boolean) n7.y.f31093e.f31096c.b(ao.f9168y7)).booleanValue() && z10) {
                this.zzf = h4Var;
            }
        }
    }

    public final void a(za1 za1Var) {
        this.zzd = za1Var;
    }

    public final oe0 b() {
        return new oe0(this.zze, "", this, this.zzd, this.f19408c);
    }

    public final void c(wa1 wa1Var) {
        String strE = e(wa1Var);
        Map map = this.f19407b;
        Object obj = map.get(strE);
        List list = this.f19406a;
        int iIndexOf = list.indexOf(obj);
        if (iIndexOf < 0 || iIndexOf >= map.size()) {
            iIndexOf = list.indexOf(this.zzf);
        }
        if (iIndexOf < 0 || iIndexOf >= map.size()) {
            return;
        }
        this.zzf = (n7.h4) list.get(iIndexOf);
        while (true) {
            iIndexOf++;
            if (iIndexOf >= list.size()) {
                return;
            }
            n7.h4 h4Var = (n7.h4) list.get(iIndexOf);
            h4Var.f30968b = 0L;
            h4Var.zzc = null;
        }
    }

    public final synchronized void d(wa1 wa1Var, int i10) {
        Map map = this.f19407b;
        String strE = e(wa1Var);
        if (map.containsKey(strE)) {
            return;
        }
        Bundle bundle = new Bundle();
        JSONObject jSONObject = wa1Var.f18009t;
        Iterator<String> itKeys = jSONObject.keys();
        while (itKeys.hasNext()) {
            String next = itKeys.next();
            try {
                bundle.putString(next, jSONObject.getString(next));
            } catch (JSONException unused) {
            }
        }
        n7.h4 h4Var = new n7.h4(wa1Var.B, 0L, null, bundle, wa1Var.C, wa1Var.D, wa1Var.E, wa1Var.F);
        try {
            this.f19406a.add(i10, h4Var);
        } catch (IndexOutOfBoundsException e10) {
            m7.n.C.f30469h.d("AdapterResponseInfoCollector.addAdapterResponseInfoEntryAtLocation", e10);
        }
        this.f19407b.put(strE, h4Var);
    }

    public final void zzd(wa1 wa1Var, long j10, @Nullable n7.l2 l2Var) {
        zzk(wa1Var, j10, null, true);
    }

    public final void zze(wa1 wa1Var, long j10, @Nullable n7.l2 l2Var) {
        zzk(wa1Var, j10, l2Var, false);
    }

    @Nullable
    public final n7.h4 zzg() {
        return this.zzf;
    }
}
