package ap;

import ap.h;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import kotlin.jvm.internal.t;
import sm.p;
import sm.u;
import sm.x0;
import sm.z;

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

    /* renamed from: d, reason: collision with root package name */
    public static final a f6101d = new a(null);

    /* renamed from: b, reason: collision with root package name */
    private final String f6102b;

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

    /* loaded from: classes3.dex */
    public static final class a {
        private a() {
        }

        public /* synthetic */ a(kotlin.jvm.internal.k kVar) {
            this();
        }

        public final h a(String debugName, Iterable scopes) {
            t.g(debugName, "debugName");
            t.g(scopes, "scopes");
            pp.f fVar = new pp.f();
            Iterator it = scopes.iterator();
            while (it.hasNext()) {
                h hVar = (h) it.next();
                if (hVar != h.b.f6148b) {
                    if (hVar instanceof b) {
                        z.B(fVar, ((b) hVar).f6103c);
                    } else {
                        fVar.add(hVar);
                    }
                }
            }
            return b(debugName, fVar);
        }

        public final h b(String debugName, List scopes) {
            t.g(debugName, "debugName");
            t.g(scopes, "scopes");
            int size = scopes.size();
            return size != 0 ? size != 1 ? new b(debugName, (h[]) scopes.toArray(new h[0]), null) : (h) scopes.get(0) : h.b.f6148b;
        }
    }

    public /* synthetic */ b(String str, h[] hVarArr, kotlin.jvm.internal.k kVar) {
        this(str, hVarArr);
    }

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

    @Override // ap.h
    public Collection b(ro.f name, ao.b location) {
        List k10;
        Set d10;
        t.g(name, "name");
        t.g(location, "location");
        h[] hVarArr = this.f6103c;
        int length = hVarArr.length;
        if (length == 0) {
            k10 = u.k();
            return k10;
        }
        if (length == 1) {
            return hVarArr[0].b(name, location);
        }
        Collection collection = null;
        for (h hVar : hVarArr) {
            collection = op.a.a(collection, hVar.b(name, location));
        }
        if (collection != null) {
            return collection;
        }
        d10 = x0.d();
        return d10;
    }

    @Override // ap.h
    public Collection c(ro.f name, ao.b location) {
        List k10;
        Set d10;
        t.g(name, "name");
        t.g(location, "location");
        h[] hVarArr = this.f6103c;
        int length = hVarArr.length;
        if (length == 0) {
            k10 = u.k();
            return k10;
        }
        if (length == 1) {
            return hVarArr[0].c(name, location);
        }
        Collection collection = null;
        for (h hVar : hVarArr) {
            collection = op.a.a(collection, hVar.c(name, location));
        }
        if (collection != null) {
            return collection;
        }
        d10 = x0.d();
        return d10;
    }

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

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

    @Override // ap.k
    public Collection f(d kindFilter, dn.l nameFilter) {
        List k10;
        Set d10;
        t.g(kindFilter, "kindFilter");
        t.g(nameFilter, "nameFilter");
        h[] hVarArr = this.f6103c;
        int length = hVarArr.length;
        if (length == 0) {
            k10 = u.k();
            return k10;
        }
        if (length == 1) {
            return hVarArr[0].f(kindFilter, nameFilter);
        }
        Collection collection = null;
        for (h hVar : hVarArr) {
            collection = op.a.a(collection, hVar.f(kindFilter, nameFilter));
        }
        if (collection != null) {
            return collection;
        }
        d10 = x0.d();
        return d10;
    }

    @Override // ap.h
    public Set g() {
        Iterable H;
        H = p.H(this.f6103c);
        return j.a(H);
    }

    public String toString() {
        return this.f6102b;
    }

    private b(String str, h[] hVarArr) {
        this.f6102b = str;
        this.f6103c = hVarArr;
    }
}
