"use strict";

exports.__esModule = true;
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _index = _interopRequireDefault(require("../html/index.native"));
var _index2 = _interopRequireDefault(require("../image-background/index.native"));
var _getCleanUri = _interopRequireDefault(require("../../util/get-clean-uri"));
var _index3 = _interopRequireDefault(require("../../hoc/touchable/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 createStyleSheet = (theme, squeezed) => _reactNative.StyleSheet.create({
  boxShadow: {
    shadowColor: '#000',
    shadowOffset: {
      width: 0,
      height: 4
    },
    shadowOpacity: 0.12,
    shadowRadius: 8,
    elevation: 8,
    backgroundColor: '#0000'
  },
  container: {
    backgroundColor: theme.colors.white,
    borderRadius: theme.radius.regular,
    flexDirection: 'row',
    alignItems: 'stretch',
    minHeight: 60
  },
  textContainer: {
    paddingHorizontal: 24,
    paddingVertical: 12,
    justifyContent: 'center',
    alignItems: 'center',
    flex: 1
  },
  squeezedTextContainer: {
    padding: theme.spacing.small,
    paddingLeft: undefined,
    paddingVertical: undefined,
    paddingRight: undefined,
    flex: 0
  },
  text: {
    fontSize: squeezed ? theme.fontSize.medium : theme.fontSize.regular,
    fontWeight: theme.fontWeight.bold,
    color: theme.colors.black,
    textAlign: 'center'
  },
  textSelected: {
    color: theme.colors.white
  },
  unselectedImageContainer: {
    borderRightColor: theme.colors.border
  },
  imageContainer: {
    height: '100%',
    width: '25%',
    overflow: 'hidden',
    borderTopLeftRadius: theme.radius.regular,
    borderBottomLeftRadius: theme.radius.regular
  },
  image: {
    flex: 1
  }
});
const Choice = ({
  children,
  isSelected = false,
  squeezed = false,
  isDisabled,
  onPress,
  media,
  testID: prefixTestID,
  style,
  questionType
}) => {
  const templateContext = (0, _templateContext.useTemplateContext)();
  const {
    theme,
    brandTheme
  } = templateContext;
  const [styleSheet, setStylesheet] = (0, _react.useState)(null);
  (0, _react.useEffect)(() => {
    const _stylesheet = createStyleSheet(theme, squeezed);
    setStylesheet(_stylesheet);
  }, [theme, squeezed]);
  if (!styleSheet) {
    return null;
  }
  const selectedSuffix = prefixTestID && isSelected ? '-selected' : '';
  const mediaType = media && media.type && media.type === 'img' && media.type.toLowerCase();
  const url = media && media.type === 'img' && media.src && media.src.length > 0 && (0, _getCleanUri.default)(media.src[0].url);
  const source = {
    uri: url ? (0, _getCleanUri.default)(url) : undefined
  };
  const mediaSuffix = prefixTestID && mediaType ? `-${mediaType}` : '';
  const textStyle = [styleSheet.text];
  const textWrapperStyle = [styleSheet.textContainer];
  if (squeezed) {
    textWrapperStyle.push(styleSheet.squeezedTextContainer);
  }
  if (isSelected) {
    textStyle.push(styleSheet.textSelected);

    // eslint-disable-next-line @coorpacademy/coorpacademy/no-overwriting-spread
    const selectionStyle = brandTheme && {
      backgroundColor: brandTheme.colors?.primary,
      borderColor: brandTheme.colors?.primary,
      ...(url ? {
        borderTopRightRadius: theme.radius.regular,
        borderBottomRightRadius: theme.radius.regular
      } : {
        borderRadius: theme.radius.regular
      })
    };
    if (selectionStyle) {
      textWrapperStyle.push(selectionStyle);
    }
  }
  return /*#__PURE__*/_react.default.createElement(_index3.default, {
    onPress: !isDisabled ? onPress : undefined,
    style: style,
    analyticsID: "question-choice",
    analyticsParams: {
      questionType
    }
  }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: [styleSheet.boxShadow, styleSheet.container],
    testID: prefixTestID && `${prefixTestID}${selectedSuffix}`
  }, url ? /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: styleSheet.imageContainer
  }, /*#__PURE__*/_react.default.createElement(_index2.default, {
    testID: prefixTestID && `${prefixTestID}${mediaSuffix}`,
    source: source,
    style: styleSheet.image
  })) : null, children ? /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: textWrapperStyle
  }, /*#__PURE__*/_react.default.createElement(_index.default, {
    style: textStyle,
    isTextCentered: true
  }, children)) : null));
};
var _default = exports.default = Choice;
//# sourceMappingURL=index.native.js.map