package defpackage;

import java.io.IOException;
import java.io.InterruptedIOException;
import java.net.IDN;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;

/* renamed from: ˀᵹᵶ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C0623 {

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public final C3460 f3111;

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public static final C2185 f3109 = new C2185(Arrays.copyOf(new byte[]{42}, 1));

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public static final List f3108 = Collections.singletonList("*");

    /* renamed from: ᵻᵢﹳᵰ, reason: contains not printable characters */
    public static final C0623 f3110 = new C0623(new C3460(3));

    public C0623(C3460 c3460) {
        this.f3111 = c3460;
    }

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public static List m2505(String str) {
        int i = 0;
        List listM5067 = AbstractC1789.m5067(str, new char[]{'.'});
        if (!ᵲᵝᵪ.ᵹᵝᵶ(AbstractC2767.m6828(listM5067), "")) {
            return listM5067;
        }
        int size = listM5067.size() - 1;
        if (size < 0) {
            size = 0;
        }
        if (size < 0) {
            ᵹˉᵞ.ᵸˑ(AbstractC3915.m8596(size, "Requested element count ", " is less than zero."));
            return null;
        }
        if (size == 0) {
            return C3035.f11677;
        }
        if (size >= listM5067.size()) {
            return AbstractC2767.m6825(listM5067);
        }
        if (size == 1) {
            return Collections.singletonList(AbstractC2767.m6819(listM5067));
        }
        ArrayList arrayList = new ArrayList(size);
        Iterator it = listM5067.iterator();
        while (it.hasNext()) {
            arrayList.add(it.next());
            i++;
            if (i == size) {
                break;
            }
        }
        return AbstractC2240.m5914(arrayList);
    }

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public final String m2506(String str) throws InterruptedException {
        String str2;
        String str3;
        String str4;
        List listM5067;
        int size;
        int size2;
        List listM2505 = m2505(IDN.toUnicode(str));
        C3460 c3460 = this.f3111;
        AtomicBoolean atomicBoolean = (AtomicBoolean) c3460.f12991;
        if (atomicBoolean.get() || !atomicBoolean.compareAndSet(false, true)) {
            try {
                ((CountDownLatch) c3460.f12990).await();
            } catch (InterruptedException unused) {
                Thread.currentThread().interrupt();
            }
        } else {
            boolean z = false;
            while (true) {
                try {
                    try {
                        c3460.m7878();
                        break;
                    } finally {
                        if (z) {
                            Thread.currentThread().interrupt();
                        }
                    }
                } catch (InterruptedIOException unused2) {
                    Thread.interrupted();
                    z = true;
                } catch (IOException e) {
                    c3460.f12989 = e;
                    if (z) {
                    }
                }
            }
        }
        if (((C2185) c3460.f12988) == null) {
            StringBuilder sb = new StringBuilder("Unable to load ");
            sb.append(c3460.f12987);
            sb.append(" resource.");
            IllegalStateException illegalStateException = new IllegalStateException(sb.toString());
            illegalStateException.initCause((IOException) c3460.f12989);
            throw illegalStateException;
        }
        int size3 = listM2505.size();
        C2185[] c2185Arr = new C2185[size3];
        for (int i = 0; i < size3; i++) {
            String str5 = (String) listM2505.get(i);
            C2185 c2185 = new C2185(str5.getBytes(AbstractC2356.f9221));
            c2185.f8600 = str5;
            c2185Arr[i] = c2185;
        }
        int i2 = 0;
        while (true) {
            if (i2 >= size3) {
                str2 = null;
                break;
            }
            C2185 c21852 = (C2185) c3460.f12988;
            if (c21852 == null) {
                c21852 = null;
            }
            str2 = ˉᵻ.ᵶᵷᵕ(c21852, c2185Arr, i2);
            if (str2 != null) {
                break;
            }
            i2++;
        }
        if (size3 > 1) {
            C2185[] c2185Arr2 = (C2185[]) c2185Arr.clone();
            int length = c2185Arr2.length - 1;
            for (int i3 = 0; i3 < length; i3++) {
                c2185Arr2[i3] = f3109;
                C2185 c21853 = (C2185) c3460.f12988;
                if (c21853 == null) {
                    c21853 = null;
                }
                str3 = ˉᵻ.ᵶᵷᵕ(c21853, c2185Arr2, i3);
                if (str3 != null) {
                    break;
                }
            }
            str3 = null;
        } else {
            str3 = null;
        }
        if (str3 != null) {
            int i4 = size3 - 1;
            for (int i5 = 0; i5 < i4; i5++) {
                C2185 c21854 = (C2185) c3460.f12986;
                if (c21854 == null) {
                    c21854 = null;
                }
                str4 = ˉᵻ.ᵶᵷᵕ(c21854, c2185Arr, i5);
                if (str4 != null) {
                    break;
                }
            }
            str4 = null;
        } else {
            str4 = null;
        }
        if (str4 != null) {
            listM5067 = AbstractC1789.m5067("!".concat(str4), new char[]{'.'});
        } else if (str2 == null && str3 == null) {
            listM5067 = f3108;
        } else {
            List listM50672 = C3035.f11677;
            List listM50673 = str2 != null ? AbstractC1789.m5067(str2, new char[]{'.'}) : listM50672;
            if (str3 != null) {
                listM50672 = AbstractC1789.m5067(str3, new char[]{'.'});
            }
            listM5067 = listM50673.size() > listM50672.size() ? listM50673 : listM50672;
        }
        if (listM2505.size() == listM5067.size() && ((String) listM5067.get(0)).charAt(0) != '!') {
            return null;
        }
        if (((String) listM5067.get(0)).charAt(0) == '!') {
            size = listM2505.size();
            size2 = listM5067.size();
        } else {
            size = listM2505.size();
            size2 = listM5067.size() + 1;
        }
        int i6 = size - size2;
        InterfaceC5533 c2696 = new C2696(0, m2505(str));
        if (i6 < 0) {
            ᵹˉᵞ.ᵸˑ(AbstractC3915.m8596(i6, "Requested element count ", " is less than zero."));
            return null;
        }
        if (i6 != 0) {
            c2696 = new C5043(c2696, i6);
        }
        return AbstractC3761.m8385(c2696, ".", 62);
    }
}
