"use strict";

require("core-js/modules/web.dom.iterable");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _react = _interopRequireWildcard(require("react"));

var _reactBootstrap = require("react-bootstrap");

var _styledComponents = _interopRequireDefault(require("styled-components"));

var _icon = _interopRequireDefault(require("../util/icon"));

var _styled = require("./styled");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

const Quote = _styledComponents.default.p`
  font-size: small;
  margin-bottom: 5px;
`;
const Footer = _styledComponents.default.footer`
  font-size: x-small;
`;

const Note = ({
  note,
  onClickDelete
}) => /*#__PURE__*/_react.default.createElement("blockquote", null, /*#__PURE__*/_react.default.createElement(_reactBootstrap.Button, {
  bsSize: "xsmall",
  className: "pull-right",
  onClick: () => onClickDelete(note)
}, /*#__PURE__*/_react.default.createElement(_icon.default, {
  className: "text-danger",
  type: "trash"
})), /*#__PURE__*/_react.default.createElement(Quote, null, note.note), /*#__PURE__*/_react.default.createElement(Footer, null, note.userName, " on ", /*#__PURE__*/_react.default.createElement("em", null, note.timeStamp)));

const Feedback = ({
  feedback
}) => /*#__PURE__*/_react.default.createElement("blockquote", null, /*#__PURE__*/_react.default.createElement(Quote, null, feedback.feedback), /*#__PURE__*/_react.default.createElement(Footer, null, feedback.userName, " on ", /*#__PURE__*/_react.default.createElement("em", null, feedback.timeStamp)));
/**
 * Renders the various notes/feedback for a field trip request.
 */


class FieldTripNotes extends _react.Component {
  constructor(...args) {
    super(...args);

    _defineProperty(this, "_getNotesCount", () => {
      const {
        request
      } = this.props;
      const {
        feedback,
        notes
      } = request;
      let notesCount = 0;
      if (notes && notes.length) notesCount += notes.length;
      if (feedback && feedback.length) notesCount += feedback.length;
      return notesCount;
    });

    _defineProperty(this, "_addInternalNote", () => this._addNote('internal'));

    _defineProperty(this, "_addOperationalNote", () => this._addNote('operational'));

    _defineProperty(this, "_addNote", type => {
      const {
        addFieldTripNote,
        request
      } = this.props;
      const note = prompt(`Type ${type} note to be attached to this request:`);
      if (note) addFieldTripNote(request, {
        note,
        type
      });
    });

    _defineProperty(this, "_deleteNote", note => {
      const {
        deleteFieldTripNote,
        request
      } = this.props;

      if (confirm(`Are you sure you want to delete note "${note.note}"?`)) {
        deleteFieldTripNote(request, note.id);
      }
    });
  }

  render() {
    const {
      request
    } = this.props;
    if (!request) return null;
    const {
      feedback,
      notes
    } = request;
    const internalNotes = [];
    const operationalNotes = [];
    notes && notes.forEach(note => {
      if (note.type === 'internal') internalNotes.push(note);else operationalNotes.push(note);
    });
    return /*#__PURE__*/_react.default.createElement(_styled.Full, null, /*#__PURE__*/_react.default.createElement(_styled.Header, null, /*#__PURE__*/_react.default.createElement(_icon.default, {
      type: "sticky-note-o"
    }), " Notes/Feedback", ' ', /*#__PURE__*/_react.default.createElement(_reactBootstrap.Badge, null, this._getNotesCount()), /*#__PURE__*/_react.default.createElement(_styled.Button, {
      bsSize: "xs",
      onClick: this._addInternalNote
    }, /*#__PURE__*/_react.default.createElement(_icon.default, {
      type: "plus"
    }), " Internal note"), /*#__PURE__*/_react.default.createElement(_styled.Button, {
      bsSize: "xs",
      onClick: this._addOperationalNote
    }, /*#__PURE__*/_react.default.createElement(_icon.default, {
      type: "plus"
    }), " Ops. note")), /*#__PURE__*/_react.default.createElement("h5", null, "Internal agent notes"), internalNotes && internalNotes.length > 0 ? internalNotes.map(n => /*#__PURE__*/_react.default.createElement(Note, {
      key: n.id,
      note: n,
      onClickDelete: this._deleteNote
    })) : 'No internal notes submitted.', /*#__PURE__*/_react.default.createElement("h5", null, "Operational notes"), operationalNotes && operationalNotes.length > 0 ? operationalNotes.map(n => /*#__PURE__*/_react.default.createElement(Note, {
      key: n.id,
      note: n,
      onClickDelete: this._deleteNote
    })) : 'No operational notes submitted.', /*#__PURE__*/_react.default.createElement("h5", null, "User feedback"), feedback && feedback.length > 0 ? feedback.map((f, i) => /*#__PURE__*/_react.default.createElement(Feedback, {
      feedback: f,
      key: i
    })) : 'No feedback submitted.');
  }

}

exports.default = FieldTripNotes;
module.exports = exports.default;

//# sourceMappingURL=field-trip-notes.js