package com.vinfast.companion.core.utils.imageUtis;

/* JADX INFO: compiled from: r8-map-id-ae6aab8d9a1033945587ffdd1bc6222159522c1d66e66a2c4cecb065134dd0a6 */
/* JADX INFO: loaded from: E:\ios\vf_dex\classes15.dex */
@kotlin.Metadata(d1 = {"\u0000\n\n\u0000\n\u0002\u0018\u0002\n\u0002\u0018\u0002\u0010\u0000\u001a\u00020\u0001*\u00020\u0002H\n"}, d2 = {"<anonymous>", "Lcom/vinfast/companion/core/utils/imageUtis/ImagePicker$Result;", "Lkotlinx/coroutines/CoroutineScope;"}, k = 3, mv = {2, 2, 0}, xi = 48)
@kotlin.coroutines.jvm.internal.DebugMetadata(c = "com.vinfast.companion.core.utils.imageUtis.ImagePicker$Companion$open$2", f = "ImagePicker.kt", l = {81}, m = "invokeSuspend", v = 1)
final class ImagePicker$Companion$open$2 extends kotlin.coroutines.jvm.internal.SuspendLambda implements kotlin.jvm.functions.Function2<kotlinx.coroutines.CoroutineScope, kotlin.coroutines.Continuation<? super com.vinfast.companion.core.utils.imageUtis.ImagePicker.Result>, java.lang.Object> {
    java.lang.Object n;
    java.lang.Object o;
    int p;
    final /* synthetic */ com.vinfast.companion.core.utils.imageUtis.ImagePicker.Type q;
    final /* synthetic */ boolean r;
    final /* synthetic */ androidx.fragment.app.FragmentManager s;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    ImagePicker$Companion$open$2(com.vinfast.companion.core.utils.imageUtis.ImagePicker.Type type, boolean z, androidx.fragment.app.FragmentManager fragmentManager, kotlin.coroutines.Continuation continuation) {
        super(2, continuation);
        this.q = type;
        this.r = z;
        this.s = fragmentManager;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final com.vinfast.companion.core.utils.imageUtis.ImagePicker j(androidx.fragment.app.FragmentManager fragmentManager) {
        com.vinfast.companion.core.utils.imageUtis.ImagePicker imagePicker = new com.vinfast.companion.core.utils.imageUtis.ImagePicker();
        fragmentManager.s().e(imagePicker, "ImagePicker").l();
        return imagePicker;
    }

    public final kotlin.coroutines.Continuation create(java.lang.Object obj, kotlin.coroutines.Continuation continuation) {
        return new com.vinfast.companion.core.utils.imageUtis.ImagePicker$Companion$open$2(this.q, this.r, this.s, continuation);
    }

    /* JADX INFO: Thrown type has an unknown type hierarchy: kotlin.NoWhenBranchMatchedException */
    public final java.lang.Object invokeSuspend(java.lang.Object obj) throws kotlin.NoWhenBranchMatchedException {
        com.vinfast.companion.core.utils.imageUtis.ImagePicker imagePicker;
        java.lang.Object objG = kotlin.coroutines.intrinsics.IntrinsicsKt.g();
        int i = this.p;
        if (i != 0) {
            if (i != 1) {
                throw new java.lang.IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            kotlin.ResultKt.b(obj);
            return obj;
        }
        kotlin.ResultKt.b(obj);
        com.vinfast.companion.core.utils.imageUtis.ImagePicker.Type type = this.q;
        kotlinx.coroutines.Deferred deferred = null;
        if (type instanceof com.vinfast.companion.core.utils.imageUtis.ImagePicker.Type.Gallery) {
            com.vinfast.companion.core.utils.imageUtis.ImagePicker.Companion companion = com.vinfast.companion.core.utils.imageUtis.ImagePicker.INSTANCE;
            com.vinfast.companion.core.utils.imageUtis.ImagePicker.GalleryType galleryType = ((com.vinfast.companion.core.utils.imageUtis.ImagePicker.Type.Gallery) type).getGalleryType();
            com.vinfast.companion.core.utils.imageUtis.ImagePicker.GalleryType.Multiple multiple = galleryType instanceof com.vinfast.companion.core.utils.imageUtis.ImagePicker.GalleryType.Multiple ? (com.vinfast.companion.core.utils.imageUtis.ImagePicker.GalleryType.Multiple) galleryType : null;
            com.vinfast.companion.core.utils.imageUtis.ImagePicker.i = multiple != null ? multiple.getMaxItems() : 5;
        }
        final androidx.fragment.app.FragmentManager fragmentManager = this.s;
        kotlin.jvm.functions.Function0 function0 = new kotlin.jvm.functions.Function0() { // from class: com.vinfast.companion.core.utils.imageUtis.i
            public final java.lang.Object invoke() {
                return com.vinfast.companion.core.utils.imageUtis.ImagePicker$Companion$open$2.j(fragmentManager);
            }
        };
        if (this.r) {
            androidx.fragment.app.Fragment fragmentR0 = this.s.r0("ImagePicker");
            if (fragmentR0 != null) {
                this.s.s().t(fragmentR0).l();
            }
            imagePicker = (com.vinfast.companion.core.utils.imageUtis.ImagePicker) function0.invoke();
        } else {
            androidx.fragment.app.Fragment fragmentR1 = this.s.r0("ImagePicker");
            imagePicker = fragmentR1 instanceof com.vinfast.companion.core.utils.imageUtis.ImagePicker ? (com.vinfast.companion.core.utils.imageUtis.ImagePicker) fragmentR1 : null;
            if (imagePicker == null) {
                imagePicker = (com.vinfast.companion.core.utils.imageUtis.ImagePicker) function0.invoke();
            }
        }
        imagePicker.completableDeferred = kotlinx.coroutines.CompletableDeferredKt.c((kotlinx.coroutines.Job) null, 1, (java.lang.Object) null);
        com.vinfast.companion.core.utils.imageUtis.ImagePicker.Type type2 = this.q;
        if (kotlin.jvm.internal.Intrinsics.g(type2, com.vinfast.companion.core.utils.imageUtis.ImagePicker.Type.Camera.a)) {
            imagePicker.B0();
        } else {
            if (!(type2 instanceof com.vinfast.companion.core.utils.imageUtis.ImagePicker.Type.Gallery)) {
                throw new kotlin.NoWhenBranchMatchedException();
            }
            if (((com.vinfast.companion.core.utils.imageUtis.ImagePicker.Type.Gallery) this.q).getGalleryType() instanceof com.vinfast.companion.core.utils.imageUtis.ImagePicker.GalleryType.Multiple) {
                imagePicker.t0();
            } else {
                imagePicker.r0();
            }
        }
        kotlinx.coroutines.Deferred deferred2 = imagePicker.completableDeferred;
        if (deferred2 == null) {
            kotlin.jvm.internal.Intrinsics.C("completableDeferred");
        } else {
            deferred = deferred2;
        }
        this.n = kotlin.coroutines.jvm.internal.SpillingKt.a(function0);
        this.o = kotlin.coroutines.jvm.internal.SpillingKt.a(imagePicker);
        this.p = 1;
        java.lang.Object objD = deferred.d(this);
        return objD == objG ? objG : objD;
    }

    public final java.lang.Object invoke(kotlinx.coroutines.CoroutineScope coroutineScope, kotlin.coroutines.Continuation continuation) {
        return create(coroutineScope, continuation).invokeSuspend(kotlin.Unit.a);
    }
}
