"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.ArcSliderDecorator = exports.ArcSliderBase = exports.ArcSlider = exports["default"] = void 0;

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

var _propTypes = _interopRequireDefault(require("@enact/core/internal/prop-types"));

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

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

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": 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; }

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

/**
 * An arc slider component.
 *
 * This component is most often not used directly but may be composed within another component as it
 * is within [ArcSlider]{@link agate/ArcSlider.ArcSlider}.
 *
 * @class ArcSliderBase
 * @memberof agate/ArcSlider
 * @ui
 * @public
 */
var 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,

    /**
     * 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: {
    backgroundColor: '#000000',
    endAngle: 250,
    foregroundColor: '#0000ff',
    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
      });
    }
  },
  render: function render(_ref3, context) {
    var ariaValuetext = _ref3['aria-valuetext'],
        backgroundColor = _ref3.backgroundColor,
        componentRef = _ref3.componentRef,
        disabled = _ref3.disabled,
        endAngle = _ref3.endAngle,
        foregroundColor = _ref3.foregroundColor,
        isFocused = _ref3.isFocused,
        max = _ref3.max,
        min = _ref3.min,
        radius = _ref3.radius,
        size = _ref3.size,
        slotCenter = _ref3.slotCenter,
        startAngle = _ref3.startAngle,
        strokeWidth = _ref3.strokeWidth,
        value = _ref3.value,
        rest = _objectWithoutProperties(_ref3, ["aria-valuetext", "backgroundColor", "componentRef", "disabled", "endAngle", "foregroundColor", "isFocused", "max", "min", "radius", "size", "slotCenter", "startAngle", "strokeWidth", "value"]);

    var _ref4 = context || {},
        accentColor = _ref4.accent;

    var valueAngle = (0, _utils2.valueToAngle)(value, min, max, startAngle, endAngle);
    var knobPosition = (0, _utils.angleToPosition)(valueAngle, radius - strokeWidth / 2, size);
    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: isFocused ? accentColor : foregroundColor,
            r: _resolution["default"].scaleToRem(15)
          })
        }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
          className: _ArcSliderModule["default"].valueDisplay,
          children: slotCenter
        })]
      }))
    );
  }
});
/**
 * Applies Agate specific behaviors to [ArcSliderBase]{@link agate/ArcSlider.ArcSliderBase} components.
 *
 * @hoc
 * @memberof agate/ArcSlider
 * @mixes agate/ArcSlider.ArcSliderBehaviorDecorator
 * @mixes ui/Touchable.Touchable
 * @mixes agate/Skinnable.Skinnable
 * @public
 */

exports.ArcSliderBase = ArcSliderBase;
var ArcSliderDecorator = (0, _compose["default"])(_Pure["default"], _ArcSliderBehaviorDecorator["default"], _Touchable["default"], _Spottable["default"], _Skinnable["default"]);
/**
 * 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
 */

exports.ArcSliderDecorator = ArcSliderDecorator;
var ArcSlider = ArcSliderDecorator(ArcSliderBase);
exports.ArcSlider = ArcSlider;
var _default = ArcSlider;
exports["default"] = _default;