"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = exports.FanSpeedControlDecorator = exports.FanSpeedControlBase = exports.FanSpeedControl = void 0;
var _kind = _interopRequireDefault(require("@enact/core/kind"));
var _util = require("@enact/core/util");
var _Changeable = _interopRequireDefault(require("@enact/ui/Changeable"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _ramda = require("ramda");
var _ArcPicker = _interopRequireDefault(require("../ArcPicker"));
var _Icon = _interopRequireDefault(require("../Icon"));
var _Skinnable = _interopRequireDefault(require("../Skinnable"));
var _FanSpeedControlModule = _interopRequireDefault(require("./FanSpeedControl.module.css"));
var _jsxRuntime = require("react/jsx-runtime");
var _excluded = ["children", "disabled", "icon", "max", "min", "onChange", "value"];
/**
 * Agate styled fan speed control components and behaviors.
 *
 * @example
 * <FanSpeedControl max={5} min={1} />
 *
 * @module agate/FanSpeedControl
 * @exports FanSpeedControl
 * @exports FanSpeedControlBase
 * @exports FanSpeedControlDecorator
 */
/**
 * An Agate component for displaying fan speed.
 * This component is most often not used directly but may be composed within another component as it
 * is within {@link agate/FanSpeedControl.FanSpeedControl|FanSpeedControl}.
 *
 * @class FanSpeedControlBase
 * @memberof agate/FanSpeedControl
 * @extends agate/ArcPicker.ArcPicker
 * @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 FanSpeedControlBase = exports.FanSpeedControlBase = (0, _kind["default"])({
  name: 'FanSpeedControlBase',
  propTypes: /** @lends agate/FanSpeedControl.FanSpeedControlBase.prototype */{
    /**
     * The maximum value of FanSpeedControl.
     *
     * @type {Number}
     * @default 10
     * @required
     * @public
     */
    max: _propTypes["default"].number.isRequired,
    /**
     * The minimum value of FanSpeedControl.
     *
     * @type {Number}
     * @default 1
     * @required
     * @public
     */
    min: _propTypes["default"].number.isRequired,
    /**
     * Whether or not the component is in a disabled state.
     *
     * @type {Boolean}
     * @public
     */
    disabled: _propTypes["default"].bool,
    /**
     * FanSpeedControl icon.
     *
     * @type {String}
     * @default 'fan'
     * @public
     */
    icon: _propTypes["default"].string,
    /**
     * Called when value is changed.
     *
     * @type {Function}
     * @public
     */
    onChange: _propTypes["default"].func,
    /**
     * Called when the path area is clicked.
     *
     * @type {Function}
     * @param {Object} event
     * @public
     */
    onClick: _propTypes["default"].func,
    /**
     * Value of FanSpeedControl.
     *
     * @type {Number}
     * @default 1
     * @public
     */
    value: _propTypes["default"].number
  },
  defaultProps: {
    icon: 'fan',
    max: 10,
    min: 1,
    value: 1
  },
  styles: {
    css: _FanSpeedControlModule["default"],
    className: 'fanSpeedControl'
  },
  computed: {
    children: function children(_ref) {
      var min = _ref.min,
        max = _ref.max;
      return (0, _ramda.range)(min, max + 1);
    },
    className: function className(_ref2) {
      var icon = _ref2.icon,
        styler = _ref2.styler;
      return styler.append({
        noIcon: !icon
      });
    }
  },
  render: function render(_ref3) {
    var children = _ref3.children,
      disabled = _ref3.disabled,
      icon = _ref3.icon,
      max = _ref3.max,
      min = _ref3.min,
      onChange = _ref3.onChange,
      value = _ref3.value,
      rest = _objectWithoutProperties(_ref3, _excluded);
    var ariaProps = (0, _util.extractAriaProps)(rest);
    return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread(_objectSpread({}, rest), {}, {
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_ArcPicker["default"], _objectSpread(_objectSpread({}, ariaProps), {}, {
        disabled: disabled,
        endAngle: 312,
        max: max,
        min: min,
        onChange: onChange,
        selectionType: "cumulative",
        slotCenter: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
          children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon["default"], {
            className: _FanSpeedControlModule["default"].fanIcon,
            css: _FanSpeedControlModule["default"],
            children: icon
          }), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
            className: _FanSpeedControlModule["default"].fanValue,
            children: value
          })]
        }),
        value: value,
        children: children
      }))
    }));
  }
});

/**
 * Applies Agate specific behaviors to {@link agate/FanSpeedControl.FanSpeedControlBase|FanSpeedControlBase} components.
 *
 * @hoc
 * @memberof agate/FanSpeedControl
 * @mixes ui/Changeable.Changeable
 * @mixes agate/Skinnable.Skinnable
 * @public
 */
var FanSpeedControlDecorator = exports.FanSpeedControlDecorator = (0, _ramda.compose)(_Changeable["default"], _Skinnable["default"]);

/**
 * FanSpeedControl with Agate styling and
 * {@link agate/FanSpeedControl.FanSpeedControlDecorator|FanSpeedControlDecorator} applied.
 *
 * Usage:
 * ```
 * <FanSpeedControl
 *   max={10}
 *   min={1}
 *   value={4}
 * />
 * ```
 *
 * @class FanSpeedControl
 * @memberof agate/FanSpeedControl
 * @extends agate/FanSpeedControl.FanSpeedControlBase
 * @mixes agate/FanSpeedControl.FanSpeedControlDecorator
 * @ui
 * @public
 */
var FanSpeedControl = exports.FanSpeedControl = FanSpeedControlDecorator(FanSpeedControlBase);
var _default = exports["default"] = FanSpeedControl;