package com.revenuecat.purchases.ui.revenuecatui.data.processed;

import E3.v;
import J4.c;
import J4.e;
import R4.i;
import S4.j;
import S4.k;
import S4.m;
import S4.w;
import a.AbstractC0872a;
import androidx.compose.runtime.internal.StabilityInferred;
import androidx.media3.extractor.AacUtil;
import androidx.media3.extractor.flac.FlacConstants;
import androidx.media3.extractor.ts.TsExtractor;
import com.google.android.recaptcha.internal.a;
import com.google.firebase.firestore.index.FirestoreIndexValueWriter;
import com.revenuecat.purchases.Package;
import com.revenuecat.purchases.PackageType;
import com.revenuecat.purchases.UiConfig;
import com.revenuecat.purchases.models.Period;
import com.revenuecat.purchases.models.Price;
import com.revenuecat.purchases.models.PricingPhase;
import com.revenuecat.purchases.models.StoreProduct;
import com.revenuecat.purchases.models.SubscriptionOption;
import com.revenuecat.purchases.paywalls.components.CountdownComponent;
import com.revenuecat.purchases.paywalls.components.common.VariableLocalizationKey;
import com.revenuecat.purchases.ui.revenuecatui.CustomVariableValue;
import com.revenuecat.purchases.ui.revenuecatui.components.countdown.CountdownTime;
import com.revenuecat.purchases.ui.revenuecatui.data.processed.VariableProcessor;
import com.revenuecat.purchases.ui.revenuecatui.helpers.Logger;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Currency;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import kotlin.jvm.internal.o;
import kotlin.jvm.internal.p;
import m1.g;
import w4.h;
import x4.AbstractC3251q;
import x4.AbstractC3252r;
import x4.AbstractC3253s;
import x4.y;
import x4.z;

/* JADX INFO: loaded from: classes3.dex */
@StabilityInferred(parameters = 0)
public final class VariableProcessorV2 {
    private static final float PERCENT_SCALE = 100.0f;
    public static final VariableProcessorV2 INSTANCE = new VariableProcessorV2();
    private static final m regex = new m("\\{\\{\\s*(.*?)\\s*\\}\\}");
    private static final List<String> customVariablePrefixes = AbstractC3252r.B("custom.", "$custom.");
    public static final int $stable = 8;

    public enum Function {
        LOWERCASE("lowercase"),
        UPPERCASE("uppercase"),
        CAPITALIZE("capitalize");

        private final String identifier;
        public static final Companion Companion = new Companion(null);
        private static final h valuesByIdentifier$delegate = g.k(VariableProcessorV2$Function$Companion$valuesByIdentifier$2.INSTANCE);

        public static final class Companion {
            public /* synthetic */ Companion(kotlin.jvm.internal.h hVar) {
                this();
            }

            private final Map<String, Function> getValuesByIdentifier() {
                return (Map) Function.valuesByIdentifier$delegate.getValue();
            }

            public final Function valueOfIdentifier(String identifier) {
                o.h(identifier, "identifier");
                return getValuesByIdentifier().get(identifier);
            }

            private Companion() {
            }
        }

        Function(String str) {
            this.identifier = str;
        }

        public final /* synthetic */ String getIdentifier() {
            return this.identifier;
        }
    }

    public enum Variable {
        PRODUCT_CURRENCY_CODE("product.currency_code"),
        PRODUCT_CURRENCY_SYMBOL("product.currency_symbol"),
        PRODUCT_PERIODLY("product.periodly"),
        PRODUCT_PRICE("product.price"),
        PRODUCT_PRICE_PER_PERIOD("product.price_per_period"),
        PRODUCT_PRICE_PER_PERIOD_ABBREVIATED("product.price_per_period_abbreviated"),
        PRODUCT_PRICE_PER_DAY("product.price_per_day"),
        PRODUCT_PRICE_PER_WEEK("product.price_per_week"),
        PRODUCT_PRICE_PER_MONTH("product.price_per_month"),
        PRODUCT_PRICE_PER_YEAR("product.price_per_year"),
        PRODUCT_PERIOD("product.period"),
        PRODUCT_PERIOD_ABBREVIATED("product.period_abbreviated"),
        PRODUCT_PERIOD_IN_DAYS("product.period_in_days"),
        PRODUCT_PERIOD_IN_WEEKS("product.period_in_weeks"),
        PRODUCT_PERIOD_IN_MONTHS("product.period_in_months"),
        PRODUCT_PERIOD_IN_YEARS("product.period_in_years"),
        PRODUCT_PERIOD_WITH_UNIT("product.period_with_unit"),
        PRODUCT_OFFER_PRICE("product.offer_price"),
        PRODUCT_OFFER_PRICE_PER_DAY("product.offer_price_per_day"),
        PRODUCT_OFFER_PRICE_PER_WEEK("product.offer_price_per_week"),
        PRODUCT_OFFER_PRICE_PER_MONTH("product.offer_price_per_month"),
        PRODUCT_OFFER_PRICE_PER_YEAR("product.offer_price_per_year"),
        PRODUCT_OFFER_PERIOD("product.offer_period"),
        PRODUCT_OFFER_PERIOD_ABBREVIATED("product.offer_period_abbreviated"),
        PRODUCT_OFFER_PERIOD_IN_DAYS("product.offer_period_in_days"),
        PRODUCT_OFFER_PERIOD_IN_WEEKS("product.offer_period_in_weeks"),
        PRODUCT_OFFER_PERIOD_IN_MONTHS("product.offer_period_in_months"),
        PRODUCT_OFFER_PERIOD_IN_YEARS("product.offer_period_in_years"),
        PRODUCT_OFFER_PERIOD_WITH_UNIT("product.offer_period_with_unit"),
        PRODUCT_OFFER_END_DATE("product.offer_end_date"),
        PRODUCT_SECONDARY_OFFER_PRICE("product.secondary_offer_price"),
        PRODUCT_SECONDARY_OFFER_PERIOD("product.secondary_offer_period"),
        PRODUCT_SECONDARY_OFFER_PERIOD_ABBREVIATED("product.secondary_offer_period_abbreviated"),
        PRODUCT_RELATIVE_DISCOUNT("product.relative_discount"),
        PRODUCT_STORE_PRODUCT_NAME("product.store_product_name"),
        COUNT_DAYS_WITH_ZERO("count_days_with_zero"),
        COUNT_DAYS_WITHOUT_ZERO("count_days_without_zero"),
        COUNT_HOURS_WITH_ZERO("count_hours_with_zero"),
        COUNT_HOURS_WITHOUT_ZERO("count_hours_without_zero"),
        COUNT_MINUTES_WITH_ZERO("count_minutes_with_zero"),
        COUNT_MINUTES_WITHOUT_ZERO("count_minutes_without_zero"),
        COUNT_SECONDS_WITH_ZERO("count_seconds_with_zero"),
        COUNT_SECONDS_WITHOUT_ZERO("count_seconds_without_zero");

        private final String identifier;
        public static final Companion Companion = new Companion(null);
        private static final h valuesByIdentifier$delegate = g.k(VariableProcessorV2$Variable$Companion$valuesByIdentifier$2.INSTANCE);

        public static final class Companion {
            public /* synthetic */ Companion(kotlin.jvm.internal.h hVar) {
                this();
            }

            private final Map<String, Variable> getValuesByIdentifier() {
                return (Map) Variable.valuesByIdentifier$delegate.getValue();
            }

            public final Variable valueOfIdentifier(String identifier) {
                o.h(identifier, "identifier");
                return getValuesByIdentifier().get(identifier);
            }

            private Companion() {
            }
        }

        Variable(String str) {
            this.identifier = str;
        }

        public final /* synthetic */ String getIdentifier() {
            return this.identifier;
        }
    }

