package com.revenuecat.purchases.ui.revenuecatui.utils;

import E3.j;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.widget.Toast;
import androidx.compose.runtime.internal.StabilityInferred;
import androidx.recyclerview.widget.i0;
import com.revenuecat.purchases.ui.revenuecatui.R;
import com.revenuecat.purchases.ui.revenuecatui.extensions.UrisKt;
import com.revenuecat.purchases.ui.revenuecatui.helpers.Logger;
import kotlin.jvm.internal.o;
import x1.AbstractC3209a;

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

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

        static {
            int[] iArr = new int[URLOpeningMethod.values().length];
            try {
                iArr[URLOpeningMethod.IN_APP_BROWSER.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                iArr[URLOpeningMethod.EXTERNAL_BROWSER.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                iArr[URLOpeningMethod.DEEP_LINK.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
            $EnumSwitchMapping$0 = iArr;
        }
    }

    private URLOpener() {
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void openURL$handleException(Context context, Exception exc) {
        String string = exc instanceof ActivityNotFoundException ? context.getString(R.string.no_browser_cannot_open_link) : context.getString(R.string.cannot_open_link);
        o.g(string, "if (exception is Activit…_open_link)\n            }");
        Toast.makeText(context, string, 0).show();
        Logger.INSTANCE.e(string, exc);
    }

    public final void openURL$revenuecatui_defaultsBc8Release(Context context, String url, URLOpeningMethod method) {
        o.h(context, "context");
        o.h(url, "url");
        o.h(method, "method");
        int i6 = WhenMappings.$EnumSwitchMapping$0[method.ordinal()];
        if (i6 != 1) {
            if (i6 == 2 || i6 == 3) {
                UrisKt.openUriOrElse(context, url, new URLOpener$openURL$1(context));
                return;
            }
            return;
        }
        i0 i0VarE = new j().e();
        try {
            Uri uri = Uri.parse(url);
            Intent intent = (Intent) i0VarE.f13105b;
            intent.setData(uri);
            AbstractC3209a.startActivity(context, intent, (Bundle) i0VarE.f13106c);
        } catch (ActivityNotFoundException e6) {
            openURL$handleException(context, e6);
        } catch (IllegalArgumentException e7) {
            openURL$handleException(context, e7);
        }
    }
}
