import _extends from "@babel/runtime/helpers/extends";
import React from 'react';
import { SmartLinkStatus } from '../../../../../constants';
import { useFlexibleCardContext, useFlexibleUiContext, useFlexibleUiOptionContext } from '../../../../../state/flexible-ui-context';
import { useSmartLinkRenderers } from '../../../../../state/renderers';
import { Snippet } from '../../elements';
import { getMaxLines } from '../../utils';
import Block from '../block';
const DEFAULT_MAX_LINES = 3;
const MAXIMUM_MAX_LINES = 6;
const MINIMUM_MAX_LINES = 1;

/**
 * Represents a SnippetBlock, which is used to display longer form text content, like descriptions.
 * @public
 * @param {SnippetBlockProps} SnippetBlockProps
 * @see Block
 */
const SnippetBlock = ({
  maxLines = DEFAULT_MAX_LINES,
  testId = 'smart-block-snippet',
  text,
  isHidden = false,
  showFooter = true,
  ...blockProps
}) => {
  var _useFlexibleUiOptionC, _blockProps$size2, _cardContext$ui2, _ref, _context$meta$objectI, _context$meta, _context$meta$resourc, _context$meta2, _context$meta$tenantI, _context$meta3;
  const context = useFlexibleUiContext();
  const renderers = useSmartLinkRenderers();
  const enableSnippetRenderer = (_useFlexibleUiOptionC = useFlexibleUiOptionContext()) === null || _useFlexibleUiOptionC === void 0 ? void 0 : _useFlexibleUiOptionC.enableSnippetRenderer;
  const cardContext = useFlexibleCardContext();
  if ((cardContext === null || cardContext === void 0 ? void 0 : cardContext.status) !== SmartLinkStatus.Resolved && !text) {
    return null;
  }
  const snippetMaxLines = getMaxLines(maxLines, DEFAULT_MAX_LINES, MAXIMUM_MAX_LINES, MINIMUM_MAX_LINES);
  const statusTestId = !text ? 'resolved' : 'non-resolved';
  const snippet = /*#__PURE__*/React.createElement(Snippet, {
    maxLines: snippetMaxLines,
    content: text
  });
  if (!enableSnippetRenderer) {
    var _blockProps$size, _cardContext$ui;
    return /*#__PURE__*/React.createElement(Block, _extends({}, blockProps, {
      size: (_blockProps$size = blockProps.size) !== null && _blockProps$size !== void 0 ? _blockProps$size : cardContext === null || cardContext === void 0 ? void 0 : (_cardContext$ui = cardContext.ui) === null || _cardContext$ui === void 0 ? void 0 : _cardContext$ui.size,
      testId: `${testId}-${statusTestId}-view`
    }), snippet);
  }
  const SnippetReplacement = renderers === null || renderers === void 0 ? void 0 : renderers.snippet;
  return /*#__PURE__*/React.createElement(Block, _extends({}, blockProps, {
    size: (_blockProps$size2 = blockProps.size) !== null && _blockProps$size2 !== void 0 ? _blockProps$size2 : cardContext === null || cardContext === void 0 ? void 0 : (_cardContext$ui2 = cardContext.ui) === null || _cardContext$ui2 === void 0 ? void 0 : _cardContext$ui2.size,
    testId: `${testId}-${statusTestId}-view`
  }), SnippetReplacement ? /*#__PURE__*/React.createElement(SnippetReplacement, {
    fallbackText: (_ref = text || (context === null || context === void 0 ? void 0 : context.snippet)) !== null && _ref !== void 0 ? _ref : '',
    fallbackComponent: snippet,
    contentId: (_context$meta$objectI = context === null || context === void 0 ? void 0 : (_context$meta = context.meta) === null || _context$meta === void 0 ? void 0 : _context$meta.objectId) !== null && _context$meta$objectI !== void 0 ? _context$meta$objectI : '',
    contentType: (_context$meta$resourc = context === null || context === void 0 ? void 0 : (_context$meta2 = context.meta) === null || _context$meta2 === void 0 ? void 0 : _context$meta2.resourceType) !== null && _context$meta$resourc !== void 0 ? _context$meta$resourc : '',
    cloudId: (_context$meta$tenantI = context === null || context === void 0 ? void 0 : (_context$meta3 = context.meta) === null || _context$meta3 === void 0 ? void 0 : _context$meta3.tenantId) !== null && _context$meta$tenantI !== void 0 ? _context$meta$tenantI : '',
    maxLines: snippetMaxLines,
    isHidden: isHidden,
    showFooter: showFooter
  }) : snippet);
};
export default SnippetBlock;