package cc;

import ca.canadapost.core.data.model.DeliveryPreference;
import ca.canadapost.core.data.model.Event;
import ca.canadapost.core.data.model.PackageDeliveryOptionInstructionResponse;
import ca.canadapost.core.data.model.ResultWrapper;
import ca.canadapost.core.data.profile.model.AMSPrerequisitesResponse;
import d9.f;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
import l8.h;

/* loaded from: classes4.dex */
public final class y3 extends r8.a {
    private final androidx.lifecycle.f0 A;
    private final androidx.lifecycle.a0 B;
    private ArrayList C;
    private final androidx.lifecycle.f0 D;
    private final androidx.lifecycle.f0 E;
    private final androidx.lifecycle.a0 F;

    /* renamed from: n, reason: collision with root package name */
    private final d9.f f11897n;

    /* renamed from: o, reason: collision with root package name */
    private final t7.c f11898o;

    /* renamed from: p, reason: collision with root package name */
    private final ka.b f11899p;

    /* renamed from: q, reason: collision with root package name */
    private final y8.c f11900q;

    /* renamed from: r, reason: collision with root package name */
    private final ca.b f11901r;

    /* renamed from: s, reason: collision with root package name */
    private final ja.d f11902s;

    /* renamed from: t, reason: collision with root package name */
    private final androidx.lifecycle.f0 f11903t;

    /* renamed from: u, reason: collision with root package name */
    private final androidx.lifecycle.a0 f11904u;

    /* renamed from: v, reason: collision with root package name */
    private final androidx.lifecycle.f0 f11905v;

    /* renamed from: w, reason: collision with root package name */
    private final androidx.lifecycle.f0 f11906w;

    /* renamed from: x, reason: collision with root package name */
    private final androidx.lifecycle.a0 f11907x;

    /* renamed from: y, reason: collision with root package name */
    private final androidx.lifecycle.f0 f11908y;

    /* renamed from: z, reason: collision with root package name */
    private final androidx.lifecycle.a0 f11909z;

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes4.dex */
    public static final class a extends kotlin.coroutines.jvm.internal.l implements dn.p {

        /* renamed from: p, reason: collision with root package name */
        int f11910p;

        a(vm.d dVar) {
            super(2, dVar);
        }

        @Override // kotlin.coroutines.jvm.internal.a
        public final vm.d create(Object obj, vm.d dVar) {
            return new a(dVar);
        }

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            Object f10;
            f10 = wm.d.f();
            int i10 = this.f11910p;
            if (i10 == 0) {
                rm.y.b(obj);
                y8.c cVar = y3.this.f11900q;
                String c10 = y3.this.n0().c();
                this.f11910p = 1;
                obj = cVar.c(c10, this);
                if (obj == f10) {
                    return f10;
                }
            } else {
                if (i10 != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                rm.y.b(obj);
            }
            ResultWrapper resultWrapper = (ResultWrapper) obj;
            if (resultWrapper instanceof ResultWrapper.Success) {
                y3.this.C.addAll((Collection) ((ResultWrapper.Success) resultWrapper).getData());
                y3.this.C.add(new PackageDeliveryOptionInstructionResponse(DeliveryPreference.NO_DEFAULT.getValue(), "No default preference", "Aucune préférence par défaut"));
                ArrayList arrayList = new ArrayList();
                String f11 = y3.this.p0().f();
                int i11 = 0;
                int i12 = 0;
                for (PackageDeliveryOptionInstructionResponse packageDeliveryOptionInstructionResponse : w8.e0.a(y3.this.C)) {
                    if (kotlin.jvm.internal.t.b(packageDeliveryOptionInstructionResponse.getCd(), f11)) {
                        i11 = i12;
                    }
                    arrayList.add(y3.this.n0().b() ? packageDeliveryOptionInstructionResponse.getDescEn() : packageDeliveryOptionInstructionResponse.getDescFr());
                    i12++;
                }
                y3.this.A.q(arrayList.toArray(new String[0]));
                y3.this.f11903t.q(kotlin.coroutines.jvm.internal.b.c(i11));
            } else if (resultWrapper instanceof ResultWrapper.Error) {
                y3.this.X((ResultWrapper.Error) resultWrapper, true);
            }
            return rm.n0.f34904a;
        }

        @Override // dn.p
        public final Object invoke(tp.m0 m0Var, vm.d dVar) {
            return ((a) create(m0Var, dVar)).invokeSuspend(rm.n0.f34904a);
        }
    }

    /* loaded from: classes4.dex */
    static final class b extends kotlin.coroutines.jvm.internal.l implements dn.p {

        /* renamed from: p, reason: collision with root package name */
        int f11912p;

        /* renamed from: r, reason: collision with root package name */
        final /* synthetic */ String f11914r;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        b(String str, vm.d dVar) {
            super(2, dVar);
            this.f11914r = str;
        }

        @Override // kotlin.coroutines.jvm.internal.a
        public final vm.d create(Object obj, vm.d dVar) {
            return new b(this.f11914r, dVar);
        }

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            Object f10;
            f10 = wm.d.f();
            int i10 = this.f11912p;
            if (i10 == 0) {
                rm.y.b(obj);
                ka.b p02 = y3.this.p0();
                String deliveryPref = this.f11914r;
                kotlin.jvm.internal.t.f(deliveryPref, "$deliveryPref");
                this.f11912p = 1;
                obj = p02.F(deliveryPref, this);
                if (obj == f10) {
                    return f10;
                }
            } else {
                if (i10 != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                rm.y.b(obj);
            }
            ResultWrapper.Error error = (ResultWrapper.Error) obj;
            if (error != null) {
                y3.this.X(error, true);
                y3 y3Var = y3.this;
                y3Var.w0((String) y3Var.r0().f());
            } else {
                y3.this.f11908y.q(new Event(kotlin.coroutines.jvm.internal.b.a(true)));
            }
            return rm.n0.f34904a;
        }

