"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
var _react = _interopRequireWildcard(require("react"));
var _react2 = require("@emotion/react");
var _reactIntlNext = require("react-intl-next");
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
var _questionCircle = _interopRequireDefault(require("@atlaskit/icon/glyph/question-circle"));
var _colors = require("@atlaskit/theme/colors");
var _constants = require("@atlaskit/theme/constants");
var _tooltip = _interopRequireDefault(require("@atlaskit/tooltip"));
var _analytics = require("../../analytics");
var _unsupportedContent = require("../../messages/unsupportedContent");
var _trackUnsupportedContent = require("../../utils/track-unsupported-content");
var _unsupportedContentHelper = require("../unsupported-content-helper");
var _templateObject;
/** @jsx jsx */
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
var blockNodeStyle = (0, _react2.css)(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\n  background: ", ";\n  border: 1px dashed ", ";\n  border-radius: ", "px;\n  box-sizing: border-box;\n  cursor: default;\n  display: flex;\n  font-size: ", ";\n  margin: ", " 0;\n  min-height: 24px;\n  padding: ", ";\n  text-align: center;\n  vertical-align: text-bottom;\n  min-width: 120px;\n  align-items: center;\n  justify-content: center;\n"])), "var(--ds-background-disabled, ".concat(_colors.N30, ")"), "var(--ds-border-disabled, ".concat(_colors.N50, ")"), (0, _constants.borderRadius)(), (0, _editorSharedStyles.relativeFontSizeToBase16)((0, _constants.fontSize)()), "var(--ds-space-100, 8px)", "var(--ds-space-150, 12px)");
var UnsupportedBlockNode = function UnsupportedBlockNode(_ref) {
  var node = _ref.node,
    intl = _ref.intl,
    dispatchAnalyticsEvent = _ref.dispatchAnalyticsEvent;
  var message = (0, _unsupportedContentHelper.getUnsupportedContent)(_unsupportedContent.unsupportedContentMessages.unsupportedBlockContent, _unsupportedContent.unsupportedContentMessages.unsupportedBlockContent.defaultMessage + ':', node, intl);
  var tooltipContent = intl.formatMessage(_unsupportedContent.unsupportedContentMessages.unsupportedContentTooltip);
  var _useRef = (0, _react.useRef)({
      padding: '4px'
    }),
    style = _useRef.current;
  var originalNodeType = node === null || node === void 0 ? void 0 : node.attrs.originalValue.type;
  var tooltipOnShowHandler = (0, _react.useCallback)(function () {
    return dispatchAnalyticsEvent && (0, _trackUnsupportedContent.trackUnsupportedContentTooltipDisplayedFor)(dispatchAnalyticsEvent, _analytics.ACTION_SUBJECT_ID.ON_UNSUPPORTED_BLOCK, originalNodeType);
  }, [dispatchAnalyticsEvent, originalNodeType]);
  return (0, _react2.jsx)("div", {
    css: blockNodeStyle,
    className: "unsupported"
  }, message, (0, _react2.jsx)(_tooltip.default, {
    content: tooltipContent,
    hideTooltipOnClick: false,
    position: "bottom",
    onShow: tooltipOnShowHandler,
    strategy: "absolute"
  }, (0, _react2.jsx)("span", {
    style: style
  }, (0, _react2.jsx)(_questionCircle.default, {
    label: "?",
    size: "small"
  }))));
};
var _default = exports.default = (0, _reactIntlNext.injectIntl)(UnsupportedBlockNode);