package ib;

import android.app.Activity;
import android.os.Bundle;
import ca.canadapost.core.data.addresscomplete.webservice.AddressCompleteFindItem;
import ca.canadapost.core.data.auth.model.UserProfile;
import ca.canadapost.core.data.db.cupboard.model.CustomsFormObject;
import ca.canadapost.core.data.db.cupboard.model.CustomsFormSenderObject;
import java.util.Arrays;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import n8.a;

/* loaded from: classes4.dex */
public final class w extends s8.l {
    private boolean A0;
    private CustomsFormSenderObject B0;

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

    /* renamed from: b0, reason: collision with root package name */
    private final o9.c f23044b0;

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

    /* renamed from: d0, reason: collision with root package name */
    private final ca.a f23046d0;

    /* renamed from: e0, reason: collision with root package name */
    private final s0 f23047e0;

    /* renamed from: f0, reason: collision with root package name */
    private final a9.b f23048f0;

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

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

    /* renamed from: i0, reason: collision with root package name */
    private final l8.g f23051i0;

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

    /* renamed from: k0, reason: collision with root package name */
    private final l8.g f23053k0;

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

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

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

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

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

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

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

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

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

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

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

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

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

    /* renamed from: y0, reason: collision with root package name */
    private s f23067y0;

    /* renamed from: z0, reason: collision with root package name */
    private final List f23068z0;

    /* loaded from: classes4.dex */
    static final class a extends kotlin.jvm.internal.v implements dn.l {
        a() {
            super(1);
        }

        public final void a(String str) {
            w.this.U1();
        }

        @Override // dn.l
        public /* bridge */ /* synthetic */ Object invoke(Object obj) {
            a((String) obj);
            return rm.n0.f34904a;
        }
    }

    /* loaded from: classes4.dex */
    static final class b extends kotlin.jvm.internal.v implements dn.l {
        b() {
            super(1);
        }

        public final void a(String str) {
            w.this.U1();
        }

        @Override // dn.l
        public /* bridge */ /* synthetic */ Object invoke(Object obj) {
            a((String) obj);
            return rm.n0.f34904a;
        }
    }

    /* loaded from: classes4.dex */
    static final class c extends kotlin.jvm.internal.v implements dn.l {
        c() {
            super(1);
        }

        public final void a(String str) {
            w.this.U1();
        }

        @Override // dn.l
        public /* bridge */ /* synthetic */ Object invoke(Object obj) {
            a((String) obj);
            return rm.n0.f34904a;
        }
    }

    /* loaded from: classes4.dex */
    static final class d extends kotlin.jvm.internal.v implements dn.l {
        d() {
            super(1);
        }

        public final void a(String str) {
            w.this.U1();
        }

        @Override // dn.l
        public /* bridge */ /* synthetic */ Object invoke(Object obj) {
            a((String) obj);
            return rm.n0.f34904a;
        }
    }

    /* loaded from: classes4.dex */
    static final class e implements androidx.lifecycle.g0, kotlin.jvm.internal.n {

        /* renamed from: a, reason: collision with root package name */
        private final /* synthetic */ dn.l f23073a;

        e(dn.l function) {
            kotlin.jvm.internal.t.g(function, "function");
            this.f23073a = function;
        }

        @Override // kotlin.jvm.internal.n
        public final rm.i b() {
            return this.f23073a;
        }

        @Override // androidx.lifecycle.g0
        public final /* synthetic */ void d(Object obj) {
            this.f23073a.invoke(obj);
        }

        public final boolean equals(Object obj) {
            if ((obj instanceof androidx.lifecycle.g0) && (obj instanceof kotlin.jvm.internal.n)) {
                return kotlin.jvm.internal.t.b(b(), ((kotlin.jvm.internal.n) obj).b());
            }
            return false;
        }

