package ca.canadapost.module.selfscan.onboarding;

import android.app.Dialog;
import android.content.Context;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.activity.p;
import androidx.activity.q;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.k;
import androidx.fragment.app.p0;
import androidx.lifecycle.c1;
import androidx.lifecycle.d1;
import androidx.lifecycle.e1;
import androidx.lifecycle.g0;
import androidx.lifecycle.u;
import androidx.lifecycle.z0;
import androidx.viewpager2.widget.ViewPager2;
import ca.canadapost.module.selfscan.onboarding.SelfScanOnBoardingDialogFragment;
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 rm.n0;
import rm.o;
import u7.x;

@Metadata(d1 = {"\u0000o\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0010\u0000\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\u0002\b\u0004\n\u0002\u0018\u0002\n\u0000\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\u0004\n\u0002\u0018\u0002\n\u0002\b\u0007\n\u0002\b\n*\u00011\u0018\u00002\u00020\u00012\b\u0012\u0004\u0012\u00020\u00030\u0002B\u0007¢\u0006\u0004\b8\u00109J\b\u0010\u0005\u001a\u00020\u0004H\u0002J5\u0010\u0011\u001a\u00020\u00102\u0006\u0010\u0007\u001a\u00020\u00062\b\u0010\t\u001a\u0004\u0018\u00010\b2\b\u0010\u000b\u001a\u0004\u0018\u00010\n2\u0006\u0010\r\u001a\u00020\f2\u0006\u0010\u000f\u001a\u00020\u000eH\u0096\u0001J$\u0010\u0012\u001a\u00020\u00102\u0006\u0010\u0007\u001a\u00020\u00062\b\u0010\t\u001a\u0004\u0018\u00010\b2\b\u0010\u000b\u001a\u0004\u0018\u00010\nH\u0016J\u001a\u0010\u0014\u001a\u00020\u00042\u0006\u0010\u0013\u001a\u00020\u00102\b\u0010\u000b\u001a\u0004\u0018\u00010\nH\u0016J\u0012\u0010\u0016\u001a\u00020\u00152\b\u0010\u000b\u001a\u0004\u0018\u00010\nH\u0016J\n\u0010\u0018\u001a\u0004\u0018\u00010\u0017H\u0016J\b\u0010\u001a\u001a\u00020\u0019H\u0016J\b\u0010\u001b\u001a\u00020\u0004H\u0016R\"\u0010#\u001a\u00020\u001c8\u0006@\u0006X\u0087.¢\u0006\u0012\n\u0004\b\u001d\u0010\u001e\u001a\u0004\b\u001f\u0010 \"\u0004\b!\u0010\"R\u001b\u0010\u000f\u001a\u00020$8BX\u0082\u0084\u0002¢\u0006\f\n\u0004\b%\u0010&\u001a\u0004\b'\u0010(R\"\u00100\u001a\u00020)8\u0006@\u0006X\u0087.¢\u0006\u0012\n\u0004\b*\u0010+\u001a\u0004\b,\u0010-\"\u0004\b.\u0010/R\u0014\u00104\u001a\u0002018\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b2\u00103R\u0014\u00107\u001a\u00020\u00038\u0016X\u0096\u0005¢\u0006\u0006\u001a\u0004\b5\u00106¨\u0006:"}, d2 = {"Lca/canadapost/module/selfscan/onboarding/SelfScanOnBoardingDialogFragment;", "Lca/canadapost/core/common/ui/b;", "", "Lbf/i;", "Lrm/n0;", "J", "Landroid/view/LayoutInflater;", "inflater", "Landroid/view/ViewGroup;", "container", "Landroid/os/Bundle;", "savedInstanceState", "Landroidx/lifecycle/u;", "viewLifecycleOwner", "Landroidx/lifecycle/z0;", "viewModel", "Landroid/view/View;", "N", "onCreateView", "view", "onViewCreated", "Landroid/app/Dialog;", "onCreateDialog", "Landroidx/appcompat/widget/Toolbar;", "C", "", "B", "D", "Landroidx/lifecycle/c1$c;", "q", "Landroidx/lifecycle/c1$c;", "M", "()Landroidx/lifecycle/c1$c;", "setViewModelFactory", "(Landroidx/lifecycle/c1$c;)V", "viewModelFactory", "Lff/d;", "r", "Lrm/o;", "L", "()Lff/d;", "Lp9/h;", "s", "Lp9/h;", "getFeatureFlagRepository", "()Lp9/h;", "setFeatureFlagRepository", "(Lp9/h;)V", "featureFlagRepository", "ca/canadapost/module/selfscan/onboarding/SelfScanOnBoardingDialogFragment$a", "t", "Lca/canadapost/module/selfscan/onboarding/SelfScanOnBoardingDialogFragment$a;", "onBackPressedCallback", "K", "()Lbf/i;", "binding", "<init>", "()V", "selfscan_productionRelease"}, k = 1, mv = {1, 9, 0})
/* loaded from: classes4.dex */
public final class SelfScanOnBoardingDialogFragment extends ca.canadapost.core.common.ui.b {

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

    /* renamed from: s, reason: collision with root package name and from kotlin metadata */
    public p9.h featureFlagRepository;

    /* renamed from: p, reason: collision with root package name */
    private final /* synthetic */ x f10724p = new x(af.d.f353e);

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

    /* renamed from: t, reason: collision with root package name and from kotlin metadata */
    private final a onBackPressedCallback = new a();

    /* loaded from: classes4.dex */
    public static final class a extends p {
        a() {
            super(true);
        }

