package com.revenuecat.purchases.ui.revenuecatui;

import androidx.compose.runtime.internal.StabilityInferred;
import com.revenuecat.purchases.ui.revenuecatui.helpers.Logger;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.NoSuchElementException;
import kotlin.jvm.internal.o;

/* JADX INFO: loaded from: classes3.dex */
@StabilityInferred(parameters = 1)
public final class CustomVariableKeyValidator {
    public static final int $stable = 0;
    public static final CustomVariableKeyValidator INSTANCE = new CustomVariableKeyValidator();

    private CustomVariableKeyValidator() {
    }

    private final boolean isValidKey(String str) {
        if (str.length() > 0) {
            if (str.length() == 0) {
                throw new NoSuchElementException("Char sequence is empty.");
            }
            if (Character.isLetter(str.charAt(0))) {
                for (int i6 = 0; i6 < str.length(); i6++) {
                    char cCharAt = str.charAt(i6);
                    if (Character.isLetter(cCharAt) || Character.isDigit(cCharAt) || cCharAt == '_') {
                    }
                }
                return true;
            }
        }
        return false;
    }

    public final Map<String, CustomVariableValue> validateAndFilter(Map<String, ? extends CustomVariableValue> variables) {
        o.h(variables, "variables");
        LinkedHashMap linkedHashMap = new LinkedHashMap();
        for (Map.Entry<String, ? extends CustomVariableValue> entry : variables.entrySet()) {
            String key = entry.getKey();
            CustomVariableValue value = entry.getValue();
            if (isValidKey(key)) {
                linkedHashMap.put(key, value);
            } else {
                Logger.INSTANCE.w("Custom variable key '" + key + "' is invalid and will be ignored. Keys must start with a letter and contain only letters, numbers, and underscores.");
            }
        }
        return linkedHashMap;
    }
}
