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

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
require("./index.compiled.css");
var _runtime = require("@compiled/react/runtime");
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _react = _interopRequireWildcard(require("react"));
var _reactMagneticDi = require("react-magnetic-di");
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
var _useAnalyticsEvents2 = require("../../../../../common/analytics/generated/use-analytics-events");
var _constants = require("../../../../../constants");
var _analytics = require("../../../../../state/analytics");
var _useAiSummaryAction = _interopRequireDefault(require("../../../../../state/hooks/use-ai-summary-action"));
var _FlexibleCard = _interopRequireDefault(require("../../../../FlexibleCard"));
var _blocks = require("../../../../FlexibleCard/components/blocks");
var _aiSummaryBlock = require("../../../../FlexibleCard/components/blocks/ai-summary-block");
var _utils = require("../../../utils");
var _ImagePreview = _interopRequireDefault(require("../../ImagePreview"));
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 hiddenSnippetStyles = null;
var titleBlockStyles = null;
var snippetBlockCss = null;
var actionBlockCss = null;
var HoverCardResolvedView = function HoverCardResolvedView(_ref) {
  var _cardState$details;
  var cardState = _ref.cardState,
    extensionKey = _ref.extensionKey,
    flexibleCardProps = _ref.flexibleCardProps,
    isAISummaryEnabled = _ref.isAISummaryEnabled,
    onActionClick = _ref.onActionClick,
    showRovoResolvedView = _ref.showRovoResolvedView,
    titleBlockProps = _ref.titleBlockProps,
    id = _ref.id,
    url = _ref.url;
  var _useAnalyticsEvents = (0, _useAnalyticsEvents2.useAnalyticsEvents)(),
    fireEvent = _useAnalyticsEvents.fireEvent;

  // We want to fire exposure event only for those cases when user otherwise can see the experiment which would be controlled
  // by all the other condition defined above as a result of what was defined in actionOptions as well as in CardContext.
  var is3PAuthRovoActionsExperimentOn = showRovoResolvedView && (0, _expValEquals.expValEquals)('platform_sl_3p_auth_rovo_action', 'isEnabled', true);
  (0, _react.useEffect)(function () {
    // Since this hover view is only rendered on resolved status,
    // there is no need to check for statuses.
    (0, _analytics.succeedUfoExperience)('smart-link-rendered', id || 'NULL', {
      extensionKey: extensionKey,
      display: _constants.CardDisplay.HoverCardPreview
    });

    // UFO will disregard this if authentication experience has not yet been started
    (0, _analytics.succeedUfoExperience)('smart-link-authenticated', id || 'NULL', {
      display: _constants.CardDisplay.HoverCardPreview
    });
    fireEvent('ui.smartLink.renderSuccess', {
      display: _constants.CardDisplay.HoverCardPreview
    });
  }, [extensionKey, fireEvent, id]);
  var data = (_cardState$details = cardState.details) === null || _cardState$details === void 0 ? void 0 : _cardState$details.data;
  var _useMemo = (0, _react.useMemo)(function () {
      return (0, _utils.getMetadata)(extensionKey, data);
    }, [data, extensionKey]),
    primary = _useMemo.primary,
    secondary = _useMemo.secondary;
  var snippetHeight = _react.default.useRef(0);
  var snippetBlockRef = (0, _react.useRef)(null);
  var onSnippetRender = (0, _react.useCallback)(function () {
    var _snippetBlockRef$curr, _snippetBlockRef$curr2;
    snippetHeight.current = (_snippetBlockRef$curr = (_snippetBlockRef$curr2 = snippetBlockRef.current) === null || _snippetBlockRef$curr2 === void 0 ? void 0 : _snippetBlockRef$curr2.getBoundingClientRect().height) !== null && _snippetBlockRef$curr !== void 0 ? _snippetBlockRef$curr : 0;
  }, []);
  var imagePreview = (0, _ImagePreview.default)({
    fallbackElementHeight: snippetHeight.current,
    response: cardState.details
  });
  var snippet = imagePreview ? null : /*#__PURE__*/_react.default.createElement(_blocks.SnippetBlock, {
    className: (0, _runtime.ax)(["_ca0q1b66"])
  });
  var aiSummaryMinHeight = snippet ? snippetHeight.current : 0;
  return /*#__PURE__*/_react.default.createElement(_FlexibleCard.default, flexibleCardProps, imagePreview, /*#__PURE__*/_react.default.createElement(_blocks.TitleBlock, (0, _extends2.default)({}, titleBlockProps, {
    metadataPosition: _constants.SmartLinkPosition.Top,
    className: (0, _runtime.ax)(["_zulpu2gc _quenze3t _oebj1txw _13mh1pd9"])
  })), /*#__PURE__*/_react.default.createElement(_blocks.MetadataBlock, {
    primary: primary,
    secondary: secondary,
    maxLines: 1,
    size: _constants.SmartLinkSize.Medium
  }), is3PAuthRovoActionsExperimentOn ? /*#__PURE__*/_react.default.createElement(_aiSummaryBlock.RovoSummaryBlock, {
    aiSummaryMinHeight: aiSummaryMinHeight,
    url: url
  }) : isAISummaryEnabled ? /*#__PURE__*/_react.default.createElement(_blocks.AISummaryBlock, {
    aiSummaryMinHeight: aiSummaryMinHeight,
    placeholder: snippet
  }) : snippet, /*#__PURE__*/_react.default.createElement(_blocks.SnippetBlock, {
    testId: "hidden-snippet",
    onRender: onSnippetRender,
    blockRef: snippetBlockRef,
    isHidden: true,
    className: (0, _runtime.ax)(["_3um015vq _kqswstnw"])
  }), /*#__PURE__*/_react.default.createElement(_blocks.ActionBlock, {
    onClick: onActionClick,
    spaceInline: "space.100",
    is3PAuthRovoActionsExperimentOn: is3PAuthRovoActionsExperimentOn,
    className: (0, _runtime.ax)(["_n3td1b66"])
  }), is3PAuthRovoActionsExperimentOn ? /*#__PURE__*/_react.default.createElement(_blocks.ResolvedHoverCardFooterBlock, {
    onActionClick: onActionClick
  }) : /*#__PURE__*/_react.default.createElement(_blocks.AIFooterBlock, null));
};
var _default = exports.default = HoverCardResolvedView;