"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.IncrementSliderDecorator = exports.IncrementSliderBase = exports.IncrementSlider = void 0;
Object.defineProperty(exports, "IncrementSliderTooltip", {
  enumerable: true,
  get: function get() {
    return _ProgressBar.ProgressBarTooltip;
  }
});
exports["default"] = void 0;
var _handle = require("@enact/core/handle");
var _propTypes = _interopRequireDefault(require("@enact/core/internal/prop-types"));
var _keymap = require("@enact/core/keymap");
var _kind = _interopRequireDefault(require("@enact/core/kind"));
var _util = require("@enact/core/util");
var _Spottable = _interopRequireDefault(require("@enact/spotlight/Spottable"));
var _Changeable = _interopRequireDefault(require("@enact/ui/Changeable"));
var _IdProvider = _interopRequireDefault(require("@enact/ui/internal/IdProvider"));
var _Pure = _interopRequireDefault(require("@enact/ui/internal/Pure"));
var _Slottable = _interopRequireDefault(require("@enact/ui/Slottable"));
var _propTypes2 = _interopRequireDefault(require("prop-types"));
var _compose = _interopRequireDefault(require("ramda/src/compose"));
var _$L = _interopRequireDefault(require("../internal/$L"));
var _ProgressBar = require("../ProgressBar");
var _Skinnable = _interopRequireDefault(require("../Skinnable"));
var _Slider = require("../Slider");
var _SliderBehaviorDecorator = _interopRequireDefault(require("../Slider/SliderBehaviorDecorator"));
var _IncrementSliderButton = _interopRequireDefault(require("./IncrementSliderButton"));
var _utils = require("./utils");
var _IncrementSliderModule = _interopRequireDefault(require("./IncrementSlider.module.css"));
var _jsxRuntime = require("react/jsx-runtime");
var _excluded = ["activateOnFocus", "active", "aria-hidden", "backgroundProgress", "css", "decrementAriaLabel", "decrementDisabled", "decrementIcon", "disabled", "focused", "id", "incrementAriaLabel", "incrementDisabled", "incrementIcon", "knobStep", "max", "min", "noFill", "onActivate", "onChange", "onDecrement", "onDecrementSpotlightDisappear", "onDragEnd", "onDragStart", "onIncrement", "onIncrementSpotlightDisappear", "onSpotlightDisappear", "orientation", "progressAnchor", "size", "sliderRef", "spotlightDisabled", "step", "tooltip", "value"];
/**
 * An interactive numeric range picker with increment decrement
 *
 * @example
 * <IncrementSlider
 * 	decrementIcon="minus"
 * 	defaultValue={-25}
 * 	incrementIcon="plus"
 * 	knobStep={25}
 * 	max={100}
 * 	min={-100}
 * 	step={5}
 * />
 *
 * @module agate/IncrementSlider
 * @exports IncrementSlider
 * @exports IncrementSliderBase
 * @exports IncrementSliderDecorator
 * @exports IncrementSliderTooltip
 */
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
var isDown = (0, _keymap.is)('down');
var isLeft = (0, _keymap.is)('left');
var isRight = (0, _keymap.is)('right');
var isUp = (0, _keymap.is)('up');
var Slider = (0, _Spottable["default"])((0, _Skinnable["default"])(_Slider.SliderBase));
var forwardWithType = function forwardWithType(type, props) {
  return (0, _handle.forward)(type, {
    type: type
  }, props);
};

/**
 * A stateless Slider with IconButtons to increment and decrement the value. In most circumstances,
 * you will want to use the stateful version: {@link agate/IncrementSlider.IncrementSlider|IncrementSlider}.
 *
 * @class IncrementSliderBase
 * @memberof agate/IncrementSlider
 * @extends agate/Slider.SliderBase
 * @ui
 * @public
 */
