"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = exports.SpinnerDecorator = exports.SpinnerBase = exports.Spinner = void 0;
var _kind = _interopRequireDefault(require("@enact/core/kind"));
var _Pure = _interopRequireDefault(require("@enact/ui/internal/Pure"));
var _Spinner = _interopRequireDefault(require("@enact/ui/Spinner"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _compose = _interopRequireDefault(require("ramda/src/compose"));
var _$L = _interopRequireDefault(require("../internal/$L"));
var _Marquee = _interopRequireDefault(require("../Marquee"));
var _Skinnable = _interopRequireDefault(require("../Skinnable"));
var _SpinnerModule = _interopRequireDefault(require("./Spinner.module.css"));
var _jsxRuntime = require("react/jsx-runtime");
var _excluded = ["children", "css", "spinnerNodes"],
  _excluded2 = ["children", "css"];
/**
 * Provides Agate-themed indeterminate progress indicator (spinner) components and behaviors.
 *
 * Used for indicating to the user that something is busy and interaction is temporarily suspended.
 *
 * @example
 * <Spinner color="dark" size="small" type="searching">Loading message...</Spinner>
 *
 * @module agate/Spinner
 * @exports Spinner
 * @exports SpinnerBase
 * @exports SpinnerDecorator
 */
/**
 * A component that shows spinning fan. Or bouncing 🏀🎾🏐⚽ , with optional text as children.
 *
 * @class SpinnerCore
 * @memberof agate/Spinner
 * @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 SpinnerCore = (0, _kind["default"])({
  name: 'SpinnerCore',
  propTypes: /** @lends agate/Spinner.SpinnerCore.prototype */{
    /**
     * The "aria-label" for the component.
     *
     * @type {String}
     * @public
     */
    'aria-label': _propTypes["default"].string,
    /**
     * Customizes the component by mapping the supplied collection of CSS class names to the
     * corresponding internal elements and states of this component.
     *
     * @type {Object}
     * @public
     */
    css: _propTypes["default"].object,
    /**
     * The type of spinner.
     *
     * @type {('loading'|'searching')}
     * @default 'searching'
     * @public
     */
    type: _propTypes["default"].oneOf(['loading', 'searching'])
  },
  defaultProps: {
    type: 'searching'
  },
  styles: {
    css: _SpinnerModule["default"]
  },
  computed: {
    'aria-label': function ariaLabel(_ref) {
      var label = _ref['aria-label'],
        type = _ref.type;
      // TODO: These static values will need to be localized
      return label || type === 'searching' ? (0, _$L["default"])('Searching') : (0, _$L["default"])('Loading');
    },
    className: function className(_ref2) {
      var styler = _ref2.styler,
        type = _ref2.type;
      return styler.append(type);
    },
    spinnerNodes: function spinnerNodes(_ref3) {
      var styler = _ref3.styler,
        type = _ref3.type;
      return Array.from({
        length: type === 'searching' ? 12 : 4
      }, function (_, index) {
        return /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
          className: styler.join('node', "node".concat(index + 1))
        }, "node".concat(index));
      });
    }
  },
  render: function render(_ref4) {
    var children = _ref4.children,
      css = _ref4.css,
      spinnerNodes = _ref4.spinnerNodes,
      rest = _objectWithoutProperties(_ref4, _excluded);
    delete rest.type;
    return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", _objectSpread(_objectSpread({
      "aria-live": "off",
      role: "alert"
    }, rest), {}, {
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
        className: css.bg,
        children: spinnerNodes
      }), children ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Marquee["default"], {
        className: css.client,
        marqueeOn: "render",
        alignment: "center",
        children: children
      }) : null]
    }));
  }
});

/**
 * The base component, defining all of the properties.
 *
 * @class SpinnerBase
 * @memberof agate/Spinner
 * @extends ui/Spinner.Spinner
 * @ui
 * @public
 */
var SpinnerBase = exports.SpinnerBase = (0, _kind["default"])({
  name: 'Spinner',
  propTypes: /** @lends agate/Spinner.SpinnerBase.prototype */{
    /**
     * The color of the component.
     *
     * @type {('dark'|'light')}
     * @default 'light'
     * @public
     */
    color: _propTypes["default"].oneOf(['dark', 'light']),
    /**
     * Customizes the component by mapping the supplied collection of CSS class names to the
     * corresponding internal elements and states of this component.
     *
     * The following classes are supported:
     *
     * * `spinner` - The root component class, unless there is a scrim. The scrim and floating
     *   layer can be a sibling or parent to this root "spinner" element.
     *
     * @type {Object}
     * @public
     */
    css: _propTypes["default"].object,
    /**
     * Pauses the animation of the spinner
     *
     * @type {Boolean}
     * @default false
     * @public
     */
    paused: _propTypes["default"].bool,
    /**
     * The size of the component.
     *
     * Recommended usage is "large" (default) for standalone and popup scenarios, while "small"
     * is best suited for use inside other elements, like {@link agate/Item.Item}.
     *
     * @type {('huge'|'large'|'small'|'smallest')}
     * @default 'large'
     * @public
     */
    size: _propTypes["default"].oneOf(['huge', 'large', 'small', 'smallest']),
    /**
     * Removes the background color (making it transparent).
     *
     * @type {Boolean}
     * @default false
     * @public
     */
    transparent: _propTypes["default"].bool
  },
  defaultProps: {
    color: 'light',
    paused: false,
    size: 'large',
    transparent: false
  },
  styles: {
    css: _SpinnerModule["default"],
    publicClassNames: ['spinner']
  },
  computed: {
    className: function className(_ref5) {
      var children = _ref5.children,
        color = _ref5.color,
        paused = _ref5.paused,
        size = _ref5.size,
        styler = _ref5.styler,
        transparent = _ref5.transparent;
      return styler.append(color, size, {
        content: !!children,
        transparent: transparent
      }, {
        pausedAnimation: paused
      }, {
        transparentBackground: transparent
      });
    }
  },
  render: function render(_ref6) {
    var children = _ref6.children,
      css = _ref6.css,
      rest = _objectWithoutProperties(_ref6, _excluded2);
    delete rest.paused;
    delete rest.transparent;
    return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Spinner["default"], _objectSpread(_objectSpread({}, rest), {}, {
      css: css,
      component: SpinnerCore,
      children: children
    }));
  }
});

/**
 * Agate-specific Spinner behaviors to apply to {@link agate/Spinner.SpinnerBase|Spinner}.
 *
 * @hoc
 * @memberof agate/Spinner
 * @mixes agate/Skinnable.Skinnable
 * @public
 */
var SpinnerDecorator = exports.SpinnerDecorator = (0, _compose["default"])(_Pure["default"], _Skinnable["default"]);

/**
 * An Agate-styled Spinner.
 *
 * @class Spinner
 * @memberof agate/Spinner
 * @extends agate/Spinner.SpinnerBase
 * @mixes agate/Spinner.SpinnerDecorator
 * @ui
 * @public
 */
var Spinner = exports.Spinner = SpinnerDecorator(SpinnerBase);
var _default = exports["default"] = Spinner;