"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.SliderDecorator = exports.SliderBase = exports.Slider = void 0;
Object.defineProperty(exports, "SliderTooltip", {
  enumerable: true,
  get: function get() {
    return _ProgressBar2.ProgressBarTooltip;
  }
});
exports["default"] = void 0;
var _handle = require("@enact/core/handle");
var _propTypes = _interopRequireDefault(require("@enact/core/internal/prop-types"));
var _kind = _interopRequireDefault(require("@enact/core/kind"));
var _Spottable = _interopRequireDefault(require("@enact/spotlight/Spottable"));
var _Changeable = _interopRequireDefault(require("@enact/ui/Changeable"));
var _ComponentOverride = _interopRequireDefault(require("@enact/ui/ComponentOverride"));
var _ProgressBar = _interopRequireDefault(require("@enact/ui/ProgressBar"));
var _Pure = _interopRequireDefault(require("@enact/ui/internal/Pure"));
var _Slottable = _interopRequireDefault(require("@enact/ui/Slottable"));
var _Slider = _interopRequireDefault(require("@enact/ui/Slider"));
var _propTypes2 = _interopRequireDefault(require("prop-types"));
var _anyPass = _interopRequireDefault(require("ramda/src/anyPass"));
var _compose = _interopRequireDefault(require("ramda/src/compose"));
var _ProgressBar2 = require("../ProgressBar");
var _Skinnable = _interopRequireDefault(require("../Skinnable"));
var _SliderBehaviorDecorator = _interopRequireDefault(require("./SliderBehaviorDecorator"));
var _utils = require("./utils");
var _SliderModule = _interopRequireDefault(require("./Slider.module.css"));
var _jsxRuntime = require("react/jsx-runtime");
var _excluded = ["css", "disabled", "focused", "sliderRef", "tooltip"];
/**
 * Provides Agate-themed slider components and behaviors.
 *
 * @example
 * <Slider
 * 	defaultValue={-30}
 * 	max={100}
 * 	min={-100}
 * 	step={10}
 * />
 *
 * @module agate/Slider
 * @exports Slider
 * @exports SliderBase
 * @exports SliderDecorator
 * @exports SliderTooltip
 */
