package fo;

import io.u;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;
import ko.t;
import kotlin.jvm.internal.g0;
import kotlin.jvm.internal.p0;
import kotlin.jvm.internal.v;
import sm.p;
import sm.x0;
import sm.z;

/* loaded from: classes3.dex */
public final class d implements ap.h {

    /* renamed from: f, reason: collision with root package name */
    static final /* synthetic */ kn.l[] f18625f = {p0.h(new g0(p0.b(d.class), "kotlinScopes", "getKotlinScopes()[Lorg/jetbrains/kotlin/resolve/scopes/MemberScope;"))};

    /* renamed from: b, reason: collision with root package name */
    private final eo.g f18626b;

    /* renamed from: c, reason: collision with root package name */
    private final h f18627c;

    /* renamed from: d, reason: collision with root package name */
    private final i f18628d;

    /* renamed from: e, reason: collision with root package name */
    private final gp.i f18629e;

    /* loaded from: classes3.dex */
    static final class a extends v implements dn.a {
        a() {
            super(0);
        }

        @Override // dn.a
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public final ap.h[] invoke() {
            Collection values = d.this.f18627c.K0().values();
            d dVar = d.this;
            ArrayList arrayList = new ArrayList();
            Iterator it = values.iterator();
            while (it.hasNext()) {
                ap.h b10 = dVar.f18626b.a().b().b(dVar.f18627c, (t) it.next());
                if (b10 != null) {
                    arrayList.add(b10);
                }
            }
            return (ap.h[]) op.a.b(arrayList).toArray(new ap.h[0]);
        }
    }

    public d(eo.g c10, u jPackage, h packageFragment) {
        kotlin.jvm.internal.t.g(c10, "c");
        kotlin.jvm.internal.t.g(jPackage, "jPackage");
        kotlin.jvm.internal.t.g(packageFragment, "packageFragment");
        this.f18626b = c10;
        this.f18627c = packageFragment;
        this.f18628d = new i(c10, jPackage, packageFragment);
        this.f18629e = c10.e().b(new a());
    }

    private final ap.h[] k() {
        return (ap.h[]) gp.m.a(this.f18629e, this, f18625f[0]);
    }

    @Override // ap.h
    public Set a() {
        ap.h[] k10 = k();
        LinkedHashSet linkedHashSet = new LinkedHashSet();
        for (ap.h hVar : k10) {
            z.A(linkedHashSet, hVar.a());
        }
        linkedHashSet.addAll(this.f18628d.a());
        return linkedHashSet;
    }

    @Override // ap.h
    public Collection b(ro.f name, ao.b location) {
        Set d10;
        kotlin.jvm.internal.t.g(name, "name");
        kotlin.jvm.internal.t.g(location, "location");
        l(name, location);
        i iVar = this.f18628d;
        ap.h[] k10 = k();
        Collection b10 = iVar.b(name, location);
        for (ap.h hVar : k10) {
            b10 = op.a.a(b10, hVar.b(name, location));
        }
        if (b10 != null) {
            return b10;
        }
        d10 = x0.d();
        return d10;
    }

    @Override // ap.h
    public Collection c(ro.f name, ao.b location) {
        Set d10;
        kotlin.jvm.internal.t.g(name, "name");
        kotlin.jvm.internal.t.g(location, "location");
        l(name, location);
        i iVar = this.f18628d;
        ap.h[] k10 = k();
        Collection c10 = iVar.c(name, location);
        for (ap.h hVar : k10) {
            c10 = op.a.a(c10, hVar.c(name, location));
        }
        if (c10 != null) {
            return c10;
        }
        d10 = x0.d();
        return d10;
    }

    @Override // ap.h
    public Set d() {
        ap.h[] k10 = k();
        LinkedHashSet linkedHashSet = new LinkedHashSet();
        for (ap.h hVar : k10) {
            z.A(linkedHashSet, hVar.d());
        }
        linkedHashSet.addAll(this.f18628d.d());
        return linkedHashSet;
    }

    @Override // ap.k
    public tn.h e(ro.f name, ao.b location) {
        kotlin.jvm.internal.t.g(name, "name");
        kotlin.jvm.internal.t.g(location, "location");
        l(name, location);
        tn.e e10 = this.f18628d.e(name, location);
        if (e10 != null) {
            return e10;
        }
        tn.h hVar = null;
        for (ap.h hVar2 : k()) {
            tn.h e11 = hVar2.e(name, location);
            if (e11 != null) {
                if (!(e11 instanceof tn.i) || !((tn.i) e11).H()) {
                    return e11;
                }
                if (hVar == null) {
                    hVar = e11;
                }
            }
        }
        return hVar;
    }

    @Override // ap.k
    public Collection f(ap.d kindFilter, dn.l nameFilter) {
        Set d10;
        kotlin.jvm.internal.t.g(kindFilter, "kindFilter");
        kotlin.jvm.internal.t.g(nameFilter, "nameFilter");
        i iVar = this.f18628d;
        ap.h[] k10 = k();
        Collection f10 = iVar.f(kindFilter, nameFilter);
        for (ap.h hVar : k10) {
            f10 = op.a.a(f10, hVar.f(kindFilter, nameFilter));
        }
        if (f10 != null) {
            return f10;
        }
        d10 = x0.d();
        return d10;
    }

    @Override // ap.h
    public Set g() {
        Iterable H;
        H = p.H(k());
        Set a10 = ap.j.a(H);
        if (a10 == null) {
            return null;
        }
        a10.addAll(this.f18628d.g());
        return a10;
    }

    public final i j() {
        return this.f18628d;
    }

    public void l(ro.f name, ao.b location) {
        kotlin.jvm.internal.t.g(name, "name");
        kotlin.jvm.internal.t.g(location, "location");
        zn.a.b(this.f18626b.a().l(), location, this.f18627c, name);
    }

    public String toString() {
        return "scope for " + this.f18627c;
    }
}
