package ca.canadapost.module.mymail.onboarding;

import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.appcompat.widget.Toolbar;
import androidx.core.view.h1;
import androidx.core.view.s0;
import androidx.fragment.app.p0;
import androidx.lifecycle.c1;
import androidx.lifecycle.d1;
import androidx.lifecycle.e1;
import androidx.lifecycle.u;
import androidx.lifecycle.z0;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager2.widget.ViewPager2;
import ca.canadapost.core.common.navigation.ui.d;
import ca.canadapost.core.data.mymail.model.MyMailStatus;
import ca.canadapost.module.mymail.onboarding.MyMailOnBoardingFragment;
import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.d;
import dn.l;
import java.util.List;
import kotlin.Metadata;
import kotlin.jvm.internal.n;
import kotlin.jvm.internal.t;
import kotlin.jvm.internal.v;
import o8.g0;
import o8.h0;
import rm.n0;
import rm.o;
import u7.x;
import yd.j;
import yd.k;

@Metadata(d1 = {"\u0000~\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u000b\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u000e\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0007\n\u0002\u0018\u0002\n\u0002\b\n\u0018\u00002\u00020\u00012\b\u0012\u0004\u0012\u00020\u00030\u00022\u00020\u0004B\u0007¢\u0006\u0004\b6\u00107J5\u0010\u0010\u001a\u00020\u000f2\u0006\u0010\u0006\u001a\u00020\u00052\b\u0010\b\u001a\u0004\u0018\u00010\u00072\b\u0010\n\u001a\u0004\u0018\u00010\t2\u0006\u0010\f\u001a\u00020\u000b2\u0006\u0010\u000e\u001a\u00020\rH\u0096\u0001J#\u0010\u0018\u001a\u00020\u00172\u0006\u0010\u0012\u001a\u00020\u00112\u0006\u0010\u0014\u001a\u00020\u00132\b\b\u0002\u0010\u0016\u001a\u00020\u0015H\u0096\u0001J#\u0010\u001b\u001a\u00020\u00172\u0006\u0010\u0012\u001a\u00020\u00112\u0006\u0010\u001a\u001a\u00020\u00192\b\b\u0002\u0010\u0016\u001a\u00020\u0015H\u0096\u0001J$\u0010\u001c\u001a\u00020\u000f2\u0006\u0010\u0006\u001a\u00020\u00052\b\u0010\b\u001a\u0004\u0018\u00010\u00072\b\u0010\n\u001a\u0004\u0018\u00010\tH\u0016J\u0012\u0010\u001e\u001a\u00020\u001d2\b\u0010\n\u001a\u0004\u0018\u00010\tH\u0016J\u001a\u0010 \u001a\u00020\u00172\u0006\u0010\u001f\u001a\u00020\u000f2\b\u0010\n\u001a\u0004\u0018\u00010\tH\u0016J\n\u0010\"\u001a\u0004\u0018\u00010!H\u0016J\b\u0010$\u001a\u00020#H\u0016J\b\u0010%\u001a\u00020\u0017H\u0016R\"\u0010-\u001a\u00020&8\u0006@\u0006X\u0087.¢\u0006\u0012\n\u0004\b'\u0010(\u001a\u0004\b)\u0010*\"\u0004\b+\u0010,R\u001b\u0010\u000e\u001a\u00020.8BX\u0082\u0084\u0002¢\u0006\f\n\u0004\b/\u00100\u001a\u0004\b1\u00102R\u0014\u00105\u001a\u00020\u00038\u0016X\u0096\u0005¢\u0006\u0006\u001a\u0004\b3\u00104¨\u00068"}, d2 = {"Lca/canadapost/module/mymail/onboarding/MyMailOnBoardingFragment;", "Lca/canadapost/core/common/ui/b;", "", "Lae/c;", "Lca/canadapost/core/common/navigation/ui/d;", "Landroid/view/LayoutInflater;", "inflater", "Landroid/view/ViewGroup;", "container", "Landroid/os/Bundle;", "savedInstanceState", "Landroidx/lifecycle/u;", "viewLifecycleOwner", "Landroidx/lifecycle/z0;", "viewModel", "Landroid/view/View;", "O", "Lo8/h0;", "profileNavigationVMHandler", "Landroidx/fragment/app/f;", "fragment", "", "showTwoSv", "Lrm/n0;", "f", "Landroidx/fragment/app/k;", "activity", "b", "onCreateView", "Landroid/app/Dialog;", "onCreateDialog", "view", "onViewCreated", "Landroidx/appcompat/widget/Toolbar;", "C", "", "B", "D", "Landroidx/lifecycle/c1$c;", "r", "Landroidx/lifecycle/c1$c;", "M", "()Landroidx/lifecycle/c1$c;", "setViewModelFactory", "(Landroidx/lifecycle/c1$c;)V", "viewModelFactory", "Lge/f;", "s", "Lrm/o;", "L", "()Lge/f;", "K", "()Lae/c;", "binding", "<init>", "()V", "mymail_productionRelease"}, k = 1, mv = {1, 9, 0})
/* loaded from: classes4.dex */
public final class MyMailOnBoardingFragment extends ca.canadapost.core.common.ui.b implements ca.canadapost.core.common.navigation.ui.d {

