"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.FanSpeedControlDecorator = exports.FanSpeedControlBase = exports.FanSpeedControl = exports["default"] = void 0;

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

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"));

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; }

/**
 * 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 [FanSpeedControl]{@link agate/FanSpeedControl.FanSpeedControl}.
 *
 * @class FanSpeedControlBase
 * @memberof agate/FanSpeedControl
 * @extends agate/ArcPicker.ArcPicker
 * @ui
 * @public
 */
var FanSpeedControlBase = (0, _kind["default"])({
  name: 'FanSpeedControlBase',
  propTypes:
  /** @lends agate/FanSpeedControl.FanSpeedControlBase.prototype */
  {
    /**
     * The maximum value of FanSpeedControl.
     *
     * @type {Number}
     * @default 10
     * @public
     */
    max: _propTypes["default"].number.isRequired,

    /**
     * The minimum value of FanSpeedControl.
     *
     * @type {Number}
     * @default 1
     * @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}
     * @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: {
    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, ["children", "disabled", "icon", "max", "min", "onChange", "value"]);

    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 [FanSpeedControlBase]{@link agate/FanSpeedControl.FanSpeedControlBase} components.
 *
 * @hoc
 * @memberof agate/FanSpeedControl
 * @mixes ui/Changeable.Changeable
 * @mixes agate/Skinnable.Skinnable
 * @public
 */

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

exports.FanSpeedControlDecorator = FanSpeedControlDecorator;
var FanSpeedControl = FanSpeedControlDecorator(FanSpeedControlBase);
exports.FanSpeedControl = FanSpeedControl;
var _default = FanSpeedControl;
exports["default"] = _default;