"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = exports.ArcSliderDecorator = exports.ArcSliderBase = exports.ArcSlider = void 0;
var _propTypes = _interopRequireDefault(require("@enact/core/internal/prop-types"));
var _kind = _interopRequireDefault(require("@enact/core/kind"));
var _util = require("@enact/core/util");
var _Spottable = _interopRequireDefault(require("@enact/spotlight/Spottable"));
var _Pure = _interopRequireDefault(require("@enact/ui/internal/Pure"));
var _resolution = _interopRequireDefault(require("@enact/ui/resolution"));
var _Touchable = _interopRequireDefault(require("@enact/ui/Touchable"));
var _propTypes2 = _interopRequireDefault(require("prop-types"));
var _compose = _interopRequireDefault(require("ramda/src/compose"));
var _Arc = _interopRequireDefault(require("../Arc"));
var _utils = require("../Arc/utils");
var _Skinnable = _interopRequireDefault(require("../Skinnable"));
var _ThemeDecorator = require("../ThemeDecorator");
var _ArcSliderBehaviorDecorator = _interopRequireDefault(require("./ArcSliderBehaviorDecorator"));
var _utils2 = require("./utils");
var _ArcSliderModule = _interopRequireDefault(require("./ArcSlider.module.css"));
var _jsxRuntime = require("react/jsx-runtime");
var _excluded = ["aria-valuetext", "backgroundColor", "componentRef", "circleRadius", "disabled", "endAngle", "foregroundColor", "max", "min", "radius", "size", "slotCenter", "startAngle", "strokeWidth", "value"];
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
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; }
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); } /**
 * Agate styled arc slider components and behaviors.
 *
 * @example
 * <ArcSlider />
 *
 * @module agate/ArcSlider
 * @exports ArcSlider
 * @exports ArcSliderBase
 * @exports ArcSliderDecorator
 */ /**
 * An arc slider component.
 *
 * This component is most often not used directly but may be composed within another component as it
 * is within {@link agate/ArcSlider.ArcSlider|ArcSlider}.
 *
 * @class ArcSliderBase
 * @memberof agate/ArcSlider
 * @ui
 * @public
 */