var IncrementSliderBase = exports.IncrementSliderBase = (0, _kind["default"])({
  name: 'IncrementSlider',
  propTypes: /** @lends agate/IncrementSlider.IncrementSliderBase.prototype */{
    /**
     * Activates the slider knob when focused so that it may be manipulated via the directional
     * input keys.
     *
     * @type {Boolean}
     * @public
     */
    activateOnFocus: _propTypes2["default"].bool,
    /**
     * Sets the knob to selected state and allows it to move via 5-way controls.
     *
     * @type {Boolean}
     * @public
     */
    active: _propTypes2["default"].bool,
    /**
     * Prevents read out of both the slider and the increment and decrement
     * buttons.
     *
     * @type {Boolean}
     * @public
     */
    'aria-hidden': _propTypes2["default"].bool,
    /**
     * Overrides the `aria-valuetext` for the slider. By default, `aria-valuetext` is set
     * to the current value. This should only be used when the parent controls the value of
     * the slider directly through the props.
     *
     * @type {String|Number}
     * @public
     */
    'aria-valuetext': _propTypes2["default"].oneOfType([_propTypes2["default"].string, _propTypes2["default"].number]),
    /**
     * Background progress, as a proportion between `0` and `1`.
     *
     * @type {Number}
     * @default 0
     * @public
     */
    backgroundProgress: _propTypes2["default"].number,
    /**
     * Customizes the component by mapping the supplied collection of CSS class names to the
     * corresponding internal elements and states of this component.
     *
     * @type {Object}
     * @private
     */
    css: _propTypes2["default"].object,
    /**
    * Sets the hint string read when focusing the decrement button.
    *
    * @type {String}
    * @default 'press button to decrease the value'
    * @public
    */
    decrementAriaLabel: _propTypes2["default"].string,
    /**
     * Assign a custom icon for the decrementer. All strings supported by {@link agate/Icon.Icon|Icon} are
     * supported. Without a custom icon, the default is used, and is automatically changed when
     * {@link agate/IncrementSlider.IncrementSlider#vertical|vertical} is changed.
     *
     * @type {String}
     * @default 'minus'
     * @public
     */
    decrementIcon: _propTypes2["default"].string,
    /**
     * Disables the slider and prevents events from firing.
     *
     * @type {Boolean}
     * @public
     */
    disabled: _propTypes2["default"].bool,
    /**
     * Indicates focused state.
     * @type {Boolean}
     * @public
     */
    focused: _propTypes2["default"].bool,
    /**
     * The slider id reference for setting aria-controls.
     *
     * @type {String}
     * @private
     */
    id: _propTypes2["default"].string,
    /**
    * Sets the hint string read when focusing the increment button.
    *
    * @default 'press button to increase the value'
    * @type {String}
    * @public
    */
    incrementAriaLabel: _propTypes2["default"].string,
    /**
     * Assign a custom icon for the incrementer. All strings supported by {@link agate/Icon.Icon|Icon} are
     * supported. Without a custom icon, the default is used, and is automatically changed when
     * {@link agate/IncrementSlider.IncrementSlider#vertical|vertical} is changed.
     *
     * @type {String}
     * @default 'plus'
     * @public
     */
    incrementIcon: _propTypes2["default"].string,
    /**
     * The amount to increment or decrement the position of the knob via 5-way controls.
     *
     * If not specified, `step` is used for the default value.
     *
     * @type {Number}
     * @public
     */
    knobStep: _propTypes2["default"].number,
    /**
     * The maximum value of the increment slider.
     *
     * @type {Number}
     * @default 100
     * @public
     */
    max: _propTypes2["default"].number,
    /**
     * The minimum value of the increment slider.
     *
     * @type {Number}
     * @default 0
     * @public
     */
    min: _propTypes2["default"].number,
    /**
     * Hides the slider bar fill and prevents highlight when spotted.
     *
     * @type {Boolean}
     * @default false
     * @public
     */
    noFill: _propTypes2["default"].bool,
    /**
     * Called when the knob is activated or deactivated by selecting it via 5-way.
     *
     * @type {Function}
     * @public
     */
    onActivate: _propTypes2["default"].func,
    /**
     * Called when the value is changed.
     *
     * @type {Function}
     * @param {Object} event
     * @param {Number} event.value The current value
     * @public
     */
    onChange: _propTypes2["default"].func,
    /**
     * Called run when the decrement button becomes disabled.
     *
     * @type {Function}
     * @private
     */
    onDecrementSpotlightDisappear: _propTypes2["default"].func,
    /**
     * Forwarded from SliderBehaviorDecorator onto the internal slider.
     *
     * @type {Function}
     * @private
     */
    onDragEnd: _propTypes2["default"].func,
    /**
     * Forwarded from SliderBehaviorDecorator onto the internal slider.
     *
     * @type {Function}
     * @private
     */
    onDragStart: _propTypes2["default"].func,
    /**
     * Called when the increment button becomes disabled.
     *
     * @type {Function}
     * @private
     */
    onIncrementSpotlightDisappear: _propTypes2["default"].func,
    /**
     * Called when the increment button becomes disabled.
     *
     * @type {Function}
     * @private
     */
    onSpotlightDirection: _propTypes2["default"].func,
    /**
     * Called when the component is removed while retaining focus.
     *
     * @type {Function}
     * @param {Object} event
     * @public
     */
    onSpotlightDisappear: _propTypes2["default"].func,
    /**
     * Called prior to focus leaving the component when the 5-way down key is pressed.
     *
     * @type {Function}
     * @param {Object} event
     * @public
     */
    onSpotlightDown: _propTypes2["default"].func,
    /**
     * Called prior to focus leaving the component when the 5-way left key is pressed.
     *
     * @type {Function}
     * @param {Object} event
     * @public
     */
    onSpotlightLeft: _propTypes2["default"].func,
    /**
     * Called prior to focus leaving the component when the 5-way right key is pressed.
     *
     * @type {Function}
     * @param {Object} event
     * @public
     */
    onSpotlightRight: _propTypes2["default"].func,
    /**
     * Called prior to focus leaving the component when the 5-way up key is pressed.
     *
     * @type {Function}
     * @param {Object} event
     * @public
     */
    onSpotlightUp: _propTypes2["default"].func,
    /**
     * Sets the orientation of the slider, whether the slider moves left and right or up and
     * down. Must be either `'horizontal'` or `'vertical'`.
     *
     * @type {String}
     * @default 'horizontal'
     * @public
     */
    orientation: _propTypes2["default"].oneOf(['horizontal', 'vertical']),
    /**
     * Sets the point, as a proportion between 0 and 1, from which the slider is filled.
     *
     * Applies to both the slider's `value` and `backgroundProgress`. In both cases,
     * setting the value of `progressAnchor` will cause the slider to fill from that point
     * down, when `value` or `backgroundProgress` is proportionally less than the anchor, or up,
     * when `value` or `backgroundProgress` is proportionally greater than the anchor, rather
     * than always from the start of the slider.
     *
     * @type {Number}
     * @default 0
     * @public
     */
    progressAnchor: _propTypes2["default"].number,
    /**
     * The size of the incrementSlider.
     *
     * @type {('small'|'large')}
     * @default 'large'
     * @public
     */
    size: _propTypes2["default"].oneOf(['small', 'large']),
    /**
     * Called with the reference to the Slider node.
     *
     * @type {Object|Function}
     * @public
     */
    sliderRef: _propTypes["default"].ref,
    /**
     * Disables spotlight navigation into the component.
     *
     * @type {Boolean}
     * @default false
     * @public
     */
    spotlightDisabled: _propTypes2["default"].bool,
    /**
     * The amount to increment or decrement the value.
     *
     * @type {Number}
     * @default 1
     * @public
     */
    step: _propTypes2["default"].number,
    /**
     * Enables the built-in tooltip
     *
     * To customize the tooltip, pass either a custom tooltip component or an instance of
     * {@link agate/IncrementSlider.IncrementSliderTooltip|IncrementSliderTooltip} with additional props configured.
     *
     * ```
     * <IncrementSlider
     *   tooltip={
     *     <IncrementSliderTooltip percent side="after" />
     *   }
     * />
     * ```
     *
     * The tooltip may also be passed as a child via the `"tooltip"` slot. See
     * {@link ui/Slottable|Slottable} for more information on how slots can be used.
     *
     * ```
     * <IncrementSlider>
     *   <IncrementSliderTooltip percent side="after" />
     * </IncrementSlider>
     * ```
     *
     * If a custom tooltip is provided, it will receive the following props:
     *
     * * `children` - The `value` prop from the slider
     * * `visible` - `true` if the tooltip should be displayed
     * * `orientation` - The value of the `orientation` prop from the slider
     * * `proportion` - A number between 0 and 1 representing the proportion of the `value` in
     *   terms of `min` and `max`
     *
     * @type {Boolean|Element|Function}
     * @public
     */
    tooltip: _propTypes2["default"].oneOfType([_propTypes2["default"].bool, _propTypes2["default"].object, _propTypes2["default"].func]),
    /**
     * The value of the increment slider.
     *
     * Defaults to the value of `min`.
     *
     * @type {Number}
     * @public
     */
    value: _propTypes2["default"].number
  },
  defaultProps: {
    backgroundProgress: 0,
    decrementIcon: 'minus',
    incrementIcon: 'plus',
    max: 100,
    min: 0,
    noFill: false,
    orientation: 'horizontal',
    progressAnchor: 0,
    size: 'large',
    spotlightDisabled: false,
    step: 1
  },
  styles: {
    css: _IncrementSliderModule["default"],
    className: 'incrementSlider',
    publicClassNames: ['incrementSlider']
  },
  handlers: {
    onDecrement: (0, _utils.emitChange)(-1),
    onIncrement: (0, _utils.emitChange)(1),
    onKeyDown: function onKeyDown(ev, props) {
      var orientation = props.orientation;
      (0, _handle.forward)('onKeyDown', ev, props);

      // if the source of the event is the slider, forward it along
      if (ev.target.classList.contains(_IncrementSliderModule["default"].slider)) {
        (0, _handle.forward)('onSpotlightDirection', ev, props);
        return;
      }
      var isIncrement = ev.target.classList.contains(_IncrementSliderModule["default"].incrementButton);
      var isDecrement = ev.target.classList.contains(_IncrementSliderModule["default"].decrementButton);
      if (isRight(ev.keyCode) && (isIncrement || orientation === 'vertical')) {
        forwardWithType('onSpotlightRight', props);
      } else if (isLeft(ev.keyCode) && (isDecrement || orientation === 'vertical')) {
        forwardWithType('onSpotlightLeft', props);
      } else if (isUp(ev.keyCode) && (isIncrement || orientation === 'horizontal')) {
        forwardWithType('onSpotlightUp', props);
      } else if (isDown(ev.keyCode) && (isDecrement || orientation === 'horizontal')) {
        forwardWithType('onSpotlightDown', props);
      }
    }
  },
  computed: {
    className: function className(_ref) {
      var orientation = _ref.orientation,
        size = _ref.size,
        styler = _ref.styler;
      return styler.append(orientation, size);
    },
    decrementDisabled: function decrementDisabled(_ref2) {
      var disabled = _ref2.disabled,
        min = _ref2.min,
        _ref2$value = _ref2.value,
        value = _ref2$value === void 0 ? min : _ref2$value;
      return disabled || value <= min;
    },
    incrementDisabled: function incrementDisabled(_ref3) {
      var disabled = _ref3.disabled,
        max = _ref3.max,
        min = _ref3.min,
        _ref3$value = _ref3.value,
        value = _ref3$value === void 0 ? min : _ref3$value;
      return disabled || value >= max;
    },
    decrementAriaLabel: function decrementAriaLabel(_ref4) {
      var valueText = _ref4['aria-valuetext'],
        _decrementAriaLabel = _ref4.decrementAriaLabel,
        min = _ref4.min,
        _ref4$value = _ref4.value,
        value = _ref4$value === void 0 ? min : _ref4$value;
      if (_decrementAriaLabel == null) {
        _decrementAriaLabel = (0, _$L["default"])('press button to decrease the value');
      }
      return "".concat(valueText != null ? valueText : value, " ").concat(_decrementAriaLabel);
    },
    incrementAriaLabel: function incrementAriaLabel(_ref5) {
      var valueText = _ref5['aria-valuetext'],
        _incrementAriaLabel = _ref5.incrementAriaLabel,
        min = _ref5.min,
        _ref5$value = _ref5.value,
        value = _ref5$value === void 0 ? min : _ref5$value;
      if (_incrementAriaLabel == null) {
        _incrementAriaLabel = (0, _$L["default"])('press button to increase the value');
      }
      return "".concat(valueText != null ? valueText : value, " ").concat(_incrementAriaLabel);
    },
    tooltip: function tooltip(_ref6) {
      var _tooltip = _ref6.tooltip;
      return _tooltip === true ? _ProgressBar.ProgressBarTooltip : _tooltip;
    }
  },
  render: function render(_ref7) {
    var activateOnFocus = _ref7.activateOnFocus,
      active = _ref7.active,
      ariaHidden = _ref7['aria-hidden'],
      backgroundProgress = _ref7.backgroundProgress,
      css = _ref7.css,
      decrementAriaLabel = _ref7.decrementAriaLabel,
      decrementDisabled = _ref7.decrementDisabled,
      decrementIcon = _ref7.decrementIcon,
      disabled = _ref7.disabled,
      focused = _ref7.focused,
      id = _ref7.id,
      incrementAriaLabel = _ref7.incrementAriaLabel,
      incrementDisabled = _ref7.incrementDisabled,
      incrementIcon = _ref7.incrementIcon,
      knobStep = _ref7.knobStep,
      max = _ref7.max,
      min = _ref7.min,
      noFill = _ref7.noFill,
      onActivate = _ref7.onActivate,
      onChange = _ref7.onChange,
      onDecrement = _ref7.onDecrement,
      onDecrementSpotlightDisappear = _ref7.onDecrementSpotlightDisappear,
      onDragEnd = _ref7.onDragEnd,
      onDragStart = _ref7.onDragStart,
      onIncrement = _ref7.onIncrement,
      onIncrementSpotlightDisappear = _ref7.onIncrementSpotlightDisappear,
      onSpotlightDisappear = _ref7.onSpotlightDisappear,
      orientation = _ref7.orientation,
      progressAnchor = _ref7.progressAnchor,
      size = _ref7.size,
      sliderRef = _ref7.sliderRef,
      spotlightDisabled = _ref7.spotlightDisabled,
      step = _ref7.step,
      tooltip = _ref7.tooltip,
      value = _ref7.value,
      rest = _objectWithoutProperties(_ref7, _excluded);
    var ariaProps = (0, _util.extractAriaProps)(rest);
    delete rest.onSpotlightDirection;
    delete rest.onSpotlightDown;
    delete rest.onSpotlightLeft;
    delete rest.onSpotlightRight;
    delete rest.onSpotlightUp;
    return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", _objectSpread(_objectSpread({
      "aria-hidden": ariaHidden
    }, rest), {}, {
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_IncrementSliderButton["default"], {
        "aria-controls": !incrementDisabled ? id : null,
        "aria-label": decrementAriaLabel,
        className: css.decrementButton,
        disabled: decrementDisabled,
        icon: decrementIcon,
        onTap: onDecrement,
        onSpotlightDisappear: onDecrementSpotlightDisappear,
        orientation: orientation,
        size: size,
        spotlightDisabled: spotlightDisabled
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)(Slider, _objectSpread(_objectSpread({}, ariaProps), {}, {
        activateOnFocus: activateOnFocus,
        active: active,
        backgroundProgress: backgroundProgress,
        css: css,
        disabled: disabled,
        focused: focused,
        id: id,
        knobStep: knobStep,
        max: max,
        min: min,
        noFill: noFill,
        onActivate: onActivate,
        onChange: onChange,
        onDragEnd: onDragEnd,
        onDragStart: onDragStart,
        onSpotlightDisappear: onSpotlightDisappear,
        orientation: orientation,
        sliderRef: sliderRef,
        spotlightDisabled: spotlightDisabled,
        progressAnchor: progressAnchor,
        step: step,
        tooltip: tooltip,
        value: value
      })), /*#__PURE__*/(0, _jsxRuntime.jsx)(_IncrementSliderButton["default"], {
        "aria-controls": !decrementDisabled ? id : null,
        "aria-label": incrementAriaLabel,
        className: css.incrementButton,
        disabled: incrementDisabled,
        icon: incrementIcon,
        onSpotlightDisappear: onIncrementSpotlightDisappear,
        onTap: onIncrement,
        orientation: orientation,
        size: size,
        spotlightDisabled: spotlightDisabled
      })]
    }));
  }
});

