/** @jsx jsx */
import React, { useCallback, useRef } from 'react';
import { css, jsx } from '@emotion/react';
import { injectIntl } from 'react-intl-next';
import { relativeFontSizeToBase16 } from '@atlaskit/editor-shared-styles';
import QuestionsIcon from '@atlaskit/icon/glyph/question-circle';
import { N30, N50 } from '@atlaskit/theme/colors';
import { borderRadius, fontSize } from '@atlaskit/theme/constants';
import Tooltip from '@atlaskit/tooltip';
import { ACTION_SUBJECT_ID } from '../../analytics';
import { unsupportedContentMessages } from '../../messages/unsupportedContent';
import { trackUnsupportedContentTooltipDisplayedFor } from '../../utils/track-unsupported-content';
import { getUnsupportedContent } from '../unsupported-content-helper';
const blockNodeStyle = css`
  background: ${`var(--ds-background-disabled, ${N30})`};
  border: 1px dashed ${`var(--ds-border-disabled, ${N50})`};
  border-radius: ${borderRadius()}px;
  box-sizing: border-box;
  cursor: default;
  display: flex;
  font-size: ${relativeFontSizeToBase16(fontSize())};
  margin: ${"var(--ds-space-100, 8px)"} 0;
  min-height: 24px;
  padding: ${"var(--ds-space-150, 12px)"};
  text-align: center;
  vertical-align: text-bottom;
  min-width: 120px;
  align-items: center;
  justify-content: center;
`;
const UnsupportedBlockNode = ({
  node,
  intl,
  dispatchAnalyticsEvent
}) => {
  const message = getUnsupportedContent(unsupportedContentMessages.unsupportedBlockContent, unsupportedContentMessages.unsupportedBlockContent.defaultMessage + ':', node, intl);
  const tooltipContent = intl.formatMessage(unsupportedContentMessages.unsupportedContentTooltip);
  const {
    current: style
  } = useRef({
    padding: '4px'
  });
  const originalNodeType = node === null || node === void 0 ? void 0 : node.attrs.originalValue.type;
  const tooltipOnShowHandler = useCallback(() => dispatchAnalyticsEvent && trackUnsupportedContentTooltipDisplayedFor(dispatchAnalyticsEvent, ACTION_SUBJECT_ID.ON_UNSUPPORTED_BLOCK, originalNodeType), [dispatchAnalyticsEvent, originalNodeType]);
  return jsx("div", {
    css: blockNodeStyle,
    className: "unsupported"
  }, message, jsx(Tooltip, {
    content: tooltipContent,
    hideTooltipOnClick: false,
    position: "bottom",
    onShow: tooltipOnShowHandler,
    strategy: "absolute"
  }, jsx("span", {
    style: style
  }, jsx(QuestionsIcon, {
    label: "?",
    size: "small"
  }))));
};
export default injectIntl(UnsupportedBlockNode);