package kotlin.reflect.w.internal.y0.n;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import kotlin.collections.EmptyList;
import kotlin.collections.j;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.internal.Lambda;
import kotlin.jvm.internal.o;
import kotlin.reflect.w.internal.y0.d.a1;
import kotlin.reflect.w.internal.y0.d.b1;
import kotlin.reflect.w.internal.y0.d.e;
import kotlin.reflect.w.internal.y0.d.h;
import kotlin.reflect.w.internal.y0.d.n1.v;
import kotlin.reflect.w.internal.y0.k.c0.i;
import kotlin.reflect.w.internal.y0.k.c0.n;
import kotlin.reflect.w.internal.y0.n.a2.f;
import kotlin.reflect.w.internal.y0.n.z0;
import kotlin.reflect.w.internal.y0.n.z1.d;

/* JADX INFO: loaded from: classes2.dex */
public final class i0 {
    public static final i0 a = new i0();

    public static final class a extends Lambda implements Function1 {

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

        public a() {
            super(1);
        }

        @Override // kotlin.jvm.functions.Function1
        public Object invoke(Object obj) {
            o.f((kotlin.reflect.w.internal.y0.n.z1.d) obj, "<anonymous parameter 0>");
            return null;
        }
    }

    public static final class b {
        public final o0 a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        public final e1 f8942b;

        public b(o0 o0Var, e1 e1Var) {
            this.a = o0Var;
            this.f8942b = e1Var;
        }
    }

    public static final class c extends Lambda implements Function1<kotlin.reflect.w.internal.y0.n.z1.d, o0> {

        /* JADX INFO: renamed from: f, reason: collision with root package name */
        public final /* synthetic */ e1 f8943f;

        /* JADX INFO: renamed from: m, reason: collision with root package name */
        public final /* synthetic */ List<l1> f8944m;

        /* JADX INFO: renamed from: n, reason: collision with root package name */
        public final /* synthetic */ c1 f8945n;

        /* JADX INFO: renamed from: o, reason: collision with root package name */
        public final /* synthetic */ boolean f8946o;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        /* JADX WARN: Multi-variable type inference failed */
        public c(e1 e1Var, List<? extends l1> list, c1 c1Var, boolean z2) {
            super(1);
            this.f8943f = e1Var;
            this.f8944m = list;
            this.f8945n = c1Var;
            this.f8946o = z2;
        }

        @Override // kotlin.jvm.functions.Function1
        public o0 invoke(kotlin.reflect.w.internal.y0.n.z1.d dVar) {
            kotlin.reflect.w.internal.y0.n.z1.d dVar2 = dVar;
            o.f(dVar2, "refiner");
            b bVarA = i0.a(i0.a, this.f8943f, dVar2, this.f8944m);
            if (bVarA == null) {
                return null;
            }
            o0 o0Var = bVarA.a;
            if (o0Var != null) {
                return o0Var;
            }
            c1 c1Var = this.f8945n;
            e1 e1Var = bVarA.f8942b;
            o.c(e1Var);
            return i0.f(c1Var, e1Var, this.f8944m, this.f8946o, dVar2);
        }
    }

    public static final class d extends Lambda implements Function1<kotlin.reflect.w.internal.y0.n.z1.d, o0> {

        /* JADX INFO: renamed from: f, reason: collision with root package name */
        public final /* synthetic */ e1 f8947f;

        /* JADX INFO: renamed from: m, reason: collision with root package name */
        public final /* synthetic */ List<l1> f8948m;

        /* JADX INFO: renamed from: n, reason: collision with root package name */
        public final /* synthetic */ c1 f8949n;

        /* JADX INFO: renamed from: o, reason: collision with root package name */
        public final /* synthetic */ boolean f8950o;

        /* JADX INFO: renamed from: p, reason: collision with root package name */
        public final /* synthetic */ i f8951p;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        /* JADX WARN: Multi-variable type inference failed */
        public d(e1 e1Var, List<? extends l1> list, c1 c1Var, boolean z2, i iVar) {
            super(1);
            this.f8947f = e1Var;
            this.f8948m = list;
            this.f8949n = c1Var;
            this.f8950o = z2;
            this.f8951p = iVar;
        }

