'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.generic = generic;
exports.getRelativeTime = getRelativeTime;

var _classnames = require('classnames');

var _classnames2 = _interopRequireDefault(_classnames);

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _moment = require('moment');

var _moment2 = _interopRequireDefault(_moment);

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

function generic(_ref) {
  var name = _ref.name,
      className = _ref.className;

  var Component = function Component(props) {
    var userClassName = props.className,
        children = props.children,
        rest = _objectWithoutProperties(props, ['className', 'children']);

    return _react2.default.createElement(
      'div',
      _extends({ className: (0, _classnames2.default)(userClassName, className) }, rest),
      children
    );
  };
  Component.displayName = name;
  return Component;
}

function getRelativeTime(date, format) {
  if (date) {
    if (!format) {
      format = 'MM/DD/YYYY';
    }

    var inputDate = (0, _moment2.default)(date);
    var oneMinMs = 60000;
    var diffMs = Math.abs((0, _moment2.default)().diff(inputDate));
    var minute = Math.floor((0, _moment2.default)().diff(inputDate) / oneMinMs);
    var hour = Math.floor(minute / 60);

    if (diffMs < oneMinMs) {
      return 'just now';
    } else if (minute < 60) {
      return minute + ' min' + (minute > 1 ? 's' : '') + ' ago';
    } else if (hour < 24) {
      return hour + ' hour' + (hour > 1 ? 's' : '') + ' ago';
    } else {
      return inputDate.format(format);
    }
  } else {
    return '';
  }
}
//# sourceMappingURL=component-factory.js.map