"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _core = require("@react-navigation/core");
var _stack = require("@react-navigation/stack");
var _react = _interopRequireDefault(require("react"));
var _reactI18next = require("react-i18next");
var _containerApi = require("../container-api");
var _configuration = require("../contexts/configuration");
var _store = require("../contexts/reducers/store");
var _store2 = require("../contexts/store");
var _theme = require("../contexts/theme");
var _NameWallet = _interopRequireDefault(require("../screens/NameWallet"));
var _OnboardingPages = require("../screens/OnboardingPages");
var _PINCreate = _interopRequireDefault(require("../screens/PINCreate"));
var _navigators = require("../types/navigators");
var _testable = require("../utils/testable");
var _defaultStackOptions = require("./defaultStackOptions");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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); }
const OnboardingStack = () => {
  const [, dispatch] = (0, _store2.useStore)();
  const {
    t
  } = (0, _reactI18next.useTranslation)();
  const container = (0, _containerApi.useContainer)();
  const Stack = (0, _stack.createStackNavigator)();
  const theme = (0, _theme.useTheme)();
  const OnboardingTheme = theme.OnboardingTheme;
  const carousel = (0, _OnboardingPages.createCarouselStyle)(OnboardingTheme);
  const Onboarding = container.resolve(_containerApi.TOKENS.SCREEN_ONBOARDING);
  const {
    pages,
    splash,
    useBiometry
  } = (0, _configuration.useConfiguration)();
  const defaultStackOptions = (0, _defaultStackOptions.createDefaultStackOptions)(theme);
  const navigation = (0, _core.useNavigation)();
  const onTutorialCompleted = container.resolve(_containerApi.TOKENS.FN_ONBOARDING_DONE)(dispatch, navigation);
  const Terms = container.resolve(_containerApi.TOKENS.SCREEN_TERMS);
  const Developer = container.resolve(_containerApi.TOKENS.SCREEN_DEVELOPER);
  const Preface = container.resolve(_containerApi.TOKENS.SCREEN_PREFACE);
  const onAuthenticated = status => {
    if (!status) {
      return;
    }
    dispatch({
      type: _store.DispatchAction.DID_AUTHENTICATE
    });
  };
  const OnBoardingScreen = () => {
    return /*#__PURE__*/_react.default.createElement(Onboarding, {
      nextButtonText: t('Global.Next'),
      previousButtonText: t('Global.Back'),
      disableSkip: true,
      pages: pages(onTutorialCompleted, OnboardingTheme),
      style: carousel
    });
  };
  const CreatePINScreen = props => {
    return /*#__PURE__*/_react.default.createElement(_PINCreate.default, _extends({
      setAuthenticated: onAuthenticated
    }, props));
  };
  const screens = [{
    name: _navigators.Screens.Preface,
    component: Preface,
    options: () => {
      return {
        title: t('Screens.Preface'),
        headerTintColor: OnboardingTheme.headerTintColor,
        headerShown: true,
        headerLeft: () => false
      };
    }
  }, {
    name: _navigators.Screens.Splash,
    component: splash
  }, {
    name: _navigators.Screens.Onboarding,
    component: OnBoardingScreen,
    options: () => {
      return {
        title: t('Screens.Onboarding'),
        headerTintColor: OnboardingTheme.headerTintColor,
        headerShown: true,
        gestureEnabled: false,
        headerLeft: () => false
      };
    }
  }, {
    name: _navigators.Screens.Terms,
    options: () => ({
      title: t('Screens.Terms'),
      headerTintColor: OnboardingTheme.headerTintColor,
      headerShown: true,
      headerLeft: () => false,
      rightLeft: () => false
    }),
    component: Terms
  }, {
    name: _navigators.Screens.CreatePIN,
    component: CreatePINScreen,
    initialParams: {},
    options: () => ({
      title: t('Screens.CreatePIN'),
      headerShown: true,
      headerLeft: () => false,
      rightLeft: () => false
    })
  }, {
    name: _navigators.Screens.NameWallet,
    options: () => ({
      title: t('Screens.NameWallet'),
      headerTintColor: OnboardingTheme.headerTintColor,
      headerShown: true,
      headerLeft: () => false,
      rightLeft: () => false
    }),
    component: _NameWallet.default
  }, {
    name: _navigators.Screens.UseBiometry,
    options: () => ({
      title: t('Screens.Biometry'),
      headerTintColor: OnboardingTheme.headerTintColor,
      headerShown: true,
      headerLeft: () => false,
      rightLeft: () => false
    }),
    component: useBiometry
  }, {
    name: _navigators.Screens.Developer,
    component: Developer,
    options: () => {
      return {
        title: t('Screens.Developer'),
        headerTintColor: OnboardingTheme.headerTintColor,
        headerShown: true,
        headerBackAccessibilityLabel: t('Global.Back'),
        headerBackTestID: (0, _testable.testIdWithKey)('Back')
      };
    }
  }];
  return /*#__PURE__*/_react.default.createElement(Stack.Navigator, {
    initialRouteName: _navigators.Screens.Splash,
    screenOptions: {
      ...defaultStackOptions,
      headerShown: false
    }
  }, screens.map(item => {
    return /*#__PURE__*/_react.default.createElement(Stack.Screen, _extends({
      key: item.name
    }, item));
  }));
};
var _default = OnboardingStack;
exports.default = _default;
//# sourceMappingURL=OnboardingStack.js.map