    /* renamed from: r, reason: collision with root package name and from kotlin metadata */
    public c1.c viewModelFactory;

    /* renamed from: p, reason: collision with root package name */
    private final /* synthetic */ x f10392p = new x(j.f52312b);

    /* renamed from: q, reason: collision with root package name */
    private final /* synthetic */ g0 f10393q = new g0();

    /* renamed from: s, reason: collision with root package name and from kotlin metadata */
    private final o viewModel = p0.a(this, kotlin.jvm.internal.p0.b(ge.f.class), new h(new g(this)), new i());

    /* loaded from: classes4.dex */
    public static final class a extends ViewPager2.i {

        /* renamed from: b, reason: collision with root package name */
        final /* synthetic */ String[] f10397b;

        a(String[] strArr) {
            this.f10397b = strArr;
        }

        @Override // androidx.viewpager2.widget.ViewPager2.i
        public void c(int i10) {
            super.c(i10);
            MyMailOnBoardingFragment.this.K().C.setText(this.f10397b[i10]);
            MyMailOnBoardingFragment.this.L().n0(i10);
        }
    }

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

        public final void a(MyMailStatus myMailStatus) {
            if (myMailStatus == MyMailStatus.LOGGED_OUT) {
                MyMailOnBoardingFragment.this.requireActivity().finish();
            }
        }

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

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

        public final void a(List list) {
            RecyclerView.h adapter = MyMailOnBoardingFragment.this.K().D.getAdapter();
            t.e(adapter, "null cannot be cast to non-null type ca.canadapost.core.common.databinding.databoundlists.DataBoundAdapter<ca.canadapost.core.common.databinding.databoundlists.IDataBoundView>");
            t.d(list);
            ((v7.a) adapter).M(list);
        }

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

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

        public final void a(n0 n0Var) {
            MyMailOnBoardingFragment.this.requireActivity().setResult(-1, new Intent());
            MyMailOnBoardingFragment.this.requireActivity().finish();
        }

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

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

        public final void a(n0 n0Var) {
            MyMailOnBoardingFragment.this.requireActivity().finish();
        }

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

    /* loaded from: classes4.dex */
    static final class f implements androidx.lifecycle.g0, n {

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

        f(l function) {
            t.g(function, "function");
            this.f10402a = function;
        }

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

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

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

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

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

        /* renamed from: p, reason: collision with root package name */
        final /* synthetic */ androidx.fragment.app.f f10403p;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public g(androidx.fragment.app.f fVar) {
            super(0);
            this.f10403p = fVar;
        }

        @Override // dn.a
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public final androidx.fragment.app.f invoke() {
            return this.f10403p;
        }
    }

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

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

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