        @Override // dn.p
        public final Object invoke(tp.m0 m0Var, vm.d dVar) {
            return ((b) create(m0Var, dVar)).invokeSuspend(rm.n0.f34904a);
        }
    }

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public y3(d9.f analyticsService, t7.c contextService, ka.b repository, y8.c deliveryPreferenceRepository, ca.b languageService, ja.d sharedPreferencesService) {
        super(contextService);
        kotlin.jvm.internal.t.g(analyticsService, "analyticsService");
        kotlin.jvm.internal.t.g(contextService, "contextService");
        kotlin.jvm.internal.t.g(repository, "repository");
        kotlin.jvm.internal.t.g(deliveryPreferenceRepository, "deliveryPreferenceRepository");
        kotlin.jvm.internal.t.g(languageService, "languageService");
        kotlin.jvm.internal.t.g(sharedPreferencesService, "sharedPreferencesService");
        this.f11897n = analyticsService;
        this.f11898o = contextService;
        this.f11899p = repository;
        this.f11900q = deliveryPreferenceRepository;
        this.f11901r = languageService;
        this.f11902s = sharedPreferencesService;
        androidx.lifecycle.f0 f0Var = new androidx.lifecycle.f0();
        this.f11903t = f0Var;
        this.f11904u = f0Var;
        this.f11905v = new androidx.lifecycle.f0();
        androidx.lifecycle.f0 f0Var2 = new androidx.lifecycle.f0();
        this.f11906w = f0Var2;
        this.f11907x = f0Var2;
        Boolean bool = Boolean.FALSE;
        androidx.lifecycle.f0 f0Var3 = new androidx.lifecycle.f0(new Event(bool));
        this.f11908y = f0Var3;
        this.f11909z = f0Var3;
        androidx.lifecycle.f0 f0Var4 = new androidx.lifecycle.f0();
        this.A = f0Var4;
        this.B = f0Var4;
        this.C = new ArrayList();
        androidx.lifecycle.f0 f0Var5 = new androidx.lifecycle.f0();
        f0Var5.q(bool);
        this.D = f0Var5;
        androidx.lifecycle.f0 f0Var6 = new androidx.lifecycle.f0();
        this.E = f0Var6;
        this.F = f0Var6;
        f.a.c(analyticsService, "Delivery_location_account", null, 2, null);
        l0();
    }

    @Override // r8.a
    public androidx.lifecycle.f0 T() {
        return this.D;
    }

    @Override // r8.b
    public boolean e() {
        return !kotlin.jvm.internal.t.b(this.f11907x.f(), this.f11905v.f());
    }

    @Override // r8.a
    public void e0() {
        V().q(Boolean.valueOf(e()));
    }

    @Override // r8.b
    public boolean g() {
        throw new rm.u("An operation is not implemented: Not yet implemented");
    }

    public final void l0() {
        h.a.a(this, androidx.lifecycle.a1.a(this), null, null, null, new a(null), 7, null);
    }

    public final androidx.lifecycle.a0 m0() {
        return this.B;
    }

    public final ca.b n0() {
        return this.f11901r;
    }

    public final androidx.lifecycle.a0 o0() {
        return this.F;
    }

    public final ka.b p0() {
        return this.f11899p;
    }

    public final androidx.lifecycle.a0 q0() {
        return this.f11904u;
    }

    public final androidx.lifecycle.a0 r0() {
        return this.f11907x;
    }

    public final androidx.lifecycle.a0 s0() {
        return this.f11909z;
    }

    public final void t0() {
        this.E.q(new Event(Boolean.TRUE));
    }

    public final void u0() {
        this.f11906w.q(this.f11899p.f());
    }

    public final void v0() {
        Map l10;
        String str = (String) this.f11905v.f();
        if (str != null) {
            Integer num = (Integer) this.f11904u.f();
            if (num != null) {
                ArrayList arrayList = this.C;
                kotlin.jvm.internal.t.d(num);
                Object obj = arrayList.get(num.intValue());
                kotlin.jvm.internal.t.f(obj, "get(...)");
                PackageDeliveryOptionInstructionResponse packageDeliveryOptionInstructionResponse = (PackageDeliveryOptionInstructionResponse) obj;
                d9.f fVar = this.f11897n;
                l10 = sm.q0.l(rm.c0.a("e.Var3", "Delivery_location_account"), rm.c0.a("e.Var13", packageDeliveryOptionInstructionResponse.getDescEn()));
                fVar.b("Set_delivery_preference_Adobe", l10);
                this.f11902s.putString("DEFAULT_DELIVERY_PREFERENCE_KEY", qa.d.s(packageDeliveryOptionInstructionResponse));
            }
            AMSPrerequisitesResponse aMSPrerequisitesResponse = (AMSPrerequisitesResponse) this.f11899p.J().f();
            if (aMSPrerequisitesResponse != null ? kotlin.jvm.internal.t.b(aMSPrerequisitesResponse.getStatus(), Boolean.TRUE) : false) {
                h.a.a(this, androidx.lifecycle.a1.a(this), null, null, null, new b(str, null), 7, null);
            } else {
                this.f11908y.q(new Event(Boolean.TRUE));
            }
        }
    }

    public final void w0(String str) {
        this.f11905v.q(str);
        e0();
    }

    public final void x0(Integer num) {
        this.f11903t.q(num);
        if (num != null) {
            w0(((PackageDeliveryOptionInstructionResponse) this.C.get(num.intValue())).getCd());
        }
    }
}
