package i1;

import i1.g;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import sm.q0;
import sm.u;

/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes.dex */
public final class h implements g {

    /* renamed from: a, reason: collision with root package name */
    private final dn.l f22278a;

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

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

    /* loaded from: classes.dex */
    public static final class a implements g.a {

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

        /* renamed from: c, reason: collision with root package name */
        final /* synthetic */ dn.a f22283c;

        a(String str, dn.a aVar) {
            this.f22282b = str;
            this.f22283c = aVar;
        }

        @Override // i1.g.a
        public void unregister() {
            List list = (List) h.this.f22280c.remove(this.f22282b);
            if (list != null) {
                list.remove(this.f22283c);
            }
            if (list == null || !(!list.isEmpty())) {
                return;
            }
            h.this.f22280c.put(this.f22282b, list);
        }
    }

    /* JADX WARN: Code restructure failed: missing block: B:3:0x0007, code lost:
    
        r1 = sm.q0.w(r1);
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public h(Map map, dn.l lVar) {
        this.f22278a = lVar;
        Map linkedHashMap = (map == null || linkedHashMap == null) ? new LinkedHashMap() : linkedHashMap;
        this.f22279b = linkedHashMap;
        this.f22280c = new LinkedHashMap();
    }

    @Override // i1.g
    public boolean a(Object obj) {
        return ((Boolean) this.f22278a.invoke(obj)).booleanValue();
    }

    @Override // i1.g
    public Map c() {
        Map w10;
        ArrayList g10;
        w10 = q0.w(this.f22279b);
        for (Map.Entry entry : this.f22280c.entrySet()) {
            String str = (String) entry.getKey();
            List list = (List) entry.getValue();
            if (list.size() == 1) {
                Object invoke = ((dn.a) list.get(0)).invoke();
                if (invoke == null) {
                    continue;
                } else {
                    if (!a(invoke)) {
                        throw new IllegalStateException(b.b(invoke).toString());
                    }
                    g10 = u.g(invoke);
                    w10.put(str, g10);
                }
            } else {
                int size = list.size();
                ArrayList arrayList = new ArrayList(size);
                for (int i10 = 0; i10 < size; i10++) {
                    Object invoke2 = ((dn.a) list.get(i10)).invoke();
                    if (invoke2 != null && !a(invoke2)) {
                        throw new IllegalStateException(b.b(invoke2).toString());
                    }
                    arrayList.add(invoke2);
                }
                w10.put(str, arrayList);
            }
        }
        return w10;
    }

    @Override // i1.g
    public Object d(String str) {
        List list = (List) this.f22279b.remove(str);
        if (list == null || !(!list.isEmpty())) {
            return null;
        }
        if (list.size() > 1) {
            this.f22279b.put(str, list.subList(1, list.size()));
        }
        return list.get(0);
    }

    @Override // i1.g
    public g.a e(String str, dn.a aVar) {
        boolean c10;
        c10 = i.c(str);
        if (!(!c10)) {
            throw new IllegalArgumentException("Registered key is empty or blank".toString());
        }
        Map map = this.f22280c;
        Object obj = map.get(str);
        if (obj == null) {
            obj = new ArrayList();
            map.put(str, obj);
        }
        ((List) obj).add(aVar);
        return new a(str, aVar);
    }
}
