"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.default = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _react = _interopRequireWildcard(require("react"));
var _LiveRegionSt = require("./LiveRegion.st.css.js");
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/cjs/LiveRegion/LiveRegion.tsx";
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
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) { (0, _defineProperty2.default)(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; }
/** LiveRegion */
var LiveRegion = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
  var {
    dataHook
  } = _ref;
  var initialState = {
    message: '',
    role: 'status'
  };
  var [state, setState] = _react.default.useReducer((currentState, newState) => _objectSpread(_objectSpread({}, currentState), newState), initialState);
  var broadcast = _ref2 => {
    var {
      message: newMessage,
      role = 'status'
    } = _ref2;
    if (state.message === newMessage) {
      // FIXME: Announcing same message multiple times doesn't work on NVDA screen reader
      setState({
        message: newMessage + ' ',
        role
      });
    } else {
      setState({
        message: newMessage,
        role
      });
    }
  };
  _react.default.useImperativeHandle(ref, () => ({
    broadcast
  }));
  return /*#__PURE__*/_react.default.createElement("div", {
    "data-hook": dataHook,
    className: _LiveRegionSt.classes.root,
    role: state.role,
    "aria-relevant": "all",
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 45,
      columnNumber: 7
    }
  }, state.message);
});
LiveRegion.displayName = 'LiveRegion';
var _default = exports.default = LiveRegion;
//# sourceMappingURL=LiveRegion.js.map