package gc;

import android.app.Application;
import android.content.Context;
import ca.canadapost.core.data.flex.model.FlexLocation;
import ca.canadapost.core.data.flex.model.FlexService;
import ca.canadapost.core.data.model.Event;
import ca.canadapost.core.data.model.ResultWrapper;
import d9.f;
import java.util.Map;
import v9.d;

/* loaded from: classes4.dex */
public final class m1 extends androidx.lifecycle.b {

    /* renamed from: c, reason: collision with root package name */
    private final v9.d f19734c;

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

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

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

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

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

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

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

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

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

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

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

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

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

        /* renamed from: s, reason: collision with root package name */
        final /* synthetic */ kotlin.jvm.internal.o0 f19748s;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        a(String str, kotlin.jvm.internal.o0 o0Var, vm.d dVar) {
            super(2, dVar);
            this.f19747r = str;
            this.f19748s = o0Var;
        }

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

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            Object f10;
            f10 = wm.d.f();
            int i10 = this.f19745p;
            if (i10 == 0) {
                rm.y.b(obj);
                m1 m1Var = m1.this;
                String str = this.f19747r;
                String str2 = (String) this.f19748s.f26199p;
                this.f19745p = 1;
                if (m1Var.Y(str, str2, this) == f10) {
                    return f10;
                }
            } else {
                if (i10 != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                rm.y.b(obj);
            }
            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);
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes4.dex */
    public static final class b extends kotlin.coroutines.jvm.internal.d {

        /* renamed from: p, reason: collision with root package name */
        Object f19749p;

        /* renamed from: q, reason: collision with root package name */
        /* synthetic */ Object f19750q;

        /* renamed from: s, reason: collision with root package name */
        int f19752s;

