import "core-js/modules/es.array.iterator";
import "core-js/modules/es.string.replace";
import "core-js/modules/web.dom-collections.iterator";
import _sliceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/slice";
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
// @flow

/*:: import type { Field, Key } from '../types'*/

/**
 * Either returns the translated user-defined label for a field, or creates a
 * label from the field key by replacing _ and - with spaces and formatting in
 * title case
 */
export function getLocalizedFieldProp(field
/*: Field*/
, prop
/*: 'label' | 'placeholder'*/
, languageTag
/*: string*/
= 'en')
/*: string*/
{
  // two-letter or three-letter ISO language code
  const languageCode = languageTag.split('-')[0]; // choose most specific label translation available e.g. language tag with
  // country code first, then just language code, then label without language
  // specified

  const label = field[prop + ':' + languageTag] || field[prop + ':' + languageCode] || field[prop];
  return label;
}
export function fieldKeyToLabel(key
/*: Key*/
)
/*: string | string[]*/
{
  const fieldkey = typeof key === 'string' ? [key] : [...key];

  const labelArray = _mapInstanceProperty(fieldkey).call(fieldkey, s => titleCase(s + ''));

  return labelArray.length === 1 ? labelArray[0] : labelArray;
}
export function sentenceCase(str
/*: string*/
= '') {
  // Matches the first letter in the string and the first letter that follows a
  // period (and 1 or more spaces) and transforms that letter to uppercase.
  return str.replace(/(^[a-z])|(\.\s*[a-z])/g, str => str.toUpperCase());
}
/**
 * For a string written in camel_case or snake-case, or space-separated, return
 * string formatted in title case
 */

export function titleCase(str
/*: string*/
) {
  var _context;

  return _mapInstanceProperty(_context = str.toLowerCase().split(/\s|_|-/)).call(_context, word => capitalize(word)).join(' ');
}
export function capitalize(str
/*: string*/
) {
  return str.charAt(0).toUpperCase() + _sliceInstanceProperty(str).call(str, 1);
}
//# sourceMappingURL=strings.js.map