"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.CardWithUrlContent = void 0;
var _react = _interopRequireWildcard(require("react"));
var _analyticsNext = require("@atlaskit/analytics-next");
var _linkExtractors = require("@atlaskit/link-extractors");
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
var _platformFeatureFlagsReact = require("@atlaskit/platform-feature-flags-react");
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
var _useAnalyticsEvents3 = require("../../common/analytics/generated/use-analytics-events");
var _constants = require("../../constants");
var _state = require("../../state");
var _analytics = require("../../state/analytics");
var _helpers = require("../../state/helpers");
var _modal = require("../../state/modal");
var _utils = require("../../utils");
var _combineActionOptions = require("../../utils/actions/combine-action-options");
var _click = require("../../utils/analytics/click");
var _SmartLinkAnalyticsContext = require("../../utils/analytics/SmartLinkAnalyticsContext");
var _flexible = require("../../utils/flexible");
var measure = _interopRequireWildcard(require("../../utils/performance"));
var _BlockCard = require("../BlockCard");
var _EmbedCard = require("../EmbedCard");
var _FlexibleCard = _interopRequireDefault(require("../FlexibleCard"));
var _InlineCard = require("../InlineCard");
var _useSmartLinkEvents = require("../SmartLinkEvents/useSmartLinkEvents");
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 thirdPartyARIPrefix = 'ari:third-party';
var EmbedCardComponent = (0, _platformFeatureFlagsReact.componentWithFG)('rovo_chat_embed_card_dwell_and_hover_metrics', _EmbedCard.EmbedCardUpdated, _EmbedCard.EmbedCard);
function Component(_ref) {
  var id = _ref.id,
    url = _ref.url,
    isSelected = _ref.isSelected,
    isHovered = _ref.isHovered,
    frameStyle = _ref.frameStyle,
    platform = _ref.platform,
    onClick = _ref.onClick,
    appearance = _ref.appearance,
    onResolve = _ref.onResolve,
    onError = _ref.onError,
    testId = _ref.testId,
    actionOptionsProp = _ref.actionOptions,
    inheritDimensions = _ref.inheritDimensions,
    embedIframeRef = _ref.embedIframeRef,
    embedIframeUrlType = _ref.embedIframeUrlType,
    inlinePreloaderStyle = _ref.inlinePreloaderStyle,
    ui = _ref.ui,
    children = _ref.children,
    showHoverPreview = _ref.showHoverPreview,
    hoverPreviewOptions = _ref.hoverPreviewOptions,
    removeTextHighlightingFromTitle = _ref.removeTextHighlightingFromTitle,
    resolvingPlaceholder = _ref.resolvingPlaceholder,
    truncateInline = _ref.truncateInline,
    CompetitorPrompt = _ref.CompetitorPrompt,
    hideIconLoadingSkeleton = _ref.hideIconLoadingSkeleton,
    disablePreviewPanel = _ref.disablePreviewPanel,
    placeholderData = _ref.placeholderData;
  var _useAnalyticsEventsNe = (0, _analyticsNext.useAnalyticsEvents)(),
    createAnalyticsEvent = _useAnalyticsEventsNe.createAnalyticsEvent;
  var _useAnalyticsEvents = (0, _useAnalyticsEvents3.useAnalyticsEvents)(),
    fireEvent = _useAnalyticsEvents.fireEvent;
  var isFlexibleUi = (0, _react.useMemo)(function () {
    return (0, _flexible.isFlexibleUiCard)(children, ui);
  }, [children, ui]);

  // Get state, actions for this card.
  var _useSmartLink = (0, _state.useSmartLink)(id, url),
    state = _useSmartLink.state,
    actions = _useSmartLink.actions,
    config = _useSmartLink.config,
    renderers = _useSmartLink.renderers,
    error = _useSmartLink.error,
    isPreviewPanelAvailable = _useSmartLink.isPreviewPanelAvailable,
    openPreviewPanel = _useSmartLink.openPreviewPanel;
  var ari = (0, _helpers.getObjectAri)(state.details);
  var name = (0, _helpers.getObjectName)(state.details);
  var definitionId = (0, _helpers.getDefinitionId)(state.details);
  var extensionKey = (0, _helpers.getExtensionKey)(state.details);
  var resourceType = (0, _helpers.getResourceType)(state.details);
  var services = (0, _helpers.getServices)(state.details);
  var thirdPartyARI = (0, _helpers.getThirdPartyARI)(state.details);
  var firstPartyIdentifier = (0, _helpers.getFirstPartyIdentifier)();
  var actionOptions = (0, _combineActionOptions.combineActionOptions)({
    actionOptions: actionOptionsProp,
    platform: platform
  });
  var fire3PClickEvent = (0, _platformFeatureFlags.fg)('platform_smartlink_3pclick_analytics') ?
  // eslint-disable-next-line react-hooks/rules-of-hooks
  (0, _useSmartLinkEvents.useFire3PWorkflowsClickEvent)(firstPartyIdentifier, thirdPartyARI) : undefined;

  // Setup UI handlers.
  var handleClickWrapper = (0, _react.useCallback)(function (event) {
    var isModifierKeyPressed = (0, _utils.isSpecialKey)(event) || (0, _utils.isSpecialClick)(event);
    fireEvent('ui.smartLink.clicked', {
      id: id,
      display: isFlexibleUi ? _constants.CardDisplay.Flexible : appearance,
      definitionId: definitionId !== null && definitionId !== void 0 ? definitionId : null,
      isModifierKeyPressed: isModifierKeyPressed
    });
    if ((0, _platformFeatureFlags.fg)('platform_smartlink_3pclick_analytics')) {
      if (thirdPartyARI && thirdPartyARI.startsWith(thirdPartyARIPrefix)) {
        var clickURL = (0, _helpers.getClickUrl)(url, state.details);
        if (clickURL === url && fire3PClickEvent) {
          // For questions or concerns about this event,
          // please reach out to the 3P Workflows Team via Slack in #help-3p-connector-workflow
          fire3PClickEvent();
        }
      }
    }
    var isDisablePreviewPanel = disablePreviewPanel && (0, _experiments.editorExperiment)('platform_editor_preview_panel_linking_exp', true, {
      exposure: true
    });

    // If preview panel is available and the user clicked on the link,
    // delegate the click to the preview panel handler
    if (!isModifierKeyPressed && ari && name && openPreviewPanel && isPreviewPanelAvailable !== null && isPreviewPanelAvailable !== void 0 && isPreviewPanelAvailable({
      ari: ari
    }) && !isDisablePreviewPanel) {
      var _extractSmartLinkEmbe;
      event.preventDefault();
      event.stopPropagation();
      openPreviewPanel({
        url: url,
        ari: ari,
        name: name,
        iconUrl: (0, _helpers.getObjectIconUrl)(state.details),
        panelData: {
          embedUrl: (0, _expValEquals.expValEquals)('platform_hover_card_preview_panel', 'cohort', 'test') ? (_extractSmartLinkEmbe = (0, _linkExtractors.extractSmartLinkEmbed)(state.details)) === null || _extractSmartLinkEmbe === void 0 ? void 0 : _extractSmartLinkEmbe.src : undefined
        }
      });
      (0, _click.fireLinkClickedEvent)(createAnalyticsEvent)(event, {
        attributes: {
          clickOutcome: 'previewPanel'
        }
      });
      return;
    } else if (!onClick && !isFlexibleUi) {
      var clickUrl = (0, _helpers.getClickUrl)(url, state.details);

      // Ctrl+left click on mac typically doesn't trigger onClick
      // The event could have potentially had `e.preventDefault()` called on it by now
      // event by smart card internally
      // If it has been called then only then can `isSpecialEvent` be true.
      var target = (0, _utils.isSpecialEvent)(event) ? '_blank' : '_self';
      window.open(clickUrl, target);
      (0, _click.fireLinkClickedEvent)(createAnalyticsEvent)(event, {
        attributes: {
          clickOutcome: target === '_blank' ? 'clickThroughNewTabOrWindow' : 'clickThrough'
        }
      });
    } else {
      if (onClick) {
        onClick(event);
      }
      (0, _click.fireLinkClickedEvent)(createAnalyticsEvent)(event);
    }
  }, [fireEvent, id, isFlexibleUi, appearance, definitionId, onClick, url, state.details, ari, name, fire3PClickEvent, isPreviewPanelAvailable, openPreviewPanel, createAnalyticsEvent, thirdPartyARI, disablePreviewPanel]);
  var handleAuthorize = (0, _react.useCallback)(function () {
    return actions.authorize(appearance);
  }, [actions, appearance]);
  var handleRetry = (0, _react.useCallback)(function () {
    actions.reload();
  }, [actions]);
  var handleInvoke = (0, _react.useCallback)(function (opts) {
    return actions.invoke(opts, appearance);
  }, [actions, appearance]);

  // NB: for each status change in a Smart Link, a performance mark is created.
  // Measures are sent relative to the first mark, matching what a user sees.
  (0, _react.useEffect)(function () {
    measure.mark(id, state.status);
    if (state.status !== 'pending' && state.status !== 'resolving') {
      var _state$error, _state$error2;
      measure.create(id, state.status);
      if (state.status === 'resolved') {
        var _measure$getMeasure$d, _measure$getMeasure;
        fireEvent('operational.smartLink.resolved', {
          definitionId: definitionId !== null && definitionId !== void 0 ? definitionId : null,
          duration: (_measure$getMeasure$d = (_measure$getMeasure = measure.getMeasure(id, state.status)) === null || _measure$getMeasure === void 0 ? void 0 : _measure$getMeasure.duration) !== null && _measure$getMeasure$d !== void 0 ? _measure$getMeasure$d : null
        });
      } else if (((_state$error = state.error) === null || _state$error === void 0 ? void 0 : _state$error.type) !== 'ResolveUnsupportedError' && ((_state$error2 = state.error) === null || _state$error2 === void 0 ? void 0 : _state$error2.type) !== 'UnsupportedError') {
        fireEvent('operational.smartLink.unresolved', {
          definitionId: definitionId !== null && definitionId !== void 0 ? definitionId : null,
          reason: state.status,
          error: state.error === undefined ? null : {
            name: state.error.name,
            kind: state.error.kind,
            type: state.error.type
          }
        });
      }
    }
  }, [id, appearance, state.status, state.error, definitionId, extensionKey, resourceType, fireEvent]);

  // NB: once the smart-card has rendered into an end state, we capture
  // this as a successful render. These can be one of:
  // - the resolved state: when metadata is shown;
  // - the unresolved states: viz. forbidden, not_found, unauthorized, errored.
  (0, _react.useEffect)(function () {
    if ((0, _helpers.isFinalState)(state.status)) {
      (0, _analytics.succeedUfoExperience)('smart-link-rendered', id || 'NULL', {
        extensionKey: extensionKey,
        display: isFlexibleUi ? 'flexible' : appearance
      });

      // UFO will disregard this if authentication experience has not yet been started
      (0, _analytics.succeedUfoExperience)('smart-link-authenticated', id || 'NULL', {
        display: isFlexibleUi ? 'flexible' : appearance
      });
      fireEvent('ui.smartLink.renderSuccess', {
        display: isFlexibleUi ? 'flexible' : appearance
      });
    }
  }, [appearance, extensionKey, fireEvent, id, isFlexibleUi, state.status]);
  var onIframeDwell = (0, _react.useCallback)(function (dwellTime, dwellPercentVisible) {
    fireEvent('ui.smartLinkIframe.dwelled', {
      id: id,
      definitionId: definitionId !== null && definitionId !== void 0 ? definitionId : null,
      display: isFlexibleUi ? 'flexible' : appearance,
      dwellPercentVisible: dwellPercentVisible,
      dwellTime: dwellTime
    });
  }, [id, appearance, definitionId, isFlexibleUi, fireEvent]);
  var onIframeFocus = (0, _react.useCallback)(function () {
    fireEvent('ui.smartLinkIframe.focused', {
      id: id,
      definitionId: definitionId !== null && definitionId !== void 0 ? definitionId : null,
      display: isFlexibleUi ? 'flexible' : appearance
    });
  }, [id, appearance, definitionId, isFlexibleUi, fireEvent]);
  if (isFlexibleUi) {
    var cardState = state;
    if (error) {
      if ((error === null || error === void 0 ? void 0 : error.name) === 'APIError') {
        cardState = {
          status: 'errored'
        };
      } else {
        throw error;
      }
    }
    return /*#__PURE__*/_react.default.createElement(_FlexibleCard.default, {
      id: id,
      cardState: cardState,
      placeholderData: placeholderData,
      onAuthorize: services.length && handleAuthorize || undefined,
      onClick: handleClickWrapper,
      origin: "smartLinkCard",
      renderers: renderers,
      ui: ui,
      showHoverPreview: showHoverPreview,
      hoverPreviewOptions: hoverPreviewOptions,
      actionOptions: actionOptions,
      url: url,
      testId: testId,
      onResolve: onResolve,
      onError: onError
    }, children);
  }

  // We have to keep this last to prevent hook order from being violated
  if (error) {
    throw error;
  }
  switch (appearance) {
    case 'inline':
      return /*#__PURE__*/_react.default.createElement(_InlineCard.InlineCard, {
        id: id,
        url: url,
        renderers: renderers,
        cardState: state,
        handleAuthorize: services.length && handleAuthorize || undefined,
        handleFrameClick: handleClickWrapper,
        isSelected: isSelected,
        isHovered: isHovered,
        onResolve: onResolve,
        onError: onError,
        testId: testId,
        inlinePreloaderStyle: inlinePreloaderStyle,
        showHoverPreview: showHoverPreview,
        hoverPreviewOptions: hoverPreviewOptions,
        actionOptions: actionOptions,
        removeTextHighlightingFromTitle: removeTextHighlightingFromTitle,
        resolvingPlaceholder: resolvingPlaceholder,
        truncateInline: truncateInline,
        hideIconLoadingSkeleton: hideIconLoadingSkeleton
      });
    case 'block':
      return /*#__PURE__*/_react.default.createElement(_BlockCard.BlockCard, {
        id: id,
        url: url,
        renderers: renderers,
        authFlow: config && config.authFlow,
        cardState: state,
        handleAuthorize: services.length && handleAuthorize || undefined,
        handleFrameClick: handleClickWrapper,
        isSelected: isSelected,
        onResolve: onResolve,
        onError: onError,
        testId: testId,
        actionOptions: actionOptions,
        CompetitorPrompt: CompetitorPrompt,
        hideIconLoadingSkeleton: hideIconLoadingSkeleton
      });
    case 'embed':
      return /*#__PURE__*/_react.default.createElement(_EmbedCard.EmbedCard, {
        id: id,
        url: url,
        renderers: renderers,
        cardState: state,
        iframeUrlType: embedIframeUrlType,
        handleAuthorize: services.length && handleAuthorize || undefined,
        handleErrorRetry: handleRetry,
        handleFrameClick: handleClickWrapper,
        handleInvoke: handleInvoke,
        isSelected: isSelected,
        frameStyle: frameStyle,
        platform: platform,
        onResolve: onResolve,
        onError: onError,
        testId: testId,
        inheritDimensions: inheritDimensions,
        actionOptions: actionOptions,
        ref: embedIframeRef,
        onIframeDwell: onIframeDwell,
        onIframeFocus: onIframeFocus,
        CompetitorPrompt: CompetitorPrompt,
        hideIconLoadingSkeleton: hideIconLoadingSkeleton
      });
  }
}
function ComponentUpdated(_ref2) {
  var id = _ref2.id,
    url = _ref2.url,
    isSelected = _ref2.isSelected,
    isHovered = _ref2.isHovered,
    frameStyle = _ref2.frameStyle,
    platform = _ref2.platform,
    onClick = _ref2.onClick,
    appearance = _ref2.appearance,
    onResolve = _ref2.onResolve,
    onError = _ref2.onError,
    testId = _ref2.testId,
    actionOptionsProp = _ref2.actionOptions,
    inheritDimensions = _ref2.inheritDimensions,
    embedIframeRef = _ref2.embedIframeRef,
    embedIframeUrlType = _ref2.embedIframeUrlType,
    inlinePreloaderStyle = _ref2.inlinePreloaderStyle,
    ui = _ref2.ui,
    children = _ref2.children,
    showHoverPreview = _ref2.showHoverPreview,
    hoverPreviewOptions = _ref2.hoverPreviewOptions,
    removeTextHighlightingFromTitle = _ref2.removeTextHighlightingFromTitle,
    resolvingPlaceholder = _ref2.resolvingPlaceholder,
    truncateInline = _ref2.truncateInline,
    CompetitorPrompt = _ref2.CompetitorPrompt,
    hideIconLoadingSkeleton = _ref2.hideIconLoadingSkeleton,
    disablePreviewPanel = _ref2.disablePreviewPanel,
    placeholderData = _ref2.placeholderData;
  var _useAnalyticsEventsNe2 = (0, _analyticsNext.useAnalyticsEvents)(),
    createAnalyticsEvent = _useAnalyticsEventsNe2.createAnalyticsEvent;
  var _useAnalyticsEvents2 = (0, _useAnalyticsEvents3.useAnalyticsEvents)(),
    fireEvent = _useAnalyticsEvents2.fireEvent;
  var isFlexibleUi = (0, _react.useMemo)(function () {
    return (0, _flexible.isFlexibleUiCard)(children, ui);
  }, [children, ui]);

  // Get state, actions for this card.
  var _useSmartLink2 = (0, _state.useSmartLink)(id, url),
    state = _useSmartLink2.state,
    actions = _useSmartLink2.actions,
    config = _useSmartLink2.config,
    renderers = _useSmartLink2.renderers,
    error = _useSmartLink2.error,
    isPreviewPanelAvailable = _useSmartLink2.isPreviewPanelAvailable,
    openPreviewPanel = _useSmartLink2.openPreviewPanel;
  var ari = (0, _helpers.getObjectAri)(state.details);
  var name = (0, _helpers.getObjectName)(state.details);
  var definitionId = (0, _helpers.getDefinitionId)(state.details);
  var extensionKey = (0, _helpers.getExtensionKey)(state.details);
  var resourceType = (0, _helpers.getResourceType)(state.details);
  var services = (0, _helpers.getServices)(state.details);
  var thirdPartyARI = (0, _helpers.getThirdPartyARI)(state.details);
  var firstPartyIdentifier = (0, _helpers.getFirstPartyIdentifier)();
  var actionOptions = (0, _combineActionOptions.combineActionOptions)({
    actionOptions: actionOptionsProp,
    platform: platform
  });
  var fire3PClickEvent = (0, _platformFeatureFlags.fg)('platform_smartlink_3pclick_analytics') ?
  // eslint-disable-next-line react-hooks/rules-of-hooks
  (0, _useSmartLinkEvents.useFire3PWorkflowsClickEvent)(firstPartyIdentifier, thirdPartyARI) : undefined;

  // Setup UI handlers.
  var handleClickWrapper = (0, _react.useCallback)(function (event) {
    var isModifierKeyPressed = (0, _utils.isSpecialKey)(event) || (0, _utils.isSpecialClick)(event);
    fireEvent('ui.smartLink.clicked', {
      id: id,
      display: isFlexibleUi ? _constants.CardDisplay.Flexible : appearance,
      definitionId: definitionId !== null && definitionId !== void 0 ? definitionId : null,
      isModifierKeyPressed: isModifierKeyPressed
    });
    if ((0, _platformFeatureFlags.fg)('platform_smartlink_3pclick_analytics')) {
      if (thirdPartyARI && thirdPartyARI.startsWith(thirdPartyARIPrefix)) {
        var clickURL = (0, _helpers.getClickUrl)(url, state.details);
        if (clickURL === url && fire3PClickEvent) {
          // For questions or concerns about this event,
          // please reach out to the 3P Workflows Team via Slack in #help-3p-connector-workflow
          fire3PClickEvent();
        }
      }
    }
    var isDisablePreviewPanel = disablePreviewPanel && (0, _experiments.editorExperiment)('platform_editor_preview_panel_linking_exp', true, {
      exposure: true
    });

    // If preview panel is available and the user clicked on the link,
    // delegate the click to the preview panel handler
    if (!isModifierKeyPressed && ari && name && openPreviewPanel && isPreviewPanelAvailable !== null && isPreviewPanelAvailable !== void 0 && isPreviewPanelAvailable({
      ari: ari
    }) && !isDisablePreviewPanel) {
      var _extractSmartLinkEmbe2;
      event.preventDefault();
      event.stopPropagation();
      openPreviewPanel({
        url: url,
        ari: ari,
        name: name,
        iconUrl: (0, _helpers.getObjectIconUrl)(state.details),
        panelData: {
          embedUrl: (0, _expValEquals.expValEquals)('platform_hover_card_preview_panel', 'cohort', 'test') ? (_extractSmartLinkEmbe2 = (0, _linkExtractors.extractSmartLinkEmbed)(state.details)) === null || _extractSmartLinkEmbe2 === void 0 ? void 0 : _extractSmartLinkEmbe2.src : undefined
        }
      });
      (0, _click.fireLinkClickedEvent)(createAnalyticsEvent)(event, {
        attributes: {
          clickOutcome: 'previewPanel'
        }
      });
      return;
    } else if (!onClick && !isFlexibleUi) {
      var clickUrl = (0, _helpers.getClickUrl)(url, state.details);

      // Ctrl+left click on mac typically doesn't trigger onClick
      // The event could have potentially had `e.preventDefault()` called on it by now
      // event by smart card internally
      // If it has been called then only then can `isSpecialEvent` be true.
      var target = (0, _utils.isSpecialEvent)(event) ? '_blank' : '_self';
      window.open(clickUrl, target);
      (0, _click.fireLinkClickedEvent)(createAnalyticsEvent)(event, {
        attributes: {
          clickOutcome: target === '_blank' ? 'clickThroughNewTabOrWindow' : 'clickThrough'
        }
      });
    } else {
      if (onClick) {
        onClick(event);
      }
      (0, _click.fireLinkClickedEvent)(createAnalyticsEvent)(event);
    }
  }, [fireEvent, id, isFlexibleUi, appearance, definitionId, onClick, url, state.details, ari, name, fire3PClickEvent, isPreviewPanelAvailable, openPreviewPanel, createAnalyticsEvent, thirdPartyARI, disablePreviewPanel]);
  var handleAuthorize = (0, _react.useCallback)(function () {
    return actions.authorize(appearance);
  }, [actions, appearance]);
  var handleRetry = (0, _react.useCallback)(function () {
    actions.reload();
  }, [actions]);
  var handleInvoke = (0, _react.useCallback)(function (opts) {
    return actions.invoke(opts, appearance);
  }, [actions, appearance]);

  // NB: for each status change in a Smart Link, a performance mark is created.
  // Measures are sent relative to the first mark, matching what a user sees.
  (0, _react.useEffect)(function () {
    measure.mark(id, state.status);
    if (state.status !== 'pending' && state.status !== 'resolving') {
      var _state$error3, _state$error4;
      measure.create(id, state.status);
      if (state.status === 'resolved') {
        var _measure$getMeasure$d2, _measure$getMeasure2;
        fireEvent('operational.smartLink.resolved', {
          definitionId: definitionId !== null && definitionId !== void 0 ? definitionId : null,
          duration: (_measure$getMeasure$d2 = (_measure$getMeasure2 = measure.getMeasure(id, state.status)) === null || _measure$getMeasure2 === void 0 ? void 0 : _measure$getMeasure2.duration) !== null && _measure$getMeasure$d2 !== void 0 ? _measure$getMeasure$d2 : null
        });
      } else if (((_state$error3 = state.error) === null || _state$error3 === void 0 ? void 0 : _state$error3.type) !== 'ResolveUnsupportedError' && ((_state$error4 = state.error) === null || _state$error4 === void 0 ? void 0 : _state$error4.type) !== 'UnsupportedError') {
        fireEvent('operational.smartLink.unresolved', {
          definitionId: definitionId !== null && definitionId !== void 0 ? definitionId : null,
          reason: state.status,
          error: state.error === undefined ? null : {
            name: state.error.name,
            kind: state.error.kind,
            type: state.error.type
          }
        });
      }
    }
  }, [id, appearance, state.status, state.error, definitionId, extensionKey, resourceType, fireEvent]);

  // NB: once the smart-card has rendered into an end state, we capture
  // this as a successful render. These can be one of:
  // - the resolved state: when metadata is shown;
  // - the unresolved states: viz. forbidden, not_found, unauthorized, errored.
  (0, _react.useEffect)(function () {
    if ((0, _helpers.isFinalState)(state.status)) {
      (0, _analytics.succeedUfoExperience)('smart-link-rendered', id || 'NULL', {
        extensionKey: extensionKey,
        display: isFlexibleUi ? 'flexible' : appearance
      });

      // UFO will disregard this if authentication experience has not yet been started
      (0, _analytics.succeedUfoExperience)('smart-link-authenticated', id || 'NULL', {
        display: isFlexibleUi ? 'flexible' : appearance
      });
      fireEvent('ui.smartLink.renderSuccess', {
        display: isFlexibleUi ? 'flexible' : appearance
      });
    }
  }, [appearance, extensionKey, fireEvent, id, isFlexibleUi, state.status]);
  var onIframeDwell = (0, _react.useCallback)(function (dwellTime, dwellPercentVisible) {
    fireEvent('ui.smartLinkIframe.dwelled', {
      id: id,
      definitionId: definitionId !== null && definitionId !== void 0 ? definitionId : null,
      display: isFlexibleUi ? 'flexible' : appearance,
      dwellPercentVisible: dwellPercentVisible,
      dwellTime: dwellTime
    });
  }, [id, appearance, definitionId, isFlexibleUi, fireEvent]);
  var onIframeFocus = (0, _react.useCallback)(function () {
    fireEvent('ui.smartLinkIframe.focused', {
      id: id,
      definitionId: definitionId !== null && definitionId !== void 0 ? definitionId : null,
      display: isFlexibleUi ? 'flexible' : appearance,
      interactionType: 'focus'
    });
  }, [id, appearance, definitionId, isFlexibleUi, fireEvent]);
  var onIframeMouseEnter = (0, _react.useCallback)(function () {
    fireEvent('ui.smartLinkIframe.focused', {
      id: id,
      definitionId: definitionId !== null && definitionId !== void 0 ? definitionId : null,
      display: isFlexibleUi ? 'flexible' : appearance,
      interactionType: 'mouseenter'
    });
  }, [id, appearance, definitionId, isFlexibleUi, fireEvent]);
  var onIframeMouseLeave = (0, _react.useCallback)(function () {
    fireEvent('ui.smartLinkIframe.focused', {
      id: id,
      definitionId: definitionId !== null && definitionId !== void 0 ? definitionId : null,
      display: isFlexibleUi ? 'flexible' : appearance,
      interactionType: 'mouseleave'
    });
  }, [id, appearance, definitionId, isFlexibleUi, fireEvent]);
  if (isFlexibleUi) {
    var cardState = state;
    if (error) {
      if ((error === null || error === void 0 ? void 0 : error.name) === 'APIError') {
        cardState = {
          status: 'errored'
        };
      } else {
        throw error;
      }
    }
    return /*#__PURE__*/_react.default.createElement(_FlexibleCard.default, {
      id: id,
      cardState: cardState,
      placeholderData: placeholderData,
      onAuthorize: services.length && handleAuthorize || undefined,
      onClick: handleClickWrapper,
      origin: "smartLinkCard",
      renderers: renderers,
      ui: ui,
      showHoverPreview: showHoverPreview,
      hoverPreviewOptions: hoverPreviewOptions,
      actionOptions: actionOptions,
      url: url,
      testId: testId,
      onResolve: onResolve,
      onError: onError
    }, children);
  }

  // We have to keep this last to prevent hook order from being violated
  if (error) {
    throw error;
  }
  switch (appearance) {
    case 'inline':
      return /*#__PURE__*/_react.default.createElement(_InlineCard.InlineCard, {
        id: id,
        url: url,
        renderers: renderers,
        cardState: state,
        handleAuthorize: services.length && handleAuthorize || undefined,
        handleFrameClick: handleClickWrapper,
        isSelected: isSelected,
        isHovered: isHovered,
        onResolve: onResolve,
        onError: onError,
        testId: testId,
        inlinePreloaderStyle: inlinePreloaderStyle,
        showHoverPreview: showHoverPreview,
        hoverPreviewOptions: hoverPreviewOptions,
        actionOptions: actionOptions,
        removeTextHighlightingFromTitle: removeTextHighlightingFromTitle,
        resolvingPlaceholder: resolvingPlaceholder,
        truncateInline: truncateInline,
        hideIconLoadingSkeleton: hideIconLoadingSkeleton
      });
    case 'block':
      return /*#__PURE__*/_react.default.createElement(_BlockCard.BlockCard, {
        id: id,
        url: url,
        renderers: renderers,
        authFlow: config && config.authFlow,
        cardState: state,
        handleAuthorize: services.length && handleAuthorize || undefined,
        handleFrameClick: handleClickWrapper,
        isSelected: isSelected,
        onResolve: onResolve,
        onError: onError,
        testId: testId,
        actionOptions: actionOptions,
        CompetitorPrompt: CompetitorPrompt,
        hideIconLoadingSkeleton: hideIconLoadingSkeleton
      });
    case 'embed':
      return /*#__PURE__*/_react.default.createElement(EmbedCardComponent, {
        id: id,
        url: url,
        renderers: renderers,
        cardState: state,
        iframeUrlType: embedIframeUrlType,
        handleAuthorize: services.length && handleAuthorize || undefined,
        handleErrorRetry: handleRetry,
        handleFrameClick: handleClickWrapper,
        handleInvoke: handleInvoke,
        isSelected: isSelected,
        frameStyle: frameStyle,
        platform: platform,
        onResolve: onResolve,
        onError: onError,
        testId: testId,
        inheritDimensions: inheritDimensions,
        actionOptions: actionOptions,
        ref: embedIframeRef,
        onIframeDwell: onIframeDwell,
        onIframeFocus: onIframeFocus,
        onIframeMouseEnter: onIframeMouseEnter,
        onIframeMouseLeave: onIframeMouseLeave,
        CompetitorPrompt: CompetitorPrompt,
        hideIconLoadingSkeleton: hideIconLoadingSkeleton
      });
  }
}
var CardWithUrlContentComponent = (0, _platformFeatureFlagsReact.componentWithFG)('rovo_chat_embed_card_dwell_and_hover_metrics', ComponentUpdated, Component);
var CardWithUrlContent = exports.CardWithUrlContent = function CardWithUrlContent(props) {
  var display = (0, _flexible.isFlexibleUiCard)(props.children, props === null || props === void 0 ? void 0 : props.ui) ? _constants.CardDisplay.Flexible : props.appearance;
  return /*#__PURE__*/_react.default.createElement(_modal.SmartLinkModalProvider, null, /*#__PURE__*/_react.default.createElement(_SmartLinkAnalyticsContext.SmartLinkAnalyticsContext, {
    url: props.url,
    id: props.id,
    display: display
  }, /*#__PURE__*/_react.default.createElement(CardWithUrlContentComponent, props)));
};