package V2;

import android.content.Context;
import com.debridstream.tv.ProfileViewModel;
import java.util.ArrayList;
import java.util.List;
import m3.AbstractC2467b;
import w4.C3137A;

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

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

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final /* synthetic */ ProfileViewModel f7625c;

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

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

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final /* synthetic */ Context f7628f;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public X2(ProfileViewModel profileViewModel, Context context, A0 a02, String str, A4.d dVar) {
        super(2, dVar);
        this.f7625c = profileViewModel;
        this.f7626d = a02;
        this.f7627e = str;
        this.f7628f = context;
    }

    @Override // C4.a
    public final A4.d create(Object obj, A4.d dVar) {
        String str = this.f7627e;
        X2 x22 = new X2(this.f7625c, this.f7628f, this.f7626d, str, dVar);
        x22.f7624b = obj;
        return x22;
    }

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

    @Override // C4.a
    public final Object invokeSuspend(Object obj) {
        Object objD;
        Y4.c0 c0Var;
        Object value;
        T2 t22;
        String message;
        Y4.c0 c0Var2;
        Object value2;
        T2 t23;
        ArrayList arrayList;
        Y4.c0 c0Var3;
        Object value3;
        B4.a aVar = B4.a.f492a;
        int i6 = this.f7623a;
        C3137A c3137a = C3137A.f25453a;
        String str = this.f7627e;
        ProfileViewModel profileViewModel = this.f7625c;
        try {
            if (i6 == 0) {
                AbstractC2467b.l(obj);
                Y4.H h5 = profileViewModel._uiState;
                do {
                    c0Var3 = (Y4.c0) h5;
                    value3 = c0Var3.getValue();
                } while (!c0Var3.i(value3, T2.a((T2) value3, null, true, false, "Deleting profile…", null, false, false, null, false, 0L, null, 1909)));
                A0 a02 = this.f7626d;
                C0741y0 c0741y0 = C0741y0.f8184a;
                String str2 = a02.f7249a;
                this.f7623a = 1;
                if (C0741y0.c(str2, str, this) == aVar) {
                    return aVar;
                }
            } else {
                if (i6 != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                AbstractC2467b.l(obj);
            }
            objD = c3137a;
        } catch (Throwable th) {
            objD = AbstractC2467b.d(th);
        }
        if (!(objD instanceof w4.m)) {
            Context context = this.f7628f;
            context.getApplicationContext().getSharedPreferences("debridstream_profile_names", 0).edit().remove(str).apply();
            context.getApplicationContext().getSharedPreferences("debridstream_profile_pins", 0).edit().remove(str).apply();
            boolean zC = kotlin.jvm.internal.o.c(((T2) ((Y4.c0) profileViewModel._uiState).getValue()).f7547e, str);
            if (zC) {
                z3.c(context, null);
            }
            Y4.H h6 = profileViewModel._uiState;
            do {
                c0Var2 = (Y4.c0) h6;
                value2 = c0Var2.getValue();
                t23 = (T2) value2;
                List list = t23.f7543a;
                arrayList = new ArrayList();
                for (Object obj2 : list) {
                    if (!kotlin.jvm.internal.o.c(((R2) obj2).f7513a, str)) {
                        arrayList.add(obj2);
                    }
                }
            } while (!c0Var2.i(value2, T2.a(t23, arrayList, false, false, "", zC ? null : t23.f7547e, false, false, null, false, 0L, null, 1892)));
        }
        Throwable thA = w4.n.a(objD);
        if (thA != null) {
            Y4.H h7 = profileViewModel._uiState;
            do {
                c0Var = (Y4.c0) h7;
                value = c0Var.getValue();
                t22 = (T2) value;
                message = thA.getMessage();
                if (message == null) {
                    message = "Failed to delete profile";
                }
            } while (!c0Var.i(value, T2.a(t22, null, false, false, "", null, false, false, message, false, 0L, null, 1909)));
        }
        return c3137a;
    }
}
