"use strict";

exports.__esModule = true;
exports.default = void 0;
var _noop2 = _interopRequireDefault(require("lodash/fp/noop"));
var _react = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _templateContext = require("../../../template/app-review/template-context");
var _index = _interopRequireDefault(require("../index.native"));
var _index2 = _interopRequireDefault(require("../select-item/index.native"));
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const createStyleSheet = theme => _reactNative.StyleSheet.create({
  content: {
    paddingHorizontal: 0
  },
  separator: {
    borderTopWidth: 1,
    borderColor: theme.colors.border
  },
  list: {
    width: '100%'
  }
});
const keyExtractor = (item, index) => {
  return `modal-select-item-${index + 1}`;
};
const createRenderItem = (value, testID, onChange) => function Item({
  item,
  index
}) {
  // eslint-disable-next-line unicorn/consistent-function-scoping
  const handleChange = _value => () => onChange(_value);
  return /*#__PURE__*/_react.default.createElement(_index2.default, {
    onPress: handleChange(item.text),
    isSelected: value === item.text,
    testID: `${testID}-item-${index + 1}`
  }, item.text);
};
const createSeparator = styleSheet => function Separator() {
  return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: styleSheet?.separator
  });
};
const ModalSelect = props => {
  const templateContext = (0, _templateContext.useTemplateContext)();
  const [styleSheet, setStylesheet] = (0, _react.useState)(null);
  const {
    theme
  } = templateContext;
  const {
    value = '',
    values,
    onChange,
    onClose = _noop2.default,
    testID = 'modal-select'
  } = props;
  (0, _react.useEffect)(() => {
    const _stylesheet = createStyleSheet(theme);
    setStylesheet(_stylesheet);
  }, [theme]);
  const renderItem = (0, _react.useMemo)(() => createRenderItem(value, testID, onChange), [value, testID, onChange]);
  const renderSeparator = (0, _react.useMemo)(() => styleSheet ? createSeparator(styleSheet) : null, [styleSheet]);
  if (!styleSheet) {
    return null;
  }
  return /*#__PURE__*/_react.default.createElement(_index.default, {
    onClose: onClose,
    contentStyle: styleSheet?.content,
    testID: testID
  }, /*#__PURE__*/_react.default.createElement(_reactNative.FlatList, {
    data: values,
    renderItem: renderItem,
    keyExtractor: keyExtractor,
    showsVerticalScrollIndicator: false,
    ItemSeparatorComponent: renderSeparator,
    style: styleSheet?.list,
    testID: `${testID}-items`
  }));
};
var _default = exports.default = ModalSelect;
//# sourceMappingURL=index.native.js.map