/* index.tsx generated by @compiled/babel-plugin v0.38.1 */
import { ax, ix } from "@compiled/react/runtime";
import React from 'react';
import { FormattedMessage } from 'react-intl-next';
import ErrorIcon from '@atlaskit/icon/core/status-error';
import { messages } from '../../../messages';
import { HoverCard } from '../../HoverCard';
import { ActionButton } from '../common/action-button';
import { Frame } from '../Frame';
import { IconAndTitleLayout } from '../IconAndTitleLayout';
var fallbackIcon = function fallbackIcon() {
  return /*#__PURE__*/React.createElement(ErrorIcon, {
    color: "var(--ds-icon-danger, #C9372C)",
    label: "error",
    testId: "errored-view-default-icon"
  });
};
export var InlineCardErroredView = function InlineCardErroredView(_ref) {
  var url = _ref.url,
    onClick = _ref.onClick,
    isSelected = _ref.isSelected,
    _ref$testId = _ref.testId,
    testId = _ref$testId === void 0 ? 'inline-card-errored-view' : _ref$testId,
    icon = _ref.icon,
    message = _ref.message,
    onRetry = _ref.onRetry,
    truncateInline = _ref.truncateInline,
    showHoverPreview = _ref.showHoverPreview;
  var frameRef = React.useRef(null);
  var hashAction = !!onRetry;
  var handleRetry = React.useCallback(function (event) {
    if (onRetry) {
      event.preventDefault();
      event.stopPropagation();
      onRetry();
    }
  }, [onRetry]);
  var renderActionButton = React.useCallback(function () {
    return onRetry && /*#__PURE__*/React.createElement(ActionButton, {
      onClick: handleRetry
    }, /*#__PURE__*/React.createElement(FormattedMessage, messages.try_again));
  }, [handleRetry, onRetry]);
  var content = /*#__PURE__*/React.createElement(Frame, {
    link: hashAction ? undefined : url,
    onClick: hashAction ? undefined : onClick,
    isSelected: isSelected,
    ref: frameRef,
    testId: testId,
    truncateInline: truncateInline
  }, /*#__PURE__*/React.createElement(IconAndTitleLayout, {
    icon: icon || fallbackIcon(),
    link: hashAction ? url : undefined,
    title: url,
    onClick: hashAction ? onClick : undefined,
    rightSide: message
  }), renderActionButton());
  if (showHoverPreview) {
    return /*#__PURE__*/React.createElement(HoverCard, {
      url: url
    }, content);
  }
  return content;
};