import _extends from "@babel/runtime/helpers/extends";

/* eslint-disable eqeqeq */

/* eslint-disable prefer-const */
var requiredCompanyFields = ['vatId', 'companyId', 'companyPerson', 'companyName'];
var requiredFields = ['additionalAddressInfo'];
export var validateBillingAddress = (data, errorLabels) => {
  var _data$custom;

  var isWithInvoice = (_data$custom = data.custom) == null ? void 0 : _data$custom.some(custom => custom.field === 'withInvoice' && custom.value == 1);
  if (!isWithInvoice) return null;
  var companyErrors = requiredCompanyFields.reduce((errors, field) => {
    var _data$company, _data$company$field;

    if (!(data != null && (_data$company = data.company) != null && (_data$company$field = _data$company[field]) != null && _data$company$field.trim())) {
      return _extends({}, errors, {
        [field]: errorLabels.fieldIsRequired
      });
    }

    return errors;
  }, {});
  var fieldErrors = requiredFields.reduce((errors, field) => {
    var _data$field;

    if (!((_data$field = data[field]) != null && _data$field.trim())) {
      return _extends({}, errors, {
        [field]: errorLabels.fieldIsRequired
      });
    }

    return errors;
  }, {});

  var errors = _extends({}, companyErrors, fieldErrors);

  return Object.keys(errors).length ? errors : null;
};
//# sourceMappingURL=validateBillingAddress.js.map