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

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;

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

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

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public ry0 f12282f;

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

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public final int f12285i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final qy0 f12286j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public wa1 f12287k;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final HashMap f12277a = new HashMap();

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final ArrayList f12278b = new ArrayList();

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final ArrayList f12280d = new ArrayList();

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final HashSet f12281e = new HashSet();

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public int f12283g = Integer.MAX_VALUE;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public boolean f12288l = false;

    public hy0(eb1 eb1Var, qy0 qy0Var, lv1 lv1Var) {
        this.f12285i = eb1Var.f10746b.f10364b.f19196q;
        this.f12286j = qy0Var;
        this.f12279c = lv1Var;
        this.f12284h = uy0.a(eb1Var);
        List list = eb1Var.f10746b.f10363a;
        for (int i10 = 0; i10 < list.size(); i10++) {
            this.f12277a.put((wa1) list.get(i10), Integer.valueOf(i10));
        }
        this.f12278b.addAll(list);
    }

    /* JADX WARN: Code restructure failed: missing block: B:12:0x0025, code lost:
    
        if (r2.f18002p0 == false) goto L16;
     */
    /* JADX WARN: Code restructure failed: missing block: B:13:0x0027, code lost:
    
        r6.f12288l = true;
     */
    /* JADX WARN: Code restructure failed: missing block: B:17:0x0031, code lost:
    
        if (android.text.TextUtils.isEmpty(r3) != false) goto L19;
     */
    /* JADX WARN: Code restructure failed: missing block: B:18:0x0033, code lost:
    
        r4.add(r3);
     */
    /* JADX WARN: Code restructure failed: missing block: B:19:0x0036, code lost:
    
        r6.f12280d.add(r2);
     */
    /* JADX WARN: Code restructure failed: missing block: B:21:0x0042, code lost:
    
        return (com.google.android.gms.internal.ads.wa1) r1.remove(r0);
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final synchronized wa1 a() {
        try {
            if (d()) {
                int i10 = 0;
                while (true) {
                    ArrayList arrayList = this.f12278b;
                    if (i10 >= arrayList.size()) {
                        break;
                    }
                    wa1 wa1Var = (wa1) arrayList.get(i10);
                    String str = wa1Var.f17998n0;
                    HashSet hashSet = this.f12281e;
                    if (!hashSet.contains(str)) {
                        break;
                    }
                    i10++;
                }
            }
            return null;
        } catch (Throwable th) {
            throw th;
        }
    }

    public final synchronized void b(ry0 ry0Var, wa1 wa1Var) {
        this.f12288l = false;
        this.f12280d.remove(wa1Var);
        synchronized (this) {
        }
        if (this.f12279c.isDone()) {
            ry0Var.zzm();
            return;
        }
        Integer num = (Integer) this.f12277a.get(wa1Var);
        Integer numValueOf = Integer.valueOf(num != null ? num.intValue() : Integer.MAX_VALUE);
        if (numValueOf.intValue() > this.f12283g) {
            this.f12286j.c(wa1Var);
            return;
        }
        if (this.f12282f != null) {
            this.f12286j.c(this.f12287k);
        }
        this.f12283g = numValueOf.intValue();
        this.f12282f = ry0Var;
        this.f12287k = wa1Var;
        synchronized (this) {
            if (!e(true)) {
                if (!f()) {
                    g();
                }
            }
        }
    }

    public final synchronized void c(wa1 wa1Var) {
        this.f12288l = false;
        this.f12280d.remove(wa1Var);
        this.f12281e.remove(wa1Var.f17998n0);
        synchronized (this) {
        }
        if (!this.f12279c.isDone()) {
            synchronized (this) {
                if (!e(true)) {
                    if (!f()) {
                        g();
                    }
                }
            }
        }
    }

    public final synchronized boolean d() {
        if (this.f12288l) {
            return false;
        }
        ArrayList arrayList = this.f12278b;
        if (!arrayList.isEmpty() && ((wa1) arrayList.get(0)).f18002p0 && !this.f12280d.isEmpty()) {
            return false;
        }
        synchronized (this) {
            if (!this.f12279c.isDone()) {
                ArrayList arrayList2 = this.f12280d;
                if (arrayList2.size() < this.f12285i && e(false)) {
                    return true;
                }
            }
            return false;
        }
    }

    public final synchronized boolean e(boolean z10) {
        try {
            for (wa1 wa1Var : this.f12278b) {
                Integer num = (Integer) this.f12277a.get(wa1Var);
                Integer numValueOf = Integer.valueOf(num != null ? num.intValue() : Integer.MAX_VALUE);
                if (z10 || !this.f12281e.contains(wa1Var.f17998n0)) {
                    if (numValueOf.intValue() < this.f12283g) {
                        return true;
                    }
                    if (numValueOf.intValue() > this.f12283g) {
                        break;
                    }
                }
            }
            return false;
        } catch (Throwable th) {
            throw th;
        }
    }

    public final synchronized boolean f() {
        try {
            Iterator it = this.f12280d.iterator();
            while (it.hasNext()) {
                Integer num = (Integer) this.f12277a.get((wa1) it.next());
                if (Integer.valueOf(num != null ? num.intValue() : Integer.MAX_VALUE).intValue() < this.f12283g) {
                    return true;
                }
            }
            return false;
        } catch (Throwable th) {
            throw th;
        }
    }

    public final synchronized void g() {
        this.f12286j.zzd(this.f12287k);
        ry0 ry0Var = this.f12282f;
        if (ry0Var != null) {
            this.f12279c.c(ry0Var);
        } else {
            this.f12279c.d(new zzenv(3, this.f12284h));
        }
    }
}
