"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _reactNative = require("react-native");
var _reactNativeBouncyCheckbox = _interopRequireDefault(require("react-native-bouncy-checkbox"));
var _reactNativeSafeAreaContext = require("react-native-safe-area-context");
var _MaterialIcons = _interopRequireDefault(require("react-native-vector-icons/MaterialIcons"));
var _InactivityWrapper = require("../components/misc/InactivityWrapper");
var _testable = require("../utils/testable");
var _store = require("../contexts/store");
var _store2 = require("../contexts/reducers/store");
var _react = _interopRequireDefault(require("react"));
var _reactNativeGestureHandler = require("react-native-gesture-handler");
var _reactI18next = require("react-i18next");
var _theme = require("../contexts/theme");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const AutoLock = () => {
  const {
    t
  } = (0, _reactI18next.useTranslation)();
  const [store, dispatch] = (0, _store.useStore)();
  const {
    ColorPallet,
    SettingsTheme,
    TextTheme
  } = (0, _theme.useTheme)();
  const currentLockoutTime = store.preferences.autoLockTime ?? _InactivityWrapper.AutoLockTime.FiveMinutes;
  const styles = _reactNative.StyleSheet.create({
    container: {
      backgroundColor: ColorPallet.brand.primaryBackground,
      width: '100%'
    },
    section: {
      backgroundColor: SettingsTheme.groupBackground,
      paddingHorizontal: 25,
      paddingVertical: 16
    },
    sectionRow: {
      flexDirection: 'row',
      alignItems: 'center',
      justifyContent: 'space-between'
    },
    itemSeparator: {
      borderBottomWidth: 1,
      borderBottomColor: ColorPallet.brand.primaryBackground,
      marginHorizontal: 25
    },
    checkboxContainer: {
      justifyContent: 'center'
    }
  });
  const handleTimeoutChange = time => {
    dispatch({
      type: _store2.DispatchAction.AUTO_LOCK_TIME,
      payload: [time]
    });
  };
  const LockoutRow = ({
    title,
    value,
    selected,
    testID,
    onPress
  }) => /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: [styles.section, styles.sectionRow]
  }, /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
    style: TextTheme.title
  }, title), /*#__PURE__*/_react.default.createElement(_reactNative.Pressable, {
    style: styles.checkboxContainer,
    accessibilityLabel: title,
    accessibilityRole: 'checkbox',
    testID: (0, _testable.testIdWithKey)('ToggleConnectionInviterCapabilitySwitch')
  }, /*#__PURE__*/_react.default.createElement(_reactNativeBouncyCheckbox.default, {
    accessibilityLabel: String(_InactivityWrapper.AutoLockTime.FiveMinutes),
    disableText: true,
    fillColor: ColorPallet.brand.secondaryBackground,
    unfillColor: ColorPallet.brand.secondaryBackground,
    size: 36,
    innerIconStyle: {
      borderColor: ColorPallet.brand.primary,
      borderWidth: 2
    },
    ImageComponent: () => /*#__PURE__*/_react.default.createElement(_MaterialIcons.default, {
      name: "circle",
      size: 18,
      color: ColorPallet.brand.primary
    }),
    onPress: () => onPress(value),
    isChecked: selected,
    disableBuiltInState: true,
    testID: (0, _testable.testIdWithKey)(testID)
  })));
  return /*#__PURE__*/_react.default.createElement(_reactNativeSafeAreaContext.SafeAreaView, {
    style: styles.container
  }, /*#__PURE__*/_react.default.createElement(_reactNativeGestureHandler.FlatList, {
    data: [{
      title: t('AutoLockTimes.FiveMinutes'),
      value: _InactivityWrapper.AutoLockTime.FiveMinutes,
      testId: `auto-lock-time-${_InactivityWrapper.AutoLockTime.FiveMinutes}`,
      onPress: handleTimeoutChange
    }, {
      title: t('AutoLockTimes.ThreeMinutes'),
      value: _InactivityWrapper.AutoLockTime.ThreeMinutes,
      testId: `auto-lock-time-${_InactivityWrapper.AutoLockTime.ThreeMinutes}`,
      onPress: handleTimeoutChange
    }, {
      title: t('AutoLockTimes.OneMinute'),
      value: _InactivityWrapper.AutoLockTime.OneMinute,
      testId: `auto-lock-time-${_InactivityWrapper.AutoLockTime.OneMinute}`,
      onPress: handleTimeoutChange
    }, {
      title: t('AutoLockTimes.Never'),
      value: _InactivityWrapper.AutoLockTime.Never,
      testId: `auto-lock-time-${_InactivityWrapper.AutoLockTime.Never}`,
      onPress: handleTimeoutChange
    }],
    renderItem: ({
      item
    }) => {
      const data = item;
      return /*#__PURE__*/_react.default.createElement(LockoutRow, {
        title: data.title,
        selected: currentLockoutTime === data.value,
        value: data.value,
        testID: data.testID,
        onPress: data.onPress
      });
    },
    ItemSeparatorComponent: () => /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: {
        backgroundColor: SettingsTheme.groupBackground
      }
    }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
      style: styles.itemSeparator
    }))
  }));
};
var _default = exports.default = AutoLock;
//# sourceMappingURL=AutoLock.js.map