/*eslint no-unused-vars:0*/
'use strict';

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

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _dateTransformer = require('../../lib/date-transformer');

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

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _Common = {
  "inner-block": "Common__inner-block___2cOrF",
  "disable-inner-block": "Common__disable-inner-block___1MLd0",
  "components": "Common__components___2fQuj",
  "component": "Common__component___3bwMg",
  "hide": "Common__hide___2HyoH",
  "desc-text-color": "Common__desc-text-color___2fV3l",
  "desc-text-block": "Common__desc-text-block___1Z4b-",
  "text-link": "Common__text-link___1jaLy",
  "image": "Common__image___AKB6W",
  "imagediff": "Common__imagediff___2j7tX",
  "slideshow": "Common__slideshow___1Fz23",
  "embeddedcode": "Common__embeddedcode___3Avmp",
  "youtube": "Common__youtube___2oq1n",
  "topic-box": "Common__topic-box___2Q-kN"
};

var _Common2 = _interopRequireDefault(_Common);

var _classnames = require('classnames');

var _classnames2 = _interopRequireDefault(_classnames);

var _PublishDate = {
  "publish-date": "PublishDate__publish-date___XzQjR"
};

var _PublishDate2 = _interopRequireDefault(_PublishDate);

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

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var PublishDate = exports.PublishDate = function (_Component) {
  _inherits(PublishDate, _Component);

  function PublishDate(props) {
    _classCallCheck(this, PublishDate);

    var _this = _possibleConstructorReturn(this, (PublishDate.__proto__ || Object.getPrototypeOf(PublishDate)).call(this, props));

    _this.state = {
      isMounted: false
    };
    return _this;
  }

  _createClass(PublishDate, [{
    key: 'componentDidMount',
    value: function componentDidMount() {
      this.setState({ isMounted: true });
    }
  }, {
    key: 'render',
    value: function render() {
      var date = this.props.date;

      var dateTime = new Date(date);
      var fDate = (0, _dateTransformer.date2yyyymmdd)(date, '.');

      // avoid the server-side rendered date being inconsistent with the client-side results rendered by react-intl
      if (this.state.isMounted) {
        fDate = _react2.default.createElement(_reactIntl.FormattedDate, { value: dateTime, day: 'numeric', month: 'numeric', year: 'numeric' });
      }

      return _react2.default.createElement(
        'span',
        { className: (0, _classnames2.default)(_PublishDate2.default['publish-date'], _Common2.default['desc-text-color']) },
        fDate
      );
    }
  }]);

  return PublishDate;
}(_react.Component);