"use strict";const e=require("react"),E=require("shortid"),_=require("./InfoIcon-57b0b7a1.js"),l=require("./Alert-dec85153.js"),y=require("classnames"),m=require("react-feather"),C=require("./useHeaderAlerts-609b825f.js");const w="floatingAlert _floatingAlert_110aa",I="messageContainer _messageContainer_9cd2c",T="icon _icon_3a8d9",N="close _close_2f39c",q="success _success_4d5be",H="danger _danger_21bfb",S="info _info_cdf42",D="warning _warning_a5e3a",b="help _help_0ff55",k="message _message_ad2c9",a={floatingAlert:w,messageContainer:I,icon:T,close:N,success:q,danger:H,info:S,warning:D,help:b,message:k};class g extends e.Component{constructor(t){super(t)}render(){const{className:t,children:c,type:n,onDismiss:r}=this.props;return e.createElement("div",{className:y(a.floatingAlert,t,n&&a[n]),role:"alert"},e.createElement("div",{className:a.messageContainer},e.createElement("span",{className:a.icon},F(n)),e.createElement("span",{className:a.message},c)),!!r&&e.createElement("span",{className:a.close,onClick:()=>{r&&r()}},e.createElement(m.X,{size:"1em"})))}}g.defaultProps={};function F(o){switch(o){case l.AlertType.success:return e.createElement(m.CheckCircle,null);case l.AlertType.danger:return e.createElement(_.DangerIcon,null);case l.AlertType.warning:return e.createElement(m.AlertCircle,null);case l.AlertType.info:return e.createElement(_.InfoIcon,null);case l.AlertType.help:return e.createElement(_.HelpIcon,null);default:return null}}const R=4e3,x=o=>{const[t,c]=e.useState(new Set),{state:n,mutations:r}=C.useHeaderAlerts(),d=s=>({...s,id:E()});e.useEffect(()=>{f(Array.from(r.popAll()).map(d))},[]);const u=e.useRef(0);e.useEffect(()=>{u.current>=n.alerts.length||(A(),u.current=n.alerts.length)},[n.alerts.length]);const f=s=>{for(const i of s)t.add(i),i.autoDismiss&&setTimeout(()=>{p(i)},R);c(new Set(t))},p=s=>{t.delete(s),c(new Set(t))},A=()=>{const s=r.pop();s&&f([d(s)])},h=()=>Array.from(t).map(s=>e.createElement(g,{key:s.id,type:s.type,onDismiss:()=>{t.delete(s),c(new Set),s.dismiss&&s.dismiss()}},s.element)).slice(-1),{className:v="commonAlertsContainer"}=o;return e.createElement("div",{className:v},h())};exports.HeaderAlerts=x;
