import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
var _excluded = ["maxLines", "testId", "text", "isHidden", "showFooter"];
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';
var DEFAULT_MAX_LINES = 3;
var MAXIMUM_MAX_LINES = 6;
var MINIMUM_MAX_LINES = 1;

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