// TODO: Add 'activated' styling for slider (If 5-way is needed)
/**
 * Range-selection input component.
 *
 * @class SliderBase
 * @memberof agate/Slider
 * @extends ui/Slider.SliderBase
 * @mixes agate/Slider.SliderDecorator
 * @ui
 * @public
 */
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 SliderBase = exports.SliderBase = (0, _kind["default"])({
  name: 'Slider',
  propTypes: /** @lends agate/Slider.SliderBase.prototype */{
    /**
     * Activates the component when focused so that it may be manipulated via the directional
     * input keys.
     *
     * @type {Boolean}
     * @default false
     * @public
     */
    activateOnFocus: _propTypes2["default"].bool,
    /**
     * Sets the knob to selected state and allows it to move via 5-way controls.
     *
     * @type {Boolean}
     * @default false
     * @public
     */
    active: _propTypes2["default"].bool,
    /**
     * 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.
     *
     * The following classes are supported:
     *
     * * `slider` - The root component class
     *
     * @type {Object}
     * @public
     */
    css: _propTypes2["default"].object,
    /**
     * Disables component and does not generate events.
     *
     * @type {Boolean}
     * @default false
     * @public
     */
    disabled: _propTypes2["default"].bool,
    /**
     * Indicates that the slider has gained focus.
     *
     * @type {Boolean}
     * @public
     */
    focused: _propTypes2["default"].bool,
    /**
     * 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 slider.
     *
     * @type {Number}
     * @default 100
     * @public
     */
    max: _propTypes2["default"].number,
    /**
     * The minimum value of the slider.
     *
     * @type {Number}
     * @default 0
     * @public
     */
    min: _propTypes2["default"].number,
    /**
     * Called when the knob is activated or deactivated by selecting it via 5-way
     *
     * @type {Function}
     * @public
     */
    onActivate: _propTypes2["default"].func,
    /**
     * Called when a key is pressed down while the slider is focused.
     *
     * When a directional key is pressed down and the knob is active (either by first
     * pressing enter or when `activateOnFocus` is enabled), the Slider will increment or
     * decrement the current value and emit an `onChange` event. This default behavior can be
     * prevented by calling `preventDefault()` on the event passed to this callback.
     *
     * @type {Function}
     * @public
     */
    onKeyDown: _propTypes2["default"].func,
    /**
     * Called when a key is released while the slider is focused.
     *
     * When the enter key is released and `activateOnFocus` is not enabled, the slider will be
     * activated to enable incrementing or decrementing the value via directional keys. This
     * default behavior can be prevented by calling `preventDefault()` on the event passed to
     * this callback.
     *
     * @type {Function}
     * @public
     */
    onKeyUp: _propTypes2["default"].func,
    /**
     * 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,
    /**
     * Called with the reference to the Slider node.
     *
     * @type {Object|Function}
     * @public
     */
    sliderRef: _propTypes["default"].ref,
    /**
     * 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/Slider.SliderTooltip|SliderTooltip} with additional props configured.
     *
     * ```
     * <Slider
     *   tooltip={
     *     <SliderTooltip 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.
     *
     * ```
     * <Slider>
     *   <SliderTooltip percent side="after" />
     * </Slider>
     * ```
     *
     * 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 slider.
     *
     * Defaults to the value of `min`.
     *
     * @type {Number}
     * @public
     */
    value: _propTypes2["default"].number
  },
  defaultProps: {
    activateOnFocus: false,
    active: false,
    disabled: false,
    max: 100,
    min: 0,
    progressAnchor: 0,
    step: 1
  },
  styles: {
    css: _SliderModule["default"],
    className: 'slider',
    publicClassNames: true
  },
  handlers: {
    onBlur: (0, _handle.handle)((0, _handle.forward)('onBlur'), (0, _handle.forProp)('active', true), (0, _handle.forward)('onActivate')),
    onKeyDown: (0, _handle.handle)((0, _handle.forProp)('disabled', false), (0, _handle.forwardWithPrevent)('onKeyDown'), (0, _anyPass["default"])([_utils.handleIncrement, _utils.handleDecrement])),
    onKeyUp: (0, _handle.handle)((0, _handle.forProp)('disabled', false), (0, _handle.forwardWithPrevent)('onKeyUp'), (0, _handle.forProp)('activateOnFocus', false), (0, _handle.forKey)('enter'), (0, _handle.forward)('onActivate'))
  },
  computed: {
    className: function className(_ref) {
      var activateOnFocus = _ref.activateOnFocus,
        active = _ref.active,
        styler = _ref.styler;
      return styler.append({
        activateOnFocus: activateOnFocus,
        active: active
      });
    },
    tooltip: function tooltip(_ref2) {
      var _tooltip = _ref2.tooltip;
      return _tooltip === true ? _ProgressBar2.ProgressBarTooltip : _tooltip;
    }
  },
  render: function render(_ref3) {
    var css = _ref3.css,
      disabled = _ref3.disabled,
      focused = _ref3.focused,
      sliderRef = _ref3.sliderRef,
      tooltip = _ref3.tooltip,
      rest = _objectWithoutProperties(_ref3, _excluded);
    delete rest.activateOnFocus;
    delete rest.active;
    delete rest.knobStep;
    delete rest.onActivate;
    return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Slider["default"], _objectSpread(_objectSpread({}, rest), {}, {
      "aria-disabled": disabled,
      css: css,
      disabled: disabled,
      progressBarComponent: /*#__PURE__*/(0, _jsxRuntime.jsx)(_ProgressBar["default"], {
        css: css
      }),
      ref: sliderRef,
      tooltipComponent: /*#__PURE__*/(0, _jsxRuntime.jsx)(_ComponentOverride["default"], {
        component: tooltip,
        css: css,
        visible: focused
      })
    }));
  }
});

/**
 * Agate-specific slider behaviors to apply to {@link agate/Slider.SliderBase|SliderBase}.
 *
 * @hoc
 * @memberof agate/Slider
 * @mixes ui/Changeable.Changeable
 * @mixes spotlight/Spottable.Spottable
 * @mixes ui/Slottable.Slottable
 * @mixes agate/Skinnable.Skinnable
 * @public
 */
var SliderDecorator = exports.SliderDecorator = (0, _compose["default"])(_Pure["default"], _Changeable["default"], _SliderBehaviorDecorator["default"], _Spottable["default"], (0, _Slottable["default"])({
  slots: ['knob', 'tooltip']
}), _Skinnable["default"]);

/**
 * Slider input with Agate styling, {@link spotlight/Spottable.Spottable|Spottable},
 * {@link ui/Touchable|Touchable} and {@link agate/Slider.SliderDecorator|SliderDecorator}
 * applied.
 *
 * By default, `Slider` 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 Slider
 * @memberof agate/Slider
 * @mixes agate/Slider.SliderDecorator
 * @ui
 * @public
 */
var Slider = exports.Slider = SliderDecorator(SliderBase);

/**
 * 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.
 *
 * @name aria-valuetext
 * @memberof agate/Slider.Slider.prototype
 * @type {String|Number}
 * @public
 */

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