function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { useNavigation } from '@react-navigation/core';
import { createStackNavigator } from '@react-navigation/stack';
import React from 'react';
import { useTranslation } from 'react-i18next';
import { TOKENS, useContainer } from '../container-api';
import { useConfiguration } from '../contexts/configuration';
import { DispatchAction } from '../contexts/reducers/store';
import { useStore } from '../contexts/store';
import { useTheme } from '../contexts/theme';
import NameWallet from '../screens/NameWallet';
import { createCarouselStyle } from '../screens/OnboardingPages';
import PINCreate from '../screens/PINCreate';
import { Screens } from '../types/navigators';
import { testIdWithKey } from '../utils/testable';
import { createDefaultStackOptions } from './defaultStackOptions';
const OnboardingStack = () => {
  const [, dispatch] = useStore();
  const {
    t
  } = useTranslation();
  const container = useContainer();
  const Stack = createStackNavigator();
  const theme = useTheme();
  const OnboardingTheme = theme.OnboardingTheme;
  const carousel = createCarouselStyle(OnboardingTheme);
  const Onboarding = container.resolve(TOKENS.SCREEN_ONBOARDING);
  const {
    pages,
    splash,
    useBiometry
  } = useConfiguration();
  const defaultStackOptions = createDefaultStackOptions(theme);
  const navigation = useNavigation();
  const onTutorialCompleted = container.resolve(TOKENS.FN_ONBOARDING_DONE)(dispatch, navigation);
  const Terms = container.resolve(TOKENS.SCREEN_TERMS);
  const Developer = container.resolve(TOKENS.SCREEN_DEVELOPER);
  const Preface = container.resolve(TOKENS.SCREEN_PREFACE);
  const onAuthenticated = status => {
    if (!status) {
      return;
    }
    dispatch({
      type: DispatchAction.DID_AUTHENTICATE
    });
  };
  const OnBoardingScreen = () => {
    return /*#__PURE__*/React.createElement(Onboarding, {
      nextButtonText: t('Global.Next'),
      previousButtonText: t('Global.Back'),
      disableSkip: true,
      pages: pages(onTutorialCompleted, OnboardingTheme),
      style: carousel
    });
  };
  const CreatePINScreen = props => {
    return /*#__PURE__*/React.createElement(PINCreate, _extends({
      setAuthenticated: onAuthenticated
    }, props));
  };
  const screens = [{
    name: Screens.Preface,
    component: Preface,
    options: () => {
      return {
        title: t('Screens.Preface'),
        headerTintColor: OnboardingTheme.headerTintColor,
        headerShown: true,
        headerLeft: () => false
      };
    }
  }, {
    name: Screens.Splash,
    component: splash
  }, {
    name: Screens.Onboarding,
    component: OnBoardingScreen,
    options: () => {
      return {
        title: t('Screens.Onboarding'),
        headerTintColor: OnboardingTheme.headerTintColor,
        headerShown: true,
        gestureEnabled: false,
        headerLeft: () => false
      };
    }
  }, {
    name: Screens.Terms,
    options: () => ({
      title: t('Screens.Terms'),
      headerTintColor: OnboardingTheme.headerTintColor,
      headerShown: true,
      headerLeft: () => false,
      rightLeft: () => false
    }),
    component: Terms
  }, {
    name: Screens.CreatePIN,
    component: CreatePINScreen,
    initialParams: {},
    options: () => ({
      title: t('Screens.CreatePIN'),
      headerShown: true,
      headerLeft: () => false,
      rightLeft: () => false
    })
  }, {
    name: Screens.NameWallet,
    options: () => ({
      title: t('Screens.NameWallet'),
      headerTintColor: OnboardingTheme.headerTintColor,
      headerShown: true,
      headerLeft: () => false,
      rightLeft: () => false
    }),
    component: NameWallet
  }, {
    name: Screens.UseBiometry,
    options: () => ({
      title: t('Screens.Biometry'),
      headerTintColor: OnboardingTheme.headerTintColor,
      headerShown: true,
      headerLeft: () => false,
      rightLeft: () => false
    }),
    component: useBiometry
  }, {
    name: Screens.Developer,
    component: Developer,
    options: () => {
      return {
        title: t('Screens.Developer'),
        headerTintColor: OnboardingTheme.headerTintColor,
        headerShown: true,
        headerBackAccessibilityLabel: t('Global.Back'),
        headerBackTestID: testIdWithKey('Back')
      };
    }
  }];
  return /*#__PURE__*/React.createElement(Stack.Navigator, {
    initialRouteName: Screens.Splash,
    screenOptions: {
      ...defaultStackOptions,
      headerShown: false
    }
  }, screens.map(item => {
    return /*#__PURE__*/React.createElement(Stack.Screen, _extends({
      key: item.name
    }, item));
  }));
};
export default OnboardingStack;
//# sourceMappingURL=OnboardingStack.js.map