/**
 * Applies Agate specific behaviors to {@link agate/IncrementSlider.IncrementSliderBase|IncrementSliderBase}
 *
 * @hoc
 * @memberof agate/IncrementSlider
 * @mixes ui/Changeable.Changeable
 * @mixes agate/Skinnable.Skinnable
 * @mixes ui/Slottable.Slottable
 * @public
 */
var IncrementSliderDecorator = exports.IncrementSliderDecorator = (0, _compose["default"])(_Pure["default"], _Changeable["default"], (0, _IdProvider["default"])({
  generateProp: null,
  prefix: 's_'
}), (0, _SliderBehaviorDecorator["default"])({
  emitSpotlightEvents: 'onSpotlightDirection'
}), _Skinnable["default"], (0, _Slottable["default"])({
  slots: ['knob', 'tooltip']
}));

/**
 * An IncrementSlider with Agate styling and SliderDecorator applied with IconButtons to
 * increment and decrement the value.
 *
 * By default, `IncrementSlider` maintains the state of its `value` property. Supply the
 * `defaultValue` property to control its initial value. If you wish to directly control updates
 * to the component, supply a value to `value` at creation time and update it in response to
 * `onChange` events.
 *
 * @class IncrementSlider
 * @memberof agate/IncrementSlider
 * @extends agate/IncrementSlider.IncrementSliderBase
 * @mixes agate/IncrementSlider.IncrementSliderDecorator
 * @ui
 * @public
 */
var IncrementSlider = exports.IncrementSlider = IncrementSliderDecorator(IncrementSliderBase);

/**
 * A {@link agate/TooltipDecorator.Tooltip|Tooltip} specifically adapted for use with
 * {@link agate/ProgressBar.ProgressBar|ProgressBar} or
 * {@link agate/IncrementSlider.IncrementSlider|IncrementSlider}.
 *
 * @see {@link agate/ProgressBar.ProgressBarTooltip}
 * @class IncrementSliderTooltip
 * @memberof agate/IncrementSlider
 * @ui
 * @public
 */
var _default = exports["default"] = IncrementSlider;