"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = exports.ArcDecorator = exports.ArcBase = exports.Arc = void 0;
var _propTypes = _interopRequireDefault(require("@enact/core/internal/prop-types"));
var _kind = _interopRequireDefault(require("@enact/core/kind"));
var _Pure = _interopRequireDefault(require("@enact/ui/internal/Pure"));
var _resolution = _interopRequireDefault(require("@enact/ui/resolution"));
var _propTypes2 = _interopRequireDefault(require("prop-types"));
var _compose = _interopRequireDefault(require("ramda/src/compose"));
var _Skinnable = _interopRequireDefault(require("../Skinnable"));
var _utils = require("./utils");
var _jsxRuntime = require("react/jsx-runtime");
var _excluded = ["children", "color", "componentRef", "endAngle", "onClick", "radius", "size", "startAngle", "strokeWidth"];
/**
 * Agate styled arc components and behaviors.
 *
 * @example
 * <Arc color="blue" endAngle={200} startAngle={0} radius={100} />
 *
 * @module agate/Arc
 * @exports Arc
 * @exports ArcBase
 * @exports ArcDecorator
 * @private
 */
/**
 * An arc component.
 *
 * This component is most often not used directly but may be composed within another component as it
 * is within {@link agate/Arc.Arc|Arc}.
 *
 * @class ArcBase
 * @memberof agate/Arc
 * @ui
 * @private
 */
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 ArcBase = exports.ArcBase = (0, _kind["default"])({
  name: 'Arc',
  propTypes: /** @lends agate/Arc.ArcBase.prototype */{
    /**
     * The color of the arc.
     *
     * @type {String}
     * @default #000000
     * @public
     */
    color: _propTypes2["default"].string,
    /**
     * Function that generates a reference to the arc svg.
     *
     * @type {Object|Function}
     * @public
     */
    componentRef: _propTypes["default"].ref,
    /**
     * The end angle(in degrees) of the arc.
     *
     * The value should be between 0 and 360 and should be greater than startAngle.
     *
     * @type {Number}
     * @default 310
     * @public
     */
    endAngle: _propTypes2["default"].number,
    /**
     * Called when the path area is clicked.
     *
     * @type {Function}
     * @param {Object} event
     * @public
     */
    onClick: _propTypes2["default"].func,
    /**
     * The radius of the arc.
     *
     * @type {Number}
     * @default 150
     * @public
     */
    radius: _propTypes2["default"].number,
    /**
     * The start angle(in degrees) of the arc.
     *
     * The value should be between 0 and 360.
     *
     * @type {Number}
     * @default 50
     * @public
     */
    startAngle: _propTypes2["default"].number,
    /**
     * The stroke width of the arc.
     *
     * @type {Number}
     * @default 9
     * @public
     */
    strokeWidth: _propTypes2["default"].number
  },
  defaultProps: {
    color: '#000000',
    endAngle: 310,
    radius: 150,
    startAngle: 50,
    strokeWidth: 9
  },
  styles: {
    className: 'arc'
  },
  computed: {
    height: function height(_ref) {
      var radius = _ref.radius;
      return _resolution["default"].scaleToRem(radius * 2);
    },
    size: function size(_ref2) {
      var radius = _ref2.radius,
        strokeWidth = _ref2.strokeWidth;
      return radius * 2 - strokeWidth;
    },
    width: function width(_ref3) {
      var radius = _ref3.radius;
      return _resolution["default"].scaleToRem(radius * 2);
    }
  },
  render: function render(_ref4) {
    var children = _ref4.children,
      color = _ref4.color,
      componentRef = _ref4.componentRef,
      endAngle = _ref4.endAngle,
      onClick = _ref4.onClick,
      radius = _ref4.radius,
      size = _ref4.size,
      startAngle = _ref4.startAngle,
      strokeWidth = _ref4.strokeWidth,
      rest = _objectWithoutProperties(_ref4, _excluded);
    var halfStrokeWidth = strokeWidth / 2;
    var viewBox = "-".concat(halfStrokeWidth, " -").concat(halfStrokeWidth, " ").concat(radius * 2, "  ").concat(radius * 2);
    return /*#__PURE__*/(0, _jsxRuntime.jsxs)("svg", _objectSpread(_objectSpread({
      pointerEvents: "none"
    }, rest), {}, {
      viewBox: viewBox,
      ref: componentRef,
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("path", {
        d: (0, _utils.arcPath)(startAngle, endAngle, radius - halfStrokeWidth, size),
        fill: "none",
        pointerEvents: "none",
        stroke: color,
        strokeWidth: strokeWidth
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)("path", {
        d: (0, _utils.arcPath)(startAngle, endAngle, radius - halfStrokeWidth, size),
        fill: "none",
        onClick: onClick,
        pointerEvents: "auto",
        stroke: "transparent",
        strokeWidth: radius
      }), children]
    }));
  }
});

/**
 * Applies Agate specific behaviors to {@link agate/Arc.ArcBase|ArcBase} components.
 *
 * @hoc
 * @memberof agate/Arc
 * @mixes agate/Skinnable.Skinnable
 * @private
 */
var ArcDecorator = exports.ArcDecorator = (0, _compose["default"])(_Pure["default"], _Skinnable["default"]);

/**
 * An arc component, ready to use in Agate applications.
 *
 * Usage:
 * ```
 * <Arc color="blue" endAngle={200} startAngle={0}" radius={100} />
 * ```
 *
 * @class Arc
 * @memberof agate/Arc
 * @extends agate/Arc.ArcBase
 * @mixes agate/Arc.ArcDecorator
 * @ui
 * @private
 */
var Arc = exports.Arc = ArcDecorator(ArcBase);
var _default = exports["default"] = Arc;