        b(vm.d dVar) {
            super(dVar);
        }

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            this.f19750q = obj;
            this.f19752s |= Integer.MIN_VALUE;
            return m1.this.Y(null, null, this);
        }
    }

    /* JADX WARN: Illegal instructions before constructor call */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public m1(v9.d repository, t7.c contextService, d9.f analyticsService) {
        super((Application) r0);
        kotlin.jvm.internal.t.g(repository, "repository");
        kotlin.jvm.internal.t.g(contextService, "contextService");
        kotlin.jvm.internal.t.g(analyticsService, "analyticsService");
        Context a10 = contextService.a();
        kotlin.jvm.internal.t.e(a10, "null cannot be cast to non-null type android.app.Application");
        this.f19734c = repository;
        this.f19735d = contextService;
        this.f19736e = analyticsService;
        Boolean bool = Boolean.FALSE;
        androidx.lifecycle.f0 f0Var = new androidx.lifecycle.f0(new Event(bool));
        this.f19737f = f0Var;
        this.f19738g = f0Var;
        androidx.lifecycle.f0 f0Var2 = new androidx.lifecycle.f0(new Event(bool));
        this.f19739h = f0Var2;
        this.f19740i = f0Var2;
        androidx.lifecycle.f0 f0Var3 = new androidx.lifecycle.f0();
        this.f19741j = f0Var3;
        this.f19742k = f0Var3;
        androidx.lifecycle.f0 f0Var4 = new androidx.lifecycle.f0();
        this.f19743l = f0Var4;
        this.f19744m = f0Var4;
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX WARN: Removed duplicated region for block: B:14:0x008b A[Catch: all -> 0x00d4, TryCatch #0 {all -> 0x00d4, blocks: (B:11:0x002c, B:12:0x0085, B:14:0x008b, B:18:0x00b2, B:22:0x003b, B:24:0x0056, B:25:0x0074), top: B:7:0x0024 }] */
    /* JADX WARN: Removed duplicated region for block: B:18:0x00b2 A[Catch: all -> 0x00d4, TRY_LEAVE, TryCatch #0 {all -> 0x00d4, blocks: (B:11:0x002c, B:12:0x0085, B:14:0x008b, B:18:0x00b2, B:22:0x003b, B:24:0x0056, B:25:0x0074), top: B:7:0x0024 }] */
    /* JADX WARN: Removed duplicated region for block: B:21:0x0038  */
    /* JADX WARN: Removed duplicated region for block: B:9:0x0026  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object Y(String str, String str2, vm.d dVar) {
        b bVar;
        Object obj;
        Object f10;
        int i10;
        Map l10;
        try {
            if (dVar instanceof b) {
                bVar = (b) dVar;
                int i11 = bVar.f19752s;
                if ((i11 & Integer.MIN_VALUE) != 0) {
                    bVar.f19752s = i11 - Integer.MIN_VALUE;
                    b bVar2 = bVar;
                    obj = bVar2.f19750q;
                    f10 = wm.d.f();
                    i10 = bVar2.f19752s;
                    if (i10 != 0) {
                        rm.y.b(obj);
                        this.f19741j.n(new Event(new w8.r0(w8.q0.ON, this.f19735d.getString(e2.f19622c))));
                        if (str2 != null) {
                            d9.f fVar = this.f19736e;
                            l10 = sm.q0.l(rm.c0.a("e.Var148", str2), rm.c0.a("s.prop68", str2));
                            fVar.b("Flex_Delete_Address_Adobe", l10);
                        }
                        v9.d dVar2 = this.f19734c;
                        bVar2.f19749p = this;
                        bVar2.f19752s = 1;
                        obj = d.a.a(dVar2, str, null, bVar2, 2, null);
                        if (obj == f10) {
                            return f10;
                        }
                    } else {
                        if (i10 != 1) {
                            throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                        }
                        this = (m1) bVar2.f19749p;
                        rm.y.b(obj);
                    }
                    if (((ResultWrapper) obj) instanceof ResultWrapper.Success) {
                        this.f19739h.q(new Event(kotlin.coroutines.jvm.internal.b.a(true)));
                    } else {
                        this.f19741j.n(new Event(new w8.r0(w8.q0.OFF, null, 2, null)));
                        f.a.a(this.f19736e, "Flex_Remove_a_post_office_Adobe", null, 2, null);
                        this.f19737f.q(new Event(kotlin.coroutines.jvm.internal.b.a(true)));
                    }
                    this.f19741j.n(new Event(new w8.r0(w8.q0.OFF, null, 2, null)));
                    return rm.n0.f34904a;
                }
            }
            if (i10 != 0) {
            }
            if (((ResultWrapper) obj) instanceof ResultWrapper.Success) {
            }
            this.f19741j.n(new Event(new w8.r0(w8.q0.OFF, null, 2, null)));
            return rm.n0.f34904a;
        } catch (Throwable th2) {
            this.f19741j.n(new Event(new w8.r0(w8.q0.OFF, null, 2, null)));
            throw th2;
        }
        bVar = new b(dVar);
        b bVar22 = bVar;
        obj = bVar22.f19750q;
        f10 = wm.d.f();
        i10 = bVar22.f19752s;
    }

    public final void R() {
        String postalCode;
        kotlin.jvm.internal.o0 o0Var = new kotlin.jvm.internal.o0();
        FlexLocation.FlexLocationItem flexLocationItem = (FlexLocation.FlexLocationItem) this.f19734c.n().f();
        if (flexLocationItem != null) {
            if (this.f19734c.v().f() == FlexService.FLEX) {
                FlexLocation.FlexLocationItem.Flex flex = flexLocationItem.getFlex();
                o0Var.f26199p = flex != null ? flex.getCostCentreId() : null;
                FlexLocation.FlexLocationItem.Flex flex2 = flexLocationItem.getFlex();
                if (flex2 != null) {
                    postalCode = flex2.getPostalCode();
                }
                postalCode = null;
            } else {
                FlexLocation.FlexLocationItem.Apl apl = flexLocationItem.getApl();
                o0Var.f26199p = apl != null ? apl.getCostCentreId() : null;
                FlexLocation.FlexLocationItem.Apl apl2 = flexLocationItem.getApl();
                if (apl2 != null) {
                    postalCode = apl2.getPostalCode();
                }
                postalCode = null;
            }
            if (postalCode != null) {
                tp.k.d(androidx.lifecycle.a1.a(this), null, null, new a(postalCode, o0Var, null), 3, null);
            }
        }
    }

    public final StringBuffer S() {
        FlexLocation.FlexLocationItem flexLocationItem = (FlexLocation.FlexLocationItem) this.f19734c.n().f();
        if (flexLocationItem == null) {
            return null;
        }
        String name = flexLocationItem.getName();
        StringBuffer stringBuffer = new StringBuffer();
        if (U() == FlexService.FLEX) {
            FlexLocation.FlexLocationItem.Flex flex = flexLocationItem.getFlex();
            if (flex != null) {
                if (!qa.d.h(flex.getAlias())) {
                    name = String.valueOf(flex.getAlias());
                }
                stringBuffer = flex.getMailingAddress().getFormattedAddress();
            }
        } else {
            FlexLocation.FlexLocationItem.Apl apl = flexLocationItem.getApl();
            if (apl != null) {
                if (!qa.d.h(apl.getAlias())) {
                    name = String.valueOf(apl.getAlias());
                }
                stringBuffer = apl.getMailingAddress().getFormattedAddress();
            }
        }
        StringBuffer stringBuffer2 = new StringBuffer();
        stringBuffer2.append(name);
        stringBuffer2.append("\n");
        stringBuffer2.append("\n");
        StringBuffer formattedAddress = flexLocationItem.getAddress().getFormattedAddress();
        stringBuffer2.append(this.f19735d.getString(e2.f19645n0));
        stringBuffer2.append("\n");
        stringBuffer2.append(stringBuffer);
        stringBuffer2.append("\n");
        stringBuffer2.append("\n");
        stringBuffer2.append(this.f19735d.getString(e2.f19635i0));
        stringBuffer2.append("\n");
        stringBuffer2.append(formattedAddress);
        return stringBuffer2;
    }

    public final androidx.lifecycle.a0 T() {
        return this.f19738g;
    }

    public final FlexService U() {
        return (FlexService) this.f19734c.v().f();
    }

    public final androidx.lifecycle.a0 V() {
        return this.f19740i;
    }

    public final androidx.lifecycle.a0 W() {
        return this.f19744m;
    }

    public final androidx.lifecycle.a0 X() {
        return this.f19742k;
    }

    public final void Z() {
        StringBuffer S = S();
        if (S != null) {
            this.f19743l.q(S.toString());
        }
    }
}
