package ca.canadapost.core.common.navigation.ui;

import android.app.Activity;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentSender;
import android.database.ContentObserver;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.provider.Settings;
import android.view.View;
import android.widget.TextView;
import androidx.appcompat.widget.Toolbar;
import androidx.lifecycle.b1;
import androidx.lifecycle.c1;
import androidx.lifecycle.d1;
import androidx.lifecycle.g0;
import androidx.lifecycle.j0;
import androidx.lifecycle.u;
import ca.canadapost.core.data.model.CoreConstants;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
import dn.r;
import java.util.List;
import kotlin.jvm.internal.t;
import kotlin.jvm.internal.v;
import kotlin.text.z;
import l8.h;
import n8.e0;
import n8.n;
import o8.d0;
import o8.f0;
import rm.n0;
import rm.o;
import sm.c0;
import u8.g;
import w8.p0;

/* loaded from: classes.dex */
public abstract class b extends i.c implements nm.e, m8.m, p0 {
    public static final a F = new a(null);
    public static final int G = 8;
    private static boolean H;
    private ContentObserver A;
    private oj.b C;
    private Toolbar D;
    private TextView E;

    /* renamed from: t, reason: collision with root package name */
    public t7.c f7894t;

    /* renamed from: u, reason: collision with root package name */
    protected nm.c f7895u;

    /* renamed from: v, reason: collision with root package name */
    protected c1.c f7896v;

    /* renamed from: w, reason: collision with root package name */
    protected q8.a f7897w;

    /* renamed from: x, reason: collision with root package name */
    protected e9.b f7898x;

    /* renamed from: y, reason: collision with root package name */
    protected h8.a f7899y;

    /* renamed from: z, reason: collision with root package name */
    protected p9.h f7900z;

    /* renamed from: r, reason: collision with root package name */
    private final /* synthetic */ x7.a f7892r = new x7.a();

    /* renamed from: s, reason: collision with root package name */
    private final /* synthetic */ w8.l f7893s = new w8.l();
    private final o B = new b1(kotlin.jvm.internal.p0.b(d0.class), new l(this), new e(), new m(null, this));

    /* loaded from: classes.dex */
    public static final class a {
        private a() {
        }

        public /* synthetic */ a(kotlin.jvm.internal.k kVar) {
            this();
        }

        public final boolean a() {
            return b.H;
        }

        public final void b(boolean z10) {
            b.H = z10;
        }
    }

