/* index.tsx generated by @compiled/babel-plugin v0.39.1 */
import _extends from "@babel/runtime/helpers/extends";
import { ax, ix } from "@compiled/react/runtime";
import React from 'react';
import { FormattedMessage } from 'react-intl-next';
import LockLockedIcon from '@atlaskit/icon/core/lock-locked';
import { useAnalyticsEvents } from '../../../common/analytics/generated/use-analytics-events';
import { messages } from '../../../messages';
import { HoverCard } from '../../HoverCard';
import { ActionButton } from '../common/action-button';
import { Frame } from '../Frame';
import { IconAndTitleLayout } from '../IconAndTitleLayout';
var fallbackUnauthorizedIcon = function fallbackUnauthorizedIcon() {
  return /*#__PURE__*/React.createElement(LockLockedIcon, {
    color: "var(--ds-icon-danger, #C9372C)",
    label: "error"
  });
};
export var InlineCardUnauthorizedView = function InlineCardUnauthorizedView(_ref) {
  var url = _ref.url,
    id = _ref.id,
    icon = _ref.icon,
    onAuthorise = _ref.onAuthorise,
    onClick = _ref.onClick,
    isSelected = _ref.isSelected,
    _ref$testId = _ref.testId,
    testId = _ref$testId === void 0 ? 'inline-card-unauthorized-view' : _ref$testId,
    _ref$showHoverPreview = _ref.showHoverPreview,
    showHoverPreview = _ref$showHoverPreview === void 0 ? false : _ref$showHoverPreview,
    truncateInline = _ref.truncateInline,
    context = _ref.context;
  var frameRef = React.useRef(null);
  var _useAnalyticsEvents = useAnalyticsEvents(),
    fireEvent = _useAnalyticsEvents.fireEvent;
  var handleConnectAccount = React.useCallback(function (event) {
    event.preventDefault();
    event.stopPropagation();
    if (onAuthorise) {
      fireEvent('track.applicationAccount.authStarted', {});
      onAuthorise();
    }
  }, [fireEvent, onAuthorise]);
  var renderActionButton = React.useCallback(function () {
    return /*#__PURE__*/React.createElement(ActionButton, {
      onClick: handleConnectAccount,
      viewType: 'unauthorised',
      testId: "button-connect-account"
    }, /*#__PURE__*/React.createElement(FormattedMessage, _extends({}, messages.connect_link_account_card_name, {
      values: {
        context: context
      }
    })));
  }, [handleConnectAccount, context]);
  var inlineCardUnauthenticatedView = /*#__PURE__*/React.createElement(Frame, {
    testId: testId,
    isSelected: isSelected,
    ref: frameRef,
    truncateInline: truncateInline,
    viewType: "unauthorised"
  }, /*#__PURE__*/React.createElement(IconAndTitleLayout, {
    icon: icon ? icon : fallbackUnauthorizedIcon(),
    title: url,
    link: url,
    onClick: onClick,
    titleColor: "var(--ds-text-subtle, #505258)"
  }), onAuthorise && renderActionButton());
  if (onAuthorise && showHoverPreview) {
    return /*#__PURE__*/React.createElement(HoverCard, {
      url: url,
      id: id
    }, inlineCardUnauthenticatedView);
  }
  return inlineCardUnauthenticatedView;
};