"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.SpinnerDecorator = exports.SpinnerBase = exports.Spinner = exports["default"] = void 0;

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

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 _Skinnable = _interopRequireDefault(require("../Skinnable"));

var _SpinnerModule = _interopRequireDefault(require("./Spinner.module.css"));

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

/**
 * A component that shows spinning fan. Or bouncing 🏀🎾🏐⚽️.
 *
 * @class SpinnerCore
 * @memberof agate/Spinner
 * @ui
 * @private
 */
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,
    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 css = _ref4.css,
        spinnerNodes = _ref4.spinnerNodes,
        rest = _objectWithoutProperties(_ref4, ["css", "spinnerNodes"]);

    delete rest.type;
    return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread(_objectSpread({
      "aria-live": "off",
      role: "alert"
    }, rest), {}, {
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
        className: css.bg,
        children: spinnerNodes
      })
    }));
  }
});
/**
 * The base component, defining all of the properties.
 *
 * @class SpinnerBase
 * @memberof agate/Spinner
 * @extends ui/Spinner.Spinner
 * @ui
 * @public
 */

var 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 css = _ref6.css,
        rest = _objectWithoutProperties(_ref6, ["css"]);

    delete rest.paused;
    delete rest.transparent;
    return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Spinner["default"], _objectSpread(_objectSpread({}, rest), {}, {
      css: css,
      component: SpinnerCore
    }));
  }
});
/**
 * Agate-specific Spinner behaviors to apply to [Spinner]{@link agate/Spinner.SpinnerBase}.
 *
 * @hoc
 * @memberof agate/Spinner
 * @mixes agate/Skinnable.Skinnable
 * @public
 */

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

exports.SpinnerDecorator = SpinnerDecorator;
var Spinner = SpinnerDecorator(SpinnerBase);
exports.Spinner = Spinner;
var _default = Spinner;
exports["default"] = _default;