'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _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; };

exports.IntlAwareDateTimeInput = IntlAwareDateTimeInput;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

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

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

function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }

var DateTimeInput = _cspaceInput.components.DateTimeInput;


var messages = (0, _reactIntl.defineMessages)({
  value: {
    'id': 'dateTimeInputContainer.value',
    'defaultMessage': '{date} {time}'
  }
});

var propTypes = {
  intl: _reactIntl.intlShape
};

function IntlAwareDateTimeInput(props) {
  var intl = props.intl,
      remainingProps = _objectWithoutProperties(props, ['intl']);

  return _react2.default.createElement(DateTimeInput, _extends({}, remainingProps, {
    formatValue: function formatValue(timestamp) {
      var date = intl.formatDate(timestamp, { day: 'numeric', month: 'short', year: 'numeric' });
      var time = intl.formatTime(timestamp, { hour: 'numeric', minute: 'numeric', second: 'numeric' });

      return intl.formatMessage(messages.value, { date: date, time: time });
    }
  }));
}

IntlAwareDateTimeInput.propTypes = propTypes;

var IntlizedDateTimeInput = (0, _reactIntl.injectIntl)(IntlAwareDateTimeInput);

IntlizedDateTimeInput.propTypes = DateTimeInput.propTypes;

exports.default = IntlizedDateTimeInput;