"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.toFloatList = exports.toFloat = exports.sumFloatList = exports.fromFloatList = exports.fromFloat = void 0;
var _isNotNumber = _interopRequireDefault(require("../../helpers/float/isNotNumber"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _checkFloat = s => {
  var n = s == undefined ? '' : s.toString().replace(/,/g, '.');
  if ((0, _isNotNumber.default)(n)) {
    return false;
  }
  return true;
};
var _checkFloatList = l => {
  if (l == undefined || l == '' || l.length == 0) {
    return false;
  }
  var valid = true;
  for (var s of l) {
    if (!_checkFloat(s)) {
      valid = false;
      break;
    }
  }
  return valid;
};
var toFloat = s => {
  if (!_checkFloat(s)) {
    //console.log(`toFloat ${typeof s} ${s} => 0.0 (not float)`)

    return 0.0;
  }
  return parseFloat(s.toString().replace(/,/g, '.'));
};
exports.toFloat = toFloat;
var toFloatList = l => {
  if (!_checkFloatList(l)) {
    return [0.0];
  }
  return l.map(s => toFloat(s));
};
exports.toFloatList = toFloatList;
var fromFloat = (f, decimalSign, forceSign) => {
  if ((0, _isNotNumber.default)(f)) {
    //console.log(`fromFloat ${typeof f} ${f} => "" (not number)`)
    return '';
  }
  var n = parseFloat(f);
  var s = n.toString().replace('.', decimalSign);
  if (forceSign === false && n == 0) {
    s = "-".concat(s);
  }

  //console.log(`fromFloat ${f} => ${s}`)

  return s;
};
exports.fromFloat = fromFloat;
var fromFloatList = (l, decimalSign) => {
  if (l == undefined || l.length == 0) {
    return [0.0];
  }
  return l.map(f => fromFloat(f, decimalSign));
};
exports.fromFloatList = fromFloatList;
var sumFloatList = l => {
  var fls = toFloatList(l);
  //console.log(fls)
  var sum = fls.reduce((a, b) => a + b, 0);
  return sum;
};
exports.sumFloatList = sumFloatList;