"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.ArcDecorator = exports.ArcBase = exports.Arc = 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 _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");

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 arc component.
 *
 * This component is most often not used directly but may be composed within another component as it
 * is within [Arc]{@link agate/Arc.Arc}.
 *
 * @class ArcBase
 * @memberof agate/Arc
 * @ui
 * @private
 */
var 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, ["children", "color", "componentRef", "endAngle", "onClick", "radius", "size", "startAngle", "strokeWidth"]);

    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 [ArcBase]{@link agate/Arc.ArcBase} components.
 *
 * @hoc
 * @memberof agate/Arc
 * @mixes agate/Skinnable.Skinnable
 * @private
 */

exports.ArcBase = ArcBase;
var 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
 */

exports.ArcDecorator = ArcDecorator;
var Arc = ArcDecorator(ArcBase);
exports.Arc = Arc;
var _default = Arc;
exports["default"] = _default;