"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _MaterialIcons = _interopRequireDefault(require("react-native-vector-icons/MaterialIcons"));
var _constants = require("../../constants");
var _theme = require("../../contexts/theme");
var _Text = _interopRequireDefault(require("../texts/Text"));
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 SingleSelectBlock = _ref => {
  let {
    selection,
    onSelect,
    initialSelect
  } = _ref;
  const [selected, setSelected] = (0, _react.useState)(initialSelect ?? selection[0]);
  const {
    Inputs
  } = (0, _theme.useTheme)();
  const styles = _reactNative.StyleSheet.create({
    container: {
      width: '100%',
      padding: 20
    },
    row: {
      ...Inputs.singleSelect,
      flexDirection: 'row',
      alignItems: 'center',
      justifyContent: 'space-between',
      marginBottom: 8
    }
  });
  const handleSelect = selected => {
    setSelected(selected);
    onSelect(selected);
  };
  return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: styles.container
  }, selection.map(item => /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
    key: item.id,
    style: styles.row,
    onPress: () => handleSelect(item),
    hitSlop: _constants.hitSlop
  }, /*#__PURE__*/_react.default.createElement(_Text.default, {
    style: Inputs.singleSelectText
  }, item.value), item.id === selected.id ? /*#__PURE__*/_react.default.createElement(_MaterialIcons.default, {
    name: 'check',
    size: 25,
    color: Inputs.singleSelectIcon.color
  }) : null)));
};
var _default = SingleSelectBlock;
exports.default = _default;
//# sourceMappingURL=SingleSelectBlock.js.map