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

import E3.v;
import androidx.compose.runtime.internal.StabilityInferred;
import com.revenuecat.purchases.Package;
import com.revenuecat.purchases.PackageType;
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.ui.revenuecatui.R;
import com.revenuecat.purchases.ui.revenuecatui.extensions.PackageExtensionsKt;
import com.revenuecat.purchases.ui.revenuecatui.extensions.PeriodExtensionsKt;
import com.revenuecat.purchases.ui.revenuecatui.extensions.PriceExtensionsKt;
import com.revenuecat.purchases.ui.revenuecatui.helpers.ResourceProvider;
import java.util.Locale;
import kotlin.jvm.internal.h;
import kotlin.jvm.internal.o;

/* JADX INFO: loaded from: classes3.dex */
@StabilityInferred(parameters = 0)
public final class VariableDataProvider {
    public static final int $stable = 8;
    private final boolean preview;
    private final ResourceProvider resourceProvider;

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

        static {
            int[] iArr = new int[PackageType.values().length];
            try {
                iArr[PackageType.LIFETIME.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                iArr[PackageType.ANNUAL.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                iArr[PackageType.SIX_MONTH.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
            try {
                iArr[PackageType.THREE_MONTH.ordinal()] = 4;
            } catch (NoSuchFieldError unused4) {
            }
            try {
                iArr[PackageType.TWO_MONTH.ordinal()] = 5;
            } catch (NoSuchFieldError unused5) {
            }
            try {
                iArr[PackageType.MONTHLY.ordinal()] = 6;
            } catch (NoSuchFieldError unused6) {
            }
            try {
                iArr[PackageType.WEEKLY.ordinal()] = 7;
            } catch (NoSuchFieldError unused7) {
            }
            try {
                iArr[PackageType.UNKNOWN.ordinal()] = 8;
            } catch (NoSuchFieldError unused8) {
            }
            try {
                iArr[PackageType.CUSTOM.ordinal()] = 9;
            } catch (NoSuchFieldError unused9) {
            }
            $EnumSwitchMapping$0 = iArr;
        }
    }

    public VariableDataProvider(ResourceProvider resourceProvider, boolean z6) {
        o.h(resourceProvider, "resourceProvider");
        this.resourceProvider = resourceProvider;
        this.preview = z6;
    }

    private final PricingPhase getFirstIntroOfferToApply(Package r22) {
        PricingPhase freePhase;
        SubscriptionOption defaultOption = r22.getProduct().getDefaultOption();
        if (defaultOption != null && (freePhase = defaultOption.getFreePhase()) != null) {
            return freePhase;
        }
        if (defaultOption != null) {
            return defaultOption.getIntroPhase();
        }
        return null;
    }

    private final PricingPhase getSecondIntroOfferToApply(Package r32) {
        SubscriptionOption defaultOption = r32.getProduct().getDefaultOption();
        if ((defaultOption != null ? defaultOption.getFreePhase() : null) != null) {
            return defaultOption.getIntroPhase();
        }
        return null;
    }

    public final String firstIntroductoryOfferDuration(Package rcPackage, Locale locale) {
        Period billingPeriod;
        o.h(rcPackage, "rcPackage");
        o.h(locale, "locale");
        PricingPhase firstIntroOfferToApply = getFirstIntroOfferToApply(rcPackage);
        if (firstIntroOfferToApply == null || (billingPeriod = firstIntroOfferToApply.getBillingPeriod()) == null) {
            return null;
        }
        return PeriodExtensionsKt.localizedPeriod$default(billingPeriod, locale, null, 2, null);
    }

    public final String getApplicationName() {
        return !this.preview ? this.resourceProvider.getApplicationName() : "Application Name";
    }

    public final String localizedFirstIntroductoryOfferPrice(Package rcPackage, Locale locale, boolean z6) {
        Price price;
        o.h(rcPackage, "rcPackage");
        o.h(locale, "locale");
        PricingPhase firstIntroOfferToApply = getFirstIntroOfferToApply(rcPackage);
        if (firstIntroOfferToApply == null || (price = firstIntroOfferToApply.getPrice()) == null) {
            return null;
        }
        return (z6 && VariableDataProviderKt.endsIn00Cents(price)) ? VariableDataProviderKt.getTruncatedFormatted(price, locale) : price.getFormatted();
    }

    public final String localizedPrice(Package rcPackage, Locale locale, boolean z6) {
        o.h(rcPackage, "rcPackage");
        o.h(locale, "locale");
        return PriceExtensionsKt.localized(rcPackage.getProduct().getPrice(), locale, z6);
    }

    public final String localizedPriceAndPerMonth(Package rcPackage, Locale locale, boolean z6) {
        o.h(rcPackage, "rcPackage");
        o.h(locale, "locale");
        if (!PackageExtensionsKt.isSubscription(rcPackage) || PackageExtensionsKt.isMonthly(rcPackage)) {
            return localizedPricePerPeriod(rcPackage, locale, z6);
        }
        String strLocalizedAbbreviatedPeriod = PeriodExtensionsKt.localizedAbbreviatedPeriod(new Period(1, Period.Unit.MONTH, "P1M"), locale);
        return localizedPricePerPeriod(rcPackage, locale, z6) + " (" + localizedPricePerMonth(rcPackage, locale, z6) + '/' + strLocalizedAbbreviatedPeriod + ')';
    }

    public final String localizedPriceAndPerMonthFull(Package rcPackage, Locale locale, boolean z6) {
        o.h(rcPackage, "rcPackage");
        o.h(locale, "locale");
        if (!PackageExtensionsKt.isSubscription(rcPackage) || PackageExtensionsKt.isMonthly(rcPackage)) {
            return localizedPricePerPeriodFull(rcPackage, locale, z6);
        }
        String strLocalizedUnitPeriod = PeriodExtensionsKt.localizedUnitPeriod(new Period(1, Period.Unit.MONTH, "P1M"), locale);
        return localizedPricePerPeriodFull(rcPackage, locale, z6) + " (" + localizedPricePerMonth(rcPackage, locale, z6) + '/' + strLocalizedUnitPeriod + ')';
    }

    public final String localizedPricePerDay(Package rcPackage, Locale locale, boolean z6) {
        o.h(rcPackage, "rcPackage");
        o.h(locale, "locale");
        Price pricePricePerDay = rcPackage.getProduct().pricePerDay(locale);
        if (pricePricePerDay == null) {
            return null;
        }
        return (z6 && VariableDataProviderKt.endsIn00Cents(pricePricePerDay)) ? VariableDataProviderKt.getTruncatedFormatted(pricePricePerDay, locale) : pricePricePerDay.getFormatted();
    }

    public final String localizedPricePerMonth(Package rcPackage, Locale locale, boolean z6) {
        o.h(rcPackage, "rcPackage");
        o.h(locale, "locale");
        Price pricePricePerMonth = rcPackage.getProduct().pricePerMonth(locale);
        if (pricePricePerMonth == null) {
            return null;
        }
        return (z6 && VariableDataProviderKt.endsIn00Cents(pricePricePerMonth)) ? VariableDataProviderKt.getTruncatedFormatted(pricePricePerMonth, locale) : pricePricePerMonth.getFormatted();
    }

    public final String localizedPricePerPeriod(Package rcPackage, Locale locale, boolean z6) {
        String strLocalizedPerPeriod;
        o.h(rcPackage, "rcPackage");
        o.h(locale, "locale");
        StoreProduct product = rcPackage.getProduct();
        Period period = product.getPeriod();
        return (period == null || (strLocalizedPerPeriod = PriceExtensionsKt.localizedPerPeriod(product.getPrice(), period, locale, z6)) == null) ? PriceExtensionsKt.localized(product.getPrice(), locale, z6) : strLocalizedPerPeriod;
    }

    public final String localizedPricePerPeriodFull(Package rcPackage, Locale locale, boolean z6) {
        o.h(rcPackage, "rcPackage");
        o.h(locale, "locale");
        StoreProduct product = rcPackage.getProduct();
        String strLocalized = PriceExtensionsKt.localized(product.getPrice(), locale, z6);
        Period period = product.getPeriod();
        if (period != null) {
            String str = strLocalized + '/' + PeriodExtensionsKt.localizedUnitPeriod(period, locale);
            if (str != null) {
                return str;
            }
        }
        return strLocalized;
    }

    public final String localizedPricePerWeek(Package rcPackage, Locale locale, boolean z6) {
        o.h(rcPackage, "rcPackage");
        o.h(locale, "locale");
        Price pricePricePerWeek = rcPackage.getProduct().pricePerWeek(locale);
        if (pricePricePerWeek == null) {
            return null;
        }
        return (z6 && VariableDataProviderKt.endsIn00Cents(pricePricePerWeek)) ? VariableDataProviderKt.getTruncatedFormatted(pricePricePerWeek, locale) : pricePricePerWeek.getFormatted();
    }

    public final String localizedPricePerYear(Package rcPackage, Locale locale, boolean z6) {
        o.h(rcPackage, "rcPackage");
        o.h(locale, "locale");
        Price pricePricePerYear = rcPackage.getProduct().pricePerYear(locale);
        if (pricePricePerYear == null) {
            return null;
        }
        return (z6 && VariableDataProviderKt.endsIn00Cents(pricePricePerYear)) ? VariableDataProviderKt.getTruncatedFormatted(pricePricePerYear, locale) : pricePricePerYear.getFormatted();
    }

    public final String localizedRelativeDiscount(Double d6) {
        return VariableDataProviderKt.localizedDiscount(this.resourceProvider, d6);
    }

    public final String localizedSecondIntroductoryOfferPrice(Package rcPackage, Locale locale, boolean z6) {
        Price price;
        o.h(rcPackage, "rcPackage");
        o.h(locale, "locale");
        PricingPhase secondIntroOfferToApply = getSecondIntroOfferToApply(rcPackage);
        if (secondIntroOfferToApply == null || (price = secondIntroOfferToApply.getPrice()) == null) {
            return null;
        }
        return (z6 && VariableDataProviderKt.endsIn00Cents(price)) ? VariableDataProviderKt.getTruncatedFormatted(price, locale) : price.getFormatted();
    }

    public final String periodLength(Package rcPackage, Locale locale) {
        o.h(rcPackage, "rcPackage");
        o.h(locale, "locale");
        Period period = rcPackage.getProduct().getPeriod();
        if (period != null) {
            return PeriodExtensionsKt.localizedUnitPeriod(period, locale);
        }
        return null;
    }

    public final String periodName(Package rcPackage) {
        Integer numValueOf;
        o.h(rcPackage, "rcPackage");
        if (rcPackage.getPackageType() == PackageType.CUSTOM || rcPackage.getPackageType() == PackageType.UNKNOWN) {
            return rcPackage.getIdentifier();
        }
        switch (WhenMappings.$EnumSwitchMapping$0[rcPackage.getPackageType().ordinal()]) {
            case 1:
                numValueOf = Integer.valueOf(R.string.lifetime);
                break;
            case 2:
                numValueOf = Integer.valueOf(R.string.annual);
                break;
            case 3:
                numValueOf = Integer.valueOf(R.string.semester);
                break;
            case 4:
                numValueOf = Integer.valueOf(R.string.quarter);
                break;
            case 5:
                numValueOf = Integer.valueOf(R.string.bimonthly);
                break;
            case 6:
                numValueOf = Integer.valueOf(R.string.monthly);
                break;
            case 7:
                numValueOf = Integer.valueOf(R.string.weekly);
                break;
            case 8:
            case 9:
                numValueOf = null;
                break;
            default:
                throw new v();
        }
        if (numValueOf == null) {
            return null;
        }
        return this.resourceProvider.getString(numValueOf.intValue(), new Object[0]);
    }

    public final String periodNameAbbreviation(Package rcPackage, Locale locale) {
        o.h(rcPackage, "rcPackage");
        o.h(locale, "locale");
        Period period = rcPackage.getProduct().getPeriod();
        if (period != null) {
            return PeriodExtensionsKt.localizedAbbreviatedPeriod(period, locale);
        }
        return null;
    }

    public final String productName(Package rcPackage) {
        o.h(rcPackage, "rcPackage");
        return rcPackage.getProduct().getName();
    }

    public final String secondIntroductoryOfferDuration(Package rcPackage, Locale locale) {
        Period billingPeriod;
        o.h(rcPackage, "rcPackage");
        o.h(locale, "locale");
        PricingPhase secondIntroOfferToApply = getSecondIntroOfferToApply(rcPackage);
        if (secondIntroOfferToApply == null || (billingPeriod = secondIntroOfferToApply.getBillingPeriod()) == null) {
            return null;
        }
        return PeriodExtensionsKt.localizedPeriod$default(billingPeriod, locale, null, 2, null);
    }

    public final String subscriptionDuration(Package rcPackage, Locale locale) {
        String strLocalizedPeriod$default;
        o.h(rcPackage, "rcPackage");
        o.h(locale, "locale");
        Period period = rcPackage.getProduct().getPeriod();
        return (period == null || (strLocalizedPeriod$default = PeriodExtensionsKt.localizedPeriod$default(period, locale, null, 2, null)) == null) ? periodName(rcPackage) : strLocalizedPeriod$default;
    }

    public final String subscriptionDurationInMonths(Package rcPackage, Locale locale) {
        Period periodNormalizedMonths;
        String strLocalizedPeriod$default;
        o.h(rcPackage, "rcPackage");
        o.h(locale, "locale");
        Period period = rcPackage.getProduct().getPeriod();
        return (period == null || (periodNormalizedMonths = VariableDataProviderKt.normalizedMonths(period)) == null || (strLocalizedPeriod$default = PeriodExtensionsKt.localizedPeriod$default(periodNormalizedMonths, locale, null, 2, null)) == null) ? periodName(rcPackage) : strLocalizedPeriod$default;
    }

    public /* synthetic */ VariableDataProvider(ResourceProvider resourceProvider, boolean z6, int i6, h hVar) {
        this(resourceProvider, (i6 & 2) != 0 ? false : z6);
    }
}