        @Override // kotlin.jvm.functions.Function1
        public o0 invoke(kotlin.reflect.w.internal.y0.n.z1.d dVar) {
            kotlin.reflect.w.internal.y0.n.z1.d dVar2 = dVar;
            o.f(dVar2, "kotlinTypeRefiner");
            b bVarA = i0.a(i0.a, this.f8947f, dVar2, this.f8948m);
            if (bVarA == null) {
                return null;
            }
            o0 o0Var = bVarA.a;
            if (o0Var != null) {
                return o0Var;
            }
            c1 c1Var = this.f8949n;
            e1 e1Var = bVarA.f8942b;
            o.c(e1Var);
            return i0.h(c1Var, e1Var, this.f8948m, this.f8950o, this.f8951p);
        }
    }

    static {
        a aVar = a.f8941f;
    }

    public static final b a(i0 i0Var, e1 e1Var, kotlin.reflect.w.internal.y0.n.z1.d dVar, List list) {
        h hVarF;
        b bVar;
        h hVarC = e1Var.c();
        if (hVarC == null || (hVarF = dVar.f(hVarC)) == null) {
            return null;
        }
        if (hVarF instanceof a1) {
            bVar = new b(b((a1) hVarF, list), null);
        } else {
            e1 e1VarA = hVarF.k().a(dVar);
            o.e(e1VarA, "descriptor.typeConstruct…refine(kotlinTypeRefiner)");
            bVar = new b(null, e1VarA);
        }
        return bVar;
    }

    public static final o0 b(a1 a1Var, List<? extends l1> list) {
        o.f(a1Var, "<this>");
        o.f(list, "arguments");
        x0 x0Var = new x0(z0.a.a, false);
        o.f(a1Var, "typeAliasDescriptor");
        o.f(list, "arguments");
        List<b1> parameters = a1Var.k().getParameters();
        o.e(parameters, "typeAliasDescriptor.typeConstructor.parameters");
        ArrayList arrayList = new ArrayList(g.h.a.i.H(parameters, 10));
        Iterator<T> it = parameters.iterator();
        while (it.hasNext()) {
            arrayList.add(((b1) it.next()).a());
        }
        y0 y0Var = new y0(null, a1Var, list, j.j0(j.q0(arrayList, list)), null);
        Objects.requireNonNull(c1.f8889m);
        c1 c1Var = c1.f8890n;
        o.f(y0Var, "typeAliasExpansion");
        o.f(c1Var, "attributes");
        return x0Var.d(y0Var, c1Var, false, 0, true);
    }

    public static final w1 c(o0 o0Var, o0 o0Var2) {
        o.f(o0Var, "lowerBound");
        o.f(o0Var2, "upperBound");
        return o.a(o0Var, o0Var2) ? o0Var : new c0(o0Var, o0Var2);
    }

    public static final o0 d(c1 c1Var, kotlin.reflect.w.internal.y0.k.x.o oVar, boolean z2) {
        o.f(c1Var, "attributes");
        o.f(oVar, "constructor");
        return h(c1Var, oVar, EmptyList.f9307f, z2, kotlin.reflect.w.internal.y0.n.a2.j.a(f.INTEGER_LITERAL_TYPE_SCOPE, true, "unknown integer literal type"));
    }

    public static final o0 e(c1 c1Var, e eVar, List<? extends l1> list) {
        o.f(c1Var, "attributes");
        o.f(eVar, "descriptor");
        o.f(list, "arguments");
        e1 e1VarK = eVar.k();
        o.e(e1VarK, "descriptor.typeConstructor");
        return g(c1Var, e1VarK, list, false, null, 16);
    }

