"use strict";

exports.__esModule = true;
exports.default = void 0;
var _reactNative = require("react-native");
var _react = _interopRequireWildcard(require("react"));
var _templateContext = require("../../../template/app-review/template-context");
var _analytics = require("../../../variables/analytics");
var _shadow = require("../../../variables/shadow");
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 = (brandTheme, theme) => _reactNative.StyleSheet.create({
  // eslint-disable-next-line @coorpacademy/coorpacademy/no-overwriting-spread
  input: {
    padding: theme.spacing.tiny,
    borderColor: theme.colors.gray.lightMedium,
    borderRadius: theme.radius.regular,
    minWidth: 175,
    marginHorizontal: 12,
    paddingVertical: 16,
    ..._shadow.BOX_STYLE,
    backgroundColor: theme.colors.white
  },
  text: {
    borderColor: brandTheme?.colors?.primary,
    color: brandTheme?.colors?.primary || theme.colors.gray.medium,
    fontWeight: theme.fontWeight.bold,
    fontSize: theme.fontSize.regular,
    textAlign: 'center'
  },
  spaced: {
    paddingVertical: theme.spacing.tiny
  },
  fullWitdh: {
    width: '100%'
  }
});
const logEvent = (eventName, analytics, questionType) => {
  analytics && analytics.logEvent(eventName, {
    id: `question-input-text`,
    questionType
  });
};
const FreeText = props => {
  const templateContext = (0, _templateContext.useTemplateContext)();
  const [styleSheet, setStylesheet] = (0, _react.useState)(null);
  const {
    brandTheme,
    theme,
    translations
  } = templateContext;
  const PLACEHOLDER_COLOR = theme.colors.gray.medium;

  // ------------------------------------

  const {
    analytics,
    questionType,
    fullWidth = false,
    testID,
    onChange,
    isDisabled = false,
    value
  } = props;

  // ------------------------------------

  const handleFocus = (0, _react.useCallback)(() => analytics && logEvent(_analytics.ANALYTICS_EVENT_TYPE.INPUT_FOCUS, analytics, questionType), [analytics, questionType]);
  const handleBlur = (0, _react.useCallback)(() => analytics && logEvent(_analytics.ANALYTICS_EVENT_TYPE.INPUT_BLUR, analytics, questionType), [analytics, questionType]);

  // ------------------------------------

  (0, _react.useEffect)(() => {
    const _stylesheet = createStyleSheet(brandTheme, theme);
    setStylesheet(_stylesheet);
  }, [brandTheme, theme]);

  // ------------------------------------

  if (!styleSheet) {
    return null;
  }
  return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: [styleSheet.spaced, fullWidth && styleSheet.fullWitdh]
  }, /*#__PURE__*/_react.default.createElement(_reactNative.TextInput, {
    style: [styleSheet.input, styleSheet.text],
    onFocus: handleFocus,
    onBlur: handleBlur,
    onChangeText: onChange,
    placeholder: translations.typeHere,
    placeholderTextColor: PLACEHOLDER_COLOR,
    value: value,
    testID: testID,
    editable: !isDisabled,
    selectTextOnFocus: !isDisabled
  }));
};
var _default = exports.default = FreeText;
//# sourceMappingURL=index.native.js.map