"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.mapStateToProps = exports.mapDispatchToProps = exports.PastComponent = exports.Past = void 0;
var _react = _interopRequireWildcard(require("react"));
var _store = require("../redux/store");
var _recompose = require("recompose");
var _bundleCommon = require("@kineticdata/bundle-common");
var _PageTitle = require("./shared/PageTitle");
var _router = require("@reach/router");
var _appointments = require("../redux/modules/appointments");
var _moment = _interopRequireDefault(require("moment"));
var _react2 = require("@kineticdata/react");
var _constants = require("../constants");
var PastComponent = exports.PastComponent = function PastComponent(_ref) {
  var techBars = _ref.techBars,
    error = _ref.error,
    pastAppointments = _ref.pastAppointments;
  return /*#__PURE__*/_react["default"].createElement(_react.Fragment, null, /*#__PURE__*/_react["default"].createElement("div", {
    className: "page-container page-container--tech-bar page-container--lg"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "page-panel"
  }, /*#__PURE__*/_react["default"].createElement(_PageTitle.PageTitle, {
    parts: ['Past Appointments'],
    breadcrumbs: [{
      label: 'Home',
      to: '/'
    }, {
      label: 'Tech Bar',
      to: '..'
    }],
    title: "Past Appointments"
  }), /*#__PURE__*/_react["default"].createElement("section", {
    className: "mb-4"
  }, /*#__PURE__*/_react["default"].createElement(_bundleCommon.StateListWrapper, {
    data: pastAppointments,
    error: error,
    emptyTitle: "You have no past appointments.",
    emptyMessage: "Your completed and cancelled appointments will appear here."
  }, function (data) {
    return /*#__PURE__*/_react["default"].createElement("div", {
      className: "cards"
    }, data.map(function (appt) {
      var techBar = techBars.find(function (t) {
        return t.values['Id'] === appt.values['Scheduler Id'];
      });
      var date = _moment["default"].utc(appt.values['Event Date'], _constants.DATE_FORMAT);
      var start = _moment["default"].utc(appt.values['Event Time'], _constants.TIME_FORMAT);
      var end = start.clone().add(appt.values['Event Duration'], 'minute');
      return /*#__PURE__*/_react["default"].createElement(_bundleCommon.Card, {
        key: appt.id,
        to: "appointment/".concat(appt.values['Scheduler Id'], "/").concat(appt.id),
        components: {
          Link: _router.Link
        }
      }, /*#__PURE__*/_react["default"].createElement(_bundleCommon.CardRow, null, /*#__PURE__*/_react["default"].createElement(_bundleCommon.CardRow, {
        type: "prepend"
      }, /*#__PURE__*/_react["default"].createElement("span", {
        className: "fa fa-calendar fa-rounded",
        style: {
          background: 'rgb(255, 74, 94)'
        }
      })), /*#__PURE__*/_react["default"].createElement(_bundleCommon.CardCol, null, /*#__PURE__*/_react["default"].createElement(_bundleCommon.CardRow, {
        type: "multi"
      }, /*#__PURE__*/_react["default"].createElement(_bundleCommon.CardRow, {
        type: "subtitle"
      }, /*#__PURE__*/_react["default"].createElement(_react2.Moment, {
        timestamp: date,
        format: _react2.Moment.formats.dateWithDay
      })), /*#__PURE__*/_react["default"].createElement(_bundleCommon.CardRow, {
        className: "text-muted"
      }, /*#__PURE__*/_react["default"].createElement(_react2.Moment, {
        timestamp: start,
        format: _react2.Moment.formats.time
      }), " - ", /*#__PURE__*/_react["default"].createElement(_react2.Moment, {
        timestamp: end,
        format: _react2.Moment.formats.time
      })), /*#__PURE__*/_react["default"].createElement(_bundleCommon.CardRow, {
        type: "meta"
      }, /*#__PURE__*/_react["default"].createElement("strong", null, /*#__PURE__*/_react["default"].createElement(_react2.I18n, null, techBar.values['Name']))), /*#__PURE__*/_react["default"].createElement(_bundleCommon.CardRow, {
        type: "meta"
      }, appt.values['Summary']))), /*#__PURE__*/_react["default"].createElement(_bundleCommon.CardRow, {
        type: "append"
      }, /*#__PURE__*/_react["default"].createElement("span", {
        className: "badge badge-stylized badge-".concat(appt.coreState === 'Closed' ? 'dark' : 'success')
      }, /*#__PURE__*/_react["default"].createElement(_react2.I18n, null, appt.values['Status'])))));
    }));
  })))));
};
var mapStateToProps = exports.mapStateToProps = function mapStateToProps(state) {
  return {
    techBars: state.techBarApp.schedulers.filter(function (s) {
      return s.values['Status'] === 'Active';
    }),
    error: state.appointments.error,
    pastAppointments: state.appointments.past
  };
};
var mapDispatchToProps = exports.mapDispatchToProps = {
  fetchPastAppointmentsRequest: _appointments.actions.fetchPastAppointmentsRequest
};
var Past = exports.Past = (0, _recompose.compose)((0, _store.connect)(mapStateToProps, mapDispatchToProps), (0, _recompose.lifecycle)({
  componentDidMount: function componentDidMount() {
    this.props.fetchPastAppointmentsRequest();
  }
}))(PastComponent);