/* ResolvedView.tsx generated by @compiled/babel-plugin v0.40.0 */
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import _extends from "@babel/runtime/helpers/extends";
import "./ResolvedView.compiled.css";
import { ax, ix } from "@compiled/react/runtime";
import React from 'react';
import Loadable from 'react-loadable';
import LinkGlyph from '@atlaskit/icon/core/link';
import { fg } from '@atlaskit/platform-feature-flags';
import { componentWithFG } from '@atlaskit/platform-feature-flags-react';
import { useThemeObserver } from '@atlaskit/tokens/use-theme-observer';
import { CardDisplay } from '../../../constants';
import extractRovoChatAction from '../../../extractors/flexible/actions/extract-rovo-chat-action';
import { getExtensionKey } from '../../../state/helpers';
import useEmbedRovoActionsFooterExperiment from '../../../state/hooks/use-embed-rovo-actions-footer-experiment';
import useRovoConfig from '../../../state/hooks/use-rovo-config';
import { getPreviewUrlWithTheme, isProfileType } from '../../../utils';
import { getRovoPostAuthPromptKeys } from '../../common/rovo-post-auth-prompts';
import { ExpandedFrame } from '../components/ExpandedFrame';
import { Frame } from '../components/Frame';
import { ImageIcon } from '../components/ImageIcon';
import { useEmbedResolvePostMessageListener } from '../useEmbedResolvePostMessageListener';
var EmbedRovoActionsFooter = Loadable({
  loader: function loader() {
    return import( /* 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 = useRovoConfig(),
    rovoOptions = _useRovoConfig.rovoOptions,
    product = _useRovoConfig.product;
  var _useEmbedRovoActionsF = useEmbedRovoActionsFooterExperiment(link, actionOptions, rovoOptions, product),
    isEmbedRovoActionsFooterEnabled = _useEmbedRovoActionsF.isEnabled;
  var rovoActionData = React.useMemo(function () {
    return isEmbedRovoActionsFooterEnabled && details ? extractRovoChatAction({
      response: details,
      rovoConfig: {
        rovoOptions: rovoOptions,
        product: product
      },
      product: product,
      actionOptions: actionOptions,
      appearance: CardDisplay.Embed,
      isEmbedRovoActionsFooterExperimentEnabled: isEmbedRovoActionsFooterEnabled
    }) : undefined;
  }, [actionOptions, details, isEmbedRovoActionsFooterEnabled, product, rovoOptions]);
  var prompts = React.useMemo(function () {
    if (!isEmbedRovoActionsFooterEnabled) {
      return [];
    }
    return getRovoPostAuthPromptKeys({
      extensionKey: getExtensionKey(details)
    });
  }, [details, isEmbedRovoActionsFooterEnabled]);
  var footer = React.useMemo(function () {
    return rovoActionData && prompts.length > 0 ? /*#__PURE__*/React.createElement(EmbedRovoActionsFooter, {
      actionData: rovoActionData,
      prompts: prompts,
      testId: "".concat(testId, "-rovo-actions-footer")
    }) : undefined;
  }, [prompts, rovoActionData, testId]);
  return footer ? /*#__PURE__*/React.createElement("div", {
    className: ax([styles.contentWithFooter])
  }, /*#__PURE__*/React.createElement("div", {
    className: ax([styles.frameWithFooter])
  }, frame), /*#__PURE__*/React.createElement("div", {
    className: ax([styles.footer])
  }, footer)) : frame;
};
var EmbedFrameWithoutRovoFooter = function EmbedFrameWithoutRovoFooter(_ref2) {
  var frame = _ref2.frame;
  return frame;
};
var EmbedFrameWithOptionalRovoFooter = componentWithFG('platform_sl_3p_auth_rovo_embed_footer_kill_switch', EmbedFrameWithRovoFooter, EmbedFrameWithoutRovoFooter);
export var EmbedCardResolvedView = /*#__PURE__*/React.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.useMemo(function () {
    return /*#__PURE__*/React.createElement(LinkGlyph, {
      label: "icon",
      testId: "embed-card-fallback-icon",
      color: "currentColor"
    });
  }, []);
  var icon = React.useMemo(function () {
    if ( /*#__PURE__*/React.isValidElement(iconFromContext)) {
      return iconFromContext;
    }
    return /*#__PURE__*/React.createElement(ImageIcon, _extends({
      src: src
    }, fg('platform_lp_use_entity_icon_url_for_icon') ? {
      alt: iconLabel
    } : undefined, {
      default: linkGlyph,
      appearance: isProfileType(type) ? 'round' : 'square',
      hideLoadingSkeleton: hideIconLoadingSkeleton
    }));
  }, [iconFromContext, src, linkGlyph, type, hideIconLoadingSkeleton, iconLabel]);
  useEmbedResolvePostMessageListener({
    url: link,
    embedIframeRef: embedIframeRef
  });
  var themeState = useThemeObserver();
  var previewUrl = preview === null || preview === void 0 ? void 0 : preview.src;
  if (previewUrl && isSupportTheming) {
    previewUrl = getPreviewUrlWithTheme(previewUrl, themeState);
  }
  var _React$useState = React.useState(false),
    _React$useState2 = _slicedToArray(_React$useState, 2),
    isMouseOver = _React$useState2[0],
    setMouseOver = _React$useState2[1];
  var frame = /*#__PURE__*/React.createElement(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.createElement(EmbedFrameWithOptionalRovoFooter, {
    actionOptions: actionOptions,
    details: details,
    frame: frame,
    link: link,
    testId: testId
  });
  return /*#__PURE__*/React.createElement(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);
});