"use strict";const e=require("react"),E=require("shortid"),_=require("./InfoIcon-57b0b7a1.js"),c=require("./Alert-dec85153.js"),y=require("classnames"),m=require("react-feather"),C=require("./useHeaderAlerts-3867f7d7.js");const w="floatingAlert _floatingAlert_3a543",I="messageContainer _messageContainer_83924",T="icon _icon_7d622",N="close _close_a6d40",q="success _success_b562f",H="danger _danger_4b05b",b="info _info_a6040",S="warning _warning_b536f",D="help _help_37b38",k="message _message_eb92c",a={floatingAlert:w,messageContainer:I,icon:T,close:N,success:q,danger:H,info:b,warning:S,help:D,message:k};class f extends e.Component{constructor(t){super(t)}render(){const{className:t,children:l,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},l)),!!r&&e.createElement("span",{className:a.close,onClick:()=>{r&&r()}},e.createElement(m.X,{size:"1em"})))}}f.defaultProps={};function F(o){switch(o){case c.AlertType.success:return e.createElement(m.CheckCircle,null);case c.AlertType.danger:return e.createElement(_.DangerIcon,null);case c.AlertType.warning:return e.createElement(m.AlertCircle,null);case c.AlertType.info:return e.createElement(_.InfoIcon,null);case c.AlertType.help:return e.createElement(_.HelpIcon,null);default:return null}}const R=4e3,x=o=>{const[t,l]=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(()=>{p(i)},R);l(new Set(t))},p=s=>{t.delete(s),l(new Set(t))},A=()=>{const s=r.pop();s&&g([d(s)])},h=()=>Array.from(t).map(s=>e.createElement(f,{key:s.id,type:s.type,onDismiss:()=>{t.delete(s),l(new Set),s.dismiss&&s.dismiss()}},s.element)).slice(-1),{className:v="commonAlertsContainer"}=o;return e.createElement("div",{className:v},h())};exports.HeaderAlerts=x;
