package Q2;

import com.google.android.gms.common.internal.ImagesContract;
import com.revenuecat.purchases.common.Constants;
import com.revenuecat.purchases.common.diagnostics.DiagnosticsEntry;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import m3.AbstractC2467b;
import n2.AbstractC2612c;
import w4.C3137A;
import x4.AbstractC3229F;
import x4.AbstractC3251q;
import x4.AbstractC3253s;
import x4.y;

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

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

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public String f5948c;

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

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

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

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final /* synthetic */ N2.r f5952j;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public k(String str, N2.r rVar, A4.d dVar) {
        super(3, dVar);
        this.f5951f = str;
        this.f5952j = rVar;
    }

    @Override // J4.f
    public final Object invoke(Object obj, Object obj2, Object obj3) {
        ((Number) obj2).intValue();
        k kVar = new k(this.f5951f, this.f5952j, (A4.d) obj3);
        kVar.f5950e = (Map) obj;
        return kVar.invokeSuspend(C3137A.f25453a);
    }

    /* JADX WARN: Removed duplicated region for block: B:35:0x0094  */
    /* JADX WARN: Removed duplicated region for block: B:37:0x0097  */
    /* JADX WARN: Removed duplicated region for block: B:40:0x009e  */
    /* JADX WARN: Removed duplicated region for block: B:43:0x00b3 A[RETURN] */
    /* JADX WARN: Removed duplicated region for block: B:44:0x00b4  */
    @Override // C4.a
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object invokeSuspend(Object obj) {
        String str;
        String string;
        String string2;
        Object objE;
        String str2;
        String str3;
        String string3;
        String string4;
        B4.a aVar = B4.a.f492a;
        int i6 = this.f5949d;
        y yVar = y.f26065a;
        if (i6 == 0) {
            AbstractC2467b.l(obj);
            Map map = (Map) this.f5950e;
            Object obj2 = map.get("requestId");
            String string5 = (obj2 == null || (string4 = obj2.toString()) == null) ? null : S4.p.o1(string4).toString();
            str = string5 == null ? "" : string5;
            if (str.length() != 0) {
                Object obj3 = map.get("originalLink");
                string = obj3 != null ? obj3.toString() : null;
                if (string != null) {
                    S4.k kVarB = r.f5980a.b(string);
                    String str4 = kVarB != null ? (String) AbstractC3251q.h0(1, kVarB.a()) : null;
                    Object obj4 = map.get("fileName");
                    string2 = (obj4 != null || (string3 = obj4.toString()) == null) ? null : S4.p.o1(string3).toString();
                    if (string2 == null) {
                        string2 = "";
                    }
                    if (S4.p.Q0(string2)) {
                        string2 = str;
                    }
                    this.f5950e = str;
                    this.f5946a = string;
                    this.f5947b = str4;
                    this.f5948c = string2;
                    this.f5949d = 1;
                    objE = r.e(str, this.f5951f, this.f5952j, this);
                    if (objE != aVar) {
                        return aVar;
                    }
                    str2 = string2;
                    str3 = str4;
                } else {
                    S4.m mVar = r.f5980a;
                }
                Object obj42 = map.get("fileName");
                if (obj42 != null) {
                    if (string2 == null) {
                    }
                    if (S4.p.Q0(string2)) {
                    }
                    this.f5950e = str;
                    this.f5946a = string;
                    this.f5947b = str4;
                    this.f5948c = string2;
                    this.f5949d = 1;
                    objE = r.e(str, this.f5951f, this.f5952j, this);
                    if (objE != aVar) {
                    }
                }
            }
            return yVar;
        }
        if (i6 != 1) {
            throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
        }
        String str5 = this.f5948c;
        String str6 = this.f5947b;
        string = this.f5946a;
        str = (String) this.f5950e;
        AbstractC2467b.l(obj);
        objE = obj;
        str2 = str5;
        str3 = str6;
        List<Map> list = (List) objE;
        if (!list.isEmpty()) {
            ArrayList arrayList = new ArrayList();
            for (Object obj5 : list) {
                S4.m mVar2 = P2.c.f5650a;
                if (P2.c.f(r.a((Map) obj5))) {
                    arrayList.add(obj5);
                }
            }
            if (!arrayList.isEmpty()) {
                list = arrayList;
            }
            if (list.size() == 1) {
                Map map2 = (Map) AbstractC3251q.e0(list);
                String strA = r.a(map2);
                Object obj6 = map2.get("id");
                String string6 = obj6 != null ? obj6.toString() : null;
                String str7 = string6 != null ? string6 : "";
                String strB = str7.length() > 0 ? Z0.o.B(str, Constants.SUBS_ID_BASE_PLAN_ID_SEPARATOR, str7) : str;
                String strL = r.l(strA);
                String str8 = S4.p.Q0(strL) ? str2 : strL;
                Object obj7 = map2.get("size");
                Number number = obj7 instanceof Number ? (Number) obj7 : null;
                Long l = number != null ? new Long(number.longValue()) : null;
                Object obj8 = map2.get(ImagesContract.URL);
                return AbstractC2612c.q(new N2.g("offcloud", "file", strB, str8, l, obj8 != null ? obj8.toString() : null, str3, null, AbstractC3229F.w(new w4.k("originalLink", string), new w4.k("requestId", str)), 128));
            }
            String str9 = str3;
            ArrayList arrayList2 = new ArrayList(AbstractC3253s.G(list, 10));
            for (Map map3 : list) {
                Map mapB = r.b(str, map3, str9, string);
                Object obj9 = mapB.get("id");
                String string7 = obj9 != null ? obj9.toString() : null;
                String str10 = string7 == null ? "" : string7;
                Object obj10 = mapB.get(DiagnosticsEntry.NAME_KEY);
                String string8 = obj10 != null ? obj10.toString() : null;
                String str11 = string8 == null ? "" : string8;
                Object obj11 = mapB.get("size");
                Number number2 = obj11 instanceof Number ? (Number) obj11 : null;
                Long l6 = number2 != null ? new Long(number2.longValue()) : null;
                Object obj12 = mapB.get("download_link");
                String string9 = obj12 != null ? obj12.toString() : null;
                w4.k kVar = new w4.k("originalLink", string);
                w4.k kVar2 = new w4.k("requestId", str);
                Object obj13 = map3.get("id");
                arrayList2.add(new N2.g("offcloud", "file", str10, str11, l6, string9, str9, null, AbstractC3229F.w(kVar, kVar2, new w4.k("fileId", obj13 != null ? obj13.toString() : null)), 128));
            }
            return AbstractC2612c.q(new N2.g("offcloud", "folder", str, str2, null, null, str9, arrayList2, AbstractC3229F.w(new w4.k("originalLink", string), new w4.k("requestId", str)), 48));
        }
        return yVar;
    }
}