        @Override // dn.a
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public final d1 invoke() {
            d1 viewModelStore = ((e1) this.f10404p.invoke()).getViewModelStore();
            t.f(viewModelStore, "ownerProducer().viewModelStore");
            return viewModelStore;
        }
    }

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

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

    /* JADX INFO: Access modifiers changed from: private */
    public final ge.f L() {
        return (ge.f) this.viewModel.getValue();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final boolean N(MyMailOnBoardingFragment this$0, DialogInterface dialogInterface, int i10, KeyEvent keyEvent) {
        t.g(this$0, "this$0");
        if (i10 != 4 || keyEvent.getAction() != 1) {
            return false;
        }
        this$0.D();
        return true;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void P(TabLayout.g gVar, int i10) {
        t.g(gVar, "<anonymous parameter 0>");
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void Q(View page, float f10) {
        t.g(page, "page");
        page.setScaleY(((1 - Math.abs(f10)) * 0.2f) + 0.8f);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final h1 R(View v10, h1 windowInsets) {
        t.g(v10, "v");
        t.g(windowInsets, "windowInsets");
        androidx.core.graphics.b f10 = windowInsets.f(h1.l.f());
        t.f(f10, "getInsets(...)");
        ViewGroup.LayoutParams layoutParams = v10.getLayoutParams();
        if (layoutParams == null) {
            throw new NullPointerException("null cannot be cast to non-null type android.view.ViewGroup.MarginLayoutParams");
        }
        ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) layoutParams;
        marginLayoutParams.bottomMargin = f10.f3727d;
        v10.setLayoutParams(marginLayoutParams);
        return h1.f3850b;
    }

    @Override // ca.canadapost.core.common.ui.b
    public String B() {
        String string = getString(k.f52348i);
        t.f(string, "getString(...)");
        return string;
    }

    @Override // ca.canadapost.core.common.ui.b
    public Toolbar C() {
        u7.c appBarBinding = K().A.getAppBarBinding();
        if (appBarBinding != null) {
            return appBarBinding.B;
        }
        return null;
    }

    @Override // ca.canadapost.core.common.ui.b
    public void D() {
        L().m0();
    }

    public ae.c K() {
        return (ae.c) this.f10392p.b();
    }

    public final c1.c M() {
        c1.c cVar = this.viewModelFactory;
        if (cVar != null) {
            return cVar;
        }
        t.y("viewModelFactory");
        return null;
    }

    public View O(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState, u viewLifecycleOwner, z0 viewModel) {
        t.g(inflater, "inflater");
        t.g(viewLifecycleOwner, "viewLifecycleOwner");
        t.g(viewModel, "viewModel");
        return this.f10392p.c(inflater, container, savedInstanceState, viewLifecycleOwner, viewModel);
    }

    @Override // ca.canadapost.core.common.navigation.ui.d
    public void b(h0 profileNavigationVMHandler, androidx.fragment.app.k activity, boolean z10) {
        t.g(profileNavigationVMHandler, "profileNavigationVMHandler");
        t.g(activity, "activity");
        this.f10393q.b(profileNavigationVMHandler, activity, z10);
    }

    @Override // ca.canadapost.core.common.navigation.ui.d
    public void f(h0 profileNavigationVMHandler, androidx.fragment.app.f fragment, boolean z10) {
        t.g(profileNavigationVMHandler, "profileNavigationVMHandler");
        t.g(fragment, "fragment");
        this.f10393q.f(profileNavigationVMHandler, fragment, z10);
    }

    @Override // androidx.fragment.app.e
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        Dialog dialog = new Dialog(requireContext(), getTheme());
        dialog.setOnKeyListener(new DialogInterface.OnKeyListener() { // from class: ge.a
            @Override // android.content.DialogInterface.OnKeyListener
            public final boolean onKey(DialogInterface dialogInterface, int i10, KeyEvent keyEvent) {
                boolean N;
                N = MyMailOnBoardingFragment.N(MyMailOnBoardingFragment.this, dialogInterface, i10, keyEvent);
                return N;
            }
        });
        return dialog;
    }

    @Override // androidx.fragment.app.f
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        t.g(inflater, "inflater");
        u viewLifecycleOwner = getViewLifecycleOwner();
        t.f(viewLifecycleOwner, "getViewLifecycleOwner(...)");
        return O(inflater, container, savedInstanceState, viewLifecycleOwner, L());
    }

    @Override // ca.canadapost.core.common.ui.b, androidx.fragment.app.f
    public void onViewCreated(View view, Bundle bundle) {
        t.g(view, "view");
        super.onViewCreated(view, bundle);
        d.a.a(this, L(), this, false, 4, null);
        String[] stringArray = getResources().getStringArray(yd.e.f52267b);
        t.f(stringArray, "getStringArray(...)");
        View findViewById = K().x().findViewById(yd.i.f52302r);
        if (findViewById != null) {
            findViewById.setPadding(0, 0, 0, 0);
        }
        ViewPager2 viewPager2 = K().D;
        viewPager2.setClipChildren(false);
        viewPager2.setClipToPadding(false);
        viewPager2.setOffscreenPageLimit(2);
        K().D.setAdapter(new v7.a());
        new com.google.android.material.tabs.d(K().B, K().D, new d.b() { // from class: ge.b
            @Override // com.google.android.material.tabs.d.b
            public final void a(TabLayout.g gVar, int i10) {
                MyMailOnBoardingFragment.P(gVar, i10);
            }
        }).a();
        androidx.viewpager2.widget.c cVar = new androidx.viewpager2.widget.c();
        cVar.b(new androidx.viewpager2.widget.e((int) (40 * Resources.getSystem().getDisplayMetrics().density)));
        cVar.b(new ViewPager2.k() { // from class: ge.c
            @Override // androidx.viewpager2.widget.ViewPager2.k
            public final void a(View view2, float f10) {
                MyMailOnBoardingFragment.Q(view2, f10);
            }
        });
        K().D.setPageTransformer(cVar);
        K().D.g(new a(stringArray));
        K().C.setText(stringArray[0]);
        L().W().j(getViewLifecycleOwner(), new f(new b()));
        L().j0().j(getViewLifecycleOwner(), new f(new c()));
        L().l0().j(getViewLifecycleOwner(), new f(new d()));
        L().k0().j(getViewLifecycleOwner(), new f(new e()));
        if (Build.VERSION.SDK_INT >= 35) {
            s0.A0(K().B, new androidx.core.view.h0() { // from class: ge.d
                @Override // androidx.core.view.h0
                public final h1 a(View view2, h1 h1Var) {
                    h1 R;
                    R = MyMailOnBoardingFragment.R(view2, h1Var);
                    return R;
                }
            });
        }
    }
}
