package V2;

import com.google.android.gms.tasks.Task;
import com.google.firebase.firestore.DocumentReference;
import com.google.firebase.firestore.DocumentSnapshot;
import com.google.firebase.firestore.ktx.FirestoreKt;
import com.google.firebase.ktx.Firebase;
import java.util.ArrayList;
import java.util.List;
import m3.AbstractC2467b;
import w4.C3137A;
import x4.AbstractC3229F;
import x4.AbstractC3251q;

/* JADX INFO: loaded from: classes.dex */
public final class J3 extends C4.j implements J4.e {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public DocumentReference f7396a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public int f7397b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public /* synthetic */ Object f7398c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final /* synthetic */ String f7399d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final /* synthetic */ String f7400e;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public J3(String str, String str2, A4.d dVar) {
        super(2, dVar);
        this.f7399d = str;
        this.f7400e = str2;
    }

    @Override // C4.a
    public final A4.d create(Object obj, A4.d dVar) {
        J3 j32 = new J3(this.f7399d, this.f7400e, dVar);
        j32.f7398c = obj;
        return j32;
    }

    @Override // J4.e
    public final Object invoke(Object obj, Object obj2) {
        return ((J3) create((V4.C) obj, (A4.d) obj2)).invokeSuspend(C3137A.f25453a);
    }

    @Override // C4.a
    public final Object invokeSuspend(Object obj) {
        Object objD;
        DocumentReference documentReference;
        String str;
        List list;
        B4.a aVar = B4.a.f492a;
        int i6 = this.f7397b;
        try {
        } catch (Throwable th) {
            objD = AbstractC2467b.d(th);
        }
        if (i6 == 0) {
            AbstractC2467b.l(obj);
            String str2 = this.f7399d;
            String str3 = this.f7400e;
            if (S4.p.Q0(str2)) {
                throw new IllegalArgumentException("Not signed in");
            }
            String string = S4.p.o1(str3).toString();
            L3 l32 = L3.f7428a;
            DocumentReference documentReferenceDocument = FirestoreKt.getFirestore(Firebase.INSTANCE).collection("addOns").document(str2);
            kotlin.jvm.internal.o.g(documentReferenceDocument, "document(...)");
            Task<DocumentSnapshot> task = documentReferenceDocument.get();
            kotlin.jvm.internal.o.g(task, "get(...)");
            this.f7398c = string;
            this.f7396a = documentReferenceDocument;
            this.f7397b = 1;
            Object objH = W0.e.h(task, this);
            if (objH == aVar) {
                return aVar;
            }
            documentReference = documentReferenceDocument;
            obj = objH;
            str = string;
        } else {
            if (i6 != 1) {
                if (i6 != 2) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                list = (List) this.f7398c;
                AbstractC2467b.l(obj);
                L3.c(list, L3.a(list));
                objD = C3137A.f25453a;
                return new w4.n(objD);
            }
            documentReference = this.f7396a;
            str = (String) this.f7398c;
            AbstractC2467b.l(obj);
        }
        DocumentSnapshot documentSnapshot = (DocumentSnapshot) obj;
        L3 l33 = L3.f7428a;
        kotlin.jvm.internal.o.e(documentSnapshot);
        ArrayList arrayListE0 = AbstractC3251q.E0(L3.b(documentSnapshot));
        ArrayList arrayList = new ArrayList();
        for (Object obj2 : arrayListE0) {
            if (!kotlin.jvm.internal.o.c((String) obj2, str)) {
                arrayList.add(obj2);
            }
        }
        Task<Void> task2 = documentReference.set(AbstractC3229F.v(new w4.k("addOns", arrayList)));
        kotlin.jvm.internal.o.g(task2, "set(...)");
        this.f7398c = arrayList;
        this.f7396a = null;
        this.f7397b = 2;
        if (W0.e.h(task2, this) != aVar) {
            list = arrayList;
            L3.c(list, L3.a(list));
            objD = C3137A.f25453a;
            return new w4.n(objD);
        }
        return aVar;
    }
}
