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;

/* JADX INFO: renamed from: ᵕᵳʨ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C2362 {

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public static final C1054 f9253 = new C1054(Arrays.copyOf(new byte[]{42}, 1));

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public static final List f9254 = Collections.singletonList("*");

    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public static final C2362 f9255 = new C2362(new C2781(3));

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public final C2781 f9256;

    public C2362(C2781 c2781) {
        this.f9256 = c2781;
    }

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public static List m6043(String str) {
        int i = 0;
        List listM8504 = AbstractC3801.m8504(str, new char[]{'.'});
        if (!ᵥˈᵛ.ˊᵫᵗ(AbstractC4126.m8994(listM8504), "")) {
            return listM8504;
        }
        int size = listM8504.size() - 1;
        if (size < 0) {
            size = 0;
        }
        if (size < 0) {
            ᵕᵩʽᵲ.ᵱᵽʡᵚ(AbstractC0793.m2876(size, "Requested element count ", " is less than zero."));
            return null;
        }
        if (size == 0) {
            return C2808.f10794;
        }
        if (size >= listM8504.size()) {
            return AbstractC4126.m8998(listM8504);
        }
        if (size == 1) {
            return Collections.singletonList(AbstractC4126.m8990(listM8504));
        }
        ArrayList arrayList = new ArrayList(size);
        Iterator it = listM8504.iterator();
        while (it.hasNext()) {
            arrayList.add(it.next());
            i++;
            if (i == size) {
                break;
            }
        }
        return AbstractC0892.m3126(arrayList);
    }

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public final String m6044(String str) {
        String str2;
        String str3;
        String str4;
        List listM8504;
        int size;
        int size2;
        List listM6043 = m6043(IDN.toUnicode(str));
        C2781 c2781 = this.f9256;
        AtomicBoolean atomicBoolean = (AtomicBoolean) c2781.f10704;
        if (atomicBoolean.get() || !atomicBoolean.compareAndSet(false, true)) {
            try {
                ((CountDownLatch) c2781.f10706).await();
            } catch (InterruptedException unused) {
                Thread.currentThread().interrupt();
            }
        } else {
            boolean z = false;
            while (true) {
                try {
                    try {
                        c2781.m6761();
                        break;
                    } finally {
                        if (z) {
                            Thread.currentThread().interrupt();
                        }
                    }
                } catch (InterruptedIOException unused2) {
                    Thread.interrupted();
                    z = true;
                } catch (IOException e) {
                    c2781.f10703 = e;
                    if (z) {
                    }
                }
            }
        }
        if (((C1054) c2781.f10707) == null) {
            StringBuilder sb = new StringBuilder("Unable to load ");
            sb.append(c2781.f10705);
            sb.append(" resource.");
            IllegalStateException illegalStateException = new IllegalStateException(sb.toString());
            illegalStateException.initCause((IOException) c2781.f10703);
            throw illegalStateException;
        }
        int size3 = listM6043.size();
        C1054[] c1054Arr = new C1054[size3];
        for (int i = 0; i < size3; i++) {
            String str5 = (String) listM6043.get(i);
            C1054 c1054 = new C1054(str5.getBytes(AbstractC4490.f17115));
            c1054.f4545 = str5;
            c1054Arr[i] = c1054;
        }
        int i2 = 0;
        while (true) {
            if (i2 >= size3) {
                str2 = null;
                break;
            }
            C1054 c10542 = (C1054) c2781.f10707;
            if (c10542 == null) {
                c10542 = null;
            }
            str2 = ᵻᵧˁ.ʽˈˋ(c10542, c1054Arr, i2);
            if (str2 != null) {
                break;
            }
            i2++;
        }
        if (size3 > 1) {
            C1054[] c1054Arr2 = (C1054[]) c1054Arr.clone();
            int length = c1054Arr2.length - 1;
            for (int i3 = 0; i3 < length; i3++) {
                c1054Arr2[i3] = f9253;
                C1054 c10543 = (C1054) c2781.f10707;
                if (c10543 == null) {
                    c10543 = null;
                }
                str3 = ᵻᵧˁ.ʽˈˋ(c10543, c1054Arr2, i3);
                if (str3 != null) {
                    break;
                }
            }
            str3 = null;
        } else {
            str3 = null;
        }
        if (str3 != null) {
            int i4 = size3 - 1;
            for (int i5 = 0; i5 < i4; i5++) {
                C1054 c10544 = (C1054) c2781.f10708;
                if (c10544 == null) {
                    c10544 = null;
                }
                str4 = ᵻᵧˁ.ʽˈˋ(c10544, c1054Arr, i5);
                if (str4 != null) {
                    break;
                }
            }
            str4 = null;
        } else {
            str4 = null;
        }
        if (str4 != null) {
            listM8504 = AbstractC3801.m8504("!".concat(str4), new char[]{'.'});
        } else if (str2 == null && str3 == null) {
            listM8504 = f9254;
        } else {
            List listM85042 = C2808.f10794;
            List listM85043 = str2 != null ? AbstractC3801.m8504(str2, new char[]{'.'}) : listM85042;
            if (str3 != null) {
                listM85042 = AbstractC3801.m8504(str3, new char[]{'.'});
            }
            listM8504 = listM85043.size() > listM85042.size() ? listM85043 : listM85042;
        }
        if (listM6043.size() == listM8504.size() && ((String) listM8504.get(0)).charAt(0) != '!') {
            return null;
        }
        if (((String) listM8504.get(0)).charAt(0) == '!') {
            size = listM6043.size();
            size2 = listM8504.size();
        } else {
            size = listM6043.size();
            size2 = listM8504.size() + 1;
        }
        int i6 = size - size2;
        InterfaceC1631 c4531 = new C4531(0, m6043(str));
        if (i6 < 0) {
            ᵕᵩʽᵲ.ᵱᵽʡᵚ(AbstractC0793.m2876(i6, "Requested element count ", " is less than zero."));
            return null;
        }
        if (i6 != 0) {
            c4531 = new C0830(c4531, i6);
        }
        return AbstractC1012.m3342(c4531, ".", 62);
    }
}