    /* renamed from: ca.canadapost.core.common.navigation.ui.b$b, reason: collision with other inner class name */
    /* loaded from: classes.dex */
    public /* synthetic */ class C0206b {

        /* renamed from: a, reason: collision with root package name */
        public static final /* synthetic */ int[] f7901a;

        static {
            int[] iArr = new int[f0.values().length];
            try {
                iArr[f0.PORTRAIT.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                iArr[f0.LANDSCAPE.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            f7901a = iArr;
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public static final class c extends v implements dn.l {

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

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

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        c(String str, String str2) {
            super(1);
            this.f7903q = str;
            this.f7904r = str2;
        }

        public final void a(oj.a aVar) {
            if (aVar.c() == 2) {
                if ((b.this.d0(this.f7903q, this.f7904r) == -1) && aVar.a(1)) {
                    b bVar = b.this;
                    t.d(aVar);
                    bVar.x0(aVar);
                }
            }
        }

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

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public static final class d extends v implements r {
        d() {
            super(4);
        }

        public final void a(String title, String desc, String linkText, String link) {
            t.g(title, "title");
            t.g(desc, "desc");
            t.g(linkText, "linkText");
            t.g(link, "link");
            Bundle bundle = new Bundle();
            bundle.putString(CoreConstants.MAINTENANCE_TITLE, title);
            bundle.putString(CoreConstants.MAINTENANCE_DESC, desc);
            bundle.putString(CoreConstants.MAINTENANCE_LINK_TEXT, linkText);
            bundle.putString(CoreConstants.MAINTENANCE_LINK_URL, link);
            n.f29860a.a(b.this, bundle);
        }

        @Override // dn.r
        public /* bridge */ /* synthetic */ Object j(Object obj, Object obj2, Object obj3, Object obj4) {
            a((String) obj, (String) obj2, (String) obj3, (String) obj4);
            return n0.f34904a;
        }
    }

    /* loaded from: classes.dex */
    static final class e extends v implements dn.a {
        e() {
            super(0);
        }

        @Override // dn.a
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public final c1.c invoke() {
            return b.this.n0();
        }
    }

    /* loaded from: classes.dex */
    public static final class f implements androidx.lifecycle.h {
        f() {
        }

        @Override // androidx.lifecycle.h
        public void onStop(u owner) {
            t.g(owner, "owner");
            b.F.b(true);
        }
    }

    /* loaded from: classes.dex */
    static final class g extends v implements dn.a {

        /* JADX INFO: Access modifiers changed from: package-private */
        /* loaded from: classes.dex */
        public static final class a extends v implements dn.a {

            /* renamed from: p, reason: collision with root package name */
            final /* synthetic */ b f7908p;

            /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
            a(b bVar) {
                super(0);
                this.f7908p = bVar;
            }

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

            /* renamed from: invoke, reason: collision with other method in class */
            public final void m53invoke() {
                this.f7908p.finishAffinity();
            }
        }

        /* JADX INFO: Access modifiers changed from: package-private */
        /* renamed from: ca.canadapost.core.common.navigation.ui.b$g$b, reason: collision with other inner class name */
        /* loaded from: classes.dex */
        public static final class C0207b extends v implements dn.a {

            /* renamed from: p, reason: collision with root package name */
            final /* synthetic */ b f7909p;

            /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
            C0207b(b bVar) {
                super(0);
                this.f7909p = bVar;
            }

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

            /* renamed from: invoke, reason: collision with other method in class */
            public final void m54invoke() {
                this.f7909p.finishAffinity();
            }
        }

        g() {
            super(0);
        }

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

        /* renamed from: invoke, reason: collision with other method in class */
        public final void m52invoke() {
            g.a aVar = u8.g.f36993k;
            b bVar = b.this;
            String string = bVar.getString(h7.l.f21116a2);
            t.f(string, "getString(...)");
            u8.g k10 = g.a.k(aVar, bVar, string, null, 4, null);
            b bVar2 = b.this;
            k10.o(new a(bVar2));
            k10.r(new C0207b(bVar2));
            k10.x(b.this);
        }
    }

    /* loaded from: classes.dex */
    static final class h extends v implements dn.l {
        h() {
            super(1);
        }

        public final void a(boolean z10) {
            if (z10) {
                b.this.k0().P0(false);
            } else {
                b.this.k0().S0(b.this.d());
            }
        }

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

    /* loaded from: classes.dex */
    static final class i extends v implements dn.l {
        i() {
            super(1);
        }

        public final void a(Boolean bool) {
            t.d(bool);
            if (!bool.booleanValue()) {
                g.a aVar = u8.g.f36993k;
                b bVar = b.this;
                String string = bVar.getString(h7.l.D3);
                t.f(string, "getString(...)");
                aVar.j(bVar, string, b.this.getString(h7.l.E3)).x(b.this);
                return;
            }
            e0.f29852a.a(b.this, "https://prod.cpgva-avgpc.ca/#/" + b.this.getString(h7.l.H3));
        }

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

    /* loaded from: classes.dex */
    static final class j implements g0, kotlin.jvm.internal.n {

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

        j(dn.l function) {
            t.g(function, "function");
            this.f7912a = function;
        }

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

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

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

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

    /* loaded from: classes.dex */
    public static final class k extends ContentObserver {
        k(Handler handler) {
            super(handler);
        }

        @Override // android.database.ContentObserver
        public void onChange(boolean z10) {
            super.onChange(z10);
            if (b.this.o0()) {
                b.this.k0().f0();
            }
        }
    }

    /* loaded from: classes.dex */
    public static final class l extends v implements dn.a {

        /* renamed from: p, reason: collision with root package name */
        final /* synthetic */ androidx.activity.h f7914p;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public l(androidx.activity.h hVar) {
            super(0);
            this.f7914p = hVar;
        }

        @Override // dn.a
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public final d1 invoke() {
            return this.f7914p.getViewModelStore();
        }
    }

    /* loaded from: classes.dex */
    public static final class m extends v implements dn.a {

        /* renamed from: p, reason: collision with root package name */
        final /* synthetic */ dn.a f7915p;

        /* renamed from: q, reason: collision with root package name */
        final /* synthetic */ androidx.activity.h f7916q;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public m(dn.a aVar, androidx.activity.h hVar) {
            super(0);
            this.f7915p = aVar;
            this.f7916q = hVar;
        }

        @Override // dn.a
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public final s4.a invoke() {
            s4.a aVar;
            dn.a aVar2 = this.f7915p;
            return (aVar2 == null || (aVar = (s4.a) aVar2.invoke()) == null) ? this.f7916q.getDefaultViewModelCreationExtras() : aVar;
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void Z(dn.l tmp0, Object obj) {
        t.g(tmp0, "$tmp0");
        tmp0.invoke(obj);
    }

    private final void a0() {
        j0().b(new d());
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX WARN: Code restructure failed: missing block: B:10:0x0044, code lost:
    
        r3 = kotlin.text.x.m(r3);
     */
    /* JADX WARN: Code restructure failed: missing block: B:5:0x0030, code lost:
    
        r2 = kotlin.text.x.m(r2);
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final int d0(String str, String str2) {
        List I0;
        List I02;
        Object f02;
        Object f03;
        Integer m10;
        Integer m11;
        I0 = z.I0(str, new String[]{"."}, false, 0, 6, null);
        I02 = z.I0(str2, new String[]{"."}, false, 0, 6, null);
        int max = Math.max(I0.size(), I02.size());
        for (int i10 = 0; i10 < max; i10++) {
            f02 = c0.f0(I0, i10);
            String str3 = (String) f02;
            int intValue = (str3 == null || m11 == null) ? 0 : m11.intValue();
            f03 = c0.f0(I02, i10);
            String str4 = (String) f03;
            int intValue2 = (str4 == null || m10 == null) ? 0 : m10.intValue();
            if (intValue > intValue2) {
                return 1;
            }
            if (intValue < intValue2) {
                return -1;
            }
        }
        return 0;
    }

    private final androidx.fragment.app.f i0() {
        androidx.fragment.app.z childFragmentManager;
        List z02;
        androidx.fragment.app.f k02 = getSupportFragmentManager().k0(h7.i.Y);
        if (k02 == null || (childFragmentManager = k02.getChildFragmentManager()) == null || (z02 = childFragmentManager.z0()) == null) {
            return null;
        }
        return (androidx.fragment.app.f) z02.get(0);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final boolean o0() {
        return Settings.Secure.getInt(getContentResolver(), "accessibility_enabled", 0) == 1;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void r0(dn.l iconClickListener, Toolbar this_run, b this$0, View view) {
        t.g(iconClickListener, "$iconClickListener");
        t.g(this_run, "$this_run");
        t.g(this$0, "this$0");
        iconClickListener.invoke(this_run);
        this$0.L();
    }

    private final void s0() {
        t0(f0.PORTRAIT);
    }

    private final void u0() {
        d9.a.f15931a.g((getResources().getConfiguration().uiMode & 48) == 32 ? "Dark mode" : "Light mode");
    }

    private final void w0() {
        this.A = new k(new Handler(Looper.getMainLooper()));
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void x0(oj.a aVar) {
        try {
            oj.b bVar = this.C;
            if (bVar != null) {
                bVar.b(aVar, 1, this, 1000);
            }
        } catch (IntentSender.SendIntentException e10) {
            e10.printStackTrace();
        }
    }

    @Override // i.c
    public boolean L() {
        v4.j jVar;
        boolean z10;
        try {
            jVar = v4.a.a(this, h7.i.Y);
        } catch (Exception e10) {
            tr.a.f36618a.d(e10, e10.getMessage(), new Object[0]);
            jVar = null;
        }
        androidx.fragment.app.f i02 = i0();
        if (i02 != null) {
            boolean E = i02 instanceof u8.b ? ((u8.b) i02).E() : false;
            Bundle arguments = i02.getArguments();
            z10 = arguments != null ? arguments.getBoolean("displayProfileIcon") : false;
            r1 = E;
        } else {
            z10 = false;
        }
        if (r1) {
            return true;
        }
        boolean w02 = k0().w0(d());
        if ((jVar != null ? jVar.H() : null) != null) {
            jVar.U();
        } else if (getSupportFragmentManager().s0() > 0) {
            getSupportFragmentManager().g1();
        } else if (z10 && w02) {
            p0();
        } else {
            finish();
        }
        return true;
    }

    public void X(l8.h spinnerVM, Activity activity, u lifecycleOwner) {
        t.g(spinnerVM, "spinnerVM");
        t.g(activity, "activity");
        t.g(lifecycleOwner, "lifecycleOwner");
        this.f7893s.a(spinnerVM, activity, lifecycleOwner);
    }

    /* JADX INFO: Access modifiers changed from: protected */
    public final void Y() {
        Task a10;
        String d12;
        oj.b bVar = this.C;
        if (bVar == null || (a10 = bVar.a()) == null) {
            return;
        }
        String str = (String) k0().l0().f();
        if (str == null) {
            str = "0.0.0";
        }
        String h10 = f0().h();
        t.f(h10, "getBuildConfigVersionName(...)");
        d12 = z.d1(h10, ".", null, 2, null);
        final c cVar = new c(d12, str);
        a10.addOnSuccessListener(new OnSuccessListener() { // from class: o8.q
            @Override // com.google.android.gms.tasks.OnSuccessListener
            public final void onSuccess(Object obj) {
                ca.canadapost.core.common.navigation.ui.b.Z(dn.l.this, obj);
            }
        });
    }

    @Override // nm.e
    public nm.b a() {
        return g0();
    }

    public boolean b0(Context context, dn.a terminator) {
        t.g(context, "context");
        t.g(terminator, "terminator");
        return this.f7892r.a(context, terminator);
    }

    @Override // w8.p0
    public void c(Activity activity, h.b event) {
        t.g(activity, "activity");
        t.g(event, "event");
        this.f7893s.c(activity, event);
    }

    public final void c0() {
        i.a E;
        if (k0().w0(d()) || (E = E()) == null) {
            return;
        }
        E.u(true);
    }

    protected final e9.b e0() {
        e9.b bVar = this.f7898x;
        if (bVar != null) {
            return bVar;
        }
        t.y("adobeAnalytics");
        return null;
    }

    public final t7.c f0() {
        t7.c cVar = this.f7894t;
        if (cVar != null) {
            return cVar;
        }
        t.y("contextService");
        return null;
    }

    protected final nm.c g0() {
        nm.c cVar = this.f7895u;
        if (cVar != null) {
            return cVar;
        }
        t.y("dispatchingAndroidInjector");
        return null;
    }

    /* JADX INFO: Access modifiers changed from: protected */
    public final p9.h h0() {
        p9.h hVar = this.f7900z;
        if (hVar != null) {
            return hVar;
        }
        t.y("featureFlagRepo");
        return null;
    }

    /* JADX INFO: Access modifiers changed from: protected */
    public final h8.a j0() {
        h8.a aVar = this.f7899y;
        if (aVar != null) {
            return aVar;
        }
        t.y("maintenanceUtil");
        return null;
    }

    /* JADX INFO: Access modifiers changed from: protected */
    public final d0 k0() {
        return (d0) this.B.getValue();
    }

    /* JADX INFO: Access modifiers changed from: protected */
    public final q8.a l0() {
        q8.a aVar = this.f7897w;
        if (aVar != null) {
            return aVar;
        }
        t.y("permissionServices");
        return null;
    }

    public final Toolbar m0() {
        return this.D;
    }

    /* JADX INFO: Access modifiers changed from: protected */
    public final c1.c n0() {
        c1.c cVar = this.f7896v;
        if (cVar != null) {
            return cVar;
        }
        t.y("viewModelFactory");
        return null;
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // androidx.fragment.app.k, androidx.activity.h, android.app.Activity
    public void onActivityResult(int i10, int i11, Intent intent) {
        super.onActivityResult(i10, i11, intent);
        if (i10 != 1000 || i11 == -1) {
            return;
        }
        Y();
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // androidx.fragment.app.k, androidx.activity.h, androidx.core.app.f, android.app.Activity
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        s0();
        w0();
        u0();
        j0.f4814x.a().getLifecycle().a(new f());
        this.C = oj.c.a(this);
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // androidx.activity.h, android.app.Activity
    public void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        j0().a(true);
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // androidx.fragment.app.k, android.app.Activity
    public void onPause() {
        super.onPause();
        e0().f();
        ContentResolver contentResolver = getContentResolver();
        ContentObserver contentObserver = this.A;
        if (contentObserver == null) {
            t.y("accessibilityContentObserver");
            contentObserver = null;
        }
        contentResolver.unregisterContentObserver(contentObserver);
    }

    @Override // androidx.fragment.app.k, androidx.activity.h, android.app.Activity
    public void onRequestPermissionsResult(int i10, String[] permissions, int[] grantResults) {
        t.g(permissions, "permissions");
        t.g(grantResults, "grantResults");
        super.onRequestPermissionsResult(i10, permissions, grantResults);
        l0().b(i10, permissions, grantResults);
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // androidx.fragment.app.k, android.app.Activity
    public void onResume() {
        super.onResume();
        a0();
        if (b0(this, new g())) {
            return;
        }
        ContentObserver contentObserver = null;
        e9.b.h(e0(), null, 1, null);
        k0().S0(d());
        ContentResolver contentResolver = getContentResolver();
        Uri uriFor = Settings.Secure.getUriFor("accessibility_enabled");
        ContentObserver contentObserver2 = this.A;
        if (contentObserver2 == null) {
            t.y("accessibilityContentObserver");
        } else {
            contentObserver = contentObserver2;
        }
        contentResolver.registerContentObserver(uriFor, false, contentObserver);
        c0();
        new w8.v(this, new h());
        X(k0(), this, this);
        k0().i0().j(this, new j(new i()));
        k0().f0();
        if (Build.VERSION.SDK_INT >= 35) {
            getWindow().setNavigationBarContrastEnforced(false);
        }
        Toolbar toolbar = this.D;
        if (toolbar != null) {
            w8.d0.k(toolbar);
        }
    }

    @Override // w8.p0
    public void p(androidx.fragment.app.f fragment, h.b event) {
        t.g(fragment, "fragment");
        t.g(event, "event");
        this.f7893s.p(fragment, event);
    }

    public void p0() {
    }

    public final void q0(int i10, final dn.l iconClickListener) {
        t.g(iconClickListener, "iconClickListener");
        Toolbar toolbar = this.D;
        if (toolbar != null) {
            toolbar.setNavigationIcon(i10);
        }
        final Toolbar toolbar2 = this.D;
        if (toolbar2 != null) {
            toolbar2.setNavigationOnClickListener(new View.OnClickListener() { // from class: o8.p
                @Override // android.view.View.OnClickListener
                public final void onClick(View view) {
                    ca.canadapost.core.common.navigation.ui.b.r0(dn.l.this, toolbar2, this, view);
                }
            });
        }
    }

    @Override // android.app.Activity
    public void setTitle(CharSequence charSequence) {
        if (this.E == null) {
            if (E() == null) {
                super.setTitle(charSequence);
                return;
            }
            i.a E = E();
            if (E == null) {
                return;
            }
            E.A(charSequence);
            return;
        }
        super.setTitle("");
        TextView textView = this.E;
        if (textView != null) {
            textView.setText(charSequence);
        }
        TextView textView2 = this.E;
        if (textView2 == null) {
            return;
        }
        textView2.setContentDescription(getString(h7.l.f21242z3, charSequence));
    }

    public void t0(f0 orientation) {
        t.g(orientation, "orientation");
        int i10 = C0206b.f7901a[orientation.ordinal()];
        int i11 = 1;
        if (i10 != 1) {
            i11 = 2;
            if (i10 == 2) {
                i11 = 0;
            }
        }
        setRequestedOrientation(i11);
    }

    public final void v0(Toolbar toolbar) {
        this.D = toolbar;
    }
}
