import { Pressable, StyleSheet, Text, View } from 'react-native';
import BouncyCheckbox from 'react-native-bouncy-checkbox';
import { SafeAreaView } from 'react-native-safe-area-context';
import Icon from 'react-native-vector-icons/MaterialIcons';
import { AutoLockTime } from '../components/misc/InactivityWrapper';
import { testIdWithKey } from '../utils/testable';
import { useStore } from '../contexts/store';
import { DispatchAction } from '../contexts/reducers/store';
import React from 'react';
import { FlatList } from 'react-native-gesture-handler';
import { useTranslation } from 'react-i18next';
import { useTheme } from '../contexts/theme';
const AutoLock = () => {
  const {
    t
  } = useTranslation();
  const [store, dispatch] = useStore();
  const {
    ColorPallet,
    SettingsTheme,
    TextTheme
  } = useTheme();
  const currentLockoutTime = store.preferences.autoLockTime ?? AutoLockTime.FiveMinutes;
  const styles = 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: DispatchAction.AUTO_LOCK_TIME,
      payload: [time]
    });
  };
  const LockoutRow = ({
    title,
    value,
    selected,
    testID,
    onPress
  }) => /*#__PURE__*/React.createElement(View, {
    style: [styles.section, styles.sectionRow]
  }, /*#__PURE__*/React.createElement(Text, {
    style: TextTheme.title
  }, title), /*#__PURE__*/React.createElement(Pressable, {
    style: styles.checkboxContainer,
    accessibilityLabel: title,
    accessibilityRole: 'checkbox',
    testID: testIdWithKey('ToggleConnectionInviterCapabilitySwitch')
  }, /*#__PURE__*/React.createElement(BouncyCheckbox, {
    accessibilityLabel: String(AutoLockTime.FiveMinutes),
    disableText: true,
    fillColor: ColorPallet.brand.secondaryBackground,
    unfillColor: ColorPallet.brand.secondaryBackground,
    size: 36,
    innerIconStyle: {
      borderColor: ColorPallet.brand.primary,
      borderWidth: 2
    },
    ImageComponent: () => /*#__PURE__*/React.createElement(Icon, {
      name: "circle",
      size: 18,
      color: ColorPallet.brand.primary
    }),
    onPress: () => onPress(value),
    isChecked: selected,
    disableBuiltInState: true,
    testID: testIdWithKey(testID)
  })));
  return /*#__PURE__*/React.createElement(SafeAreaView, {
    style: styles.container
  }, /*#__PURE__*/React.createElement(FlatList, {
    data: [{
      title: t('AutoLockTimes.FiveMinutes'),
      value: AutoLockTime.FiveMinutes,
      testId: `auto-lock-time-${AutoLockTime.FiveMinutes}`,
      onPress: handleTimeoutChange
    }, {
      title: t('AutoLockTimes.ThreeMinutes'),
      value: AutoLockTime.ThreeMinutes,
      testId: `auto-lock-time-${AutoLockTime.ThreeMinutes}`,
      onPress: handleTimeoutChange
    }, {
      title: t('AutoLockTimes.OneMinute'),
      value: AutoLockTime.OneMinute,
      testId: `auto-lock-time-${AutoLockTime.OneMinute}`,
      onPress: handleTimeoutChange
    }, {
      title: t('AutoLockTimes.Never'),
      value: AutoLockTime.Never,
      testId: `auto-lock-time-${AutoLockTime.Never}`,
      onPress: handleTimeoutChange
    }],
    renderItem: ({
      item
    }) => {
      const data = item;
      return /*#__PURE__*/React.createElement(LockoutRow, {
        title: data.title,
        selected: currentLockoutTime === data.value,
        value: data.value,
        testID: data.testID,
        onPress: data.onPress
      });
    },
    ItemSeparatorComponent: () => /*#__PURE__*/React.createElement(View, {
      style: {
        backgroundColor: SettingsTheme.groupBackground
      }
    }, /*#__PURE__*/React.createElement(View, {
      style: styles.itemSeparator
    }))
  }));
};
export default AutoLock;
//# sourceMappingURL=AutoLock.js.map