'use strict';

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

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 _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

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

var _immutable = require('immutable');

var _immutable2 = _interopRequireDefault(_immutable);

var _TitleBar = require('../sections/TitleBar');

var _TitleBar2 = _interopRequireDefault(_TitleBar);

var _SearchPanelContainer = require('../../containers/search/SearchPanelContainer');

var _SearchPanelContainer2 = _interopRequireDefault(_SearchPanelContainer);

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

var _DashboardPage = require('../../../styles/cspace-ui/DashboardPage.css');

var _DashboardPage2 = _interopRequireDefault(_DashboardPage);

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 messages = (0, _reactIntl.defineMessages)({
  title: {
    'id': 'dashboardPage.title',
    'defaultMessage': 'My CollectionSpace'
  },
  recentPanelTitle: {
    'id': 'dashboardPage.recentPanelTitle',
    'defaultMessage': 'Recently Updated Records'
  }
});

var propTypes = {
  history: _propTypes2.default.object
};

var contextTypes = {
  config: _propTypes2.default.object.isRequired
};

var recordType = 'all';

var getSearchDescriptor = function getSearchDescriptor() {
  var range = 7 * 24 * 60 * 60 * 1000; // 7 days
  var afterDate = new Date(Date.now() - range);

  return _immutable2.default.fromJS({
    recordType: recordType,
    searchQuery: {
      as: {
        op: _searchOperators.OP_GTE,
        path: 'ns2:collectionspace_core/updatedAt',
        value: afterDate.toISOString()
      },
      size: 20
    }
  });
};

var DashboardPage = function (_Component) {
  _inherits(DashboardPage, _Component);

  function DashboardPage() {
    _classCallCheck(this, DashboardPage);

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

    _this.handleSearchDescriptorChange = _this.handleSearchDescriptorChange.bind(_this);

    _this.state = {
      searchDescriptor: getSearchDescriptor()
    };
    return _this;
  }

  _createClass(DashboardPage, [{
    key: 'handleSearchDescriptorChange',
    value: function handleSearchDescriptorChange(searchDescriptor) {
      this.setState({
        searchDescriptor: searchDescriptor
      });
    }
  }, {
    key: 'render',
    value: function render() {
      var config = this.context.config;
      var history = this.props.history;
      var searchDescriptor = this.state.searchDescriptor;


      var title = _react2.default.createElement(_reactIntl.FormattedMessage, messages.title);
      var recentPanelTitle = _react2.default.createElement(_reactIntl.FormattedMessage, messages.recentPanelTitle);

      return _react2.default.createElement(
        'div',
        { className: _DashboardPage2.default.common },
        _react2.default.createElement(_TitleBar2.default, { title: title, updateDocumentTitle: true }),
        _react2.default.createElement(_SearchPanelContainer2.default, {
          config: config,
          history: history,
          name: 'dashboardRecentPanel',
          searchDescriptor: searchDescriptor,
          title: recentPanelTitle,
          recordType: recordType,
          showSearchButton: false,
          onSearchDescriptorChange: this.handleSearchDescriptorChange
        })
      );
    }
  }]);

  return DashboardPage;
}(_react.Component);

exports.default = DashboardPage;


DashboardPage.propTypes = propTypes;
DashboardPage.contextTypes = contextTypes;