/* index.tsx generated by @compiled/babel-plugin v0.40.0 */
"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = exports.RovoSummaryBlockResolvedView = void 0;
require("./index.compiled.css");
var _react = _interopRequireWildcard(require("react"));
var React = _react;
var _runtime = require("@compiled/react/runtime");
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _reactIntl = require("react-intl");
var _reactMagneticDi = require("react-magnetic-di");
var _logo = require("@atlaskit/logo");
var _compiled = require("@atlaskit/primitives/compiled");
var _constants = require("../../../../../../constants");
var _messages = require("../../../../../../messages");
var _useAiSummaryAction = _interopRequireDefault(require("../../../../../../state/hooks/use-ai-summary-action"));
var _aiSummary = _interopRequireDefault(require("../../../../../common/ai-summary"));
var _aiFooter = _interopRequireDefault(require("../../../../../common/ai-summary/ai-footer"));
var _motionWrapper = _interopRequireDefault(require("../../../common/motion-wrapper"));
var _block = _interopRequireDefault(require("../../block"));
var _aiEventSummaryViewed = _interopRequireDefault(require("../ai-event-summary-viewed"));
var _ellipses = require("../assets/ellipses");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
var styles = null;
var newStyles = {
  iconWrapper: "_19bv1b66 _u5f3utpp _1e0c1txw _4cvr1h6o",
  placeholderWrapper: "_1e0c1txw _4cvr1h6o",
  summaryWrapper: "_ca0q1b66 _1e0c1txw",
  ellipsesContainer: "_19bv1b66"
};
var AISummaryBlockResolvedView = function AISummaryBlockResolvedView(props) {
  var testId = props.testId,
    _props$aiSummaryMinHe = props.aiSummaryMinHeight,
    aiSummaryMinHeight = _props$aiSummaryMinHe === void 0 ? 0 : _props$aiSummaryMinHe,
    placeholder = props.placeholder,
    url = props.url;
  var _useAISummaryAction = (0, _useAiSummaryAction.default)(url),
    _useAISummaryAction$s = _useAISummaryAction.state,
    content = _useAISummaryAction$s.content,
    status = _useAISummaryAction$s.status;
  var showAISummary = status === 'done' ||
  // We want to display the AI Summary component only when there is content available during the loading process.
  status === 'loading' && !!content;
  var isSummarisedOnMountRef = (0, _react.useRef)(status === 'done');
  var minHeight = isSummarisedOnMountRef.current ? 0 : aiSummaryMinHeight;
  if (!showAISummary) {
    return /*#__PURE__*/React.createElement(_react.Fragment, null, placeholder);
  }
  return /*#__PURE__*/React.createElement(_block.default, (0, _extends2.default)({}, props, {
    direction: _constants.SmartLinkDirection.Vertical,
    testId: "".concat(testId, "-resolved-view"),
    className: (0, _runtime.ax)(["_1reoewfl _18m9ewfl"])
  }), status === 'done' && /*#__PURE__*/React.createElement(_aiEventSummaryViewed.default, {
    fromCache: isSummarisedOnMountRef.current
  }), /*#__PURE__*/React.createElement(_motionWrapper.default, {
    minHeight: minHeight,
    show: showAISummary,
    showTransition: !isSummarisedOnMountRef.current
  }, /*#__PURE__*/React.createElement(_aiSummary.default, {
    testId: "".concat(testId, "-ai-summary"),
    minHeight: minHeight,
    content: content
  })));
};
var RovoSummaryBlockResolvedView = exports.RovoSummaryBlockResolvedView = function RovoSummaryBlockResolvedView(props) {
  var testId = props.testId,
    _props$aiSummaryMinHe2 = props.aiSummaryMinHeight,
    aiSummaryMinHeight = _props$aiSummaryMinHe2 === void 0 ? 0 : _props$aiSummaryMinHe2,
    placeholder = props.placeholder,
    url = props.url;
  var _useAISummaryAction2 = (0, _useAiSummaryAction.default)(url),
    _useAISummaryAction2$ = _useAISummaryAction2.state,
    content = _useAISummaryAction2$.content,
    status = _useAISummaryAction2$.status;
  var isSummarisedOnMountRef = (0, _react.useRef)(status === 'done');
  var minHeight = isSummarisedOnMountRef.current ? 0 : aiSummaryMinHeight;
  if (status === 'error') {
    return null;
  }

  // Show summary when there is content to display
  if (content && content !== '') {
    return /*#__PURE__*/React.createElement(_block.default, (0, _extends2.default)({}, props, {
      direction: _constants.SmartLinkDirection.Vertical,
      testId: "".concat(testId, "-resolved-view"),
      className: (0, _runtime.ax)(["_1reoewfl _18m9ewfl"])
    }), /*#__PURE__*/React.createElement(_compiled.Inline, {
      xcss: newStyles.summaryWrapper
    }, /*#__PURE__*/React.createElement("div", {
      className: (0, _runtime.ax)([newStyles.iconWrapper])
    }, /*#__PURE__*/React.createElement(_logo.RovoIcon, {
      shouldUseHexLogo: true,
      size: "xxsmall"
    })), status === 'done' && /*#__PURE__*/React.createElement(_aiEventSummaryViewed.default, {
      fromCache: isSummarisedOnMountRef.current
    }), /*#__PURE__*/React.createElement(_motionWrapper.default, {
      minHeight: minHeight,
      show: true,
      showTransition: !isSummarisedOnMountRef.current
    }, /*#__PURE__*/React.createElement(_aiSummary.default, {
      testId: "".concat(testId, "-ai-summary"),
      minHeight: minHeight,
      content: content
    }), status === 'done' && /*#__PURE__*/React.createElement(_aiFooter.default, null))));
  }

  // Show loading state on initial request where content hasn't returned yet.
  if (status === 'loading') {
    return /*#__PURE__*/React.createElement(_motionWrapper.default, {
      minHeight: minHeight,
      show: true,
      showTransition: true
    }, /*#__PURE__*/React.createElement(_compiled.Inline, {
      testId: "".concat(testId, "-placeholder"),
      xcss: newStyles.placeholderWrapper
    }, /*#__PURE__*/React.createElement("div", {
      className: (0, _runtime.ax)([newStyles.iconWrapper])
    }, /*#__PURE__*/React.createElement(_logo.RovoIcon, {
      shouldUseHexLogo: true,
      size: 'xxsmall'
    })), /*#__PURE__*/React.createElement(_compiled.Text, {
      size: "small",
      color: "color.text"
    }, /*#__PURE__*/React.createElement(_reactIntl.FormattedMessage, _messages.messages.rovo_summary_loading)), /*#__PURE__*/React.createElement(_compiled.Box, {
      xcss: newStyles.ellipsesContainer
    }, /*#__PURE__*/React.createElement(_ellipses.EllipsesAnimation, {
      isAnimated: true
    }))));
  }

  // Otherwise, show placeholder if provided
  if (placeholder) {
    return /*#__PURE__*/React.createElement(_react.Fragment, null, placeholder);
  }
  return null;
};
var _default = exports.default = AISummaryBlockResolvedView;