const controlUtils = {
  checkFormatType: function (formatType) {
    let result = {
      number:
        formatType == 'numeric' ||
        formatType == 'integer' ||
        formatType == 'money',
      currency: formatType == 'numeric' || formatType == 'money',
      integer: formatType == 'integer',
      date: formatType == 'date',
      time: formatType == 'time',
      datetime: formatType == 'datetime',
      time_hh: formatType == 'time_hh',
      time_mi: formatType == 'time_mi',
      time_ss: formatType == 'time_ss',
      formatTypeClass: 'c-ft-' + formatType,
      checkbox: formatType == 'boolean',
      type: null
    }
    if (result.number) {
      result.type = 'number'
    } else if (result.date || result.time) {
      result.type = formatType
    } else if (result.checkbox) {
      result.type = 'checkbox'
    }
    return result
  },
  parseFloatWithLocales: function(value, locales) {
    if (value == null) return null

    locales = locales || 'pl-PL'
    let result, thousandsSep, decimalSep

    switch (locales) {
      case 'pl-PL': { 
        thousandsSep = /\s/g
        decimalSep = /,/g
      }
    }

    result = value.replace(new RegExp(thousandsSep), '')
    result = result.replace(new RegExp(decimalSep), '.')

    if (result === '.') result = '0'

    return result
  }
}
export default controlUtils
