/* index.tsx generated by @compiled/babel-plugin v0.39.1 */
import _extends from "@babel/runtime/helpers/extends";
import "./index.compiled.css";
import { ax, ix } from "@compiled/react/runtime";
import React, { useCallback, useEffect, useMemo, useRef } from 'react';
import { di } from 'react-magnetic-di';
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
import { useAnalyticsEvents } from '../../../../../common/analytics/generated/use-analytics-events';
import { CardDisplay, SmartLinkPosition, SmartLinkSize } from '../../../../../constants';
import { succeedUfoExperience } from '../../../../../state/analytics';
import useAISummaryAction from '../../../../../state/hooks/use-ai-summary-action';
import FlexibleCard from '../../../../FlexibleCard';
import { ActionBlock, AIFooterBlock, AISummaryBlock, ResolvedHoverCardFooterBlock, MetadataBlock, SnippetBlock, TitleBlock } from '../../../../FlexibleCard/components/blocks';
import { RovoSummaryBlock } from '../../../../FlexibleCard/components/blocks/ai-summary-block';
import { getMetadata } from '../../../utils';
import ImagePreview from '../../ImagePreview';
const hiddenSnippetStyles = null;
const titleBlockStyles = null;
const snippetBlockCss = null;
const actionBlockCss = null;
const HoverCardResolvedView = ({
  cardState,
  extensionKey,
  flexibleCardProps,
  isAISummaryEnabled,
  onActionClick,
  showRovoResolvedView,
  titleBlockProps,
  id,
  url
}) => {
  var _cardState$details;
  const {
    fireEvent
  } = useAnalyticsEvents();

  // 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.
  const is3PAuthRovoActionsExperimentOn = showRovoResolvedView && expValEquals('platform_sl_3p_auth_rovo_action', 'isEnabled', true);
  useEffect(() => {
    // Since this hover view is only rendered on resolved status,
    // there is no need to check for statuses.
    succeedUfoExperience('smart-link-rendered', id || 'NULL', {
      extensionKey,
      display: CardDisplay.HoverCardPreview
    });

    // UFO will disregard this if authentication experience has not yet been started
    succeedUfoExperience('smart-link-authenticated', id || 'NULL', {
      display: CardDisplay.HoverCardPreview
    });
    fireEvent('ui.smartLink.renderSuccess', {
      display: CardDisplay.HoverCardPreview
    });
  }, [extensionKey, fireEvent, id]);
  const data = (_cardState$details = cardState.details) === null || _cardState$details === void 0 ? void 0 : _cardState$details.data;
  const {
    primary,
    secondary
  } = useMemo(() => {
    return getMetadata(extensionKey, data);
  }, [data, extensionKey]);
  const snippetHeight = React.useRef(0);
  const snippetBlockRef = useRef(null);
  const onSnippetRender = useCallback(() => {
    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;
  }, []);
  const imagePreview = ImagePreview({
    fallbackElementHeight: snippetHeight.current,
    response: cardState.details
  });
  const snippet = imagePreview ? null : /*#__PURE__*/React.createElement(SnippetBlock, {
    className: ax(["_ca0q1b66"])
  });
  const aiSummaryMinHeight = snippet ? snippetHeight.current : 0;
  return /*#__PURE__*/React.createElement(FlexibleCard, flexibleCardProps, imagePreview, /*#__PURE__*/React.createElement(TitleBlock, _extends({}, titleBlockProps, {
    metadataPosition: SmartLinkPosition.Top,
    className: ax(["_zulpu2gc _quenze3t _oebj1txw _13mh1pd9"])
  })), /*#__PURE__*/React.createElement(MetadataBlock, {
    primary: primary,
    secondary: secondary,
    maxLines: 1,
    size: SmartLinkSize.Medium
  }), is3PAuthRovoActionsExperimentOn ? /*#__PURE__*/React.createElement(RovoSummaryBlock, {
    aiSummaryMinHeight: aiSummaryMinHeight,
    url: url
  }) : isAISummaryEnabled ? /*#__PURE__*/React.createElement(AISummaryBlock, {
    aiSummaryMinHeight: aiSummaryMinHeight,
    placeholder: snippet
  }) : snippet, /*#__PURE__*/React.createElement(SnippetBlock, {
    testId: "hidden-snippet",
    onRender: onSnippetRender,
    blockRef: snippetBlockRef,
    isHidden: true,
    className: ax(["_3um015vq _kqswstnw"])
  }), /*#__PURE__*/React.createElement(ActionBlock, {
    onClick: onActionClick,
    spaceInline: "space.100",
    is3PAuthRovoActionsExperimentOn: is3PAuthRovoActionsExperimentOn,
    className: ax(["_n3td1b66"])
  }), is3PAuthRovoActionsExperimentOn ? /*#__PURE__*/React.createElement(ResolvedHoverCardFooterBlock, {
    onActionClick: onActionClick
  }) : /*#__PURE__*/React.createElement(AIFooterBlock, null));
};
export default HoverCardResolvedView;