    public static final o0 f(c1 c1Var, e1 e1Var, List<? extends l1> list, boolean z2, kotlin.reflect.w.internal.y0.n.z1.d dVar) {
        i iVarA;
        v vVar;
        o.f(c1Var, "attributes");
        o.f(e1Var, "constructor");
        o.f(list, "arguments");
        if (c1Var.isEmpty() && list.isEmpty() && !z2 && e1Var.c() != null) {
            h hVarC = e1Var.c();
            o.c(hVarC);
            o0 o0VarS = hVarC.s();
            o.e(o0VarS, "constructor.declarationDescriptor!!.defaultType");
            return o0VarS;
        }
        h hVarC2 = e1Var.c();
        if (hVarC2 instanceof b1) {
            iVarA = ((b1) hVarC2).s().q();
        } else if (hVarC2 instanceof e) {
            if (dVar == null) {
                kotlin.reflect.w.internal.y0.k.z.a.j(kotlin.reflect.w.internal.y0.k.z.a.k(hVarC2));
                dVar = d.a.a;
            }
            e eVar = (e) hVarC2;
            if (list.isEmpty()) {
                o.f(eVar, "<this>");
                o.f(dVar, "kotlinTypeRefiner");
                o.f(eVar, "<this>");
                o.f(dVar, "kotlinTypeRefiner");
                vVar = eVar instanceof v ? (v) eVar : null;
                if (vVar == null || (iVarA = vVar.J(dVar)) == null) {
                    iVarA = eVar.B0();
                    o.e(iVarA, "this.unsubstitutedMemberScope");
                }
            } else {
                o1 o1VarB = g1.f8930b.b(e1Var, list);
                o.f(eVar, "<this>");
                o.f(o1VarB, "typeSubstitution");
                o.f(dVar, "kotlinTypeRefiner");
                o.f(eVar, "<this>");
                o.f(o1VarB, "typeSubstitution");
                o.f(dVar, "kotlinTypeRefiner");
                vVar = eVar instanceof v ? (v) eVar : null;
                if (vVar == null || (iVarA = vVar.F(o1VarB, dVar)) == null) {
                    iVarA = eVar.Z(o1VarB);
                    o.e(iVarA, "this.getMemberScope(\n   …ubstitution\n            )");
                }
            }
        } else if (hVarC2 instanceof a1) {
            f fVar = f.SCOPE_FOR_ABBREVIATION_TYPE;
            String str = ((a1) hVarC2).getName().f8195f;
            o.e(str, "descriptor.name.toString()");
            iVarA = kotlin.reflect.w.internal.y0.n.a2.j.a(fVar, true, str);
        } else {
            if (!(e1Var instanceof f0)) {
                throw new IllegalStateException("Unsupported classifier: " + hVarC2 + " for constructor: " + e1Var);
            }
            iVarA = n.a.a("member scope for intersection type", ((f0) e1Var).f8918b);
        }
        return i(c1Var, e1Var, list, z2, iVarA, new c(e1Var, list, c1Var, z2));
    }

    public static /* synthetic */ o0 g(c1 c1Var, e1 e1Var, List list, boolean z2, kotlin.reflect.w.internal.y0.n.z1.d dVar, int i2) {
        int i3 = i2 & 16;
        return f(c1Var, e1Var, list, z2, null);
    }

    public static final o0 h(c1 c1Var, e1 e1Var, List<? extends l1> list, boolean z2, i iVar) {
        o.f(c1Var, "attributes");
        o.f(e1Var, "constructor");
        o.f(list, "arguments");
        o.f(iVar, "memberScope");
        p0 p0Var = new p0(e1Var, list, z2, iVar, new d(e1Var, list, c1Var, z2, iVar));
        return c1Var.isEmpty() ? p0Var : new q0(p0Var, c1Var);
    }

    public static final o0 i(c1 c1Var, e1 e1Var, List<? extends l1> list, boolean z2, i iVar, Function1<? super kotlin.reflect.w.internal.y0.n.z1.d, ? extends o0> function1) {
        o.f(c1Var, "attributes");
        o.f(e1Var, "constructor");
        o.f(list, "arguments");
        o.f(iVar, "memberScope");
        o.f(function1, "refinedTypeFactory");
        p0 p0Var = new p0(e1Var, list, z2, iVar, function1);
        return c1Var.isEmpty() ? p0Var : new q0(p0Var, c1Var);
    }
}
