/* index.tsx generated by @compiled/babel-plugin v0.39.1 */
import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
var _excluded = ["maxLines", "testId", "primary", "secondary"];
import "./index.compiled.css";
import * as React from 'react';
import { ax, ix } from "@compiled/react/runtime";
/* eslint-disable @atlaskit/design-system/use-tokens-typography */

import { SmartLinkAlignment, SmartLinkDirection, SmartLinkSize, SmartLinkStatus, SmartLinkWidth } from '../../../../../constants';
import { useFlexibleCardContext } from '../../../../../state/flexible-ui-context';
import Block from '../block';
import ElementGroup from '../element-group';
import { renderElementItems } from '../utils';
var DEFAULT_MAX_LINES = 2;
var MAXIMUM_MAX_LINES = 2;
var MINIMUM_MAX_LINES = 1;
var truncateStyles = {
  '1': "_1reo15vq _18m915vq _1e0ccj1k _1bto1l2s _1nmz1hna _1yyjkb7n _sudp1e54",
  '2': "_1reo15vq _18m915vq _1e0ccj1k _1bto1l2s _1nmz1hna _1yyjcs5v _sudp1e54"
};
var sizeStyles = {
  xlarge: "_102k8vuz",
  large: "_102k8vuz",
  medium: "_102kckbl",
  small: "_102kckbl"
};
var getMaxLines = function getMaxLines(maxLines) {
  if (maxLines > MAXIMUM_MAX_LINES) {
    return DEFAULT_MAX_LINES;
  }
  if (maxLines < MINIMUM_MAX_LINES) {
    return MINIMUM_MAX_LINES;
  }
  return maxLines;
};
var ElementItemRenderer = function ElementItemRenderer(_ref) {
  var _ref$align = _ref.align,
    align = _ref$align === void 0 ? SmartLinkAlignment.Left : _ref$align,
    _ref$items = _ref.items,
    items = _ref$items === void 0 ? [] : _ref$items,
    _ref$display = _ref.display,
    display = _ref$display === void 0 ? 'inline' : _ref$display,
    _ref$size = _ref.size,
    size = _ref$size === void 0 ? SmartLinkSize.Medium : _ref$size,
    _ref$maxLines = _ref.maxLines,
    maxLines = _ref$maxLines === void 0 ? DEFAULT_MAX_LINES : _ref$maxLines;
  var elements = renderElementItems(items, display);
  return elements && /*#__PURE__*/React.createElement(ElementGroup, {
    align: align,
    direction: SmartLinkDirection.Horizontal,
    width: SmartLinkWidth.Flexible,
    size: size,
    className: ax([truncateStyles[maxLines], sizeStyles[size]])
  }, elements);
};

/**
 * Represents a MetadataBlock, designed to contain groups of metadata in the form of elements.
 * Accepts an array of elements to be shown either primary (left hand side) or secondary (right hand side).
 * @public
 * @param {MetadataBlockProps} MetadataBlockProps
 * @see Block
 */
var MetadataBlock = function MetadataBlock(_ref2) {
  var _ref3, _blockProps$size, _cardContext$ui;
  var _ref2$maxLines = _ref2.maxLines,
    maxLines = _ref2$maxLines === void 0 ? DEFAULT_MAX_LINES : _ref2$maxLines,
    _ref2$testId = _ref2.testId,
    testId = _ref2$testId === void 0 ? 'smart-block-metadata' : _ref2$testId,
    _ref2$primary = _ref2.primary,
    primary = _ref2$primary === void 0 ? [] : _ref2$primary,
    _ref2$secondary = _ref2.secondary,
    secondary = _ref2$secondary === void 0 ? [] : _ref2$secondary,
    blockProps = _objectWithoutProperties(_ref2, _excluded);
  var cardContext = useFlexibleCardContext();
  if (primary.length === 0 && secondary.length === 0 || (cardContext === null || cardContext === void 0 ? void 0 : cardContext.status) !== SmartLinkStatus.Resolved) {
    return null;
  }
  var size = (_ref3 = (_blockProps$size = blockProps === null || blockProps === void 0 ? void 0 : 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) !== null && _ref3 !== void 0 ? _ref3 : SmartLinkSize.Medium;
  var maxLinesTotal = getMaxLines(maxLines);
  return /*#__PURE__*/React.createElement(Block, _extends({}, blockProps, {
    size: size,
    testId: "".concat(testId, "-resolved-view")
  }), /*#__PURE__*/React.createElement(ElementItemRenderer, {
    items: primary,
    size: size,
    maxLines: maxLinesTotal
  }), /*#__PURE__*/React.createElement(ElementItemRenderer, {
    align: SmartLinkAlignment.Right,
    items: secondary,
    size: size,
    maxLines: maxLinesTotal
  }));
};
export default MetadataBlock;