import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
var _excluded = ["loading", "color", "fullWidth", "size", "children", "ariaStatusLabel", "aria-live"];
import * as React from 'react';
import Spinner from '../spinner/Spinner';
import classnames from 'classnames';
export { SPINNER_SIZE, SPINNER_COLOR } from '../spinner/Spinner';

var SpinnerContainer = function SpinnerContainer(_ref) {
  var loading = _ref.loading,
      color = _ref.color,
      fullWidth = _ref.fullWidth,
      size = _ref.size,
      children = _ref.children,
      _ref$ariaStatusLabel = _ref.ariaStatusLabel,
      ariaStatusLabel = _ref$ariaStatusLabel === void 0 ? {
    loaded: 'content loaded',
    loading: 'content is loading'
  } : _ref$ariaStatusLabel,
      _ref$ariaLive = _ref['aria-live'],
      ariaLive = _ref$ariaLive === void 0 ? 'assertive' : _ref$ariaLive,
      props = _objectWithoutProperties(_ref, _excluded);

  var childrenWithAriaBusy = React.useMemo(function () {
    if (!loading) {
      return children;
    }

    return React.Children.map(children, function (child) {
      if ( /*#__PURE__*/React.isValidElement(child)) {
        return /*#__PURE__*/React.cloneElement(child, {
          // @ts-expect-error ts migration
          'aria-busy': loading
        });
      }

      return child;
    });
  }, [children, loading]);
  return /*#__PURE__*/React.createElement("div", _extends({}, props, {
    className: classnames('sg-spinner-container', {
      'sg-spinner-container--full-width': fullWidth
    })
  }), loading ? /*#__PURE__*/React.createElement("div", {
    className: "sg-spinner-container__overlay"
  }, /*#__PURE__*/React.createElement(Spinner, {
    color: color,
    size: size,
    "aria-label": ariaStatusLabel.loading,
    "aria-live": ariaLive
  })) : /*#__PURE__*/React.createElement("span", {
    className: "sg-visually-hidden",
    "aria-live": ariaLive,
    role: "status",
    "aria-atomic": "true"
  }, ariaStatusLabel.loaded), childrenWithAriaBusy);
};

export default SpinnerContainer;