"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _react = _interopRequireDefault(require("react"));

var _propTypes = _interopRequireDefault(require("prop-types"));

var _reactIntl = require("react-intl");

var _cspaceInput = require("cspace-input");

var _searchOperators = require("../../../constants/searchOperators");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

const {
  OptionPickerInput
} = _cspaceInput.baseComponents;
const operatorMessages = {
  full: (0, _reactIntl.defineMessages)({
    [_searchOperators.OP_COMPLETE]: {
      "id": "operatorInput.OP_COMPLETE",
      "defaultMessage": "is complete"
    },
    [_searchOperators.OP_CONTAIN]: {
      "id": "operatorInput.OP_CONTAIN",
      "defaultMessage": "contains"
    },
    [_searchOperators.OP_EQ]: {
      "id": "operatorInput.OP_EQ",
      "defaultMessage": "is"
    },
    [_searchOperators.OP_GT]: {
      "id": "operatorInput.OP_GT",
      "defaultMessage": "is greater than"
    },
    [_searchOperators.OP_GTC]: {
      "id": "operatorInput.OP_GTC",
      "defaultMessage": "is greater than or contains"
    },
    [_searchOperators.OP_GTE]: {
      "id": "operatorInput.OP_GTE",
      "defaultMessage": "is at least"
    },
    [_searchOperators.OP_LT]: {
      "id": "operatorInput.OP_LT",
      "defaultMessage": "is less than"
    },
    [_searchOperators.OP_LTC]: {
      "id": "operatorInput.OP_LTC",
      "defaultMessage": "is less than or contains"
    },
    [_searchOperators.OP_LTE]: {
      "id": "operatorInput.OP_LTE",
      "defaultMessage": "is at most"
    },
    [_searchOperators.OP_MATCH]: {
      "id": "operatorInput.OP_MATCH",
      "defaultMessage": "matches"
    },
    [_searchOperators.OP_RANGE]: {
      "id": "operatorInput.OP_RANGE",
      "defaultMessage": "is between"
    },
    [_searchOperators.OP_NULL]: {
      "id": "operatorInput.OP_NULL",
      "defaultMessage": "is blank"
    },
    [_searchOperators.OP_NOT_COMPLETE]: {
      "id": "operatorInput.OP_NOT_COMPLETE",
      "defaultMessage": "is incomplete"
    },
    [_searchOperators.OP_NOT_CONTAIN]: {
      "id": "operatorInput.OP_NOT_CONTAIN",
      "defaultMessage": "does not contain"
    },
    [_searchOperators.OP_NOT_EQ]: {
      "id": "operatorInput.OP_NOT_EQ",
      "defaultMessage": "is not"
    },
    [_searchOperators.OP_NOT_MATCH]: {
      "id": "operatorInput.OP_NOT_MATCH",
      "defaultMessage": "does not match"
    },
    [_searchOperators.OP_NOT_RANGE]: {
      "id": "operatorInput.OP_NOT_RANGE",
      "defaultMessage": "is not between"
    },
    [_searchOperators.OP_NOT_NULL]: {
      "id": "operatorInput.OP_NOT_NULL",
      "defaultMessage": "is not blank"
    }
  }),
  compact: (0, _reactIntl.defineMessages)({
    [_searchOperators.OP_COMPLETE]: {
      "id": "operatorInput.compact.OP_COMPLETE",
      "defaultMessage": "is complete"
    },
    [_searchOperators.OP_CONTAIN]: {
      "id": "operatorInput.compact.OP_CONTAIN",
      "defaultMessage": "contains"
    },
    [_searchOperators.OP_EQ]: {
      "id": "operatorInput.compact.OP_EQ",
      "defaultMessage": "="
    },
    [_searchOperators.OP_GT]: {
      "id": "operatorInput.compact.OP_GT",
      "defaultMessage": ">"
    },
    [_searchOperators.OP_GTC]: {
      "id": "operatorInput.compact.OP_GTC",
      "defaultMessage": "> or contains"
    },
    [_searchOperators.OP_GTE]: {
      "id": "operatorInput.compact.OP_GTE",
      "defaultMessage": "\u2265"
    },
    [_searchOperators.OP_LT]: {
      "id": "operatorInput.compact.OP_LT",
      "defaultMessage": "<"
    },
    [_searchOperators.OP_LTC]: {
      "id": "operatorInput.compact.OP_LTC",
      "defaultMessage": "< or contains"
    },
    [_searchOperators.OP_LTE]: {
      "id": "operatorInput.compact.OP_LTE",
      "defaultMessage": "\u2264"
    },
    [_searchOperators.OP_MATCH]: {
      "id": "operatorInput.compact.OP_MATCH",
      "defaultMessage": "matches"
    },
    [_searchOperators.OP_RANGE]: {
      "id": "operatorInput.compact.OP_RANGE",
      "defaultMessage": "is between"
    },
    [_searchOperators.OP_NULL]: {
      "id": "operatorInput.compact.OP_NULL",
      "defaultMessage": "is blank"
    },
    [_searchOperators.OP_NOT_COMPLETE]: {
      "id": "operatorInput.compact.OP_NOT_COMPLETE",
      "defaultMessage": "is incomplete"
    },
    [_searchOperators.OP_NOT_CONTAIN]: {
      "id": "operatorInput.compact.OP_NOT_CONTAIN",
      "defaultMessage": "doesn't contain"
    },
    [_searchOperators.OP_NOT_EQ]: {
      "id": "operatorInput.compact.OP_NOT_EQ",
      "defaultMessage": "\u2260"
    },
    [_searchOperators.OP_NOT_MATCH]: {
      "id": "operatorInput.compact.OP_NOT_MATCH",
      "defaultMessage": "doesn't match"
    },
    [_searchOperators.OP_NOT_RANGE]: {
      "id": "operatorInput.compact.OP_NOT_RANGE",
      "defaultMessage": "isn't between"
    },
    [_searchOperators.OP_NOT_NULL]: {
      "id": "operatorInput.compact.OP_NOT_NULL",
      "defaultMessage": "isn't blank"
    }
  })
};
const propTypes = {
  compact: _propTypes.default.bool,
  intl: _reactIntl.intlShape,
  name: _propTypes.default.string,
  operators: _propTypes.default.arrayOf(_propTypes.default.string),
  readOnly: _propTypes.default.bool,
  value: _propTypes.default.string,
  onCommit: _propTypes.default.func
};

function OperatorInput(props) {
  const {
    compact,
    intl,
    name,
    operators,
    readOnly,
    value,
    onCommit
  } = props;
  const messages = compact ? operatorMessages.compact : operatorMessages.full;

  if (readOnly) {
    return _react.default.createElement(_reactIntl.FormattedMessage, _extends({}, messages[value], {
      tagName: "div"
    }));
  }

  const options = operators.map(op => ({
    value: op,
    label: intl.formatMessage(messages[op])
  }));
  return _react.default.createElement(OptionPickerInput, {
    blankable: false,
    name: name,
    options: options,
    value: value,
    onCommit: onCommit
  });
}

OperatorInput.propTypes = propTypes;

var _default = (0, _reactIntl.injectIntl)(OperatorInput);

exports.default = _default;