"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.validateStepped = exports.validateRange = exports.warn = void 0;

/**
 * Exports various utilities for performing dev-time validations
 *
 * @module moonstone/internal/validators
 * @private
 */

/**
 * Issues a warning to the console
 *
 * @function
 * @param {String} msg				Event name
 * @param	{Function}	fn					Event handler
 * @param	{Node}		[target=`document`]	Event listener target
 *
 * @returns {undefined}
 * @memberof moonstone/internal/validators
 * @private
 */
var warn = function warn(msg) {
  if (typeof console !== 'undefined') {
    console.warn(msg); // eslint-disable-line no-console
  }
};
/**
 * Issues a warning to the console if `value` is not within the range
 * `min` to `max` or if `min` is less than `max`. In production mode,
 * no action is taken.
 *
 * @function
 * @param {Number} value The value to validate
 * @param {Number} min   The minimum acceptable value to validate
 * @param {Number} max   The maximum acceptable value to validate
 * @param {String} component The name of the invoker, used to decorate warning message
 * @param {String} [valueName='value'] The name of the value property
 * @param {String} [minName='min'] The name of the min property
 * @param {String} [maxName='max'] The name of the max property
 *
 * @returns {undefined}
 * @memberof moonstone/internal/validators
 * @private
 */


exports.warn = warn;

var validateRange = function validateRange(value, min, max, component) {
  var valueName = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : '"value"';
  var minName = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : '"min"';
  var maxName = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : '"max"';

  if (process.env.NODE_ENV !== "production") {
    if (value < min) {
      warn("Warning: ".concat(component, " ").concat(valueName, " (").concat(value, ") less than ").concat(minName, " (").concat(min, ")"));
    } else if (value > max) {
      warn("Warning: ".concat(component, " ").concat(valueName, " (").concat(value, ") greater than ").concat(maxName, " (").concat(max, ")"));
    }

    if (min > max) {
      warn("Warning: ".concat(component, " ").concat(minName, " (").concat(min, ") greater than ").concat(maxName, " (").concat(max, ")"));
    }
  }
};
/**
 * Issues a warning to the console if `value`, adjusted for `min` is not evenly
 * divisible by `step`. In production mode, no action is taken.
 *
 * @function
 * @param {Number} value The value to validate
 * @param {Number} min   The minimum acceptable value to validate
 * @param {Number} step  The step
 * @param {String} component The name of the invoker, used to decorate warning message
 * @param {String} [valueName='value'] The name of the value property
 * @param {String} [stepName='step'] The name of the step property
 *
 * @returns {undefined}
 * @memberof moonstone/internal/validators
 * @private
 */


exports.validateRange = validateRange;

var validateStepped = function validateStepped(value, min, step, component) {
  var valueName = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : '"value"';
  var stepName = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : '"step"';

  if (process.env.NODE_ENV !== "production") {
    if ((value - min) % step !== 0) {
      warn("Warning: ".concat(component, " ").concat(valueName, " (").concat(value, ") must be evenly divisible by ").concat(stepName, " (").concat(step, ")"));
    }
  }
};

exports.validateStepped = validateStepped;