        @Override // androidx.activity.p
        public void d() {
            SelfScanOnBoardingDialogFragment.this.J();
            j(false);
        }
    }

    /* loaded from: classes4.dex */
    public static final class b extends Dialog {
        b(Context context, int i10) {
            super(context, i10);
        }

        @Override // android.app.Dialog
        public void onBackPressed() {
            SelfScanOnBoardingDialogFragment.this.J();
        }
    }

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

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

        c(int i10) {
            this.f10732b = i10;
        }

        @Override // androidx.viewpager2.widget.ViewPager2.i
        public void c(int i10) {
            super.c(i10);
            SelfScanOnBoardingDialogFragment.this.L().Z(i10);
            if (i10 < this.f10732b - 1) {
                SelfScanOnBoardingDialogFragment.this.K().C.setText(SelfScanOnBoardingDialogFragment.this.requireActivity().getText(af.f.f368h));
            } else {
                SelfScanOnBoardingDialogFragment.this.K().C.setText(SelfScanOnBoardingDialogFragment.this.requireActivity().getText(af.f.f367g));
            }
        }
    }

    /* loaded from: classes4.dex */
    static final class d extends v implements l {

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

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

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        d(v7.a aVar, SelfScanOnBoardingDialogFragment selfScanOnBoardingDialogFragment) {
            super(1);
            this.f10733p = aVar;
            this.f10734q = selfScanOnBoardingDialogFragment;
        }

        public final void a(List list) {
            Object c02;
            v7.a aVar = this.f10733p;
            t.d(list);
            aVar.M(list);
            int tabCount = this.f10734q.K().D.getTabCount();
            if (tabCount < 0) {
                return;
            }
            int i10 = 0;
            while (true) {
                TabLayout.g v10 = this.f10734q.K().D.v(i10);
                c02 = sm.p.c0(this.f10734q.L().W(), i10);
                Integer num = (Integer) c02;
                if (num != null) {
                    int intValue = num.intValue();
                    if (v10 != null) {
                        v10.m(intValue);
                    }
                }
                if (i10 == tabCount) {
                    return;
                } else {
                    i10++;
                }
            }
        }

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

    /* loaded from: classes4.dex */
    static final class e extends v implements l {

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

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

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        e(int i10, SelfScanOnBoardingDialogFragment selfScanOnBoardingDialogFragment) {
            super(1);
            this.f10735p = i10;
            this.f10736q = selfScanOnBoardingDialogFragment;
        }

        public final void a(n0 n0Var) {
            if (this.f10735p != 0) {
                if (this.f10736q.K().E.getCurrentItem() >= this.f10735p - 1) {
                    this.f10736q.dismiss();
                } else {
                    ViewPager2 viewPager2 = this.f10736q.K().E;
                    viewPager2.setCurrentItem(viewPager2.getCurrentItem() + 1);
                }
            }
        }

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

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

        public final void a(n0 n0Var) {
            SelfScanOnBoardingDialogFragment.this.J();
        }

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

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

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

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

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

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

        public final boolean equals(Object obj) {
            if ((obj instanceof 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 h extends v implements dn.a {

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

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

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

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

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

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

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

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

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

    /* JADX INFO: Access modifiers changed from: private */
    public final void J() {
        if (L().S()) {
            requireActivity().finish();
        } else {
            dismiss();
        }
    }

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

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

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

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

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

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

    public bf.i K() {
        return (bf.i) this.f10724p.b();
    }

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

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

    @Override // androidx.fragment.app.e
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        return new b(requireContext(), getTheme());
    }

    @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 N(inflater, container, savedInstanceState, viewLifecycleOwner, L());
    }

    @Override // ca.canadapost.core.common.ui.b, androidx.fragment.app.f
    public void onViewCreated(View view, Bundle bundle) {
        q onBackPressedDispatcher;
        t.g(view, "view");
        super.onViewCreated(view, bundle);
        View findViewById = K().x().findViewById(af.c.f342t);
        if (findViewById != null) {
            findViewById.setPadding(0, 0, 0, 0);
        }
        List list = (List) L().T().f();
        int size = list != null ? list.size() : 1;
        K().E.setOffscreenPageLimit(size - 1);
        v7.a aVar = new v7.a();
        K().E.setAdapter(aVar);
        new com.google.android.material.tabs.d(K().D, K().E, new d.b() { // from class: ff.a
            @Override // com.google.android.material.tabs.d.b
            public final void a(TabLayout.g gVar, int i10) {
                SelfScanOnBoardingDialogFragment.O(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: ff.b
            @Override // androidx.viewpager2.widget.ViewPager2.k
            public final void a(View view2, float f10) {
                SelfScanOnBoardingDialogFragment.P(view2, f10);
            }
        });
        K().E.setPageTransformer(cVar);
        K().E.g(new c(size));
        L().T().j(getViewLifecycleOwner(), new g(new d(aVar, this)));
        L().V().j(getViewLifecycleOwner(), new g(new e(size, this)));
        L().U().j(getViewLifecycleOwner(), new g(new f()));
        k activity = getActivity();
        if (activity == null || (onBackPressedDispatcher = activity.getOnBackPressedDispatcher()) == null) {
            return;
        }
        u viewLifecycleOwner = getViewLifecycleOwner();
        t.f(viewLifecycleOwner, "getViewLifecycleOwner(...)");
        onBackPressedDispatcher.i(viewLifecycleOwner, this.onBackPressedCallback);
    }
}