        public final int hashCode() {
            return b().hashCode();
        }
    }

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public w(t7.c contextService, o9.c cpEventBus, w8.r shareDataService, ka.b profileRepository, ca.a languageService, s0 customsFormObjectDataManager, a9.b addressSearchRepository, w8.q debounce, d9.f analyticsService) {
        super(profileRepository, contextService, cpEventBus, debounce, languageService, addressSearchRepository, analyticsService);
        List n10;
        List n11;
        kotlin.jvm.internal.t.g(contextService, "contextService");
        kotlin.jvm.internal.t.g(cpEventBus, "cpEventBus");
        kotlin.jvm.internal.t.g(shareDataService, "shareDataService");
        kotlin.jvm.internal.t.g(profileRepository, "profileRepository");
        kotlin.jvm.internal.t.g(languageService, "languageService");
        kotlin.jvm.internal.t.g(customsFormObjectDataManager, "customsFormObjectDataManager");
        kotlin.jvm.internal.t.g(addressSearchRepository, "addressSearchRepository");
        kotlin.jvm.internal.t.g(debounce, "debounce");
        kotlin.jvm.internal.t.g(analyticsService, "analyticsService");
        this.f23043a0 = contextService;
        this.f23044b0 = cpEventBus;
        this.f23045c0 = profileRepository;
        this.f23046d0 = languageService;
        this.f23047e0 = customsFormObjectDataManager;
        this.f23048f0 = addressSearchRepository;
        androidx.lifecycle.f0 f0Var = new androidx.lifecycle.f0();
        this.f23049g0 = f0Var;
        this.f23050h0 = f0Var;
        l8.g gVar = new l8.g();
        this.f23051i0 = gVar;
        this.f23052j0 = gVar;
        l8.g gVar2 = new l8.g();
        this.f23053k0 = gVar2;
        this.f23054l0 = gVar2;
        androidx.lifecycle.f0 f0Var2 = new androidx.lifecycle.f0();
        this.f23055m0 = f0Var2;
        androidx.lifecycle.f0 f0Var3 = new androidx.lifecycle.f0(0);
        this.f23056n0 = f0Var3;
        this.f23057o0 = f0Var3;
        androidx.lifecycle.f0 f0Var4 = new androidx.lifecycle.f0();
        this.f23058p0 = f0Var4;
        androidx.lifecycle.f0 f0Var5 = new androidx.lifecycle.f0();
        this.f23059q0 = f0Var5;
        this.f23060r0 = f0Var5;
        androidx.lifecycle.f0 f0Var6 = new androidx.lifecycle.f0();
        this.f23061s0 = f0Var6;
        this.f23062t0 = f0Var6;
        androidx.lifecycle.f0 f0Var7 = new androidx.lifecycle.f0();
        this.f23063u0 = f0Var7;
        androidx.lifecycle.f0 f0Var8 = new androidx.lifecycle.f0();
        this.f23064v0 = f0Var8;
        androidx.lifecycle.f0 f0Var9 = new androidx.lifecycle.f0();
        this.f23065w0 = f0Var9;
        androidx.lifecycle.f0 f0Var10 = new androidx.lifecycle.f0();
        this.f23066x0 = f0Var10;
        R1(false);
        analyticsService.c("Customsform_step1of6", null);
        String[] c10 = contextService.c(u0.f23038b);
        kotlin.jvm.internal.t.f(c10, "getStringArray(...)");
        n10 = sm.u.n(Arrays.copyOf(c10, c10.length));
        f0Var2.q(n10);
        String[] c11 = contextService.c(u0.f23037a);
        kotlin.jvm.internal.t.f(c11, "getStringArray(...)");
        n11 = sm.u.n(Arrays.copyOf(c11, c11.length));
        this.f23068z0 = n11;
        f0Var10.q(Boolean.FALSE);
        f0Var4.k(new e(new a()));
        f0Var7.k(new e(new b()));
        f0Var8.k(new e(new c()));
        f0Var9.k(new e(new d()));
        if (shareDataService.a("CUSTOMS_FORM_SHARE_DATA_CUSTOMS_FORM_OBJECT_VIEWMODEL")) {
            this.f23067y0 = (s) shareDataService.e("CUSTOMS_FORM_SHARE_DATA_CUSTOMS_FORM_OBJECT_VIEWMODEL");
        } else {
            CustomsFormObject customsFormObject = new CustomsFormObject();
            customsFormObject.creationDate = new Date();
            s sVar = new s(customsFormObject, languageService);
            this.f23067y0 = sVar;
            shareDataService.d("CUSTOMS_FORM_SHARE_DATA_CUSTOMS_FORM_OBJECT_VIEWMODEL", sVar);
        }
        N1();
        cpEventBus.a(this);
    }

