package com.revenuecat.purchases.utils;

import B1.g;
import S4.w;
import com.revenuecat.purchases.common.LogWrapperKt;
import java.util.List;
import java.util.Locale;
import java.util.MissingResourceException;
import kotlin.jvm.internal.o;
import x4.AbstractC3250p;

/* JADX INFO: loaded from: classes3.dex */
public final class LocaleExtensionsKt {
    public static final Locale convertToCorrectlyFormattedLocale(Locale locale) {
        o.h(locale, "<this>");
        String string = locale.toString();
        o.g(string, "toString()");
        return toLocale(string);
    }

    public static final List<Locale> getDefaultLocales() {
        return toList(g.b());
    }

    private static final String inferScript(Locale locale) {
        String country;
        String script = locale.getScript();
        if (script != null && script.length() != 0) {
            String script2 = locale.getScript();
            o.g(script2, "script");
            return script2;
        }
        if (o.c(locale.getLanguage(), "zh") && (country = locale.getCountry()) != null) {
            int iHashCode = country.hashCode();
            if (iHashCode != 2155) {
                if (iHashCode != 2307) {
                    if (iHashCode != 2466) {
                        if (iHashCode != 2644) {
                            if (iHashCode == 2691 && country.equals("TW")) {
                                return "Hant";
                            }
                        } else if (country.equals("SG")) {
                            return "Hans";
                        }
                    } else if (country.equals("MO")) {
                        return "Hant";
                    }
                } else if (country.equals("HK")) {
                    return "Hant";
                }
            } else if (country.equals("CN")) {
                return "Hans";
            }
        }
        return "";
    }

    public static final boolean sharedLanguageCodeWith(Locale locale, Locale locale2) {
        o.h(locale, "<this>");
        o.h(locale2, "locale");
        try {
            return o.c(locale.getISO3Language(), locale2.getISO3Language()) && o.c(inferScript(locale), inferScript(locale2));
        } catch (MissingResourceException e6) {
            LogWrapperKt.getCurrentLogHandler().e("[Purchases] - ERROR", "Locale " + locale + " or " + locale2 + " can't obtain ISO3 language code (" + e6 + "). Falling back to language.", null);
            return o.c(locale.getLanguage(), locale2.getLanguage());
        }
    }

    private static final List<Locale> toList(g gVar) {
        int size = gVar.f448a.f449a.size();
        Locale[] localeArr = new Locale[size];
        for (int i6 = 0; i6 < size; i6++) {
            localeArr[i6] = gVar.a(i6);
        }
        return AbstractC3250p.K(localeArr);
    }

    public static final Locale toLocale(String str) {
        o.h(str, "<this>");
        Locale localeForLanguageTag = Locale.forLanguageTag(w.y0(str, "_", "-"));
        o.g(localeForLanguageTag, "forLanguageTag(replace(\"_\", \"-\"))");
        return localeForLanguageTag;
    }
}
