/* index.tsx generated by @compiled/babel-plugin v0.39.1 */
import _extends from "@babel/runtime/helpers/extends";
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';
const DEFAULT_MAX_LINES = 2;
const MAXIMUM_MAX_LINES = 2;
const MINIMUM_MAX_LINES = 1;
const truncateStyles = {
  '1': "_1reo15vq _18m915vq _1e0ccj1k _1bto1l2s _1nmz1hna _1yyjkb7n _sudp1e54",
  '2': "_1reo15vq _18m915vq _1e0ccj1k _1bto1l2s _1nmz1hna _1yyjcs5v _sudp1e54"
};
const sizeStyles = {
  xlarge: "_102k8vuz",
  large: "_102k8vuz",
  medium: "_102kckbl",
  small: "_102kckbl"
};
const getMaxLines = maxLines => {
  if (maxLines > MAXIMUM_MAX_LINES) {
    return DEFAULT_MAX_LINES;
  }
  if (maxLines < MINIMUM_MAX_LINES) {
    return MINIMUM_MAX_LINES;
  }
  return maxLines;
};
const ElementItemRenderer = ({
  align = SmartLinkAlignment.Left,
  items = [],
  display = 'inline',
  size = SmartLinkSize.Medium,
  maxLines = DEFAULT_MAX_LINES
}) => {
  const 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
 */
const MetadataBlock = ({
  maxLines = DEFAULT_MAX_LINES,
  testId = 'smart-block-metadata',
  primary = [],
  secondary = [],
  ...blockProps
}) => {
  var _ref, _blockProps$size, _cardContext$ui;
  const cardContext = useFlexibleCardContext();
  if (primary.length === 0 && secondary.length === 0 || (cardContext === null || cardContext === void 0 ? void 0 : cardContext.status) !== SmartLinkStatus.Resolved) {
    return null;
  }
  const size = (_ref = (_blockProps$size = blockProps === null || blockProps === void 0 ? void 0 : 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) !== null && _ref !== void 0 ? _ref : SmartLinkSize.Medium;
  const maxLinesTotal = getMaxLines(maxLines);
  return /*#__PURE__*/React.createElement(Block, _extends({}, blockProps, {
    size: size,
    testId: `${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;