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

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.EmbedCardResolvedView = void 0;
require("./ResolvedView.compiled.css");
var _runtime = require("@compiled/react/runtime");
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _react = _interopRequireDefault(require("react"));
var _reactLoadable = _interopRequireDefault(require("react-loadable"));
var _link = _interopRequireDefault(require("@atlaskit/icon/core/link"));
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
var _platformFeatureFlagsReact = require("@atlaskit/platform-feature-flags-react");
var _useThemeObserver = require("@atlaskit/tokens/use-theme-observer");
var _constants = require("../../../constants");
var _extractRovoChatAction = _interopRequireDefault(require("../../../extractors/flexible/actions/extract-rovo-chat-action"));
var _helpers = require("../../../state/helpers");
var _useEmbedRovoActionsFooterExperiment = _interopRequireDefault(require("../../../state/hooks/use-embed-rovo-actions-footer-experiment"));
var _useRovoConfig2 = _interopRequireDefault(require("../../../state/hooks/use-rovo-config"));
var _utils = require("../../../utils");
var _rovoPostAuthPrompts = require("../../common/rovo-post-auth-prompts");
var _ExpandedFrame = require("../components/ExpandedFrame");
var _Frame = require("../components/Frame");
var _ImageIcon = require("../components/ImageIcon");
var _useEmbedResolvePostMessageListener = require("../useEmbedResolvePostMessageListener");
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" != (0, _typeof2.default)(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 EmbedRovoActionsFooter = (0, _reactLoadable.default)({
  loader: function loader() {
    return Promise.resolve().then(function () {
      return _interopRequireWildcard(require( /* webpackChunkName: "smart-card-embed-rovo-actions-footer" */'../components/rovo-actions-footer'));
    }).then(function (module) {
      return module.default;
    });
  },
  loading: function loading() {
    return null;
  }
});
EmbedRovoActionsFooter.displayName = 'lazy(EmbedRovoActionsFooter)';
var styles = {
  contentWithFooter: "_1e0c1txw _2lx21bp4 _4t3i1osq _1tkeidpf",
  frameWithFooter: "_16jlkb7n _1tkeidpf",
  footer: "_1e0c1txw _1bah1y6m _85i5u2gc _1q51u2gc _y4tiu2gc _bozgu2gc"
};
var EmbedFrameWithRovoFooter = function EmbedFrameWithRovoFooter(_ref) {
  var actionOptions = _ref.actionOptions,
    details = _ref.details,
    frame = _ref.frame,
    link = _ref.link,
    testId = _ref.testId;
  var _useRovoConfig = (0, _useRovoConfig2.default)(),
    rovoOptions = _useRovoConfig.rovoOptions,
    product = _useRovoConfig.product;
  var _useEmbedRovoActionsF = (0, _useEmbedRovoActionsFooterExperiment.default)(link, actionOptions, rovoOptions, product),
    isEmbedRovoActionsFooterEnabled = _useEmbedRovoActionsF.isEnabled;
  var rovoActionData = _react.default.useMemo(function () {
    return isEmbedRovoActionsFooterEnabled && details ? (0, _extractRovoChatAction.default)({
      response: details,
      rovoConfig: {
        rovoOptions: rovoOptions,
        product: product
      },
      product: product,
      actionOptions: actionOptions,
      appearance: _constants.CardDisplay.Embed,
      isEmbedRovoActionsFooterExperimentEnabled: isEmbedRovoActionsFooterEnabled
    }) : undefined;
  }, [actionOptions, details, isEmbedRovoActionsFooterEnabled, product, rovoOptions]);
  var prompts = _react.default.useMemo(function () {
    if (!isEmbedRovoActionsFooterEnabled) {
      return [];
    }
    return (0, _rovoPostAuthPrompts.getRovoPostAuthPromptKeys)({
      extensionKey: (0, _helpers.getExtensionKey)(details)
    });
  }, [details, isEmbedRovoActionsFooterEnabled]);
  var footer = _react.default.useMemo(function () {
    return rovoActionData && prompts.length > 0 ? /*#__PURE__*/_react.default.createElement(EmbedRovoActionsFooter, {
      actionData: rovoActionData,
      prompts: prompts,
      testId: "".concat(testId, "-rovo-actions-footer")
    }) : undefined;
  }, [prompts, rovoActionData, testId]);
  return footer ? /*#__PURE__*/_react.default.createElement("div", {
    className: (0, _runtime.ax)([styles.contentWithFooter])
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: (0, _runtime.ax)([styles.frameWithFooter])
  }, frame), /*#__PURE__*/_react.default.createElement("div", {
    className: (0, _runtime.ax)([styles.footer])
  }, footer)) : frame;
};
var EmbedFrameWithoutRovoFooter = function EmbedFrameWithoutRovoFooter(_ref2) {
  var frame = _ref2.frame;
  return frame;
};
var EmbedFrameWithOptionalRovoFooter = (0, _platformFeatureFlagsReact.componentWithFG)('platform_sl_3p_auth_rovo_embed_footer_kill_switch', EmbedFrameWithRovoFooter, EmbedFrameWithoutRovoFooter);
var EmbedCardResolvedView = exports.EmbedCardResolvedView = /*#__PURE__*/_react.default.forwardRef(function (_ref3, embedIframeRef) {
  var actionOptions = _ref3.actionOptions,
    link = _ref3.link,
    context = _ref3.context,
    details = _ref3.details,
    onClick = _ref3.onClick,
    onAuxClick = _ref3.onAuxClick,
    onContextMenu = _ref3.onContextMenu,
    isSelected = _ref3.isSelected,
    frameStyle = _ref3.frameStyle,
    preview = _ref3.preview,
    title = _ref3.title,
    isTrusted = _ref3.isTrusted,
    _ref3$testId = _ref3.testId,
    testId = _ref3$testId === void 0 ? 'embed-card-resolved-view' : _ref3$testId,
    inheritDimensions = _ref3.inheritDimensions,
    onIframeDwell = _ref3.onIframeDwell,
    onIframeFocus = _ref3.onIframeFocus,
    onIframeMouseEnter = _ref3.onIframeMouseEnter,
    onIframeMouseLeave = _ref3.onIframeMouseLeave,
    isSupportTheming = _ref3.isSupportTheming,
    type = _ref3.type,
    CompetitorPrompt = _ref3.CompetitorPrompt,
    hideIconLoadingSkeleton = _ref3.hideIconLoadingSkeleton,
    extensionKey = _ref3.extensionKey;
  var iconFromContext = context === null || context === void 0 ? void 0 : context.icon;
  var iconLabel = context === null || context === void 0 ? void 0 : context.iconLabel;
  var src = typeof iconFromContext === 'string' ? iconFromContext : undefined;
  var text = title || (context === null || context === void 0 ? void 0 : context.text);
  var linkGlyph = _react.default.useMemo(function () {
    return /*#__PURE__*/_react.default.createElement(_link.default, {
      label: "icon",
      testId: "embed-card-fallback-icon",
      color: "currentColor"
    });
  }, []);
  var icon = _react.default.useMemo(function () {
    if ( /*#__PURE__*/_react.default.isValidElement(iconFromContext)) {
      return iconFromContext;
    }
    return /*#__PURE__*/_react.default.createElement(_ImageIcon.ImageIcon, (0, _extends2.default)({
      src: src
    }, (0, _platformFeatureFlags.fg)('platform_lp_use_entity_icon_url_for_icon') ? {
      alt: iconLabel
    } : undefined, {
      default: linkGlyph,
      appearance: (0, _utils.isProfileType)(type) ? 'round' : 'square',
      hideLoadingSkeleton: hideIconLoadingSkeleton
    }));
  }, [iconFromContext, src, linkGlyph, type, hideIconLoadingSkeleton, iconLabel]);
  (0, _useEmbedResolvePostMessageListener.useEmbedResolvePostMessageListener)({
    url: link,
    embedIframeRef: embedIframeRef
  });
  var themeState = (0, _useThemeObserver.useThemeObserver)();
  var previewUrl = preview === null || preview === void 0 ? void 0 : preview.src;
  if (previewUrl && isSupportTheming) {
    previewUrl = (0, _utils.getPreviewUrlWithTheme)(previewUrl, themeState);
  }
  var _React$useState = _react.default.useState(false),
    _React$useState2 = (0, _slicedToArray2.default)(_React$useState, 2),
    isMouseOver = _React$useState2[0],
    setMouseOver = _React$useState2[1];
  var frame = /*#__PURE__*/_react.default.createElement(_Frame.Frame, {
    url: previewUrl,
    isTrusted: isTrusted,
    testId: testId,
    ref: embedIframeRef,
    onIframeDwell: onIframeDwell,
    onIframeFocus: onIframeFocus,
    onIframeMouseEnter: onIframeMouseEnter,
    onIframeMouseLeave: onIframeMouseLeave,
    isMouseOver: isMouseOver,
    title: text,
    extensionKey: extensionKey
  });
  var frameWithFooter = /*#__PURE__*/_react.default.createElement(EmbedFrameWithOptionalRovoFooter, {
    actionOptions: actionOptions,
    details: details,
    frame: frame,
    link: link,
    testId: testId
  });
  return /*#__PURE__*/_react.default.createElement(_ExpandedFrame.ExpandedFrame, {
    isSelected: isSelected,
    frameStyle: frameStyle,
    href: link,
    testId: testId,
    icon: icon,
    text: text,
    onClick: onClick,
    onAuxClick: onAuxClick,
    onContextMenu: onContextMenu,
    inheritDimensions: inheritDimensions,
    setOverflow: false,
    CompetitorPrompt: CompetitorPrompt,
    onContentMouseEnter: function onContentMouseEnter() {
      setMouseOver(true);
      onIframeMouseEnter === null || onIframeMouseEnter === void 0 || onIframeMouseEnter();
    },
    onContentMouseLeave: function onContentMouseLeave() {
      setMouseOver(false);
      onIframeMouseLeave === null || onIframeMouseLeave === void 0 || onIframeMouseLeave();
    }
  }, frameWithFooter);
});