import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import 'core-js/modules/es.symbol.js';
import 'core-js/modules/es.array.concat.js';
import 'core-js/modules/es.array.filter.js';
import 'core-js/modules/es.array.iterator.js';
import 'core-js/modules/es.array.map.js';
import 'core-js/modules/es.object.get-own-property-descriptor.js';
import 'core-js/modules/es.object.get-own-property-descriptors.js';
import 'core-js/modules/es.object.keys.js';
import 'core-js/modules/es.object.to-string.js';
import 'core-js/modules/web.dom-collections.for-each.js';
import 'core-js/modules/web.dom-collections.iterator.js';
import React__default from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { CARD_SIZES, CARD_LAYOUTS } from '../../constants/LayoutConstants.js';
import { ValueContentPropTypes } from '../../constants/CardPropTypes.js';
import DataStateRenderer from '../Card/DataStateRenderer.js';
import { DEFAULT_FONT_SIZE, BASE_CLASS_NAME, determineValue } from './valueCardUtils.js';
import Attribute from './Attribute.js';

var _excluded = ["id", "title", "content", "values", "layout", "dataState", "locale", "isEditable", "shouldUseTranslatedLabels", "customFormatter", "formatter", "fontSize", "isNumberValueCompact", "testId", "onAttributeClick", "size"];
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var propTypes = _objectSpread({
  id: PropTypes.string,
  title: PropTypes.string,
  layout: PropTypes.oneOf(['HORIZONTAL', 'VERTICAL']),
  locale: PropTypes.string,
  isEditable: PropTypes.bool,
  /** whether to use translated labels in cards */
  shouldUseTranslatedLabels: PropTypes.bool
}, ValueContentPropTypes);
var defaultProps = {
  id: 'valueContent-id',
  title: '',
  layout: 'VERTICAL',
  locale: 'en',
  isEditable: false,
  shouldUseTranslatedLabels: false,
  dataState: null,
  values: null,
  fontSize: DEFAULT_FONT_SIZE,
  customFormatter: null,
  formatter: null,
  isNumberValueCompact: false,
  testId: 'ValueContent',
  onAttributeClick: null,
  size: CARD_SIZES.MEDIUM
};
var ValueContent = function ValueContent(_ref) {
  var id = _ref.id,
    title = _ref.title,
    content = _ref.content,
    values = _ref.values,
    layout = _ref.layout,
    dataState = _ref.dataState,
    locale = _ref.locale,
    isEditable = _ref.isEditable,
    shouldUseTranslatedLabels = _ref.shouldUseTranslatedLabels,
    customFormatter = _ref.customFormatter,
    formatter = _ref.formatter,
    fontSize = _ref.fontSize,
    isNumberValueCompact = _ref.isNumberValueCompact,
    testId = _ref.testId,
    onAttributeClick = _ref.onAttributeClick,
    size = _ref.size,
    others = _objectWithoutProperties(_ref, _excluded);
  var attributeCount = content.attributes.length;
  return /*#__PURE__*/React__default.createElement("div", {
    className: classnames("".concat(BASE_CLASS_NAME, "__content-wrapper"), _defineProperty({}, "".concat(BASE_CLASS_NAME, "__content-wrapper--vertical"), layout === CARD_LAYOUTS.VERTICAL))
  }, !dataState ? content.attributes.map(function (attribute, index) {
    return /*#__PURE__*/React__default.createElement(Attribute, {
      key: "fragment-".concat(attribute.dataSourceId, "-").concat(JSON.stringify(attribute.dataFilter || {})),
      attribute: attribute,
      attributeCount: attributeCount,
      layout: layout,
      locale: locale,
      isEditable: isEditable,
      title: title,
      shouldUseTranslatedLabels: shouldUseTranslatedLabels,
      i18n: others.i18n,
      renderIconByName: others.renderIconByName,
      value: determineValue(attribute.dataSourceId, values, attribute.dataFilter),
      secondaryValue: attribute.secondaryValue && _objectSpread(_objectSpread({}, attribute.secondaryValue), {}, {
        value: determineValue(attribute.secondaryValue.dataSourceId, values)
      })
      // Prefer new formatter. Fall back to legacy customFormatter.
      ,
      formatter: formatter,
      customFormatter: customFormatter,
      fontSize: fontSize,
      isNumberValueCompact: isNumberValueCompact,
      testId: "".concat(testId, "-attribute-").concat(index),
      onValueClick: onAttributeClick
    });
  }) : /*#__PURE__*/React__default.createElement(DataStateRenderer, {
    dataState: dataState,
    size: size,
    id: id,
    testId: "".concat(testId, "-data-state")
  }));
};
ValueContent.propTypes = propTypes;
ValueContent.defaultProps = defaultProps;
ValueContent.__docgenInfo = {
  "description": "",
  "methods": [],
  "displayName": "ValueContent",
  "props": {
    "id": {
      "defaultValue": {
        "value": "'valueContent-id'",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "title": {
      "defaultValue": {
        "value": "''",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "layout": {
      "defaultValue": {
        "value": "'VERTICAL'",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "enum",
        "value": [{
          "value": "'HORIZONTAL'",
          "computed": false
        }, {
          "value": "'VERTICAL'",
          "computed": false
        }]
      },
      "required": false
    },
    "locale": {
      "defaultValue": {
        "value": "'en'",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "isEditable": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "shouldUseTranslatedLabels": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "whether to use translated labels in cards",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "dataState": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "required": false
    },
    "values": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "required": false
    },
    "fontSize": {
      "defaultValue": {
        "value": "DEFAULT_FONT_SIZE",
        "computed": true
      },
      "required": false
    },
    "customFormatter": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "required": false
    },
    "formatter": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "required": false
    },
    "isNumberValueCompact": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "required": false
    },
    "testId": {
      "defaultValue": {
        "value": "'ValueContent'",
        "computed": false
      },
      "required": false
    },
    "onAttributeClick": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "required": false
    },
    "size": {
      "defaultValue": {
        "value": "CARD_SIZES.MEDIUM",
        "computed": true
      },
      "required": false
    }
  },
  "composes": ["../../constants/CardPropTypes"]
};
var ValueContent$1 = ValueContent;

export { ValueContent$1 as default };
