/* index.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.InlineCardErroredView = void 0;
var _runtime = require("@compiled/react/runtime");
var _react = _interopRequireDefault(require("react"));
var _reactIntl = require("react-intl");
var _statusError = _interopRequireDefault(require("@atlaskit/icon/core/status-error"));
var _messages = require("../../../messages");
var _HoverCard = require("../../HoverCard");
var _actionButton = require("../common/action-button");
var _Frame = require("../Frame");
var _IconAndTitleLayout = require("../IconAndTitleLayout");
var fallbackIcon = function fallbackIcon() {
  return /*#__PURE__*/_react.default.createElement(_statusError.default, {
    color: "var(--ds-icon-danger, #C9372C)",
    label: "error",
    testId: "errored-view-default-icon"
  });
};
var InlineCardErroredView = exports.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.default.useRef(null);
  var hashAction = !!onRetry;
  var handleRetry = _react.default.useCallback(function (event) {
    if (onRetry) {
      event.preventDefault();
      event.stopPropagation();
      onRetry();
    }
  }, [onRetry]);
  var renderActionButton = _react.default.useCallback(function () {
    return onRetry && /*#__PURE__*/_react.default.createElement(_actionButton.ActionButton, {
      onClick: handleRetry
    }, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, _messages.messages.try_again));
  }, [handleRetry, onRetry]);
  var content = /*#__PURE__*/_react.default.createElement(_Frame.Frame, {
    link: hashAction ? undefined : url,
    onClick: hashAction ? undefined : onClick,
    isSelected: isSelected,
    ref: frameRef,
    testId: testId,
    truncateInline: truncateInline
  }, /*#__PURE__*/_react.default.createElement(_IconAndTitleLayout.IconAndTitleLayout, {
    icon: icon || fallbackIcon(),
    link: hashAction ? url : undefined,
    title: url,
    onClick: hashAction ? onClick : undefined,
    rightSide: message
  }), renderActionButton());
  if (showHoverPreview) {
    return /*#__PURE__*/_react.default.createElement(_HoverCard.HoverCard, {
      url: url
    }, content);
  }
  return content;
};