"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _bottomTabs = require("@react-navigation/bottom-tabs");
var _react = _interopRequireWildcard(require("react"));
var _reactI18next = require("react-i18next");
var _reactNative = require("react-native");
var _reactNativeDeviceInfo = require("react-native-device-info");
var _reactNativeOrientationLocker = require("react-native-orientation-locker");
var _reactNativeSafeAreaContext = require("react-native-safe-area-context");
var _MaterialCommunityIcons = _interopRequireDefault(require("react-native-vector-icons/MaterialCommunityIcons"));
var _AttachTourStep = require("../components/tour/AttachTourStep");
var _configuration = require("../contexts/configuration");
var _network = require("../contexts/network");
var _theme = require("../contexts/theme");
var _navigators = require("../types/navigators");
var _tour = require("../types/tour");
var _testable = require("../utils/testable");
var _CredentialStack = _interopRequireDefault(require("./CredentialStack"));
var _HomeStack = _interopRequireDefault(require("./HomeStack"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
const TabStack = () => {
  const {
    fontScale
  } = (0, _reactNative.useWindowDimensions)();
  const {
    useCustomNotifications
  } = (0, _configuration.useConfiguration)();
  const {
    total
  } = useCustomNotifications();
  const {
    t
  } = (0, _reactI18next.useTranslation)();
  const Tab = (0, _bottomTabs.createBottomTabNavigator)();
  const {
    assertConnectedNetwork
  } = (0, _network.useNetwork)();
  const {
    ColorPallet,
    TabTheme,
    TextTheme
  } = (0, _theme.useTheme)();
  const [orientation, setOrientation] = (0, _react.useState)(_reactNativeOrientationLocker.OrientationType.PORTRAIT);
  const showLabels = fontScale * TabTheme.tabBarTextStyle.fontSize < 18;
  const styles = _reactNative.StyleSheet.create({
    tabBarIcon: {
      flex: 1
    }
  });
  (0, _reactNativeOrientationLocker.useOrientationChange)(orientationType => {
    setOrientation(orientationType);
  });
  const leftMarginForDevice = () => {
    if ((0, _reactNativeDeviceInfo.isTablet)()) {
      return orientation in [_reactNativeOrientationLocker.OrientationType.PORTRAIT, _reactNativeOrientationLocker.OrientationType['PORTRAIT-UPSIDEDOWN']] ? 130 : 170;
    }
    return 0;
  };
  return /*#__PURE__*/_react.default.createElement(_reactNativeSafeAreaContext.SafeAreaView, {
    style: {
      flex: 1,
      backgroundColor: ColorPallet.brand.primary
    }
  }, /*#__PURE__*/_react.default.createElement(Tab.Navigator, {
    screenOptions: {
      unmountOnBlur: true,
      tabBarStyle: {
        ...TabTheme.tabBarStyle
      },
      tabBarActiveTintColor: TabTheme.tabBarActiveTintColor,
      tabBarInactiveTintColor: TabTheme.tabBarInactiveTintColor,
      header: () => null
    }
  }, /*#__PURE__*/_react.default.createElement(Tab.Screen, {
    name: _navigators.TabStacks.HomeStack,
    component: _HomeStack.default,
    options: {
      tabBarIconStyle: styles.tabBarIcon,
      tabBarIcon: _ref => {
        let {
          color,
          focused
        } = _ref;
        return /*#__PURE__*/_react.default.createElement(_AttachTourStep.AttachTourStep, {
          tourID: _tour.TourID.HomeTour,
          index: 1
        }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
          style: {
            ...TabTheme.tabBarContainerStyle,
            justifyContent: showLabels ? 'flex-end' : 'center'
          }
        }, /*#__PURE__*/_react.default.createElement(_MaterialCommunityIcons.default, {
          name: focused ? 'message-text' : 'message-text-outline',
          color: color,
          size: 30
        }), showLabels && /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
          style: {
            ...TabTheme.tabBarTextStyle,
            color: focused ? TabTheme.tabBarActiveTintColor : TabTheme.tabBarInactiveTintColor,
            fontWeight: focused ? TextTheme.bold.fontWeight : TextTheme.normal.fontWeight
          }
        }, t('TabStack.Home'))));
      },
      tabBarShowLabel: false,
      tabBarAccessibilityLabel: `${t('TabStack.Home')} (${total ?? 0})`,
      tabBarTestID: (0, _testable.testIdWithKey)(t('TabStack.Home')),
      tabBarBadge: total || undefined,
      tabBarBadgeStyle: {
        marginLeft: leftMarginForDevice(),
        backgroundColor: ColorPallet.semantic.error
      }
    }
  }), /*#__PURE__*/_react.default.createElement(Tab.Screen, {
    name: _navigators.TabStacks.ConnectStack,
    options: {
      tabBarIconStyle: styles.tabBarIcon,
      tabBarIcon: _ref2 => {
        let {
          focused
        } = _ref2;
        return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
          style: {
            position: 'relative',
            flex: 1,
            width: 90
          }
        }, /*#__PURE__*/_react.default.createElement(_AttachTourStep.AttachTourStep, {
          tourID: _tour.TourID.HomeTour,
          index: 0,
          fill: true
        }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
          style: {
            position: 'absolute',
            flexGrow: 1,
            width: 90,
            bottom: 0,
            minHeight: 90,
            margin: 'auto'
          }
        }, /*#__PURE__*/_react.default.createElement(_AttachTourStep.AttachTourStep, {
          tourID: _tour.TourID.CredentialsTour,
          index: 0,
          fill: true
        }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
          style: {
            flexGrow: 1,
            justifyContent: 'flex-end',
            alignItems: 'center'
          }
        }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
          accessible: true,
          accessibilityRole: 'button',
          accessibilityLabel: t('TabStack.Scan'),
          style: {
            ...TabTheme.focusTabIconStyle
          }
        }, /*#__PURE__*/_react.default.createElement(_MaterialCommunityIcons.default, {
          accessible: false,
          name: "qrcode-scan",
          color: TabTheme.tabBarButtonIconStyle.color,
          size: 32,
          style: {
            paddingLeft: 0.5,
            paddingTop: 0.5
          }
        })), /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
          style: {
            ...TabTheme.tabBarTextStyle,
            color: focused ? TabTheme.tabBarActiveTintColor : TabTheme.tabBarInactiveTintColor,
            marginTop: 5
          }
        }, t('TabStack.Scan')))))));
      },
      tabBarShowLabel: false,
      tabBarAccessibilityLabel: t('TabStack.Scan'),
      tabBarTestID: (0, _testable.testIdWithKey)(t('TabStack.Scan'))
    },
    listeners: _ref3 => {
      let {
        navigation
      } = _ref3;
      return {
        tabPress: e => {
          e.preventDefault();
          if (!assertConnectedNetwork()) {
            return;
          }
          navigation.navigate(_navigators.Stacks.ConnectStack, {
            screen: _navigators.Screens.Scan
          });
        }
      };
    }
  }, () => /*#__PURE__*/_react.default.createElement(_reactNative.View, null)), /*#__PURE__*/_react.default.createElement(Tab.Screen, {
    name: _navigators.TabStacks.CredentialStack,
    component: _CredentialStack.default,
    options: {
      tabBarIconStyle: styles.tabBarIcon,
      tabBarIcon: _ref4 => {
        let {
          color,
          focused
        } = _ref4;
        return /*#__PURE__*/_react.default.createElement(_AttachTourStep.AttachTourStep, {
          tourID: _tour.TourID.HomeTour,
          index: 2
        }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
          style: {
            ...TabTheme.tabBarContainerStyle,
            justifyContent: showLabels ? 'flex-end' : 'center'
          }
        }, /*#__PURE__*/_react.default.createElement(_MaterialCommunityIcons.default, {
          name: focused ? 'wallet' : 'wallet-outline',
          color: color,
          size: 30
        }), showLabels && /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
          style: {
            ...TabTheme.tabBarTextStyle,
            color: focused ? TabTheme.tabBarActiveTintColor : TabTheme.tabBarInactiveTintColor,
            fontWeight: focused ? TextTheme.bold.fontWeight : TextTheme.normal.fontWeight
          }
        }, t('TabStack.Credentials'))));
      },
      tabBarShowLabel: false,
      tabBarAccessibilityLabel: t('TabStack.Credentials'),
      tabBarTestID: (0, _testable.testIdWithKey)(t('TabStack.Credentials'))
    }
  })));
};
var _default = TabStack;
exports.default = _default;
//# sourceMappingURL=TabStack.js.map