"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 _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; 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 propTypes = {
  history: _propTypes.default.object
};
const contextTypes = {
  config: _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() {
    super();
    this.handleSearchDescriptorChange = this.handleSearchDescriptorChange.bind(this);
    this.state = {
      searchDescriptor: getSearchDescriptor()
    };
  }

  handleSearchDescriptorChange(searchDescriptor) {
    this.setState({
      searchDescriptor
    });
  }

  render() {
    const {
      config
    } = this.context;
    const {
      history
    } = this.props;
    const {
      searchDescriptor
    } = this.state;

    const title = _react.default.createElement(_reactIntl.FormattedMessage, messages.title);

    const recentPanelTitle = _react.default.createElement(_reactIntl.FormattedMessage, messages.recentPanelTitle);

    return _react.default.createElement("div", {
      className: _DashboardPage.default.common
    }, _react.default.createElement(_TitleBar.default, {
      title: title,
      updateDocumentTitle: true
    }), _react.default.createElement(_SearchPanelContainer.default, {
      config: config,
      history: history,
      name: "dashboardRecentPanel",
      searchDescriptor: searchDescriptor,
      title: recentPanelTitle,
      recordType: recordType,
      showSearchButton: false,
      onSearchDescriptorChange: this.handleSearchDescriptorChange
    }));
  }

}

exports.default = DashboardPage;
DashboardPage.propTypes = propTypes;
DashboardPage.contextTypes = contextTypes;