package com.revenuecat.purchases.models;

import E3.v;
import L4.a;
import S4.j;
import com.revenuecat.purchases.models.Period;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import kotlin.jvm.internal.o;
import w4.k;

/* JADX INFO: loaded from: classes3.dex */
public final class PeriodKt {

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

        static {
            int[] iArr = new int[Period.Unit.values().length];
            try {
                iArr[Period.Unit.YEAR.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                iArr[Period.Unit.MONTH.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                iArr[Period.Unit.WEEK.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
            try {
                iArr[Period.Unit.DAY.ordinal()] = 4;
            } catch (NoSuchFieldError unused4) {
            }
            try {
                iArr[Period.Unit.UNKNOWN.ordinal()] = 5;
            } catch (NoSuchFieldError unused5) {
            }
            $EnumSwitchMapping$0 = iArr;
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final k toPeriod(String input) {
        double d6;
        double d7;
        double d8;
        Pattern patternCompile = Pattern.compile("^P(?!$)(\\d+(?:\\.\\d+)?Y)?(\\d+(?:\\.\\d+)?M)?(\\d+(?:\\.\\d+)?W)?(\\d+(?:\\.\\d+)?D)?$");
        o.g(patternCompile, "compile(...)");
        o.h(input, "input");
        Matcher matcher = patternCompile.matcher(input);
        o.g(matcher, "matcher(...)");
        S4.k kVar = !matcher.matches() ? null : new S4.k(matcher, input);
        if (kVar == null) {
            return new k(0, Period.Unit.UNKNOWN);
        }
        PeriodKt$toPeriod$1$toInt$1 periodKt$toPeriod$1$toInt$1 = PeriodKt$toPeriod$1$toInt$1.INSTANCE;
        String str = (String) ((j) kVar.a()).get(1);
        String str2 = (String) ((j) kVar.a()).get(2);
        String str3 = (String) ((j) kVar.a()).get(3);
        String str4 = (String) ((j) kVar.a()).get(4);
        int iIntValue = ((Number) periodKt$toPeriod$1$toInt$1.invoke((Object) str)).intValue();
        int iIntValue2 = ((Number) periodKt$toPeriod$1$toInt$1.invoke((Object) str2)).intValue();
        int iIntValue3 = ((Number) periodKt$toPeriod$1$toInt$1.invoke((Object) str3)).intValue();
        int iIntValue4 = ((Number) periodKt$toPeriod$1$toInt$1.invoke((Object) str4)).intValue();
        Period.Unit unit = iIntValue4 > 0 ? Period.Unit.DAY : iIntValue3 > 0 ? Period.Unit.WEEK : iIntValue2 > 0 ? Period.Unit.MONTH : iIntValue > 0 ? Period.Unit.YEAR : Period.Unit.UNKNOWN;
        int i6 = WhenMappings.$EnumSwitchMapping$0[unit.ordinal()];
        if (i6 != 1) {
            if (i6 == 2) {
                d7 = ((double) iIntValue) * 12.0d;
                d8 = iIntValue2;
            } else if (i6 == 3) {
                d6 = ((double) iIntValue3) + (((double) iIntValue2) * 4.345238095238096d) + (((double) iIntValue) * 52.142857142857146d);
            } else if (i6 == 4) {
                d7 = (((double) iIntValue3) * 7.0d) + (((double) iIntValue2) * 30.0d) + (((double) iIntValue) * 365.0d);
                d8 = iIntValue4;
            } else {
                if (i6 != 5) {
                    throw new v();
                }
                d6 = 0.0d;
            }
            d6 = d7 + d8;
        } else {
            d6 = iIntValue;
        }
        return new k(Integer.valueOf(a.c0(d6)), unit);
    }
}
