"use strict";

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

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

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

var _reactRedux = require("react-redux");

var callTakerActions = _interopRequireWildcard(require("../../actions/call-taker"));

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

var _callRecord = _interopRequireDefault(require("./call-record"));

var _draggableWindow = _interopRequireDefault(require("./draggable-window"));

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

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 _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function CallHistoryWindow(props) {
  const {
    callTaker,
    fetchQueries,
    searches,
    toggleCallHistory
  } = props;
  const {
    activeCall,
    callHistory
  } = callTaker;
  if (!callHistory.visible) return null;
  return /*#__PURE__*/_react.default.createElement(_draggableWindow.default, {
    header: /*#__PURE__*/_react.default.createElement(_styled.WindowHeader, null, /*#__PURE__*/_react.default.createElement(_icon.default, {
      type: "history"
    }), " Call history"),
    onClickClose: toggleCallHistory,
    style: {
      right: '15px',
      top: '50px',
      width: '450px'
    }
  }, activeCall ? /*#__PURE__*/_react.default.createElement(_callRecord.default, {
    call: activeCall,
    inProgress: true,
    searches: searches
  }) : null, callHistory.calls.data.length > 0 ? callHistory.calls.data.map((call, i) => /*#__PURE__*/_react.default.createElement(_callRecord.default // Create a key so that when call records get added, elements in this list are
  // recreated/remounted so that they don't show the state from the previous list.
  , {
    call: call,
    fetchQueries: fetchQueries,
    index: i,
    key: `${call.id}-${i}`
  })) : /*#__PURE__*/_react.default.createElement("div", null, "No calls in history"));
}

const mapStateToProps = (state, ownProps) => {
  return {
    callTaker: state.callTaker,
    currentQuery: state.otp.currentQuery,
    searches: state.otp.searches
  };
};

const mapDispatchToProps = {
  fetchQueries: callTakerActions.fetchQueries,
  toggleCallHistory: callTakerActions.toggleCallHistory
};

var _default = (0, _reactRedux.connect)(mapStateToProps, mapDispatchToProps)(CallHistoryWindow);

exports.default = _default;
module.exports = exports.default;

//# sourceMappingURL=call-history-window.js