'use strict';

var filter = require('../../node_modules/lodash-es/filter.js');
var warning = require('warning');
var LayoutConstants = require('../../constants/LayoutConstants.js');
var Settings = require('../../constants/Settings.js');

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

var warning__default = /*#__PURE__*/_interopDefault(warning);

var iotPrefix = Settings.settings.iotPrefix;
var BASE_CLASS_NAME = "".concat(iotPrefix, "--value-card");
var PREVIEW_DATA = '--';
var DEFAULT_FONT_SIZE = 42;

/**
 * Support either an array of values or an object of values
 * @param {string} dataSourceId
 * @param {Array<Object>} values
 * @param {Object} dataFilter
 */
var determineValue = function determineValue(dataSourceId, values) {
  var dataFilter = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  return Array.isArray(values) ? filter(values, dataFilter)[0] && filter(values, dataFilter)[0][dataSourceId] : values && values[dataSourceId];
};

/**
 * @param {string} size card size
 * @param {Array<Object>} attributes
 * @param {Number} measuredWidth
 * @returns card layout - horizontal or vertical
 */
var determineLayout = function determineLayout(size) {
  switch (size) {
    case LayoutConstants.CARD_SIZES.SMALL:
    case LayoutConstants.CARD_SIZES.SMALLWIDE:
    case LayoutConstants.CARD_SIZES.SMALLFULL:
    case LayoutConstants.CARD_SIZES.MEDIUMWIDE:
      return LayoutConstants.CARD_LAYOUTS.HORIZONTAL;
    case LayoutConstants.CARD_SIZES.MEDIUM:
    case LayoutConstants.CARD_SIZES.MEDIUMTHIN:
    case LayoutConstants.CARD_SIZES.LARGETHIN:
    case LayoutConstants.CARD_SIZES.LARGE:
    case LayoutConstants.CARD_SIZES.LARGEWIDE:
      return LayoutConstants.CARD_LAYOUTS.VERTICAL;
    default:
      return LayoutConstants.CARD_LAYOUTS.HORIZONTAL;
  }
};

/** Determine the max value card attribute count
 * TODO: remove in next release
 */
var determineMaxValueCardAttributeCount = function determineMaxValueCardAttributeCount(size, currentAttributeCount) {
  {
    warning__default.default(false, 'Deprecation warning: There is no longer a max number of attributes allowed in ValueCards. This function will me removed in the next release.') ;
  }
  var attributeCount = currentAttributeCount;
  switch (size) {
    case LayoutConstants.CARD_SIZES.SMALL:
      attributeCount = 1;
      break;
    case LayoutConstants.CARD_SIZES.SMALLWIDE:
      attributeCount = 2;
      break;
    case LayoutConstants.CARD_SIZES.MEDIUMTHIN:
    case LayoutConstants.CARD_SIZES.MEDIUM:
      attributeCount = 3;
      break;
    case LayoutConstants.CARD_SIZES.SMALLFULL:
    case LayoutConstants.CARD_SIZES.MEDIUMWIDE:
      attributeCount = 4;
      break;
    case LayoutConstants.CARD_SIZES.LARGE:
      attributeCount = 5;
      break;
    case LayoutConstants.CARD_SIZES.LARGETHIN:
    case LayoutConstants.CARD_SIZES.LARGEWIDE:
      attributeCount = 7;
      break;
  }
  return attributeCount;
};

exports.BASE_CLASS_NAME = BASE_CLASS_NAME;
exports.DEFAULT_FONT_SIZE = DEFAULT_FONT_SIZE;
exports.PREVIEW_DATA = PREVIEW_DATA;
exports.determineLayout = determineLayout;
exports.determineMaxValueCardAttributeCount = determineMaxValueCardAttributeCount;
exports.determineValue = determineValue;