    public /* synthetic */ class WhenMappings {
        public static final /* synthetic */ int[] $EnumSwitchMapping$0;
        public static final /* synthetic */ int[] $EnumSwitchMapping$1;
        public static final /* synthetic */ int[] $EnumSwitchMapping$2;
        public static final /* synthetic */ int[] $EnumSwitchMapping$3;

        static {
            int[] iArr = new int[CountdownComponent.CountFrom.values().length];
            try {
                iArr[CountdownComponent.CountFrom.DAYS.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                iArr[CountdownComponent.CountFrom.HOURS.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                iArr[CountdownComponent.CountFrom.MINUTES.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
            $EnumSwitchMapping$0 = iArr;
            int[] iArr2 = new int[Variable.values().length];
            try {
                iArr2[Variable.PRODUCT_CURRENCY_CODE.ordinal()] = 1;
            } catch (NoSuchFieldError unused4) {
            }
            try {
                iArr2[Variable.PRODUCT_CURRENCY_SYMBOL.ordinal()] = 2;
            } catch (NoSuchFieldError unused5) {
            }
            try {
                iArr2[Variable.PRODUCT_PERIODLY.ordinal()] = 3;
            } catch (NoSuchFieldError unused6) {
            }
            try {
                iArr2[Variable.PRODUCT_PRICE.ordinal()] = 4;
            } catch (NoSuchFieldError unused7) {
            }
            try {
                iArr2[Variable.PRODUCT_PRICE_PER_PERIOD.ordinal()] = 5;
            } catch (NoSuchFieldError unused8) {
            }
            try {
                iArr2[Variable.PRODUCT_PRICE_PER_PERIOD_ABBREVIATED.ordinal()] = 6;
            } catch (NoSuchFieldError unused9) {
            }
            try {
                iArr2[Variable.PRODUCT_PRICE_PER_DAY.ordinal()] = 7;
            } catch (NoSuchFieldError unused10) {
            }
            try {
                iArr2[Variable.PRODUCT_PRICE_PER_WEEK.ordinal()] = 8;
            } catch (NoSuchFieldError unused11) {
            }
            try {
                iArr2[Variable.PRODUCT_PRICE_PER_MONTH.ordinal()] = 9;
            } catch (NoSuchFieldError unused12) {
            }
            try {
                iArr2[Variable.PRODUCT_PRICE_PER_YEAR.ordinal()] = 10;
            } catch (NoSuchFieldError unused13) {
            }
            try {
                iArr2[Variable.PRODUCT_PERIOD.ordinal()] = 11;
            } catch (NoSuchFieldError unused14) {
            }
            try {
                iArr2[Variable.PRODUCT_PERIOD_ABBREVIATED.ordinal()] = 12;
            } catch (NoSuchFieldError unused15) {
            }
            try {
                iArr2[Variable.PRODUCT_PERIOD_IN_DAYS.ordinal()] = 13;
            } catch (NoSuchFieldError unused16) {
            }
            try {
                iArr2[Variable.PRODUCT_PERIOD_IN_WEEKS.ordinal()] = 14;
            } catch (NoSuchFieldError unused17) {
            }
            try {
                iArr2[Variable.PRODUCT_PERIOD_IN_MONTHS.ordinal()] = 15;
            } catch (NoSuchFieldError unused18) {
            }
            try {
                iArr2[Variable.PRODUCT_PERIOD_IN_YEARS.ordinal()] = 16;
            } catch (NoSuchFieldError unused19) {
            }
            try {
                iArr2[Variable.PRODUCT_PERIOD_WITH_UNIT.ordinal()] = 17;
            } catch (NoSuchFieldError unused20) {
            }
            try {
                iArr2[Variable.PRODUCT_OFFER_PRICE.ordinal()] = 18;
            } catch (NoSuchFieldError unused21) {
            }
            try {
                iArr2[Variable.PRODUCT_OFFER_PRICE_PER_DAY.ordinal()] = 19;
            } catch (NoSuchFieldError unused22) {
            }
            try {
                iArr2[Variable.PRODUCT_OFFER_PRICE_PER_WEEK.ordinal()] = 20;
            } catch (NoSuchFieldError unused23) {
            }
            try {
                iArr2[Variable.PRODUCT_OFFER_PRICE_PER_MONTH.ordinal()] = 21;
            } catch (NoSuchFieldError unused24) {
            }
            try {
                iArr2[Variable.PRODUCT_OFFER_PRICE_PER_YEAR.ordinal()] = 22;
            } catch (NoSuchFieldError unused25) {
            }
            try {
                iArr2[Variable.PRODUCT_OFFER_PERIOD.ordinal()] = 23;
            } catch (NoSuchFieldError unused26) {
            }
            try {
                iArr2[Variable.PRODUCT_OFFER_PERIOD_ABBREVIATED.ordinal()] = 24;
            } catch (NoSuchFieldError unused27) {
            }
            try {
                iArr2[Variable.PRODUCT_OFFER_PERIOD_IN_DAYS.ordinal()] = 25;
            } catch (NoSuchFieldError unused28) {
            }
            try {
                iArr2[Variable.PRODUCT_OFFER_PERIOD_IN_WEEKS.ordinal()] = 26;
            } catch (NoSuchFieldError unused29) {
            }
            try {
                iArr2[Variable.PRODUCT_OFFER_PERIOD_IN_MONTHS.ordinal()] = 27;
            } catch (NoSuchFieldError unused30) {
            }
            try {
                iArr2[Variable.PRODUCT_OFFER_PERIOD_IN_YEARS.ordinal()] = 28;
            } catch (NoSuchFieldError unused31) {
            }
            try {
                iArr2[Variable.PRODUCT_OFFER_PERIOD_WITH_UNIT.ordinal()] = 29;
            } catch (NoSuchFieldError unused32) {
            }
            try {
                iArr2[Variable.PRODUCT_OFFER_END_DATE.ordinal()] = 30;
            } catch (NoSuchFieldError unused33) {
            }
            try {
                iArr2[Variable.PRODUCT_SECONDARY_OFFER_PRICE.ordinal()] = 31;
            } catch (NoSuchFieldError unused34) {
            }
            try {
                iArr2[Variable.PRODUCT_SECONDARY_OFFER_PERIOD.ordinal()] = 32;
            } catch (NoSuchFieldError unused35) {
            }
            try {
                iArr2[Variable.PRODUCT_SECONDARY_OFFER_PERIOD_ABBREVIATED.ordinal()] = 33;
            } catch (NoSuchFieldError unused36) {
            }
            try {
                iArr2[Variable.PRODUCT_RELATIVE_DISCOUNT.ordinal()] = 34;
            } catch (NoSuchFieldError unused37) {
            }
            try {
                iArr2[Variable.PRODUCT_STORE_PRODUCT_NAME.ordinal()] = 35;
            } catch (NoSuchFieldError unused38) {
            }
            try {
                iArr2[Variable.COUNT_DAYS_WITH_ZERO.ordinal()] = 36;
            } catch (NoSuchFieldError unused39) {
            }
            try {
                iArr2[Variable.COUNT_DAYS_WITHOUT_ZERO.ordinal()] = 37;
            } catch (NoSuchFieldError unused40) {
            }
            try {
                iArr2[Variable.COUNT_HOURS_WITH_ZERO.ordinal()] = 38;
            } catch (NoSuchFieldError unused41) {
            }
            try {
                iArr2[Variable.COUNT_HOURS_WITHOUT_ZERO.ordinal()] = 39;
            } catch (NoSuchFieldError unused42) {
            }
            try {
                iArr2[Variable.COUNT_MINUTES_WITH_ZERO.ordinal()] = 40;
            } catch (NoSuchFieldError unused43) {
            }
            try {
                iArr2[Variable.COUNT_MINUTES_WITHOUT_ZERO.ordinal()] = 41;
            } catch (NoSuchFieldError unused44) {
            }
            try {
                iArr2[Variable.COUNT_SECONDS_WITH_ZERO.ordinal()] = 42;
            } catch (NoSuchFieldError unused45) {
            }
            try {
                iArr2[Variable.COUNT_SECONDS_WITHOUT_ZERO.ordinal()] = 43;
            } catch (NoSuchFieldError unused46) {
            }
            $EnumSwitchMapping$1 = iArr2;
            int[] iArr3 = new int[Function.values().length];
            try {
                iArr3[Function.LOWERCASE.ordinal()] = 1;
            } catch (NoSuchFieldError unused47) {
            }
            try {
                iArr3[Function.UPPERCASE.ordinal()] = 2;
            } catch (NoSuchFieldError unused48) {
            }
            try {
                iArr3[Function.CAPITALIZE.ordinal()] = 3;
            } catch (NoSuchFieldError unused49) {
            }
            $EnumSwitchMapping$2 = iArr3;
            int[] iArr4 = new int[Period.Unit.values().length];
            try {
                iArr4[Period.Unit.DAY.ordinal()] = 1;
            } catch (NoSuchFieldError unused50) {
            }
            try {
                iArr4[Period.Unit.WEEK.ordinal()] = 2;
            } catch (NoSuchFieldError unused51) {
            }
            try {
                iArr4[Period.Unit.MONTH.ordinal()] = 3;
            } catch (NoSuchFieldError unused52) {
            }
            try {
                iArr4[Period.Unit.YEAR.ordinal()] = 4;
            } catch (NoSuchFieldError unused53) {
            }
            try {
                iArr4[Period.Unit.UNKNOWN.ordinal()] = 5;
            } catch (NoSuchFieldError unused54) {
            }
            $EnumSwitchMapping$3 = iArr4;
        }
    }

    /* JADX INFO: renamed from: com.revenuecat.purchases.ui.revenuecatui.data.processed.VariableProcessorV2$processVariables$1, reason: invalid class name */
    public static final class AnonymousClass1 extends p implements e {
        final /* synthetic */ CountdownComponent.CountFrom $countFrom;
        final /* synthetic */ CountdownTime $countdownTime;
        final /* synthetic */ Locale $currencyLocale;
        final /* synthetic */ Map<String, CustomVariableValue> $customVariables;
        final /* synthetic */ Date $date;
        final /* synthetic */ Locale $dateLocale;
        final /* synthetic */ Map<String, CustomVariableValue> $defaultCustomVariables;
        final /* synthetic */ Map<VariableLocalizationKey, String> $localizedVariableKeys;
        final /* synthetic */ VariableProcessor.PackageContext $packageContext;
        final /* synthetic */ Package $rcPackage;
        final /* synthetic */ SubscriptionOption $subscriptionOption;
        final /* synthetic */ UiConfig.VariableConfig $variableConfig;
        final /* synthetic */ VariableDataProvider $variableDataProvider;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        /* JADX WARN: Multi-variable type inference failed */
        public AnonymousClass1(Map<VariableLocalizationKey, String> map, UiConfig.VariableConfig variableConfig, VariableDataProvider variableDataProvider, VariableProcessor.PackageContext packageContext, Package r5, SubscriptionOption subscriptionOption, Locale locale, Locale locale2, Date date, CountdownTime countdownTime, CountdownComponent.CountFrom countFrom, Map<String, ? extends CustomVariableValue> map2, Map<String, ? extends CustomVariableValue> map3) {
            super(2);
            this.$localizedVariableKeys = map;
            this.$variableConfig = variableConfig;
            this.$variableDataProvider = variableDataProvider;
            this.$packageContext = packageContext;
            this.$rcPackage = r5;
            this.$subscriptionOption = subscriptionOption;
            this.$currencyLocale = locale;
            this.$dateLocale = locale2;
            this.$date = date;
            this.$countdownTime = countdownTime;
            this.$countFrom = countFrom;
            this.$customVariables = map2;
            this.$defaultCustomVariables = map3;
        }

        @Override // J4.e
        public final String invoke(String variable, List<String> functions) {
            o.h(variable, "variable");
            o.h(functions, "functions");
            return VariableProcessorV2.INSTANCE.getVariableValue(variable, functions, this.$localizedVariableKeys, this.$variableConfig, this.$variableDataProvider, this.$packageContext, this.$rcPackage, this.$subscriptionOption, this.$currencyLocale, this.$dateLocale, this.$date, this.$countdownTime, this.$countFrom, this.$customVariables, this.$defaultCustomVariables);
        }
    }

    /* JADX INFO: renamed from: com.revenuecat.purchases.ui.revenuecatui.data.processed.VariableProcessorV2$productOfferPricePerDay$1, reason: invalid class name and case insensitive filesystem */
    public static final class C17221 extends p implements c {
        final /* synthetic */ Locale $locale;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C17221(Locale locale) {
            super(1);
            this.$locale = locale;
        }

        @Override // J4.c
        public final Price invoke(PricingPhase productOfferPricePerPeriod) {
            o.h(productOfferPricePerPeriod, "$this$productOfferPricePerPeriod");
            return productOfferPricePerPeriod.pricePerDay(this.$locale);
        }
    }

    /* JADX INFO: renamed from: com.revenuecat.purchases.ui.revenuecatui.data.processed.VariableProcessorV2$productOfferPricePerMonth$1, reason: invalid class name and case insensitive filesystem */
    public static final class C17231 extends p implements c {
        final /* synthetic */ Locale $locale;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C17231(Locale locale) {
            super(1);
            this.$locale = locale;
        }

        @Override // J4.c
        public final Price invoke(PricingPhase productOfferPricePerPeriod) {
            o.h(productOfferPricePerPeriod, "$this$productOfferPricePerPeriod");
            return productOfferPricePerPeriod.pricePerMonth(this.$locale);
        }
    }

    /* JADX INFO: renamed from: com.revenuecat.purchases.ui.revenuecatui.data.processed.VariableProcessorV2$productOfferPricePerWeek$1, reason: invalid class name and case insensitive filesystem */
    public static final class C17241 extends p implements c {
        final /* synthetic */ Locale $locale;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C17241(Locale locale) {
            super(1);
            this.$locale = locale;
        }

        @Override // J4.c
        public final Price invoke(PricingPhase productOfferPricePerPeriod) {
            o.h(productOfferPricePerPeriod, "$this$productOfferPricePerPeriod");
            return productOfferPricePerPeriod.pricePerWeek(this.$locale);
        }
    }

    /* JADX INFO: renamed from: com.revenuecat.purchases.ui.revenuecatui.data.processed.VariableProcessorV2$productOfferPricePerYear$1, reason: invalid class name and case insensitive filesystem */
    public static final class C17251 extends p implements c {
        final /* synthetic */ Locale $locale;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C17251(Locale locale) {
            super(1);
            this.$locale = locale;
        }

        @Override // J4.c
        public final Price invoke(PricingPhase productOfferPricePerPeriod) {
            o.h(productOfferPricePerPeriod, "$this$productOfferPricePerPeriod");
            return productOfferPricePerPeriod.pricePerYear(this.$locale);
        }
    }

    private VariableProcessorV2() {
    }

    private final boolean canDisplay(PricingPhase pricingPhase, Period.Unit unit) {
        return unit.ordinal() <= pricingPhase.getBillingPeriod().getUnit().ordinal();
    }

    private final void checkForMalformedCustomVariable(String str) {
        for (String str2 : AbstractC3252r.B("custom", "$custom")) {
            if (!o.c(str, str2)) {
                if (w.A0(str, str2 + ' ', false)) {
                }
            }
            Logger.INSTANCE.w("Variable '" + str + "' looks like it might be intended as a custom variable. Use 'custom.<variable_name>' or '$custom.<variable_name>' syntax instead.");
            return;
        }
    }

    private final String extractCustomVariableKey(String str) {
        for (String str2 : customVariablePrefixes) {
            if (w.A0(str, str2, false)) {
                String strX0 = S4.p.X0(str, str2);
                if (strX0.length() != 0) {
                    return strX0;
                }
                Logger.INSTANCE.w("Custom variable '" + str + "' appears to be malformed. Expected format: 'custom.<variable_name>' or '$custom.<variable_name>'.");
                return null;
            }
        }
        checkForMalformedCustomVariable(str);
        return null;
    }

    private final void failedToGetValue(Logger logger, String str, Package r5) {
        StringBuilder sbS = a.s("Could not process value for variable '", str, "' for package '");
        sbS.append(r5.getIdentifier());
        sbS.append("'. Please check that the product for that package matches the requirements for that variable. Defaulting to empty string.");
        logger.w(sbS.toString());
    }

    private final Function findFunction(String str, Map<String, String> map) {
        Function functionValueOfIdentifier = Function.Companion.valueOfIdentifier(str);
        if (functionValueOfIdentifier != null) {
            return functionValueOfIdentifier;
        }
        String str2 = map.get(str);
        if (str2 == null) {
            unsupportedFunctionWithoutFallback(Logger.INSTANCE, str);
            return null;
        }
        Function functionFindFunction = findFunction(str2, map);
        if (functionFindFunction == null) {
            return null;
        }
        INSTANCE.usingFallbackFunction(Logger.INSTANCE, str, str2);
        return functionFindFunction;
    }

    private final Variable findVariable(String str, Map<String, String> map) {
        Variable variableValueOfIdentifier = Variable.Companion.valueOfIdentifier(str);
        if (variableValueOfIdentifier != null) {
            return variableValueOfIdentifier;
        }
        String str2 = map.get(str);
        if (str2 == null) {
            unsupportedVariableWithoutFallback(Logger.INSTANCE, str);
            return null;
        }
        Variable variableFindVariable = findVariable(str2, map);
        if (variableFindVariable == null) {
            return null;
        }
        INSTANCE.usingFallbackVariable(Logger.INSTANCE, str, str2);
        return variableFindVariable;
    }

    private final VariableLocalizationKey getPeriodUnitAbbreviatedLocalizationKey(Package r22) {
        if (isLifetime(r22)) {
            return VariableLocalizationKey.LIFETIME;
        }
        Period period = r22.getProduct().getPeriod();
        if (period != null) {
            return getPeriodUnitAbbreviatedLocalizationKey(period);
        }
        return null;
    }

    private final VariableLocalizationKey getPeriodUnitLocalizationKey(Package r22) {
        if (isLifetime(r22)) {
            return VariableLocalizationKey.LIFETIME;
        }
        Period period = r22.getProduct().getPeriod();
        if (period != null) {
            return getPeriodUnitLocalizationKey(period);
        }
        return null;
    }

    private final VariableLocalizationKey getPeriodValueWithUnitAbbreviatedLocalizationKey(Period period) {
        int i6 = WhenMappings.$EnumSwitchMapping$3[period.getUnit().ordinal()];
        if (i6 == 1) {
            return VariableLocalizationKey.NUM_DAYS_SHORT;
        }
        if (i6 == 2) {
            return VariableLocalizationKey.NUM_WEEKS_SHORT;
        }
        if (i6 == 3) {
            return VariableLocalizationKey.NUM_MONTHS_SHORT;
        }
        if (i6 == 4) {
            return VariableLocalizationKey.NUM_YEARS_SHORT;
        }
        if (i6 == 5) {
            return null;
        }
        throw new v();
    }

    private final VariableLocalizationKey getPeriodValueWithUnitLocalizationKey(Period period) {
        if (period.getValue() == 0 && period.getUnit() == Period.Unit.DAY) {
            return VariableLocalizationKey.NUM_DAY_ZERO;
        }
        if (period.getValue() == 0 && period.getUnit() == Period.Unit.WEEK) {
            return VariableLocalizationKey.NUM_WEEK_ZERO;
        }
        if (period.getValue() == 0 && period.getUnit() == Period.Unit.MONTH) {
            return VariableLocalizationKey.NUM_MONTH_ZERO;
        }
        if (period.getValue() == 0 && period.getUnit() == Period.Unit.YEAR) {
            return VariableLocalizationKey.NUM_YEAR_ZERO;
        }
        if (period.getValue() == 1 && period.getUnit() == Period.Unit.DAY) {
            return VariableLocalizationKey.NUM_DAY_ONE;
        }
        if (period.getValue() == 1 && period.getUnit() == Period.Unit.WEEK) {
            return VariableLocalizationKey.NUM_WEEK_ONE;
        }
        if (period.getValue() == 1 && period.getUnit() == Period.Unit.MONTH) {
            return VariableLocalizationKey.NUM_MONTH_ONE;
        }
        if (period.getValue() == 1 && period.getUnit() == Period.Unit.YEAR) {
            return VariableLocalizationKey.NUM_YEAR_ONE;
        }
        if (period.getValue() == 2 && period.getUnit() == Period.Unit.DAY) {
            return VariableLocalizationKey.NUM_DAY_TWO;
        }
        if (period.getValue() == 2 && period.getUnit() == Period.Unit.WEEK) {
            return VariableLocalizationKey.NUM_WEEK_TWO;
        }
        if (period.getValue() == 2 && period.getUnit() == Period.Unit.MONTH) {
            return VariableLocalizationKey.NUM_MONTH_TWO;
        }
        if (period.getValue() == 2 && period.getUnit() == Period.Unit.YEAR) {
            return VariableLocalizationKey.NUM_YEAR_TWO;
        }
        int value = period.getValue();
        if (3 <= value && value < 5 && period.getUnit() == Period.Unit.DAY) {
            return VariableLocalizationKey.NUM_DAY_FEW;
        }
        int value2 = period.getValue();
        if (3 <= value2 && value2 < 5 && period.getUnit() == Period.Unit.WEEK) {
            return VariableLocalizationKey.NUM_WEEK_FEW;
        }
        int value3 = period.getValue();
        if (3 <= value3 && value3 < 5 && period.getUnit() == Period.Unit.MONTH) {
            return VariableLocalizationKey.NUM_MONTH_FEW;
        }
        int value4 = period.getValue();
        if (3 <= value4 && value4 < 5 && period.getUnit() == Period.Unit.YEAR) {
            return VariableLocalizationKey.NUM_YEAR_FEW;
        }
        int value5 = period.getValue();
        if (5 <= value5 && value5 < 11 && period.getUnit() == Period.Unit.DAY) {
            return VariableLocalizationKey.NUM_DAY_MANY;
        }
        int value6 = period.getValue();
        if (5 <= value6 && value6 < 11 && period.getUnit() == Period.Unit.WEEK) {
            return VariableLocalizationKey.NUM_WEEK_MANY;
        }
        int value7 = period.getValue();
        if (5 <= value7 && value7 < 11 && period.getUnit() == Period.Unit.MONTH) {
            return VariableLocalizationKey.NUM_MONTH_MANY;
        }
        int value8 = period.getValue();
        return (5 > value8 || value8 >= 11 || period.getUnit() != Period.Unit.YEAR) ? period.getUnit() == Period.Unit.DAY ? VariableLocalizationKey.NUM_DAY_OTHER : period.getUnit() == Period.Unit.WEEK ? VariableLocalizationKey.NUM_WEEK_OTHER : period.getUnit() == Period.Unit.MONTH ? VariableLocalizationKey.NUM_MONTH_OTHER : period.getUnit() == Period.Unit.YEAR ? VariableLocalizationKey.NUM_YEAR_OTHER : VariableLocalizationKey.NUM_DAY_OTHER : VariableLocalizationKey.NUM_YEAR_MANY;
    }

    private static /* synthetic */ void getPeriodValueWithUnitLocalizationKey$annotations(Period period) {
    }

    private final String getProductOfferPeriodInDays(PricingPhase pricingPhase) {
        return productOfferPeriodInPeriodUnit(pricingPhase, Period.Unit.DAY, VariableProcessorV2$productOfferPeriodInDays$1.INSTANCE);
    }

    private final String getProductOfferPeriodInMonths(PricingPhase pricingPhase) {
        return productOfferPeriodInPeriodUnit(pricingPhase, Period.Unit.MONTH, VariableProcessorV2$productOfferPeriodInMonths$1.INSTANCE);
    }

    private final String getProductOfferPeriodInWeeks(PricingPhase pricingPhase) {
        return productOfferPeriodInPeriodUnit(pricingPhase, Period.Unit.WEEK, VariableProcessorV2$productOfferPeriodInWeeks$1.INSTANCE);
    }

    private final String getProductOfferPeriodInYears(PricingPhase pricingPhase) {
        return productOfferPeriodInPeriodUnit(pricingPhase, Period.Unit.YEAR, VariableProcessorV2$productOfferPeriodInYears$1.INSTANCE);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final String getRoundedValueInDays(Period period) {
        return String.valueOf(L4.a.c0(period.getValueInDays()));
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final String getRoundedValueInMonths(Period period) {
        return String.valueOf(L4.a.c0(period.getValueInMonths()));
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final String getRoundedValueInWeeks(Period period) {
        return String.valueOf(L4.a.c0(period.getValueInWeeks()));
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final String getRoundedValueInYears(Period period) {
        return String.valueOf(L4.a.c0(period.getValueInYears()));
    }

    private final String getStringOrLogError(Map<VariableLocalizationKey, String> map, VariableLocalizationKey variableLocalizationKey) {
        String str = map.get(variableLocalizationKey);
        if (str == null) {
            Logger.INSTANCE.e("Could not find localized string for variable key: " + variableLocalizationKey);
        }
        return str;
    }

    private final String getValue(Variable variable, Map<VariableLocalizationKey, String> map, VariableDataProvider variableDataProvider, VariableProcessor.PackageContext packageContext, Package r22, SubscriptionOption subscriptionOption, Locale locale, Locale locale2, Date date, CountdownTime countdownTime, CountdownComponent.CountFrom countFrom) {
        StoreProduct product;
        Price price;
        StoreProduct product2;
        Period period;
        StoreProduct product3;
        Period period2;
        StoreProduct product4;
        Period period3;
        StoreProduct product5;
        Period period4;
        StoreProduct product6;
        int days;
        int days2;
        int hours;
        int hours2;
        int minutes;
        int minutes2;
        switch (WhenMappings.$EnumSwitchMapping$1[variable.ordinal()]) {
            case 1:
                if (r22 == null || (product = r22.getProduct()) == null || (price = product.getPrice()) == null) {
                    return null;
                }
                return price.getCurrencyCode();
            case 2:
                if (r22 != null) {
                    return Currency.getInstance(r22.getProduct().getPrice().getCurrencyCode()).getSymbol(locale);
                }
                return null;
            case 3:
                if (r22 != null) {
                    return productPeriodly(r22, map);
                }
                return null;
            case 4:
                if (r22 == null || variableDataProvider == null) {
                    return null;
                }
                return variableDataProvider.localizedPrice(r22, locale, packageContext != null ? packageContext.getShowZeroDecimalPlacePrices() : false);
            case 5:
                if (r22 != null && variableDataProvider != null) {
                    String strLocalizedPrice = variableDataProvider.localizedPrice(r22, locale, packageContext != null ? packageContext.getShowZeroDecimalPlacePrices() : false);
                    if (strLocalizedPrice != null) {
                        VariableProcessorV2 variableProcessorV2 = INSTANCE;
                        String strProductPeriod = variableProcessorV2.productPeriod(r22, map);
                        if (variableProcessorV2.isLifetime(r22)) {
                            return strLocalizedPrice;
                        }
                        if (strProductPeriod != null) {
                            return strLocalizedPrice + '/' + strProductPeriod;
                        }
                    }
                }
                return null;
            case 6:
                if (r22 != null && variableDataProvider != null) {
                    String strLocalizedPrice2 = variableDataProvider.localizedPrice(r22, locale, packageContext != null ? packageContext.getShowZeroDecimalPlacePrices() : false);
                    if (strLocalizedPrice2 != null) {
                        VariableProcessorV2 variableProcessorV22 = INSTANCE;
                        String strProductPeriodAbbreviated = variableProcessorV22.productPeriodAbbreviated(r22, map);
                        if (variableProcessorV22.isLifetime(r22)) {
                            return strLocalizedPrice2;
                        }
                        if (strProductPeriodAbbreviated != null) {
                            return strLocalizedPrice2 + '/' + strProductPeriodAbbreviated;
                        }
                    }
                }
                return null;
            case 7:
                if (r22 != null) {
                    boolean showZeroDecimalPlacePrices = packageContext != null ? packageContext.getShowZeroDecimalPlacePrices() : false;
                    if (INSTANCE.isLifetime(r22)) {
                        if (variableDataProvider != null) {
                            return variableDataProvider.localizedPrice(r22, locale, showZeroDecimalPlacePrices);
                        }
                        return null;
                    }
                    if (variableDataProvider != null) {
                        return variableDataProvider.localizedPricePerDay(r22, locale, showZeroDecimalPlacePrices);
                    }
                }
                return null;
            case 8:
                if (r22 != null) {
                    boolean showZeroDecimalPlacePrices2 = packageContext != null ? packageContext.getShowZeroDecimalPlacePrices() : false;
                    if (INSTANCE.isLifetime(r22)) {
                        if (variableDataProvider != null) {
                            return variableDataProvider.localizedPrice(r22, locale, showZeroDecimalPlacePrices2);
                        }
                        return null;
                    }
                    if (variableDataProvider != null) {
                        return variableDataProvider.localizedPricePerWeek(r22, locale, showZeroDecimalPlacePrices2);
                    }
                }
                return null;
            case 9:
                if (r22 != null) {
                    boolean showZeroDecimalPlacePrices3 = packageContext != null ? packageContext.getShowZeroDecimalPlacePrices() : false;
                    if (INSTANCE.isLifetime(r22)) {
                        if (variableDataProvider != null) {
                            return variableDataProvider.localizedPrice(r22, locale, showZeroDecimalPlacePrices3);
                        }
                        return null;
                    }
                    if (variableDataProvider != null) {
                        return variableDataProvider.localizedPricePerMonth(r22, locale, showZeroDecimalPlacePrices3);
                    }
                }
                return null;
            case 10:
                if (r22 != null) {
                    boolean showZeroDecimalPlacePrices4 = packageContext != null ? packageContext.getShowZeroDecimalPlacePrices() : false;
                    if (INSTANCE.isLifetime(r22)) {
                        if (variableDataProvider != null) {
                            return variableDataProvider.localizedPrice(r22, locale, showZeroDecimalPlacePrices4);
                        }
                        return null;
                    }
                    if (variableDataProvider != null) {
                        return variableDataProvider.localizedPricePerYear(r22, locale, showZeroDecimalPlacePrices4);
                    }
                }
                return null;
            case 11:
                if (r22 != null) {
                    return productPeriod(r22, map);
                }
                return null;
            case 12:
                if (r22 != null) {
                    return productPeriodAbbreviated(r22, map);
                }
                return null;
            case 13:
                if (r22 == null || (product2 = r22.getProduct()) == null || (period = product2.getPeriod()) == null) {
                    return null;
                }
                return getRoundedValueInDays(period);
            case 14:
                if (r22 == null || (product3 = r22.getProduct()) == null || (period2 = product3.getPeriod()) == null) {
                    return null;
                }
                return getRoundedValueInWeeks(period2);
            case 15:
                if (r22 == null || (product4 = r22.getProduct()) == null || (period3 = product4.getPeriod()) == null) {
                    return null;
                }
                return getRoundedValueInMonths(period3);
            case 16:
                if (r22 == null || (product5 = r22.getProduct()) == null || (period4 = product5.getPeriod()) == null) {
                    return null;
                }
                return getRoundedValueInYears(period4);
            case 17:
                if (r22 != null) {
                    return productPeriodWithUnit(r22, map);
                }
                return null;
            case 18:
                PricingPhase pricingPhasePrimaryDiscountPhase = primaryDiscountPhase(subscriptionOption, r22);
                if (pricingPhasePrimaryDiscountPhase != null) {
                    return productOfferPrice(pricingPhasePrimaryDiscountPhase, map);
                }
                return null;
            case 19:
                PricingPhase pricingPhasePrimaryDiscountPhase2 = primaryDiscountPhase(subscriptionOption, r22);
                if (pricingPhasePrimaryDiscountPhase2 != null) {
                    return productOfferPricePerDay(pricingPhasePrimaryDiscountPhase2, locale, map);
                }
                return null;
            case 20:
                PricingPhase pricingPhasePrimaryDiscountPhase3 = primaryDiscountPhase(subscriptionOption, r22);
                if (pricingPhasePrimaryDiscountPhase3 != null) {
                    return productOfferPricePerWeek(pricingPhasePrimaryDiscountPhase3, locale, map);
                }
                return null;
            case 21:
                PricingPhase pricingPhasePrimaryDiscountPhase4 = primaryDiscountPhase(subscriptionOption, r22);
                if (pricingPhasePrimaryDiscountPhase4 != null) {
                    return productOfferPricePerMonth(pricingPhasePrimaryDiscountPhase4, locale, map);
                }
                return null;
            case 22:
                PricingPhase pricingPhasePrimaryDiscountPhase5 = primaryDiscountPhase(subscriptionOption, r22);
                if (pricingPhasePrimaryDiscountPhase5 != null) {
                    return productOfferPricePerYear(pricingPhasePrimaryDiscountPhase5, locale, map);
                }
                return null;
            case 23:
                PricingPhase pricingPhasePrimaryDiscountPhase6 = primaryDiscountPhase(subscriptionOption, r22);
                if (pricingPhasePrimaryDiscountPhase6 != null) {
                    return productOfferPeriod(pricingPhasePrimaryDiscountPhase6, map);
                }
                return null;
            case 24:
                PricingPhase pricingPhasePrimaryDiscountPhase7 = primaryDiscountPhase(subscriptionOption, r22);
                if (pricingPhasePrimaryDiscountPhase7 != null) {
                    return productOfferPeriodAbbreviated(pricingPhasePrimaryDiscountPhase7, map);
                }
                return null;
            case 25:
                PricingPhase pricingPhasePrimaryDiscountPhase8 = primaryDiscountPhase(subscriptionOption, r22);
                if (pricingPhasePrimaryDiscountPhase8 != null) {
                    return getProductOfferPeriodInDays(pricingPhasePrimaryDiscountPhase8);
                }
                return null;
            case 26:
                PricingPhase pricingPhasePrimaryDiscountPhase9 = primaryDiscountPhase(subscriptionOption, r22);
                if (pricingPhasePrimaryDiscountPhase9 != null) {
                    return getProductOfferPeriodInWeeks(pricingPhasePrimaryDiscountPhase9);
                }
                return null;
            case 27:
                PricingPhase pricingPhasePrimaryDiscountPhase10 = primaryDiscountPhase(subscriptionOption, r22);
                if (pricingPhasePrimaryDiscountPhase10 != null) {
                    return getProductOfferPeriodInMonths(pricingPhasePrimaryDiscountPhase10);
                }
                return null;
            case 28:
                PricingPhase pricingPhasePrimaryDiscountPhase11 = primaryDiscountPhase(subscriptionOption, r22);
                if (pricingPhasePrimaryDiscountPhase11 != null) {
                    return getProductOfferPeriodInYears(pricingPhasePrimaryDiscountPhase11);
                }
                return null;
            case 29:
                PricingPhase pricingPhasePrimaryDiscountPhase12 = primaryDiscountPhase(subscriptionOption, r22);
                if (pricingPhasePrimaryDiscountPhase12 != null) {
                    return productOfferPeriodWithUnit(pricingPhasePrimaryDiscountPhase12, map);
                }
                return null;
            case 30:
                PricingPhase pricingPhasePrimaryDiscountPhase13 = primaryDiscountPhase(subscriptionOption, r22);
                if (pricingPhasePrimaryDiscountPhase13 != null) {
                    return productOfferEndDate(pricingPhasePrimaryDiscountPhase13, locale2, date);
                }
                return null;
            case 31:
                PricingPhase pricingPhaseSecondaryDiscountPhase = secondaryDiscountPhase(subscriptionOption, r22);
                if (pricingPhaseSecondaryDiscountPhase != null) {
                    return productOfferPrice(pricingPhaseSecondaryDiscountPhase, map);
                }
                return null;
            case 32:
                PricingPhase pricingPhaseSecondaryDiscountPhase2 = secondaryDiscountPhase(subscriptionOption, r22);
                if (pricingPhaseSecondaryDiscountPhase2 != null) {
                    return productOfferPeriod(pricingPhaseSecondaryDiscountPhase2, map);
                }
                return null;
            case 33:
                PricingPhase pricingPhaseSecondaryDiscountPhase3 = secondaryDiscountPhase(subscriptionOption, r22);
                if (pricingPhaseSecondaryDiscountPhase3 != null) {
                    return productOfferPeriodAbbreviated(pricingPhaseSecondaryDiscountPhase3, map);
                }
                return null;
            case 34:
                if (packageContext != null) {
                    return relativeDiscount(packageContext, map);
                }
                return null;
            case 35:
                if (r22 == null || (product6 = r22.getProduct()) == null) {
                    return null;
                }
                return product6.getName();
            case TsExtractor.TS_STREAM_TYPE_H265 /* 36 */:
                if (countdownTime == null) {
                    return "";
                }
                int i6 = WhenMappings.$EnumSwitchMapping$0[countFrom.ordinal()];
                if (i6 == 1) {
                    days = countdownTime.getDays();
                } else {
                    if (i6 != 2 && i6 != 3) {
                        throw new v();
                    }
                    days = 0;
                }
                return String.format(locale2, "%02d", Arrays.copyOf(new Object[]{Integer.valueOf(days)}, 1));
            case FirestoreIndexValueWriter.INDEX_TYPE_REFERENCE /* 37 */:
                if (countdownTime == null) {
                    return "";
                }
                int i7 = WhenMappings.$EnumSwitchMapping$0[countFrom.ordinal()];
                if (i7 == 1) {
                    days2 = countdownTime.getDays();
                } else {
                    if (i7 != 2 && i7 != 3) {
                        throw new v();
                    }
                    days2 = 0;
                }
                return String.format(locale2, "%d", Arrays.copyOf(new Object[]{Integer.valueOf(days2)}, 1));
            case FlacConstants.STREAM_INFO_BLOCK_SIZE /* 38 */:
                if (countdownTime == null) {
                    return "";
                }
                int i8 = WhenMappings.$EnumSwitchMapping$0[countFrom.ordinal()];
                if (i8 == 1) {
                    hours = countdownTime.getHours();
                } else if (i8 == 2) {
                    hours = countdownTime.getTotalHours();
                } else {
                    if (i8 != 3) {
                        throw new v();
                    }
                    hours = 0;
                }
                return String.format(locale2, "%02d", Arrays.copyOf(new Object[]{Integer.valueOf(hours)}, 1));
            case 39:
                if (countdownTime == null) {
                    return "";
                }
                int i9 = WhenMappings.$EnumSwitchMapping$0[countFrom.ordinal()];
                if (i9 == 1) {
                    hours2 = countdownTime.getHours();
                } else if (i9 == 2) {
                    hours2 = countdownTime.getTotalHours();
                } else {
                    if (i9 != 3) {
                        throw new v();
                    }
                    hours2 = 0;
                }
                return String.format(locale2, "%d", Arrays.copyOf(new Object[]{Integer.valueOf(hours2)}, 1));
            case 40:
                if (countdownTime == null) {
                    return "";
                }
                int i10 = WhenMappings.$EnumSwitchMapping$0[countFrom.ordinal()];
                if (i10 == 1 || i10 == 2) {
                    minutes = countdownTime.getMinutes();
                } else {
                    if (i10 != 3) {
                        throw new v();
                    }
                    minutes = countdownTime.getTotalMinutes();
                }
                return String.format(locale2, "%02d", Arrays.copyOf(new Object[]{Integer.valueOf(minutes)}, 1));
            case 41:
                if (countdownTime == null) {
                    return "";
                }
                int i11 = WhenMappings.$EnumSwitchMapping$0[countFrom.ordinal()];
                if (i11 == 1 || i11 == 2) {
                    minutes2 = countdownTime.getMinutes();
                } else {
                    if (i11 != 3) {
                        throw new v();
                    }
                    minutes2 = countdownTime.getTotalMinutes();
                }
                return String.format(locale2, "%d", Arrays.copyOf(new Object[]{Integer.valueOf(minutes2)}, 1));
            case AacUtil.AUDIO_OBJECT_TYPE_AAC_XHE /* 42 */:
                return countdownTime != null ? String.format(locale2, "%02d", Arrays.copyOf(new Object[]{Integer.valueOf(countdownTime.getSeconds())}, 1)) : "";
            case 43:
                return countdownTime != null ? String.format(locale2, "%d", Arrays.copyOf(new Object[]{Integer.valueOf(countdownTime.getSeconds())}, 1)) : "";
            default:
                throw new v();
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final String getVariableValue(String str, List<String> list, Map<VariableLocalizationKey, String> map, UiConfig.VariableConfig variableConfig, VariableDataProvider variableDataProvider, VariableProcessor.PackageContext packageContext, Package r22, SubscriptionOption subscriptionOption, Locale locale, Locale locale2, Date date, CountdownTime countdownTime, CountdownComponent.CountFrom countFrom, Map<String, ? extends CustomVariableValue> map2, Map<String, ? extends CustomVariableValue> map3) {
        ArrayList arrayList = new ArrayList();
        Iterator<T> it = list.iterator();
        while (it.hasNext()) {
            Function functionFindFunction = INSTANCE.findFunction((String) it.next(), variableConfig.getFunctionCompatibilityMap());
            if (functionFindFunction != null) {
                arrayList.add(functionFindFunction);
            }
        }
        String strExtractCustomVariableKey = extractCustomVariableKey(str);
        if (strExtractCustomVariableKey != null) {
            return resolveCustomVariable(strExtractCustomVariableKey, map2, map3, arrayList, locale);
        }
        Variable variableFindVariable = findVariable(str, variableConfig.getVariableCompatibilityMap());
        if (variableFindVariable == null) {
            return "";
        }
        String value = getValue(variableFindVariable, map, variableDataProvider, packageContext, r22, subscriptionOption, locale, locale2, date, countdownTime, countFrom);
        if (value != null) {
            Iterator it2 = arrayList.iterator();
            while (it2.hasNext()) {
                value = INSTANCE.processFunction(value, (Function) it2.next(), locale);
            }
        } else {
            value = null;
        }
        if (value != null) {
            return value;
        }
        if (r22 != null) {
            failedToGetValue(Logger.INSTANCE, str, r22);
        }
        return "";
    }

    private final boolean isLifetime(Package r22) {
        return r22.getPackageType() == PackageType.LIFETIME;
    }

    private final PricingPhase primaryDiscountPhase(SubscriptionOption subscriptionOption, Package r32) {
        StoreProduct product;
        if (subscriptionOption == null) {
            subscriptionOption = (r32 == null || (product = r32.getProduct()) == null) ? null : product.getDefaultOption();
        }
        if (subscriptionOption == null) {
            return null;
        }
        PricingPhase freePhase = subscriptionOption.getFreePhase();
        return freePhase == null ? subscriptionOption.getIntroPhase() : freePhase;
    }

    private final String processFunction(String str, Function function, Locale locale) {
        int i6 = WhenMappings.$EnumSwitchMapping$2[function.ordinal()];
        if (i6 == 1) {
            String lowerCase = str.toLowerCase(Locale.ROOT);
            o.g(lowerCase, "toLowerCase(...)");
            return lowerCase;
        }
        if (i6 == 2) {
            String upperCase = str.toUpperCase(Locale.ROOT);
            o.g(upperCase, "toUpperCase(...)");
            return upperCase;
        }
        if (i6 != 3) {
            throw new v();
        }
        if (str.length() <= 0) {
            return str;
        }
        StringBuilder sb = new StringBuilder();
        char cCharAt = str.charAt(0);
        sb.append((Object) (Character.isLowerCase(cCharAt) ? AbstractC0872a.f0(cCharAt, locale) : String.valueOf(cCharAt)));
        String strSubstring = str.substring(1);
        o.g(strSubstring, "substring(...)");
        sb.append(strSubstring);
        return sb.toString();
    }

    /* JADX WARN: Multi-variable type inference failed */
    public static /* synthetic */ String processVariables$default(VariableProcessorV2 variableProcessorV2, String str, Map map, UiConfig.VariableConfig variableConfig, VariableDataProvider variableDataProvider, VariableProcessor.PackageContext packageContext, Package r24, SubscriptionOption subscriptionOption, Locale locale, Locale locale2, Date date, CountdownTime countdownTime, CountdownComponent.CountFrom countFrom, Map map2, Map map3, int i6, Object obj) {
        Locale locale3;
        int i7 = i6 & 2;
        z zVar = z.f26066a;
        Map map4 = i7 != 0 ? zVar : map;
        VariableDataProvider variableDataProvider2 = (i6 & 8) != 0 ? null : variableDataProvider;
        VariableProcessor.PackageContext packageContext2 = (i6 & 16) != 0 ? null : packageContext;
        Package r9 = (i6 & 32) != 0 ? null : r24;
        SubscriptionOption subscriptionOption2 = (i6 & 64) != 0 ? null : subscriptionOption;
        if ((i6 & 128) != 0) {
            Locale locale4 = Locale.getDefault();
            o.g(locale4, "getDefault()");
            locale3 = locale4;
        } else {
            locale3 = locale;
        }
        return variableProcessorV2.processVariables(str, map4, variableConfig, variableDataProvider2, packageContext2, r9, subscriptionOption2, locale3, locale2, (i6 & 512) != 0 ? new Date() : date, (i6 & 1024) != 0 ? null : countdownTime, (i6 & 2048) != 0 ? CountdownComponent.CountFrom.DAYS : countFrom, (i6 & 4096) != 0 ? zVar : map2, (i6 & 8192) != 0 ? zVar : map3);
    }

    private final String productOfferEndDate(PricingPhase pricingPhase, Locale locale, Date date) {
        Calendar calendar = Calendar.getInstance(locale);
        calendar.setTime(date);
        calendar.add(6, L4.a.c0(pricingPhase.getBillingPeriod().getValueInDays()));
        return DateFormat.getDateInstance(1, locale).format(calendar.getTime());
    }

    private final String productOfferPeriod(PricingPhase pricingPhase, Map<VariableLocalizationKey, String> map) {
        VariableLocalizationKey periodUnitLocalizationKey = getPeriodUnitLocalizationKey(pricingPhase.getBillingPeriod());
        if (periodUnitLocalizationKey != null) {
            return INSTANCE.getStringOrLogError(map, periodUnitLocalizationKey);
        }
        return null;
    }

    private final String productOfferPeriodAbbreviated(PricingPhase pricingPhase, Map<VariableLocalizationKey, String> map) {
        VariableLocalizationKey periodUnitAbbreviatedLocalizationKey = getPeriodUnitAbbreviatedLocalizationKey(pricingPhase.getBillingPeriod());
        if (periodUnitAbbreviatedLocalizationKey != null) {
            return INSTANCE.getStringOrLogError(map, periodUnitAbbreviatedLocalizationKey);
        }
        return null;
    }

    private final String productOfferPeriodInPeriodUnit(PricingPhase pricingPhase, Period.Unit unit, c cVar) {
        Period billingPeriod;
        if (!INSTANCE.canDisplay(pricingPhase, unit)) {
            pricingPhase = null;
        }
        if (pricingPhase == null || (billingPeriod = pricingPhase.getBillingPeriod()) == null) {
            return null;
        }
        return (String) cVar.invoke(billingPeriod);
    }

    private final String productOfferPeriodWithUnit(PricingPhase pricingPhase, Map<VariableLocalizationKey, String> map) {
        String stringOrLogError = getStringOrLogError(map, getPeriodValueWithUnitLocalizationKey(pricingPhase.getBillingPeriod()));
        if (stringOrLogError != null) {
            return String.format(stringOrLogError, Arrays.copyOf(new Object[]{Integer.valueOf(pricingPhase.getBillingPeriod().getValue())}, 1));
        }
        return null;
    }

    private final String productOfferPrice(PricingPhase pricingPhase, Map<VariableLocalizationKey, String> map) {
        return pricingPhase.getPrice().getAmountMicros() == 0 ? getStringOrLogError(map, VariableLocalizationKey.FREE_PRICE) : pricingPhase.getPrice().getFormatted();
    }

    private final String productOfferPricePerDay(PricingPhase pricingPhase, Locale locale, Map<VariableLocalizationKey, String> map) {
        return productOfferPricePerPeriod(pricingPhase, map, Period.Unit.DAY, new C17221(locale));
    }

    private final String productOfferPricePerMonth(PricingPhase pricingPhase, Locale locale, Map<VariableLocalizationKey, String> map) {
        return productOfferPricePerPeriod(pricingPhase, map, Period.Unit.MONTH, new C17231(locale));
    }

    private final String productOfferPricePerPeriod(PricingPhase pricingPhase, Map<VariableLocalizationKey, String> map, Period.Unit unit, c cVar) {
        Price price;
        VariableProcessorV2 variableProcessorV2 = INSTANCE;
        if (!variableProcessorV2.canDisplay(pricingPhase, unit)) {
            pricingPhase = null;
        }
        if (pricingPhase == null || (price = (Price) cVar.invoke(pricingPhase)) == null) {
            return null;
        }
        return price.getAmountMicros() == 0 ? variableProcessorV2.getStringOrLogError(map, VariableLocalizationKey.FREE_PRICE) : price.getFormatted();
    }

    private final String productOfferPricePerWeek(PricingPhase pricingPhase, Locale locale, Map<VariableLocalizationKey, String> map) {
        return productOfferPricePerPeriod(pricingPhase, map, Period.Unit.WEEK, new C17241(locale));
    }

    private final String productOfferPricePerYear(PricingPhase pricingPhase, Locale locale, Map<VariableLocalizationKey, String> map) {
        return productOfferPricePerPeriod(pricingPhase, map, Period.Unit.YEAR, new C17251(locale));
    }

    private final String productPeriod(Package r5, Map<VariableLocalizationKey, String> map) {
        Period period = r5.getProduct().getPeriod();
        if (isLifetime(r5)) {
            return getStringOrLogError(map, VariableLocalizationKey.LIFETIME);
        }
        if (period == null) {
            return null;
        }
        if (period.getValue() > 1) {
            String stringOrLogError = getStringOrLogError(map, getPeriodValueWithUnitLocalizationKey(period));
            if (stringOrLogError != null) {
                return String.format(stringOrLogError, Arrays.copyOf(new Object[]{Integer.valueOf(period.getValue())}, 1));
            }
            return null;
        }
        VariableLocalizationKey periodUnitLocalizationKey = getPeriodUnitLocalizationKey(r5);
        if (periodUnitLocalizationKey != null) {
            return INSTANCE.getStringOrLogError(map, periodUnitLocalizationKey);
        }
        return null;
    }

    private final String productPeriodAbbreviated(Package r5, Map<VariableLocalizationKey, String> map) {
        String stringOrLogError;
        Period period = r5.getProduct().getPeriod();
        if (isLifetime(r5)) {
            return getStringOrLogError(map, VariableLocalizationKey.LIFETIME);
        }
        if (period == null) {
            return null;
        }
        if (period.getValue() <= 1) {
            VariableLocalizationKey periodUnitAbbreviatedLocalizationKey = getPeriodUnitAbbreviatedLocalizationKey(r5);
            if (periodUnitAbbreviatedLocalizationKey != null) {
                return INSTANCE.getStringOrLogError(map, periodUnitAbbreviatedLocalizationKey);
            }
            return null;
        }
        VariableLocalizationKey periodValueWithUnitAbbreviatedLocalizationKey = getPeriodValueWithUnitAbbreviatedLocalizationKey(period);
        if (periodValueWithUnitAbbreviatedLocalizationKey == null || (stringOrLogError = INSTANCE.getStringOrLogError(map, periodValueWithUnitAbbreviatedLocalizationKey)) == null) {
            return null;
        }
        return String.format(stringOrLogError, Arrays.copyOf(new Object[]{Integer.valueOf(period.getValue())}, 1));
    }

    private final String productPeriodWithUnit(Package r42, Map<VariableLocalizationKey, String> map) {
        if (isLifetime(r42)) {
            return getStringOrLogError(map, VariableLocalizationKey.LIFETIME);
        }
        Period period = r42.getProduct().getPeriod();
        if (period != null) {
            VariableProcessorV2 variableProcessorV2 = INSTANCE;
            String stringOrLogError = variableProcessorV2.getStringOrLogError(map, variableProcessorV2.getPeriodValueWithUnitLocalizationKey(period));
            if (stringOrLogError != null) {
                return String.format(stringOrLogError, Arrays.copyOf(new Object[]{Integer.valueOf(period.getValue())}, 1));
            }
        }
        return null;
    }

    private final String productPeriodly(Package r42, Map<VariableLocalizationKey, String> map) {
        VariableLocalizationKey variableLocalizationKey;
        Period period = r42.getProduct().getPeriod();
        if (isLifetime(r42)) {
            return getStringOrLogError(map, VariableLocalizationKey.LIFETIME);
        }
        if (period == null) {
            return null;
        }
        if (period.getValue() > 1) {
            String stringOrLogError = getStringOrLogError(map, getPeriodValueWithUnitLocalizationKey(period));
            if (stringOrLogError != null) {
                return String.format(stringOrLogError, Arrays.copyOf(new Object[]{Integer.valueOf(period.getValue())}, 1));
            }
            return null;
        }
        int i6 = WhenMappings.$EnumSwitchMapping$3[period.getUnit().ordinal()];
        if (i6 == 1) {
            variableLocalizationKey = VariableLocalizationKey.DAILY;
        } else if (i6 == 2) {
            variableLocalizationKey = VariableLocalizationKey.WEEKLY;
        } else if (i6 == 3) {
            variableLocalizationKey = VariableLocalizationKey.MONTHLY;
        } else if (i6 == 4) {
            variableLocalizationKey = VariableLocalizationKey.YEARLY;
        } else {
            if (i6 != 5) {
                throw new v();
            }
            variableLocalizationKey = null;
        }
        if (variableLocalizationKey != null) {
            return INSTANCE.getStringOrLogError(map, variableLocalizationKey);
        }
        return null;
    }

    private final String relativeDiscount(VariableProcessor.PackageContext packageContext, Map<VariableLocalizationKey, String> map) {
        Double discountRelativeToMostExpensivePerMonth = packageContext.getDiscountRelativeToMostExpensivePerMonth();
        if (discountRelativeToMostExpensivePerMonth != null) {
            int iC0 = L4.a.c0(discountRelativeToMostExpensivePerMonth.doubleValue() * ((double) PERCENT_SCALE));
            String stringOrLogError = INSTANCE.getStringOrLogError(map, VariableLocalizationKey.PERCENT);
            if (stringOrLogError != null) {
                return String.format(stringOrLogError, Arrays.copyOf(new Object[]{Integer.valueOf(iC0)}, 1));
            }
        }
        return null;
    }

    private final String replaceVariablesWithValues(String str, e eVar) {
        StringBuilder sb = new StringBuilder();
        i iVar = new i(m.c(regex, str));
        int i6 = 0;
        while (iVar.hasNext()) {
            k kVar = (k) ((S4.i) iVar.next());
            sb.append((CharSequence) str, i6, kVar.b().f5676a);
            List listD1 = S4.p.d1((String) ((j) kVar.a()).get(1), new String[]{"|"}, 6);
            ArrayList arrayList = new ArrayList(AbstractC3253s.G(listD1, 10));
            Iterator it = listD1.iterator();
            while (it.hasNext()) {
                arrayList.add(S4.p.o1((String) it.next()).toString());
            }
            sb.append((String) eVar.invoke((String) arrayList.get(0), arrayList.size() > 1 ? AbstractC3251q.a0(arrayList, 1) : y.f26065a));
            i6 = kVar.b().f5677b + 1;
        }
        sb.append((CharSequence) str, i6, str.length());
        String string = sb.toString();
        o.g(string, "toString(...)");
        return string;
    }

    private final String resolveCustomVariable(String str, Map<String, ? extends CustomVariableValue> map, Map<String, ? extends CustomVariableValue> map2, List<? extends Function> list, Locale locale) {
        CustomVariableValue customVariableValue = map.get(str);
        if (customVariableValue != null || (customVariableValue = map2.get(str)) != null) {
            String stringValue = customVariableValue.getStringValue();
            Iterator<T> it = list.iterator();
            while (it.hasNext()) {
                stringValue = INSTANCE.processFunction(stringValue, (Function) it.next(), locale);
            }
            return stringValue;
        }
        Logger.INSTANCE.w("Custom variable '" + str + "' was not provided and has no default value. Defaulting to empty string.");
        return "";
    }

    private final PricingPhase secondaryDiscountPhase(SubscriptionOption subscriptionOption, Package r32) {
        StoreProduct product;
        if (subscriptionOption == null) {
            subscriptionOption = (r32 == null || (product = r32.getProduct()) == null) ? null : product.getDefaultOption();
        }
        if (subscriptionOption == null || subscriptionOption.getFreePhase() == null) {
            return null;
        }
        return subscriptionOption.getIntroPhase();
    }

    private final void unsupportedFunctionWithoutFallback(Logger logger, String str) {
        logger.e("Paywall function '" + str + "' is not supported and no backwards compatible replacement found.");
    }

    private final void unsupportedVariableWithoutFallback(Logger logger, String str) {
        logger.e("Paywall variable '" + str + "' is not supported and no backwards compatible replacement found.");
    }

    private final void usingFallbackFunction(Logger logger, String str, String str2) {
        logger.w(Z0.o.p("Paywall function '", str, "' is not supported. Using backward compatible '", str2, "' instead."));
    }

    private final void usingFallbackVariable(Logger logger, String str, String str2) {
        logger.w(Z0.o.p("Paywall variable '", str, "' is not supported. Using backwards compatible '", str2, "' instead."));
    }

    public final String processVariables(String template, Map<VariableLocalizationKey, String> localizedVariableKeys, UiConfig.VariableConfig variableConfig, VariableDataProvider variableDataProvider, VariableProcessor.PackageContext packageContext, Package r22, SubscriptionOption subscriptionOption, Locale currencyLocale, Locale dateLocale, Date date, CountdownTime countdownTime, CountdownComponent.CountFrom countFrom, Map<String, ? extends CustomVariableValue> customVariables, Map<String, ? extends CustomVariableValue> defaultCustomVariables) {
        o.h(template, "template");
        o.h(localizedVariableKeys, "localizedVariableKeys");
        o.h(variableConfig, "variableConfig");
        o.h(currencyLocale, "currencyLocale");
        o.h(dateLocale, "dateLocale");
        o.h(date, "date");
        o.h(countFrom, "countFrom");
        o.h(customVariables, "customVariables");
        o.h(defaultCustomVariables, "defaultCustomVariables");
        return replaceVariablesWithValues(template, new AnonymousClass1(localizedVariableKeys, variableConfig, variableDataProvider, packageContext, r22, subscriptionOption, currencyLocale, dateLocale, date, countdownTime, countFrom, customVariables, defaultCustomVariables));
    }

    private final VariableLocalizationKey getPeriodUnitLocalizationKey(Period period) {
        int i6 = WhenMappings.$EnumSwitchMapping$3[period.getUnit().ordinal()];
        if (i6 == 1) {
            return VariableLocalizationKey.DAY;
        }
        if (i6 == 2) {
            return VariableLocalizationKey.WEEK;
        }
        if (i6 == 3) {
            return VariableLocalizationKey.MONTH;
        }
        if (i6 == 4) {
            return VariableLocalizationKey.YEAR;
        }
        if (i6 == 5) {
            return null;
        }
        throw new v();
    }

    private final VariableLocalizationKey getPeriodUnitAbbreviatedLocalizationKey(Period period) {
        int i6 = WhenMappings.$EnumSwitchMapping$3[period.getUnit().ordinal()];
        if (i6 == 1) {
            return VariableLocalizationKey.DAY_SHORT;
        }
        if (i6 == 2) {
            return VariableLocalizationKey.WEEK_SHORT;
        }
        if (i6 == 3) {
            return VariableLocalizationKey.MONTH_SHORT;
        }
        if (i6 == 4) {
            return VariableLocalizationKey.YEAR_SHORT;
        }
        if (i6 == 5) {
            return null;
        }
        throw new v();
    }
}
