"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.SliderDecorator = exports.SliderBase = exports.Slider = exports["default"] = void 0;

var _jsxRuntime = require("react/jsx-runtime");

var _handle = require("@enact/core/handle");

var _kind = _interopRequireDefault(require("@enact/core/kind"));

var _Spottable = _interopRequireDefault(require("@enact/spotlight/Spottable"));

var _Changeable = _interopRequireDefault(require("@enact/ui/Changeable"));

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 _propTypes = _interopRequireDefault(require("prop-types"));

var _anyPass = _interopRequireDefault(require("ramda/src/anyPass"));

var _compose = _interopRequireDefault(require("ramda/src/compose"));

var _Skinnable = _interopRequireDefault(require("../Skinnable"));

var _SliderBehaviorDecorator = _interopRequireDefault(require("./SliderBehaviorDecorator"));

var _utils = require("./utils");

var _SliderModule = _interopRequireDefault(require("./Slider.module.css"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

/**
 * Range-selection input component.
 *
 * @class SliderBase
 * @memberof agate/Slider
 * @extends ui/Slider.SliderBase
 * @mixes agate/Slider.SliderDecorator
 * @ui
 * @public
 */
var 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: _propTypes["default"].bool,

    /**
     * Sets the knob to selected state and allows it to move via 5-way controls.
     *
     * @type {Boolean}
     * @default false
     * @public
     */
    active: _propTypes["default"].bool,

    /**
     * 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: _propTypes["default"].object,

    /**
     * Disables component and does not generate events.
     *
     * @type {Boolean}
     * @default false
     * @public
     */
    disabled: _propTypes["default"].bool,

    /**
     * Indicates that the slider has gained focus.
     *
     * @type {Boolean}
     * @public
     */
    focused: _propTypes["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: _propTypes["default"].number,

    /**
     * The maximum value of the slider.
     *
     * @type {Number}
     * @default 100
     * @public
     */
    max: _propTypes["default"].number,

    /**
     * The minimum value of the slider.
     *
     * @type {Number}
     * @default 0
     * @public
     */
    min: _propTypes["default"].number,

    /**
     * Called when the knob is activated or deactivated by selecting it via 5-way
     *
     * @type {Function}
     * @public
     */
    onActivate: _propTypes["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: _propTypes["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: _propTypes["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: _propTypes["default"].number,

    /**
     * The amount to increment or decrement the value.
     *
     * @type {Number}
     * @default 1
     * @public
     */
    step: _propTypes["default"].number,

    /**
     * The value of the slider.
     *
     * Defaults to the value of `min`.
     *
     * @type {Number}
     * @public
     */
    value: _propTypes["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.forwardWithPrevent)('onKeyDown'), (0, _anyPass["default"])([_utils.handleIncrement, _utils.handleDecrement])),
    onKeyUp: (0, _handle.handle)((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
      });
    }
  },
  render: function render(_ref2) {
    var css = _ref2.css,
        disabled = _ref2.disabled,
        rest = _objectWithoutProperties(_ref2, ["css", "disabled"]);

    delete rest.activateOnFocus;
    delete rest.active;
    delete rest.focused;
    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
      })
    }));
  }
});
/**
 * Agate-specific slider behaviors to apply to [SliderBase]{@link agate/Slider.SliderBase}.
 *
 * @hoc
 * @memberof agate/Slider
 * @mixes ui/Changeable.Changeable
 * @mixes spotlight/Spottable.Spottable
 * @mixes ui/Slottable.Slottable
 * @mixes agate/Skinnable.Skinnable
 * @public
 */

exports.SliderBase = SliderBase;
var SliderDecorator = (0, _compose["default"])(_Pure["default"], _Changeable["default"], _SliderBehaviorDecorator["default"], _Spottable["default"], (0, _Slottable["default"])({
  slots: ['knob']
}), _Skinnable["default"]);
/**
 * Slider input with Agate styling, [`Spottable`]{@link spotlight/Spottable.Spottable},
 * [Touchable]{@link ui/Touchable} and [`SliderDecorator`]{@link agate/Slider.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
 */

exports.SliderDecorator = SliderDecorator;
var 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
 */

exports.Slider = Slider;
var _default = Slider;
exports["default"] = _default;