import{useRef as e,useMemo as t,createElement as r,useEffect as n,cloneElement as u}from"react";import{render as i}from"react-dom";import o from"../../visually-hidden/dist/reach-visually-hidden.esm.js";import{forwardRefWithAs as a,useForkedRef as c,usePrevious as l,getOwnerDocument as s}from"../../utils/dist/reach-utils.esm.js";import p from"../../../prop-types/index.js";function f(){return(f=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}var d,v={polite:-1,assertive:-1},m={polite:{},assertive:{}},y={polite:null,assertive:null},h=a((function(u,i){var o=u.as,a=void 0===o?"div":o,p=u.children,d=u.type,v=void 0===d?"polite":d,m=function(e,t){if(null==e)return{};var r,n,u={},i=Object.keys(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||(u[r]=e[r]);return u}(u,["as","children","type"]),y=e(null),h=c(i,y),j=t((function(){return r(a,f({},m,{ref:h,"data-reach-alert":!0}),p)}),[p,m]);return function(t,r,u){var i=l(t),o=e(null),a=e(!1);n((function(){var e=s(u.current);a.current?i!==t?(o.current&&o.current.unmount(),o.current=O(t,e),o.current.mount(r)):o.current&&o.current.update(r):(a.current=!0,o.current=O(t,e),o.current.mount(r))}),[r,t,i,u]),n((function(){return function(){o.current&&o.current.unmount()}}),[])}(v,j,y),j}));function O(e,t){var r=++v[e];return{mount:function n(u){if(y[e])m[e][r]=u,j();else{var i=t.createElement("div");i.setAttribute("data-reach-live-"+e,"true"),y[e]=i,t.body.appendChild(y[e]),n(u)}},update:function(t){m[e][r]=t,j()},unmount:function(){delete m[e][r],j()}}}function j(){null!=d&&window.clearTimeout(d),d=window.setTimeout((function(){Object.keys(m).forEach((function(e){var t=e;y[t]&&i(r(o,{as:"div"},r("div",{role:"assertive"===t?"alert":"status","aria-live":t},Object.keys(m[t]).map((function(e){return u(m[t][e],{key:e,ref:null})})))),y[t])}))}),500)}"production"!==process.env.NODE_ENV&&(h.displayName="Alert",h.propTypes={children:p.node,type:p.oneOf(["assertive","polite"])});export default h;export{h as Alert};
//# sourceMappingURL=reach-alert.esm.js.map
