"use strict";

exports.__esModule = true;
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _index = _interopRequireDefault(require("../../../../atom/choice/index.native"));
var _templateContext = require("../../../../template/app-review/template-context");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
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; }
const createSelectionStyle = theme => _reactNative.StyleSheet.create({
  choice: {
    margin: theme.spacing.micro
  },
  selectionArea: {
    flexWrap: 'wrap',
    flexDirection: 'row'
  },
  text: {
    color: theme.colors.gray.medium
  }
});
const Selection = props => {
  const templateContext = (0, _templateContext.useTemplateContext)();
  const {
    theme
  } = templateContext;
  const {
    onPress
  } = props;
  const [styleSheet, setStylesheet] = (0, _react.useState)(null);
  (0, _react.useEffect)(() => {
    const _stylesheet = createSelectionStyle(theme);
    setStylesheet(_stylesheet);
  }, [theme]);
  if (!styleSheet) {
    return null;
  }
  const {
    choices
  } = props;
  const mappedSortedChoices = choices.map(item => /*#__PURE__*/_react.default.createElement(_index.default, {
    style: styleSheet.choice,
    key: item._id,
    squeezed: true,
    isSelected: true,
    testID: `choice-${item._id}`,
    onPress: onPress(item),
    questionType: "qcmDrag"
  }, item.label));
  return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: styleSheet.selectionArea
  }, mappedSortedChoices);
};
const createStyleSheet = theme => _reactNative.StyleSheet.create({
  container: {
    flex: 1
  },
  pickableChoices: {
    flexDirection: 'row',
    flexWrap: 'wrap'
  },
  choice: {
    margin: theme.spacing.micro
  },
  line: {
    borderWidth: 1,
    borderColor: '#E1E1E3',
    borderRadius: 17,
    marginHorizontal: 4,
    marginBottom: 24,
    marginTop: 16,
    height: 2
  }
});
const QuestionDraggable = props => {
  const templateContext = (0, _templateContext.useTemplateContext)();
  const {
    theme
  } = templateContext;
  const [styleSheet, setStylesheet] = (0, _react.useState)(null);
  (0, _react.useEffect)(() => {
    const _stylesheet = createStyleSheet(theme);
    setStylesheet(_stylesheet);
  }, [theme]);
  if (!styleSheet) {
    return null;
  }
  const {
    choices,
    onPress,
    testID
  } = props;
  const selectedChoices = choices.filter(item => item.selected);
  const pickableChoices = choices.filter(item => !item.selected).map(item => /*#__PURE__*/_react.default.createElement(_index.default, {
    style: styleSheet.choice,
    key: item._id,
    squeezed: true,
    testID: `choice-${item._id}-unselected`,
    onPress: onPress(item),
    questionType: "qcmDrag"
  }, item.label));
  return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    testID: testID,
    style: styleSheet.container
  }, /*#__PURE__*/_react.default.createElement(Selection, {
    choices: selectedChoices,
    onPress: onPress
  }), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: styleSheet.line
  }), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: styleSheet.pickableChoices
  }, pickableChoices));
};
var _default = exports.default = QuestionDraggable;
//# sourceMappingURL=index.native.js.map