"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");

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 {
  labelable
} = _cspaceInput.enhancers;
const BaseCheckboxInput = labelable(_cspaceInput.baseComponents.CheckboxInput);
const messages = (0, _reactIntl.defineMessages)({
  true: {
    "id": "checkboxInput.true",
    "defaultMessage": "yes"
  },
  false: {
    "id": "checkboxInput.false",
    "defaultMessage": "no"
  },
  indeterminate: {
    "id": "checkboxInput.indeterminate",
    "defaultMessage": "indeterminate"
  }
});
const propTypes = { // eslint-disable-next-line react/forbid-foreign-prop-types
  ...BaseCheckboxInput.propTypes,
  intl: _reactIntl.intlShape,
  viewType: _propTypes.default.string,
  trueLabel: _propTypes.default.string,
  falseLabel: _propTypes.default.string,
  indeterminateLabel: _propTypes.default.string
};
/*
 * A wrapper around a cspace-input CheckboxInput that supplies i18n and alternate transitions
 * when displayed in a search form.
 */

function CheckboxInput(props) {
  const {
    intl,
    viewType,
    trueLabel = intl.formatMessage(messages.true),
    falseLabel = intl.formatMessage(messages.false),
    indeterminateLabel = intl.formatMessage(messages.indeterminate),
    ...remainingProps
  } = props;
  let transition;

  if (viewType === 'search') {
    // When searching, the indeterminate value should be togglable.
    transition = {
      null: true,
      true: false,
      false: null
    };
  }

  return /*#__PURE__*/_react.default.createElement(BaseCheckboxInput, _extends({
    trueLabel: trueLabel,
    falseLabel: falseLabel,
    indeterminateLabel: indeterminateLabel,
    transition: transition
  }, remainingProps));
}

CheckboxInput.propTypes = propTypes;
const IntlAwareCheckboxInput = (0, _reactIntl.injectIntl)(CheckboxInput);
IntlAwareCheckboxInput.propTypes = CheckboxInput.propTypes;
var _default = IntlAwareCheckboxInput;
exports.default = _default;