    private final void N1() {
        List d10 = this.f23047e0.d();
        if (d10 != null) {
            Iterator it = d10.iterator();
            if (it.hasNext()) {
                CustomsFormSenderObject customsFormSenderObject = (CustomsFormSenderObject) it.next();
                this.B0 = customsFormSenderObject;
                this.f23058p0.q(customsFormSenderObject.senderName);
                this.f23059q0.q(customsFormSenderObject.senderName);
                this.f23063u0.q(customsFormSenderObject.senderStreetAddress);
                this.f23064v0.q(customsFormSenderObject.senderCityName);
                this.f23065w0.q(customsFormSenderObject.senderPostalCode);
                List list = this.f23068z0;
                String senderProvinceCode = customsFormSenderObject.senderProvinceCode;
                kotlin.jvm.internal.t.f(senderProvinceCode, "senderProvinceCode");
                Locale locale = Locale.getDefault();
                kotlin.jvm.internal.t.f(locale, "getDefault(...)");
                String upperCase = senderProvinceCode.toUpperCase(locale);
                kotlin.jvm.internal.t.f(upperCase, "toUpperCase(...)");
                int lastIndexOf = list.lastIndexOf(upperCase);
                if (lastIndexOf <= -1 || lastIndexOf >= this.f23068z0.size()) {
                    return;
                }
                S1(lastIndexOf);
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void U1() {
        boolean z10 = !qa.d.h((String) this.f23065w0.f());
        if (qa.d.h((String) this.f23064v0.f())) {
            z10 = false;
        }
        if (qa.d.h((String) this.f23063u0.f())) {
            z10 = false;
        }
        this.f23066x0.q(Boolean.valueOf(qa.d.h((String) this.f23058p0.f()) ? false : z10));
    }

    private final boolean V1() {
        String str;
        CharSequence e12;
        String str2 = (String) this.f23059q0.f();
        if (str2 != null) {
            e12 = kotlin.text.z.e1(str2);
            str = e12.toString();
        } else {
            str = null;
        }
        if (str == null) {
            str = "";
        }
        if (str.length() == 0) {
            this.f23061s0.q(this.f23043a0.getString(b1.f22613t));
            return false;
        }
        this.f23061s0.q(null);
        return true;
    }

    public final List A1() {
        return this.f23068z0;
    }

    public final androidx.lifecycle.f0 B1() {
        return this.f23055m0;
    }

    public final androidx.lifecycle.f0 C1() {
        return this.f23064v0;
    }

    public final androidx.lifecycle.f0 D1() {
        return this.f23066x0;
    }

    public final androidx.lifecycle.a0 E1() {
        return this.f23052j0;
    }

    public final androidx.lifecycle.f0 F1() {
        return this.f23065w0;
    }

    public final androidx.lifecycle.a0 G1() {
        return this.f23050h0;
    }

    public final androidx.lifecycle.a0 H1() {
        return this.f23057o0;
    }

    public final androidx.lifecycle.f0 I1() {
        return this.f23058p0;
    }

    public final androidx.lifecycle.a0 J1() {
        return this.f23062t0;
    }

    public final androidx.lifecycle.a0 K1() {
        return this.f23060r0;
    }

    public final androidx.lifecycle.f0 L1() {
        return this.f23063u0;
    }

    public final androidx.lifecycle.a0 M1() {
        return this.f23054l0;
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // s8.l, androidx.lifecycle.z0
    public void O() {
        this.f23044b0.b(this);
        super.O();
    }

    /* JADX WARN: Code restructure failed: missing block: B:25:0x0080, code lost:
    
        if (r2 == null) goto L36;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void O1() {
        String str;
        if (!qa.d.l((String) this.f23065w0.f())) {
            this.f23053k0.q(this.f23043a0.getString(b1.f22575a));
            R1(true);
            return;
        }
        CustomsFormSenderObject customsFormSenderObject = this.B0;
        if (customsFormSenderObject == null) {
            customsFormSenderObject = new CustomsFormSenderObject();
            this.B0 = customsFormSenderObject;
        }
        if (customsFormSenderObject != null) {
            customsFormSenderObject.senderName = (String) this.f23058p0.f();
        }
        if (customsFormSenderObject != null) {
            customsFormSenderObject.senderStreetAddress = (String) this.f23063u0.f();
        }
        if (customsFormSenderObject != null) {
            customsFormSenderObject.senderCityName = (String) this.f23064v0.f();
        }
        if (customsFormSenderObject != null) {
            customsFormSenderObject.senderPostalCode = (String) this.f23065w0.f();
        }
        if (customsFormSenderObject != null) {
            customsFormSenderObject.senderCountryISOCode = "CA";
        }
        if (customsFormSenderObject != null) {
            customsFormSenderObject.senderCountryName = "Canada";
        }
        if (customsFormSenderObject != null) {
            Integer num = (Integer) this.f23057o0.f();
            if (num != null) {
                List list = (List) this.f23055m0.f();
                str = list != null ? (String) list.get(num.intValue()) : null;
            }
            str = "";
            customsFormSenderObject.senderProvinceName = str;
        }
        Integer num2 = (Integer) this.f23057o0.f();
        if (num2 != null && customsFormSenderObject != null) {
            customsFormSenderObject.senderProvinceCode = (String) this.f23068z0.get(num2.intValue());
        }
        s sVar = this.f23067y0;
        androidx.lifecycle.f0 C = sVar != null ? sVar.C() : null;
        if (C != null) {
            C.q(customsFormSenderObject != null ? customsFormSenderObject.senderName : null);
        }
        s sVar2 = this.f23067y0;
        androidx.lifecycle.f0 G = sVar2 != null ? sVar2.G() : null;
        if (G != null) {
            G.q(customsFormSenderObject != null ? customsFormSenderObject.senderStreetAddress : null);
        }
        s sVar3 = this.f23067y0;
        androidx.lifecycle.f0 z10 = sVar3 != null ? sVar3.z() : null;
        if (z10 != null) {
            z10.q(customsFormSenderObject != null ? customsFormSenderObject.senderCityName : null);
        }
        s sVar4 = this.f23067y0;
        androidx.lifecycle.f0 D = sVar4 != null ? sVar4.D() : null;
        if (D != null) {
            D.q(customsFormSenderObject != null ? customsFormSenderObject.senderPostalCode : null);
        }
        s sVar5 = this.f23067y0;
        androidx.lifecycle.f0 E = sVar5 != null ? sVar5.E() : null;
        if (E != null) {
            E.q(customsFormSenderObject != null ? customsFormSenderObject.senderProvinceCode : null);
        }
        s sVar6 = this.f23067y0;
        androidx.lifecycle.f0 F = sVar6 != null ? sVar6.F() : null;
        if (F != null) {
            F.q(customsFormSenderObject != null ? customsFormSenderObject.senderProvinceName : null);
        }
        s sVar7 = this.f23067y0;
        androidx.lifecycle.f0 A = sVar7 != null ? sVar7.A() : null;
        if (A != null) {
            A.q(customsFormSenderObject != null ? customsFormSenderObject.senderCountryISOCode : null);
        }
        s sVar8 = this.f23067y0;
        androidx.lifecycle.f0 B = sVar8 != null ? sVar8.B() : null;
        if (B != null) {
            B.q(customsFormSenderObject != null ? customsFormSenderObject.senderCountryName : null);
        }
        CustomsFormSenderObject customsFormSenderObject2 = this.B0;
        if (customsFormSenderObject2 != null) {
            customsFormSenderObject2._id = this.f23047e0.b(customsFormSenderObject);
        }
        this.f23051i0.s();
    }

    /* JADX WARN: Code restructure failed: missing block: B:24:0x007b, code lost:
    
        if (r1 == null) goto L34;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final boolean P1() {
        String str;
        if (!g()) {
            return false;
        }
        CustomsFormSenderObject customsFormSenderObject = this.B0;
        if (customsFormSenderObject == null) {
            customsFormSenderObject = new CustomsFormSenderObject();
            this.B0 = customsFormSenderObject;
        }
        if (customsFormSenderObject != null) {
            customsFormSenderObject.senderName = (String) this.f23059q0.f();
        }
        if (customsFormSenderObject != null) {
            customsFormSenderObject.senderStreetAddress = (String) M0().f();
        }
        if (customsFormSenderObject != null) {
            customsFormSenderObject.senderCityName = (String) P0().f();
        }
        if (customsFormSenderObject != null) {
            customsFormSenderObject.senderPostalCode = (String) Q0().f();
        }
        if (customsFormSenderObject != null) {
            customsFormSenderObject.senderCountryISOCode = "CA";
        }
        if (customsFormSenderObject != null) {
            customsFormSenderObject.senderCountryName = "Canada";
        }
        if (customsFormSenderObject != null) {
            z7.b a10 = z7.b.Companion.a((z7.a) V0().f());
            if (a10 != null) {
                str = this.f23043a0.getString(a10.getResId());
            }
            str = "";
            customsFormSenderObject.senderProvinceName = str;
        }
        if (customsFormSenderObject != null) {
            z7.a aVar = (z7.a) V0().f();
            customsFormSenderObject.senderProvinceCode = aVar != null ? aVar.getCode() : null;
        }
        s sVar = this.f23067y0;
        androidx.lifecycle.f0 C = sVar != null ? sVar.C() : null;
        if (C != null) {
            C.q(customsFormSenderObject != null ? customsFormSenderObject.senderName : null);
        }
        s sVar2 = this.f23067y0;
        androidx.lifecycle.f0 G = sVar2 != null ? sVar2.G() : null;
        if (G != null) {
            G.q(customsFormSenderObject != null ? customsFormSenderObject.senderStreetAddress : null);
        }
        s sVar3 = this.f23067y0;
        androidx.lifecycle.f0 z10 = sVar3 != null ? sVar3.z() : null;
        if (z10 != null) {
            z10.q(customsFormSenderObject != null ? customsFormSenderObject.senderCityName : null);
        }
        s sVar4 = this.f23067y0;
        androidx.lifecycle.f0 D = sVar4 != null ? sVar4.D() : null;
        if (D != null) {
            D.q(customsFormSenderObject != null ? customsFormSenderObject.senderPostalCode : null);
        }
        s sVar5 = this.f23067y0;
        androidx.lifecycle.f0 E = sVar5 != null ? sVar5.E() : null;
        if (E != null) {
            E.q(customsFormSenderObject != null ? customsFormSenderObject.senderProvinceCode : null);
        }
        s sVar6 = this.f23067y0;
        androidx.lifecycle.f0 F = sVar6 != null ? sVar6.F() : null;
        if (F != null) {
            F.q(customsFormSenderObject != null ? customsFormSenderObject.senderProvinceName : null);
        }
        s sVar7 = this.f23067y0;
        androidx.lifecycle.f0 A = sVar7 != null ? sVar7.A() : null;
        if (A != null) {
            A.q(customsFormSenderObject != null ? customsFormSenderObject.senderCountryISOCode : null);
        }
        s sVar8 = this.f23067y0;
        androidx.lifecycle.f0 B = sVar8 != null ? sVar8.B() : null;
        if (B != null) {
            B.q(customsFormSenderObject != null ? customsFormSenderObject.senderCountryName : null);
        }
        CustomsFormSenderObject customsFormSenderObject2 = this.B0;
        if (customsFormSenderObject2 == null) {
            return true;
        }
        customsFormSenderObject2._id = this.f23047e0.b(customsFormSenderObject);
        return true;
    }

    public final void Q1(String name) {
        kotlin.jvm.internal.t.g(name, "name");
        this.f23059q0.q(name);
        V1();
    }

    public final void R1(boolean z10) {
        this.f23049g0.q(Boolean.valueOf(z10));
    }

    public final void S1(int i10) {
        this.f23056n0.q(Integer.valueOf(i10));
    }

    public final void T1() {
        this.A0 = true;
        Bundle bundle = new Bundle();
        bundle.putString("responseTag", "getFindPostalCodeOrigin");
        bundle.putBoolean("disableDrawer", true);
        a.C0681a c0681a = n8.a.f29843a;
        Activity b10 = this.f23043a0.b();
        kotlin.jvm.internal.t.f(b10, "getCurrentActivity(...)");
        c0681a.a(b10, bundle);
    }

    @mm.h
    public final void answerAvailable(AddressCompleteFindItem.a event) {
        kotlin.jvm.internal.t.g(event, "event");
        if (this.A0) {
            this.A0 = false;
            this.f23065w0.q(event.f8021b.PostalCode);
            this.f23064v0.q(event.f8021b.City);
            this.f23063u0.q(event.f8021b.Line1);
            List list = this.f23068z0;
            String ProvinceCode = event.f8021b.ProvinceCode;
            kotlin.jvm.internal.t.f(ProvinceCode, "ProvinceCode");
            Locale locale = Locale.getDefault();
            kotlin.jvm.internal.t.f(locale, "getDefault(...)");
            String upperCase = ProvinceCode.toUpperCase(locale);
            kotlin.jvm.internal.t.f(upperCase, "toUpperCase(...)");
            int lastIndexOf = list.lastIndexOf(upperCase);
            if (lastIndexOf <= -1 || lastIndexOf >= this.f23068z0.size()) {
                return;
            }
            S1(lastIndexOf);
        }
    }

    @Override // s8.l, r8.b
    public boolean g() {
        return super.g() && V1();
    }

    @Override // s8.l
    public void q1() {
        super.q1();
        UserProfile userProfile = (UserProfile) this.f23045c0.a().f();
        String firstName = userProfile != null ? userProfile.getFirstName() : null;
        if (firstName == null) {
            firstName = "";
        }
        String lastName = userProfile != null ? userProfile.getLastName() : null;
        String str = lastName != null ? lastName : "";
        this.f23059q0.q(firstName + " " + str);
    }
}
