'use strict';

var _extends = require('@babel/runtime/helpers/extends');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
var isEmpty = require('../../node_modules/lodash-es/isEmpty.js');
require('core-js/modules/es.symbol.js');
require('core-js/modules/es.array.filter.js');
require('core-js/modules/es.array.iterator.js');
require('core-js/modules/es.object.get-own-property-descriptor.js');
require('core-js/modules/es.object.get-own-property-descriptors.js');
require('core-js/modules/es.object.keys.js');
require('core-js/modules/es.object.to-string.js');
require('core-js/modules/web.dom-collections.for-each.js');
require('core-js/modules/web.dom-collections.iterator.js');
var React = require('react');
var classnames = require('classnames');
var CardPropTypes = require('../../constants/CardPropTypes.js');
var LayoutConstants = require('../../constants/LayoutConstants.js');
var Card = require('../Card/Card.js');
var cardUtilityFunctions = require('../../utils/cardUtilityFunctions.js');
var dayjs = require('../../utils/dayjs.js');
var valueCardUtils = require('./valueCardUtils.js');
var ValueContent = require('./ValueContent.js');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var _extends__default = /*#__PURE__*/_interopDefault(_extends);
var _defineProperty__default = /*#__PURE__*/_interopDefault(_defineProperty);
var _objectWithoutProperties__default = /*#__PURE__*/_interopDefault(_objectWithoutProperties);
var React__default = /*#__PURE__*/_interopDefault(React);
var classnames__default = /*#__PURE__*/_interopDefault(classnames);

var _excluded = ["title", "content", "size", "values", "isEditable", "isResizable", "i18n", "dataState", "id", "locale", "timeZone", "customFormatter", "formatter", "children", "fontSize", "isNumberValueCompact", "testID", "testId", "onAttributeClick", "className", "shouldUseTranslatedLabels"];
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__default.default(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; }

/**
 * This components responsibilities include:
 * Rendering the attribute groups
 * Determining the layout
 * determines the data to render
 */
var ValueCard = function ValueCard(_ref) {
  var titleProp = _ref.title,
    contentProp = _ref.content,
    size = _ref.size,
    valuesProp = _ref.values,
    isEditable = _ref.isEditable,
    isResizable = _ref.isResizable,
    i18n = _ref.i18n,
    dataState = _ref.dataState,
    id = _ref.id,
    locale = _ref.locale,
    timeZone = _ref.timeZone,
    customFormatter = _ref.customFormatter,
    formatter = _ref.formatter,
    children = _ref.children,
    fontSize = _ref.fontSize,
    isNumberValueCompact = _ref.isNumberValueCompact,
    testID = _ref.testID,
    testId = _ref.testId,
    onAttributeClick = _ref.onAttributeClick,
    className = _ref.className,
    shouldUseTranslatedLabels = _ref.shouldUseTranslatedLabels,
    others = _objectWithoutProperties__default.default(_ref, _excluded);
  var effectiveTimezone = timeZone || dayjs.default.tz.guess();
  dayjs.default.tz.setDefault(effectiveTimezone);
  var availableActions = _objectSpread({
    expand: false
  }, others.availableActions);

  // Checks size property against new size naming convention and reassigns to closest supported size if necessary.
  var newSize = cardUtilityFunctions.getUpdatedCardSize(size);
  var resizeHandles = isResizable ? cardUtilityFunctions.getResizeHandles(children) : [];

  /** Searches for variables and updates the card if it is passed the cardVariables prop */
  var _handleCardVariables = cardUtilityFunctions.handleCardVariables(titleProp, contentProp, valuesProp, others),
    title = _handleCardVariables.title,
    content = _handleCardVariables.content,
    values = _handleCardVariables.values;
  var layout = valueCardUtils.determineLayout(newSize);
  return /*#__PURE__*/React__default.default.createElement(Card.default, _extends__default.default({
    title: title,
    size: newSize,
    availableActions: availableActions,
    isEmpty: isEmpty(values) && !dataState,
    isEditable: isEditable,
    isResizable: isResizable,
    resizeHandles: resizeHandles,
    i18n: i18n,
    shouldUseTranslatedLabels: shouldUseTranslatedLabels,
    locale: locale,
    timeZone: effectiveTimezone,
    id: id,
    className: classnames__default.default(className, _defineProperty__default.default(_defineProperty__default.default({}, "".concat(valueCardUtils.BASE_CLASS_NAME, "__horizontal"), layout === LayoutConstants.CARD_LAYOUTS.HORIZONTAL), "".concat(valueCardUtils.BASE_CLASS_NAME, "__vertical"), layout === LayoutConstants.CARD_LAYOUTS.VERTICAL))
    // TODO: remove deprecated 'testID' in v3.
    ,
    testId: testID || testId
  }, others), /*#__PURE__*/React__default.default.createElement(ValueContent, _extends__default.default({
    id: id,
    layout: layout,
    dataState: dataState,
    content: content,
    locale: locale,
    title: title
    // Prefer new formatter. Fall back to legacy customFormatter.
    ,
    formatter: formatter,
    customFormatter: customFormatter,
    testId: testID || testId,
    onAttributeClick: onAttributeClick,
    size: newSize,
    values: values,
    isEditable: isEditable,
    fontSize: fontSize,
    isNumberValueCompact: isNumberValueCompact,
    i18n: i18n,
    shouldUseTranslatedLabels: shouldUseTranslatedLabels
  }, others)), resizeHandles);
};
ValueCard.propTypes = _objectSpread(_objectSpread({}, CardPropTypes.CardPropTypes), CardPropTypes.ValueContentPropTypes);
ValueCard.defaultProps = {
  size: LayoutConstants.CARD_SIZES.MEDIUM,
  locale: 'en',
  dataState: null,
  values: null,
  // default productive-heading-06 font size
  fontSize: valueCardUtils.DEFAULT_FONT_SIZE,
  cardVariables: null,
  customFormatter: null,
  formatter: null,
  isNumberValueCompact: false,
  // TODO: fix this default in V3, so that cards are unique not inherited from the base Card
  testId: 'Card',
  onAttributeClick: null,
  shouldUseTranslatedLabels: false
};
ValueCard.__docgenInfo = {
  "description": "This components responsibilities include:\nRendering the attribute groups\nDetermining the layout\ndetermines the data to render",
  "methods": [],
  "displayName": "ValueCard",
  "props": {
    "size": {
      "defaultValue": {
        "value": "CARD_SIZES.MEDIUM",
        "computed": true
      },
      "required": false
    },
    "locale": {
      "defaultValue": {
        "value": "'en'",
        "computed": false
      },
      "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
    },
    "cardVariables": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "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": "'Card'",
        "computed": false
      },
      "required": false
    },
    "onAttributeClick": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "required": false
    },
    "shouldUseTranslatedLabels": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "required": false
    }
  },
  "composes": ["../../constants/CardPropTypes"]
};
var ValueCard$1 = ValueCard;

module.exports = ValueCard$1;
