package kn;

import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import kotlin.text.y;
import sm.c0;

/* loaded from: classes3.dex */
public abstract class w {

    /* loaded from: classes3.dex */
    public /* synthetic */ class a {

        /* renamed from: a, reason: collision with root package name */
        public static final /* synthetic */ int[] f26041a;

        static {
            int[] iArr = new int[s.values().length];
            try {
                iArr[s.IN.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                iArr[s.INVARIANT.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                iArr[s.OUT.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
            f26041a = iArr;
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes3.dex */
    public /* synthetic */ class b extends kotlin.jvm.internal.q implements dn.l {

        /* renamed from: p, reason: collision with root package name */
        public static final b f26042p = new b();

        b() {
            super(1, Class.class, "getComponentType", "getComponentType()Ljava/lang/Class;", 0);
        }

        @Override // dn.l
        /* renamed from: l, reason: merged with bridge method [inline-methods] */
        public final Class invoke(Class p02) {
            kotlin.jvm.internal.t.g(p02, "p0");
            return p02.getComponentType();
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final Type c(p pVar, boolean z10) {
        Object F0;
        e c10 = pVar.c();
        if (c10 instanceof q) {
            return new v((q) c10);
        }
        if (!(c10 instanceof d)) {
            throw new UnsupportedOperationException("Unsupported type classifier: " + pVar);
        }
        d dVar = (d) c10;
        Class c11 = z10 ? cn.a.c(dVar) : cn.a.b(dVar);
        List b10 = pVar.b();
        if (b10.isEmpty()) {
            return c11;
        }
        if (!c11.isArray()) {
            return e(c11, b10);
        }
        if (c11.getComponentType().isPrimitive()) {
            return c11;
        }
        F0 = c0.F0(b10);
        r rVar = (r) F0;
        if (rVar == null) {
            throw new IllegalArgumentException("kotlin.Array must have exactly one type argument: " + pVar);
        }
        s a10 = rVar.a();
        p b11 = rVar.b();
        int i10 = a10 == null ? -1 : a.f26041a[a10.ordinal()];
        if (i10 == -1 || i10 == 1) {
            return c11;
        }
        if (i10 != 2 && i10 != 3) {
            throw new rm.t();
        }
        kotlin.jvm.internal.t.d(b11);
        Type d10 = d(b11, false, 1, null);
        return d10 instanceof Class ? c11 : new kn.a(d10);
    }

    static /* synthetic */ Type d(p pVar, boolean z10, int i10, Object obj) {
        if ((i10 & 1) != 0) {
            z10 = false;
        }
        return c(pVar, z10);
    }

    private static final Type e(Class cls, List list) {
        int v10;
        int v11;
        int v12;
        Class<?> declaringClass = cls.getDeclaringClass();
        if (declaringClass == null) {
            List list2 = list;
            v12 = sm.v.v(list2, 10);
            ArrayList arrayList = new ArrayList(v12);
            Iterator it = list2.iterator();
            while (it.hasNext()) {
                arrayList.add(g((r) it.next()));
            }
            return new u(cls, null, arrayList);
        }
        if (Modifier.isStatic(cls.getModifiers())) {
            List list3 = list;
            v11 = sm.v.v(list3, 10);
            ArrayList arrayList2 = new ArrayList(v11);
            Iterator it2 = list3.iterator();
            while (it2.hasNext()) {
                arrayList2.add(g((r) it2.next()));
            }
            return new u(cls, declaringClass, arrayList2);
        }
        int length = cls.getTypeParameters().length;
        Type e10 = e(declaringClass, list.subList(length, list.size()));
        List subList = list.subList(0, length);
        v10 = sm.v.v(subList, 10);
        ArrayList arrayList3 = new ArrayList(v10);
        Iterator it3 = subList.iterator();
        while (it3.hasNext()) {
            arrayList3.add(g((r) it3.next()));
        }
        return new u(cls, e10, arrayList3);
    }

    public static final Type f(p pVar) {
        Type m10;
        kotlin.jvm.internal.t.g(pVar, "<this>");
        return (!(pVar instanceof kotlin.jvm.internal.u) || (m10 = ((kotlin.jvm.internal.u) pVar).m()) == null) ? d(pVar, false, 1, null) : m10;
    }

    private static final Type g(r rVar) {
        s d10 = rVar.d();
        if (d10 == null) {
            return x.f26043r.a();
        }
        p c10 = rVar.c();
        kotlin.jvm.internal.t.d(c10);
        int i10 = a.f26041a[d10.ordinal()];
        if (i10 == 1) {
            return new x(null, c(c10, true));
        }
        if (i10 == 2) {
            return c(c10, true);
        }
        if (i10 == 3) {
            return new x(c(c10, true), null);
        }
        throw new rm.t();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final String h(Type type) {
        String name;
        rp.h i10;
        Object w10;
        int m10;
        String F;
        if (!(type instanceof Class)) {
            return type.toString();
        }
        Class cls = (Class) type;
        if (cls.isArray()) {
            i10 = rp.n.i(type, b.f26042p);
            StringBuilder sb2 = new StringBuilder();
            w10 = rp.p.w(i10);
            sb2.append(((Class) w10).getName());
            m10 = rp.p.m(i10);
            F = y.F("[]", m10);
            sb2.append(F);
            name = sb2.toString();
        } else {
            name = cls.getName();
        }
        kotlin.jvm.internal.t.d(name);
        return name;
    }
}
