/* ResolvedView.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("./ResolvedView.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 _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _userAgent = require("@atlaskit/linking-common/user-agent");
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
var _constants = require("../../../constants");
var _extractRovoChatAction = _interopRequireDefault(require("../../../extractors/flexible/actions/extract-rovo-chat-action"));
var _helpers = require("../../../state/helpers");
var _useBlockCardRovoActionExperiment = _interopRequireDefault(require("../../../state/hooks/use-block-card-rovo-action-experiment"));
var _useRovoConfig = _interopRequireDefault(require("../../../state/hooks/use-rovo-config"));
var _rovoChatUtils = require("../../common/rovo-chat-utils");
var _FlexibleCard = _interopRequireDefault(require("../../FlexibleCard"));
var _blocks = require("../../FlexibleCard/components/blocks");
var _utils = require("./utils");
var _withFlexibleUIBlockCardStyle = require("./utils/withFlexibleUIBlockCardStyle");
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 titleBlockCss = null;
var footerBlockCss = null;
var footerExtraSpacingCss = null;
var footerBlockSafariStyles = null;

/**
 * This view represents a Block card that has an 'Resolved' status.
 * @see SmartLinkStatus
 * @see FlexibleCardProps
 */
var ResolvedView = function ResolvedView(_ref) {
  var _cardState$details2;
  var cardState = _ref.cardState,
    onClick = _ref.onClick,
    onAuxClick = _ref.onAuxClick,
    onContextMenu = _ref.onContextMenu,
    onError = _ref.onError,
    onResolve = _ref.onResolve,
    actionOptions = _ref.actionOptions,
    _ref$testId = _ref.testId,
    testId = _ref$testId === void 0 ? 'smart-block-resolved-view' : _ref$testId,
    url = _ref.url,
    CompetitorPrompt = _ref.CompetitorPrompt,
    hideIconLoadingSkeleton = _ref.hideIconLoadingSkeleton;
  var _useState = (0, _react.useState)(false),
    _useState2 = (0, _slicedToArray2.default)(_useState, 2),
    isPreviewBlockErrored = _useState2[0],
    setIsPreviewBlockErrored = _useState2[1];
  var extensionKey = (0, _helpers.getExtensionKey)(cardState.details);
  var is3PRovoBlockRovoActionEnabled = (0, _useBlockCardRovoActionExperiment.default)(url, actionOptions);
  var rovoConfig = (0, _useRovoConfig.default)();

  // eslint-disable-next-line react-hooks/rules-of-hooks
  var _useMemo = (0, _react.useMemo)(function () {
      return (0, _userAgent.browser)();
    }, []),
    _useMemo$safari = _useMemo.safari,
    safari = _useMemo$safari === void 0 ? false : _useMemo$safari;
  (0, _react.useEffect)(function () {
    setIsPreviewBlockErrored(false);
  }, [url, cardState]);
  var _getSimulatedBetterMe = (0, _utils.getSimulatedBetterMetadata)(cardState.details),
    titleMetadata = _getSimulatedBetterMe.titleMetadata,
    topMetadata = _getSimulatedBetterMe.topMetadata,
    bottomMetadata = _getSimulatedBetterMe.bottomMetadata;
  var prompts = (0, _react.useMemo)(function () {
    if (is3PRovoBlockRovoActionEnabled) {
      var _cardState$details;
      var defaultPrompts = [_rovoChatUtils.RovoChatPromptKey.KEY_HIGHLIGHTS];
      var linkType = (_cardState$details = cardState.details) === null || _cardState$details === void 0 || (_cardState$details = _cardState$details.data) === null || _cardState$details === void 0 ? void 0 : _cardState$details['@type'];
      if (extensionKey === 'slack-object-provider') {
        return [_rovoChatUtils.RovoChatPromptKey.FIND_OPEN_QUESTIONS].concat(defaultPrompts);
      }
      if (extensionKey === 'google-object-provider' && linkType !== null && linkType !== void 0 && linkType.includes('schema:PresentationDigitalDocument')) {
        return [_rovoChatUtils.RovoChatPromptKey.IDENTIFY_KEY_POINTS].concat(defaultPrompts);
      }
      if (extensionKey === 'google-object-provider' && linkType !== null && linkType !== void 0 && linkType.includes('schema:SpreadsheetDigitalDocument')) {
        return [_rovoChatUtils.RovoChatPromptKey.IDENTIFY_KEY_TRENDS].concat(defaultPrompts);
      }
      return [_rovoChatUtils.RovoChatPromptKey.SUMMARIZE_LINK].concat(defaultPrompts);
    }
    return [];
  }, [cardState === null || cardState === void 0 || (_cardState$details2 = cardState.details) === null || _cardState$details2 === void 0 ? void 0 : _cardState$details2.data, extensionKey, is3PRovoBlockRovoActionEnabled]);
  var footerActions = (0, _react.useMemo)(function () {
    var showRovoResolvedView = (cardState === null || cardState === void 0 ? void 0 : cardState.status) === 'resolved' && cardState.details && (0, _extractRovoChatAction.default)({
      response: cardState.details,
      rovoConfig: rovoConfig,
      actionOptions: actionOptions
    }) !== undefined;
    return showRovoResolvedView && is3PRovoBlockRovoActionEnabled ? [{
      name: _constants.ActionName.RovoChatAction,
      prompts: prompts,
      iconSize: 'small',
      cardAppearance: _constants.CardDisplay.Block
    }, {
      name: _constants.ActionName.FollowAction,
      iconSize: 'small'
    }, {
      name: _constants.ActionName.DownloadAction,
      iconSize: 'small'
    }] : [{
      name: _constants.ActionName.FollowAction,
      hideIcon: true
    }, {
      name: _constants.ActionName.PreviewAction,
      hideIcon: true
    }, {
      name: _constants.ActionName.DownloadAction,
      hideIcon: true
    }];
  }, [prompts, is3PRovoBlockRovoActionEnabled, cardState, rovoConfig, actionOptions]);
  var uiOptions = _utils.FlexibleCardUiOptions;
  uiOptions.enableSnippetRenderer = true;
  uiOptions.hideLoadingSkeleton = hideIconLoadingSkeleton;
  return /*#__PURE__*/React.createElement(_FlexibleCard.default, {
    appearance: "block",
    cardState: cardState,
    onClick: onClick,
    onAuxClick: onAuxClick,
    onContextMenu: onContextMenu,
    onError: onError,
    onResolve: onResolve,
    origin: "smartLinkCard",
    actionOptions: actionOptions,
    testId: testId,
    ui: uiOptions,
    url: url
  }, /*#__PURE__*/React.createElement(_blocks.TitleBlock, (0, _extends2.default)({}, _utils.titleBlockOptions, {
    metadata: titleMetadata,
    subtitle: [{
      name: _constants.ElementName.Location
    }],
    metadataPosition: _constants.SmartLinkPosition.Top,
    CompetitorPrompt: CompetitorPrompt,
    url: url,
    hideIconLoadingSkeleton: hideIconLoadingSkeleton,
    className: (0, _runtime.ax)(["_zulpu2gc _13mh1pd9 _2yhz13af"])
  })), /*#__PURE__*/React.createElement(_blocks.MetadataBlock, {
    primary: topMetadata,
    maxLines: 1
  }), /*#__PURE__*/React.createElement(_blocks.SnippetBlock, null), /*#__PURE__*/React.createElement(_blocks.MetadataBlock, {
    primary: bottomMetadata,
    maxLines: 1
  }), !isPreviewBlockErrored ? /*#__PURE__*/React.createElement(_blocks.PreviewBlock, (0, _extends2.default)({}, _utils.PreviewBlockOptions, {
    onError: function onError() {
      setIsPreviewBlockErrored(true);
    }
  })) : null, /*#__PURE__*/React.createElement(_blocks.FooterBlock, {
    actions: footerActions,
    isPreviewBlockErrored: isPreviewBlockErrored,
    className: (0, _runtime.ax)(["_4t3i1k8s _1e0c1txw _1bah1yb4 _4cvresu3 _1wpz1fhb", safari && "_4t3i1osq", (0, _platformFeatureFlags.fg)('platform_navx_block_card_footer_spacing') && "_19pku2gc"])
  }));
};
var _default_1 = (0, _withFlexibleUIBlockCardStyle.withFlexibleUIBlockCardStyle)(ResolvedView);
var _default = exports.default = _default_1;