"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.emitChange = void 0;
var _clamp = _interopRequireDefault(require("ramda/src/clamp"));
var _handle = require("@enact/core/handle");
var _utils = require("@enact/ui/Slider/utils");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
var calcStep = function calcStep(knobStep, step) {
  var s;
  if (knobStep != null) {
    s = knobStep;
  } else if (step != null) {
    s = step;
  }

  // default to a step of 1 if neither are set or are set to 0
  // otherwise, increment/decrement would be no-ops
  return s || 1;
};
var emitChange = exports.emitChange = function emitChange(direction) {
  return (0, _handle.adaptEvent)(function (ev, _ref) {
    var knobStep = _ref.knobStep,
      max = _ref.max,
      min = _ref.min,
      step = _ref.step,
      _ref$value = _ref.value,
      value = _ref$value === void 0 ? min : _ref$value;
    var newValue = (0, _clamp["default"])(min, max, value + calcStep(knobStep, step) * direction);
    return {
      value: newValue,
      proportion: (0, _utils.calcProportion)(min, max, newValue),
      type: 'onChange'
    };
  }, (0, _handle.forward)('onChange'));
};