package com.chartboost.sdk.impl;

import android.view.View;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import org.json.JSONObject;
/* loaded from: classes2.dex */
public class bc extends p {

    /* renamed from: a  reason: collision with root package name */
    public final r f1659a;
    public final q b;
    public final md c;
    public jc d;
    public t e;
    public boolean f;
    public boolean g;
    public final String h;
    public boolean i;
    public boolean j;

    public bc(q qVar, r rVar) {
        this(qVar, rVar, UUID.randomUUID().toString());
    }

    public void a(List list) {
        if (g()) {
            ArrayList arrayList = new ArrayList();
            Iterator it = list.iterator();
            while (it.hasNext()) {
                View view = (View) ((jc) it.next()).get();
                if (view != null) {
                    arrayList.add(view);
                }
            }
            throw null;
        }
    }

    public final void b(View view) {
        Collection<bc> b = vc.c().b();
        if (b == null || b.isEmpty()) {
            return;
        }
        for (bc bcVar : b) {
            if (bcVar != this && bcVar.e() == view) {
                bcVar.d.clear();
            }
        }
    }

    public final void c() {
        if (this.i) {
            throw new IllegalStateException("Impression event can only be sent once");
        }
    }

    public final void d() {
        if (this.j) {
            throw new IllegalStateException("Loaded event can only be sent once");
        }
    }

    public View e() {
        return (View) this.d.get();
    }

    public List f() {
        return this.c.a();
    }

    public boolean g() {
        return false;
    }

    public boolean h() {
        return this.f && !this.g;
    }

    public boolean i() {
        return this.g;
    }

    public String j() {
        return this.h;
    }

    public t k() {
        return this.e;
    }

    public boolean l() {
        return this.b.a();
    }

    public boolean m() {
        return this.b.b();
    }

    public boolean n() {
        return this.f;
    }

    public void o() {
        c();
        k().g();
        this.i = true;
    }

    public void p() {
        d();
        k().i();
        this.j = true;
    }

    public void q() {
        if (this.g) {
            return;
        }
        this.c.b();
    }

    public bc(q qVar, r rVar, String str) {
        this.c = new md();
        this.f = false;
        this.g = false;
        this.b = qVar;
        this.f1659a = rVar;
        this.h = str;
        c(null);
        this.e = (rVar.a() == s.HTML || rVar.a() == s.JAVASCRIPT) ? new fc(str, rVar.h()) : new lc(str, rVar.d(), rVar.e());
        this.e.j();
        vc.c().a(this);
        this.e.a(qVar);
    }

    public void a(JSONObject jSONObject) {
        d();
        k().a(jSONObject);
        this.j = true;
    }

    @Override // com.chartboost.sdk.impl.p
    public void b() {
        if (this.f) {
            return;
        }
        this.f = true;
        vc.c().c(this);
        this.e.a(rd.c().b());
        this.e.a(dc.a().b());
        this.e.a(this, this.f1659a);
    }

    public final void c(View view) {
        this.d = new jc(view);
    }

    @Override // com.chartboost.sdk.impl.p
    public void a(View view, i5 i5Var, String str) {
        if (this.g) {
            return;
        }
        this.c.a(view, i5Var, str);
    }

    @Override // com.chartboost.sdk.impl.p
    public void a() {
        if (this.g) {
            return;
        }
        this.d.clear();
        q();
        this.g = true;
        k().f();
        vc.c().b(this);
        k().b();
        this.e = null;
    }

    @Override // com.chartboost.sdk.impl.p
    public void a(View view) {
        if (this.g || e() == view) {
            return;
        }
        c(view);
        k().a();
        b(view);
    }
}