var ArcSliderBase = exports.ArcSliderBase = (0, _kind["default"])({
  name: 'ArcSlider',
  propTypes: /** @lends agate/ArcSlider.ArcSliderBase.prototype */{
    /**
     * Overrides the `aria-valuetext` for the ArcSlider. By default, `aria-valuetext` is set
     * to the current value.
     *
     * @type {String|Number}
     * @public
     */
    'aria-valuetext': _propTypes2["default"].oneOfType([_propTypes2["default"].string, _propTypes2["default"].number]),
    /**
     * The color of the background arc.
     *
     * @type {String}
     * @default #000000
     * @public
     */
    backgroundColor: _propTypes2["default"].string,
    /**
     * Function that generates a reference to the arc svg.
     *
     * @type {Object|Function}
     * @public
     */
    componentRef: _propTypes["default"].ref,
    /**
     * Whether or not the component is in a disabled state.
     *
     * @type {Boolean}
     * @public
     */
    disabled: _propTypes2["default"].bool,
    /**
     * The end angle(in degrees) of the arc slider.
     *
     * The value should be between 0 and 360 and should be greater than startAngle.
     *
     * @type {Number}
     * @default 250
     * @public
     */
    endAngle: _propTypes2["default"].number,
    /**
     * The color of the foreground arc.
     *
     * @type {String}
     * @default #0000ff
     * @public
     */
    foregroundColor: _propTypes2["default"].string,
    /**
     * Whether or not the component is focused.
     *
     * @type {Boolean}
     * @private
     */
    isFocused: _propTypes2["default"].bool,
    /**
     * The maximum value of the slider and should be greater than min.
     *
     * @type {Number}
     * @default 100
     * @public
     */
    max: _propTypes2["default"].number,
    /**
     * The minimum value of the slider.
     *
     * @type {Number}
     * @default 0
     * @public
     */
    min: _propTypes2["default"].number,
    /**
     * The radius of the arc circle.
     *
     * @type {Number}
     * @default 150
     * @public
     */
    radius: _propTypes2["default"].number,
    /**
     * The current skin for this component.
     *
     * @type {String}
     * @private
     */
    skin: _propTypes2["default"].string,
    /**
     * State of possible skin variants.
     *
     * Used to set backgroundColor and foregroundColor.
     *
     * @type {Object}
     * @private
     */
    skinVariants: _propTypes2["default"].object,
    /**
     * Nodes to be inserted in the center of the ArcSlider.
     *
     * @type {Node}
     * @public
     */
    slotCenter: _propTypes2["default"].node,
    /**
     * The start angle(in degrees) of the arc slider.
     *
     * The value should be between 0 and 360.
     *
     * @type {Number}
     * @default 30
     * @public
     */
    startAngle: _propTypes2["default"].number,
    /**
     * The amount to increment or decrement the value.
     *
     * @type {Number}
     * @default 1
     * @public
     */
    step: _propTypes2["default"].number,
    /**
     * The stroke width of the arc slider.
     *
     * @type {Number}
     * @default 6
     * @public
     */
    strokeWidth: _propTypes2["default"].number,
    /**
     * The value of the slider.
     *
     * Defaults to the value of `min`.
     *
     * @type {Number}
     * @public
     */
    value: _propTypes2["default"].number
  },
  defaultProps: {
    endAngle: 250,
    max: 100,
    min: 0,
    radius: 150,
    startAngle: 30,
    step: 1,
    strokeWidth: 6
  },
  contextType: _ThemeDecorator.ThemeContext,
  styles: {
    css: _ArcSliderModule["default"],
    className: 'arcSlider'
  },
  computed: {
    size: function size(_ref) {
      var radius = _ref.radius,
        strokeWidth = _ref.strokeWidth;
      return radius * 2 - strokeWidth;
    },
    style: function style(_ref2) {
      var radius = _ref2.radius,
        _style = _ref2.style;
      var size = _resolution["default"].scaleToRem(radius * 2);
      return _objectSpread(_objectSpread({}, _style), {}, {
        height: size,
        width: size
      });
    },
    circleRadius: function circleRadius(_ref3) {
      var isFocused = _ref3.isFocused;
      return isFocused ? 20 : 15;
    },
    backgroundColor: function backgroundColor(_ref4) {
      var _backgroundColor = _ref4.backgroundColor,
        skinVariants = _ref4.skinVariants;
      return _backgroundColor || (skinVariants && skinVariants.night ? '#444444' : '#888888');
    },
    foregroundColor: function foregroundColor(_ref5) {
      var _foregroundColor = _ref5.foregroundColor,
        skin = _ref5.skin,
        skinVariants = _ref5.skinVariants;
      if (_foregroundColor) {
        return _foregroundColor;
      } else if (skinVariants && skinVariants.night) {
        return '#ffffff';
      } else if (skin === 'carbon') {
        return '#343434';
      } else {
        return '#000000';
      }
    }
  },
  render: function render(_ref6) {
    var ariaValuetext = _ref6['aria-valuetext'],
      backgroundColor = _ref6.backgroundColor,
      componentRef = _ref6.componentRef,
      circleRadius = _ref6.circleRadius,
      disabled = _ref6.disabled,
      endAngle = _ref6.endAngle,
      foregroundColor = _ref6.foregroundColor,
      max = _ref6.max,
      min = _ref6.min,
      radius = _ref6.radius,
      size = _ref6.size,
      slotCenter = _ref6.slotCenter,
      startAngle = _ref6.startAngle,
      strokeWidth = _ref6.strokeWidth,
      value = _ref6.value,
      rest = _objectWithoutProperties(_ref6, _excluded);
    var valueAngle = (0, _utils2.valueToAngle)((0, _util.clamp)(min, max, value), min, Math.max(min, max), startAngle, endAngle);
    var knobPosition = (0, _utils.angleToPosition)(valueAngle, radius - strokeWidth / 2, size);
    delete rest.isFocused;
    delete rest.skinVariants;
    delete rest.step;
    return (
      /*#__PURE__*/
      // eslint-disable-next-line jsx-a11y/role-has-required-aria-props
      (0, _jsxRuntime.jsxs)("div", _objectSpread(_objectSpread({
        "aria-disabled": disabled,
        "aria-valuetext": ariaValuetext || value,
        role: "slider"
      }, rest), {}, {
        disabled: disabled,
        children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Arc["default"], {
          className: _ArcSliderModule["default"].arc,
          color: backgroundColor,
          endAngle: endAngle,
          radius: radius,
          startAngle: valueAngle,
          strokeWidth: strokeWidth
        }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Arc["default"], {
          className: _ArcSliderModule["default"].arc,
          color: foregroundColor,
          endAngle: valueAngle,
          radius: radius,
          startAngle: startAngle,
          strokeWidth: strokeWidth,
          pointerEvents: "auto",
          componentRef: componentRef,
          children: /*#__PURE__*/(0, _jsxRuntime.jsx)("circle", {
            cx: knobPosition.x,
            cy: knobPosition.y,
            fill: foregroundColor,
            r: _resolution["default"].scaleToRem(circleRadius)
          })
        }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
          className: _ArcSliderModule["default"].valueDisplay,
          children: slotCenter
        })]
      }))
    );
  }
});

/**
 * Applies Agate specific behaviors to {@link agate/ArcSlider.ArcSliderBase|ArcSliderBase} components.
 *
 * @hoc
 * @memberof agate/ArcSlider
 * @mixes agate/ArcSlider.ArcSliderBehaviorDecorator
 * @mixes ui/Touchable.Touchable
 * @mixes agate/Skinnable.Skinnable
 * @public
 */
var ArcSliderDecorator = exports.ArcSliderDecorator = (0, _compose["default"])(_Pure["default"], _ArcSliderBehaviorDecorator["default"], _Touchable["default"], _Spottable["default"], (0, _Skinnable["default"])({
  prop: 'skin',
  variantsProp: 'skinVariants'
}));

/**
 * An arc slider component, ready to use in Agate applications.
 *
 * Usage:
 * ```
 * <ArcSlider backgroundColor="blue" endAngle={200} foregroundColor="red" radius={150} startAngle={0} step={2} />
 * ```
 *
 * @class ArcSlider
 * @memberof agate/ArcSlider
 * @extends agate/ArcSlider.ArcSliderBase
 * @mixes agate/ArcSlider.ArcSliderDecorator
 * @ui
 * @public
 */
var ArcSlider = exports.ArcSlider = ArcSliderDecorator(ArcSliderBase);
var _default = exports["default"] = ArcSlider;