"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _reactIntl = require("react-intl");
var _immutable = _interopRequireDefault(require("immutable"));
var _TitleBar = _interopRequireDefault(require("../sections/TitleBar"));
var _SearchPanelContainer = _interopRequireDefault(require("../../containers/search/SearchPanelContainer"));
var _searchOperators = require("../../constants/searchOperators");
var _DashboardPage = _interopRequireDefault(require("../../../styles/cspace-ui/DashboardPage.css"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
const messages = (0, _reactIntl.defineMessages)({
  title: {
    "id": "dashboardPage.title",
    "defaultMessage": "My CollectionSpace"
  },
  recentPanelTitle: {
    "id": "dashboardPage.recentPanelTitle",
    "defaultMessage": "Records Updated in Last 7 Days"
  }
});
const contextTypes = {
  config: _propTypes.default.shape({
    listTypes: _propTypes.default.object
  }).isRequired
};
const recordType = 'all';
const getSearchDescriptor = () => {
  const range = 7 * 24 * 60 * 60 * 1000; // 7 days
  const afterDate = new Date(Date.now() - range);
  return _immutable.default.fromJS({
    recordType,
    searchQuery: {
      as: {
        op: _searchOperators.OP_GTE,
        path: 'ns2:collectionspace_core/updatedAt',
        value: afterDate.toISOString()
      },
      size: 20
    }
  });
};
class DashboardPage extends _react.Component {
  constructor(props, context) {
    super(props, context);
    this.handleSearchDescriptorChange = this.handleSearchDescriptorChange.bind(this);
    const {
      config
    } = context;
    this.state = {
      searchDescriptor: getSearchDescriptor(config)
    };
  }
  handleSearchDescriptorChange(searchDescriptor) {
    this.setState({
      searchDescriptor
    });
  }
  render() {
    const {
      config
    } = this.context;
    const {
      searchDescriptor
    } = this.state;
    const title = /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, messages.title);
    const recentPanelTitle = /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, messages.recentPanelTitle);
    return /*#__PURE__*/_react.default.createElement("div", {
      className: _DashboardPage.default.common
    }, /*#__PURE__*/_react.default.createElement(_TitleBar.default, {
      title: title,
      updateDocumentTitle: true
    }), /*#__PURE__*/_react.default.createElement(_SearchPanelContainer.default, {
      config: config,
      name: "dashboardRecentPanel",
      searchDescriptor: searchDescriptor,
      title: recentPanelTitle,
      recordType: recordType,
      showSearchButton: false,
      onSearchDescriptorChange: this.handleSearchDescriptorChange
    }));
  }
}
exports.default = DashboardPage;
DashboardPage.contextTypes = contextTypes;