function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { useNavigation } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import React, { useCallback } from 'react';
import { useTranslation } from 'react-i18next';
import { TOKENS, useServices } from '../container-api';
import { DispatchAction } from '../contexts/reducers/store';
import { useStore } from '../contexts/store';
import { useTheme } from '../contexts/theme';
import AttemptLockout from '../screens/AttemptLockout';
import NameWallet from '../screens/NameWallet';
import { createCarouselStyle } from '../screens/OnboardingPages';
import PINCreate from '../screens/PINCreate';
import PINEnter from '../screens/PINEnter';
import PushNotification from '../screens/PushNotification';
import { Screens } from '../types/navigators';
import { useDefaultStackOptions } from './defaultStackOptions';
const OnboardingStack = () => {
  const [, dispatch] = useStore();
  const {
    t
  } = useTranslation();
  const Stack = createStackNavigator();
  const theme = useTheme();
  const OnboardingTheme = theme.OnboardingTheme;
  const carousel = createCarouselStyle(OnboardingTheme);
  const [splash, pages, useBiometry, Onboarding, Developer, {
    screen: Terms
  }, onTutorialCompletedCurried, ScreenOptionsDictionary, Preface] = useServices([TOKENS.SCREEN_SPLASH, TOKENS.SCREEN_ONBOARDING_PAGES, TOKENS.SCREEN_USE_BIOMETRY, TOKENS.SCREEN_ONBOARDING, TOKENS.SCREEN_DEVELOPER, TOKENS.SCREEN_TERMS, TOKENS.FN_ONBOARDING_DONE, TOKENS.OBJECT_SCREEN_CONFIG, TOKENS.SCREEN_PREFACE]);
  const defaultStackOptions = useDefaultStackOptions(theme);
  const navigation = useNavigation();
  const onTutorialCompleted = onTutorialCompletedCurried(dispatch, navigation);
  const [{
    disableOnboardingSkip
  }] = useServices([TOKENS.CONFIG]);
  const onAuthenticated = useCallback(status => {
    if (!status) {
      return;
    }
    dispatch({
      type: DispatchAction.DID_AUTHENTICATE
    });
  }, [dispatch]);
  const OnBoardingScreen = () => {
    return /*#__PURE__*/React.createElement(Onboarding, {
      nextButtonText: t('Global.Next'),
      previousButtonText: t('Global.Back'),
      disableSkip: disableOnboardingSkip,
      pages: pages(onTutorialCompleted, OnboardingTheme),
      style: carousel
    });
  };

  // these need to be in the children of the stack screen otherwise they will unmount/remount which resets the component state in memory and causes issues
  const CreatePINScreen = props => {
    return /*#__PURE__*/React.createElement(PINCreate, _extends({
      setAuthenticated: onAuthenticated
    }, props));
  };
  const EnterPINScreen = props => {
    return /*#__PURE__*/React.createElement(PINEnter, _extends({
      setAuthenticated: onAuthenticated
    }, props));
  };
  const screens = [{
    name: Screens.Preface,
    component: Preface,
    options: () => {
      return {
        ...ScreenOptionsDictionary[Screens.Preface],
        title: t('Screens.Preface')
      };
    }
  }, {
    name: Screens.Splash,
    component: splash,
    options: ScreenOptionsDictionary[Screens.Splash]
  }, {
    name: Screens.Onboarding,
    children: OnBoardingScreen,
    options: () => {
      return {
        ...ScreenOptionsDictionary[Screens.Onboarding],
        title: t('Screens.Onboarding'),
        headerLeft: () => false
      };
    }
  }, {
    name: Screens.Terms,
    options: () => ({
      ...ScreenOptionsDictionary[Screens.Terms],
      title: t('Screens.Terms'),
      headerLeft: () => false
    }),
    component: Terms
  }, {
    name: Screens.CreatePIN,
    children: CreatePINScreen,
    initialParams: {},
    options: () => ({
      ...ScreenOptionsDictionary[Screens.CreatePIN],
      title: t('Screens.CreatePIN'),
      headerLeft: () => false
    })
  }, {
    name: Screens.NameWallet,
    options: () => ({
      ...ScreenOptionsDictionary[Screens.NameWallet],
      title: t('Screens.NameWallet'),
      headerLeft: () => false
    }),
    component: NameWallet
  }, {
    name: Screens.UseBiometry,
    options: () => ({
      ...ScreenOptionsDictionary[Screens.UseBiometry],
      title: t('Screens.Biometry'),
      headerLeft: () => false
    }),
    component: useBiometry
  }, {
    name: Screens.UsePushNotifications,
    options: () => ({
      ...ScreenOptionsDictionary[Screens.UsePushNotifications],
      title: t('Screens.UsePushNotifications'),
      headerLeft: () => false
    }),
    children: PushNotification
  }, {
    name: Screens.Developer,
    component: Developer,
    options: () => {
      return {
        ...ScreenOptionsDictionary[Screens.Developer],
        title: t('Screens.Developer'),
        headerBackAccessibilityLabel: t('Global.Back')
      };
    }
  }, {
    name: Screens.EnterPIN,
    children: EnterPINScreen,
    options: () => {
      return {
        title: t('Screens.EnterPIN'),
        headerShown: true,
        headerLeft: () => false,
        rightLeft: () => false
      };
    }
  }, {
    name: Screens.AttemptLockout,
    component: AttemptLockout,
    options: () => ({
      headerShown: true,
      headerLeft: () => null,
      title: t('Screens.AttemptLockout')
    })
  }];
  return /*#__PURE__*/React.createElement(Stack.Navigator, {
    initialRouteName: Screens.Splash,
    screenOptions: {
      ...defaultStackOptions
    }
  }, screens.map(item => {
    return /*#__PURE__*/React.createElement(Stack.Screen, _extends({
      key: item.name
    }, item));
  }));
};
export default OnboardingStack;
//# sourceMappingURL=OnboardingStack.js.map