package e5;

import A6.n;
import E6.j;
import O6.p;
import Z6.AbstractC0385z;
import Z6.InterfaceC0382w;
import a5.C0405d;
import android.content.SharedPreferences;
import com.google.android.gms.internal.measurement.C1;
import com.martsnew.data.model.response.LoginResponse;
import com.martsnew.data.model.response.RefreshTokenResponse;
import com.martsnew.data.model.response.TokenDataResponse;
import g6.o;
import k7.C;
import k7.y;

/* JADX INFO: renamed from: e5.g, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C0887g extends G6.i implements p {

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public i7.d f12484u;

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

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    public final /* synthetic */ i7.d f12486w;

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    public final /* synthetic */ C f12487x;

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    public final /* synthetic */ K2.e f12488y;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public C0887g(i7.d dVar, E6.d dVar2, C c3, K2.e eVar) {
        super(2, dVar2);
        this.f12486w = dVar;
        this.f12487x = c3;
        this.f12488y = eVar;
    }

    @Override // O6.p
    public final Object k(Object obj, Object obj2) {
        return ((C0887g) m((E6.d) obj2, (InterfaceC0382w) obj)).p(n.f457a);
    }

    @Override // G6.a
    public final E6.d m(E6.d dVar, Object obj) {
        return new C0887g(this.f12486w, dVar, this.f12487x, this.f12488y);
    }

    /* JADX WARN: Removed duplicated region for block: B:16:0x0039  */
    @Override // G6.a
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object p(Object obj) throws Throwable {
        i7.d dVar;
        y yVarQ;
        C c3 = this.f12487x;
        K2.e eVar = this.f12488y;
        F6.a aVar = F6.a.f2580q;
        int i = this.f12485v;
        if (i == 0) {
            C1.N(obj);
            i7.d dVar2 = this.f12486w;
            this.f12484u = dVar2;
            this.f12485v = 1;
            if (dVar2.b(this) == aVar) {
                return aVar;
            }
            dVar = dVar2;
        } else {
            if (i != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            dVar = this.f12484u;
            C1.N(obj);
        }
        try {
            int i5 = c3.f14013t;
            y yVar = c3.f14010q;
            if (i5 != 401) {
                yVarQ = null;
            } else {
                eVar.f3555t = C1.w((C0405d) eVar.f3552q);
                o oVar = o.f12958a;
                String strA = oVar.A();
                LoginResponse loginResponse = (LoginResponse) eVar.f3555t;
                String str = strA + " " + (loginResponse != null ? loginResponse.f10852b.f10967a.f10971a : null);
                if (yVar.f14204c.a("Authorization") != null) {
                    if (P6.g.a(yVar.f14204c.a("Authorization"), str)) {
                        LoginResponse loginResponse2 = (LoginResponse) eVar.f3555t;
                        X4.c cVar = (X4.c) AbstractC0385z.v(j.f2226q, new C0888h(loginResponse2 != null ? loginResponse2.f10852b.f10968b.f10971a : null, eVar, null));
                        if (!(cVar instanceof X4.b)) {
                            if (!(cVar instanceof X4.a)) {
                                throw new A6.b();
                            }
                            if (!(((X4.a) cVar).f7227a instanceof W4.b)) {
                                throw new Exception("");
                            }
                            C0405d c0405d = (C0405d) eVar.f3552q;
                            String strK = oVar.K();
                            P6.g.e(strK, "key");
                            SharedPreferences.Editor editorEdit = c0405d.f7619a.edit();
                            editorEdit.remove(strK);
                            editorEdit.apply();
                            throw new W4.b();
                        }
                        RefreshTokenResponse refreshTokenResponse = (RefreshTokenResponse) ((X4.b) cVar).f7228a;
                        TokenDataResponse tokenDataResponse = refreshTokenResponse.f10912a;
                        K2.e.l(eVar, tokenDataResponse.f10967a.f10971a, tokenDataResponse.f10968b.f10971a);
                        K2.e eVarB = yVar.b();
                        eVarB.K("Authorization");
                        eVarB.p("Authorization", oVar.A() + " " + refreshTokenResponse.f10912a.f10967a.f10971a);
                        yVarQ = eVarB.q();
                    } else {
                        LoginResponse loginResponse3 = (LoginResponse) eVar.f3555t;
                        if (loginResponse3 != null) {
                            TokenDataResponse tokenDataResponse2 = loginResponse3.f10852b;
                            K2.e.l(eVar, tokenDataResponse2.f10967a.f10971a, tokenDataResponse2.f10968b.f10971a);
                        }
                        K2.e eVarB2 = yVar.b();
                        eVarB2.K("Authorization");
                        eVarB2.p("Authorization", str);
                        yVarQ = eVarB2.q();
                    }
                }
            }
            dVar.a(null);
            return yVarQ;
        } catch (Throwable th) {
            dVar.a(null);
            throw th;
        }
    }
}
