import { map } from './collection'
import _ from 'lodash/fp'
import { when } from './logic'

export const wrap = (pre, post, content) =>
  (pre || '') + content + (post || pre || '')
export const quote = _.partial(wrap, ['"', '"'])
export const parens = _.partial(wrap, ['(', ')'])
export const concatStrings = _.flow(
  _.compact,
  _.map(_.trim),
  _.join(' ')
)
export const trimStrings = map(when(_.isString, _.trim))

export let autoLabel = (string = '') => {
  // Prevent Acronyms from being lower cased
  let acronymRegex = new RegExp('([A-Z])([A-Z])($|.)', 'g')
  while (string.match(acronymRegex)) {
    string = string.replace(acronymRegex, '$1 $2$3')
  }
  string = _.startCase(string)
  // Remove Mid-Acronym Whitespace
  let whitespacedAcronymRegex = new RegExp('([A-Z])[ ]([A-Z])($|[^a-z])', 'g')
  while (string.match(whitespacedAcronymRegex)) {
    string = string.replace(whitespacedAcronymRegex, '$1$2$3')
  }
  // Put a space between words and numbers
  string = string.replace(/([a-z]|[A-Z])([0-9])/g, '$1 $2')

  return string
}
export let autoLabelOption = a => ({
  value: a.value || a,
  label: a.label || autoLabel(a.value || a),
})
export let autoLabelOptions = _.map(autoLabelOption)

@@ -420,634 +420,87 @@
 ))%0A%0A
-export let autoLabel = (string = '') =%3E %7B%0A  // Prevent Acronyms from being lower cased%0A  let acronymRegex = new RegExp('(%5BA-Z%5D)(%5BA-Z%5D)($%7C.)', 'g')%0A  while (string.match(acronymRegex)) %7B%0A    string = string.replace(acronymRegex, '$1 $2$3')%0A  %7D%0A  string = _.startCase(string)%0A  // Remove Mid-Acronym Whitespace%0A  let whitespacedAcronymRegex = new RegExp('(%5BA-Z%5D)%5B %5D(%5BA-Z%5D)($%7C%5B%5Ea-z%5D)', 'g')%0A  while (string.match(whitespacedAcronymRegex)) %7B%0A    string = string.replace(whitespacedAcronymRegex, '$1$2$3')%0A  %7D%0A  // Put a space between words and numbers%0A  string = string.replace(/(%5Ba-z%5D%7C%5BA-Z%5D)(%5B0-9%5D)/g, '$1 $2')%0A%0A  return string%0A%7D
+// _.startCase does the trick, deprecate it!%0Aexport let autoLabel = _.startCase
 %0Aexp

replace autoLabel implementation with _.startCase