"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_b9c31",I="messageContainer _messageContainer_c65e6",T="icon _icon_dc9b5",N="close _close_4a6c4",q="success _success_2e31b",H="danger _danger_b5e8b",S="info _info_a227c",b="warning _warning_265de",D="help _help_2cd79",k="message _message_3095c",a={floatingAlert:w,messageContainer:I,icon:T,close:N,success:q,danger:H,info:S,warning:b,help:D,message:k};class p 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"})))}}p.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(()=>{g(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 g=s=>{for(const i of s)t.add(i),i.autoDismiss&&setTimeout(()=>{f(i)},R);c(new Set(t))},f=s=>{t.delete(s),c(new Set(t))},A=()=>{const s=r.pop();s&&g([d(s)])},h=()=>Array.from(t).map(s=>e.createElement(p,{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;
