"use strict";

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

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

require("../App.css");

var _ChatTheme = _interopRequireDefault(require("./ChatTheme"));

var _Header = _interopRequireDefault(require("./chatWindow/Header"));

var _Conversation = _interopRequireDefault(require("./chatWindow/Conversation"));

var _Footer = _interopRequireDefault(require("./chatWindow/Footer"));

var _MainLoader = _interopRequireDefault(require("./chatWindow/MainLoader"));

var _loading_dots = _interopRequireDefault(require("../images/icons/loading_dots.gif"));

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

function formatDate(date) {
  const h = "0" + date.getHours();
  const m = "0" + date.getMinutes();
  return "".concat(h.slice(-2), ":").concat(m.slice(-2));
}

function ChatWindow(props) {
  function handleUserMessage(msg) {
    props.handleUserResponse({
      sender: "Me",
      timestamp: formatDate(new Date()),
      messageType: "plainText",
      message: msg
    });
  }

  function handleButtonClick(data) {
    console.log("handleButtonClick >", data);

    switch (data.action) {
      case "hyperLink":
        if (data.link) window.open(data.link, "_blank");
        break;

      case "quickReplies":
        if (data.actualMessage) handleUserMessage(data.actualMessage);
        break;

      case "date":
        if (data.date) handleUserMessage(data.date);
        break;

      case "cardCarousel":
        if (data.date) handleUserMessage(data.response);
        break;

      default:
        break;
    }
  }

  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, (0, _ChatTheme.default)(props.theme, props.windowSize), !props.isConnected ? /*#__PURE__*/_react.default.createElement(_MainLoader.default, null) : /*#__PURE__*/_react.default.createElement("section", {
    className: "messenger"
  }, /*#__PURE__*/_react.default.createElement(_Header.default, {
    title: props.title,
    handleMinizeClick: () => props.minimizeWindow(),
    handleCloseClick: () => props.closeConversation()
  }), /*#__PURE__*/_react.default.createElement(_Conversation.default, {
    messageData: props.chatHistory,
    handleButtonClick: handleButtonClick
  }), props.enableMessageLoader ? /*#__PURE__*/_react.default.createElement("img", {
    src: _loading_dots.default,
    alt: "loading bot response",
    style: {
      width: "50px",
      position: "absolute",
      bottom: "45px",
      left: "40%"
    }
  }) : "", /*#__PURE__*/_react.default.createElement(_Footer.default, {
    handleSubmit: e => {
      handleUserMessage(e);
    }
  })));
}

var _default = ChatWindow;
exports.default = _default;