package com.revenuecat.purchases.ui.revenuecatui;

import A4.d;
import B4.a;
import C4.e;
import C4.j;
import android.app.Activity;
import android.content.Context;
import com.revenuecat.purchases.Package;
import com.revenuecat.purchases.ui.revenuecatui.components.PaywallAction;
import com.revenuecat.purchases.ui.revenuecatui.data.PaywallViewModel;
import com.revenuecat.purchases.ui.revenuecatui.helpers.Logger;
import com.revenuecat.purchases.ui.revenuecatui.helpers.ResolvedOffer;
import m3.AbstractC2467b;
import w4.C3137A;

/* JADX INFO: loaded from: classes3.dex */
@e(c = "com.revenuecat.purchases.ui.revenuecatui.InternalPaywallKt$rememberPaywallActionHandler$1$1", f = "InternalPaywall.kt", l = {276, 281}, m = "invokeSuspend")
public final class InternalPaywallKt$rememberPaywallActionHandler$1$1 extends j implements J4.e {
    final /* synthetic */ Activity $activity;
    final /* synthetic */ Context $context;
    final /* synthetic */ PaywallViewModel $viewModel;
    /* synthetic */ Object L$0;
    int label;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public InternalPaywallKt$rememberPaywallActionHandler$1$1(PaywallViewModel paywallViewModel, Activity activity, Context context, d dVar) {
        super(2, dVar);
        this.$viewModel = paywallViewModel;
        this.$activity = activity;
        this.$context = context;
    }

    @Override // C4.a
    public final d create(Object obj, d dVar) {
        InternalPaywallKt$rememberPaywallActionHandler$1$1 internalPaywallKt$rememberPaywallActionHandler$1$1 = new InternalPaywallKt$rememberPaywallActionHandler$1$1(this.$viewModel, this.$activity, this.$context, dVar);
        internalPaywallKt$rememberPaywallActionHandler$1$1.L$0 = obj;
        return internalPaywallKt$rememberPaywallActionHandler$1$1;
    }

    @Override // J4.e
    public final Object invoke(PaywallAction.External external, d dVar) {
        return ((InternalPaywallKt$rememberPaywallActionHandler$1$1) create(external, dVar)).invokeSuspend(C3137A.f25453a);
    }

    /* JADX WARN: Code restructure failed: missing block: B:13:0x002d, code lost:
    
        if (r6.handleRestorePurchases(r5) == r0) goto L22;
     */
    /* JADX WARN: Code restructure failed: missing block: B:21:0x0053, code lost:
    
        if (r3.handlePackagePurchase(r1, r4, r6, r5) == r0) goto L22;
     */
    /* JADX WARN: Code restructure failed: missing block: B:22:0x0055, code lost:
    
        return r0;
     */
    @Override // C4.a
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object invokeSuspend(Object obj) {
        a aVar = a.f492a;
        int i6 = this.label;
        if (i6 == 0) {
            AbstractC2467b.l(obj);
            PaywallAction.External external = (PaywallAction.External) this.L$0;
            if (external instanceof PaywallAction.External.RestorePurchases) {
                PaywallViewModel paywallViewModel = this.$viewModel;
                this.label = 1;
            } else if (external instanceof PaywallAction.External.PurchasePackage) {
                Activity activity = this.$activity;
                if (activity == null) {
                    Logger.INSTANCE.e("Activity is null, not initiating package purchase");
                } else {
                    PaywallViewModel paywallViewModel2 = this.$viewModel;
                    PaywallAction.External.PurchasePackage purchasePackage = (PaywallAction.External.PurchasePackage) external;
                    Package rcPackage = purchasePackage.getRcPackage();
                    ResolvedOffer resolvedOffer = purchasePackage.getResolvedOffer();
                    this.label = 2;
                }
            } else if (external instanceof PaywallAction.External.LaunchWebCheckout) {
                PaywallAction.External.LaunchWebCheckout launchWebCheckout = (PaywallAction.External.LaunchWebCheckout) external;
                String webCheckoutUrl = this.$viewModel.getWebCheckoutUrl(launchWebCheckout);
                if (webCheckoutUrl == null) {
                    Logger.INSTANCE.e("Web checkout URL cannot be found, not launching web checkout.");
                } else {
                    this.$viewModel.invalidateCustomerInfoCache();
                    InternalPaywallKt.handleUrlDestination(this.$context, webCheckoutUrl, launchWebCheckout.getOpenMethod());
                    if (launchWebCheckout.getAutoDismiss()) {
                        Logger.INSTANCE.d("Auto-dismissing paywall after launching web checkout.");
                        PaywallViewModel.DefaultImpls.closePaywall$default(this.$viewModel, null, 1, null);
                    }
                }
            } else if (external instanceof PaywallAction.External.NavigateBack) {
                PaywallViewModel.DefaultImpls.closePaywall$default(this.$viewModel, null, 1, null);
            } else if (external instanceof PaywallAction.External.NavigateTo) {
                PaywallAction.External.NavigateTo.Destination destination = ((PaywallAction.External.NavigateTo) external).getDestination();
                if (destination instanceof PaywallAction.External.NavigateTo.Destination.CustomerCenter) {
                    Logger.INSTANCE.w("Customer Center is not yet implemented on Android.");
                } else if (destination instanceof PaywallAction.External.NavigateTo.Destination.Url) {
                    PaywallAction.External.NavigateTo.Destination.Url url = (PaywallAction.External.NavigateTo.Destination.Url) destination;
                    InternalPaywallKt.handleUrlDestination(this.$context, url.getUrl(), url.getMethod());
                }
            }
        } else {
            if (i6 != 1 && i6 != 2) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            AbstractC2467b.l(obj);
        }
        return C3137A.f25453a;
    }
}
