import React, { useEffect, useState } from 'react';
import { View, StyleSheet } from 'react-native';
import QuestionChoice from '../../../../atom/choice/index.native';
import { useTemplateContext } from '../../../../template/app-review/template-context';
const createSelectionStyle = theme => StyleSheet.create({
  choice: {
    margin: theme.spacing.micro
  },
  selectionArea: {
    flexWrap: 'wrap',
    flexDirection: 'row'
  },
  text: {
    color: theme.colors.gray.medium
  }
});
const Selection = props => {
  const templateContext = useTemplateContext();
  const {
    theme
  } = templateContext;
  const {
    onPress
  } = props;
  const [styleSheet, setStylesheet] = useState(null);
  useEffect(() => {
    const _stylesheet = createSelectionStyle(theme);
    setStylesheet(_stylesheet);
  }, [theme]);
  if (!styleSheet) {
    return null;
  }
  const {
    choices
  } = props;
  const mappedSortedChoices = choices.map(item => /*#__PURE__*/React.createElement(QuestionChoice, {
    style: styleSheet.choice,
    key: item._id,
    squeezed: true,
    isSelected: true,
    testID: `choice-${item._id}`,
    onPress: onPress(item),
    questionType: "qcmDrag"
  }, item.label));
  return /*#__PURE__*/React.createElement(View, {
    style: styleSheet.selectionArea
  }, mappedSortedChoices);
};
const createStyleSheet = theme => 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 = useTemplateContext();
  const {
    theme
  } = templateContext;
  const [styleSheet, setStylesheet] = useState(null);
  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.createElement(QuestionChoice, {
    style: styleSheet.choice,
    key: item._id,
    squeezed: true,
    testID: `choice-${item._id}-unselected`,
    onPress: onPress(item),
    questionType: "qcmDrag"
  }, item.label));
  return /*#__PURE__*/React.createElement(View, {
    testID: testID,
    style: styleSheet.container
  }, /*#__PURE__*/React.createElement(Selection, {
    choices: selectedChoices,
    onPress: onPress
  }), /*#__PURE__*/React.createElement(View, {
    style: styleSheet.line
  }), /*#__PURE__*/React.createElement(View, {
    style: styleSheet.pickableChoices
  }, pickableChoices));
};
export default QuestionDraggable;
//# sourceMappingURL=index.native.js.map