var __extends=(this&&this.__extends)||(function(){var extendStatics=function(d,b){extendStatics=Object.setPrototypeOf||({__proto__:[]}instanceof Array&&function(d,b){d.__proto__=b;})||function(d,b){for(var p in b)if(b.hasOwnProperty(p))d[p]=b[p];};return extendStatics(d,b);};return function(d,b){extendStatics(d,b);function __(){this.constructor=d;} d.prototype=b===null?Object.create(b):(__.prototype=b.prototype,new __());};})();var __decorate=(this&&this.__decorate)||function(decorators,target,key,desc){var c=arguments.length,r=c<3?target:desc===null?desc=Object.getOwnPropertyDescriptor(target,key):desc,d;if(typeof Reflect==="object"&&typeof Reflect.decorate==="function")r=Reflect.decorate(decorators,target,key,desc);else for(var i=decorators.length-1;i>=0;i--)if(d=decorators[i])r=(c<3?d(r):c>3?d(target,key,r):d(target,key))||r;return c>3&&r&&Object.defineProperty(target,key,r),r;};define(["require","exports","react","@core/material-ui-components","dojo/on","@core/with-state-manager"],function(require,exports,React,material_ui_components_1,on,with_state_manager_1){Object.defineProperty(exports,"__esModule",{value:true});var styles=function(theme){return({close:{width:theme.spacing.unit*4,height:theme.spacing.unit*4,padding:4},success:{backgroundColor:material_ui_components_1.green[600],},error:{backgroundColor:theme.palette.error.dark,},info:{backgroundColor:theme.palette.primary.dark,},warning:{backgroundColor:material_ui_components_1.amber[700],},icon:{fontSize:20,},iconVariant:{opacity:0.9,marginRight:theme.spacing.unit,},message:{display:'flex',alignItems:'center',}});};var Snackbar_container=(function(_super){__extends(Snackbar_container,_super);function Snackbar_container(props){var _this=_super.call(this,props)||this;_this.queue=[];_this.state={open:false,message_info:{content:"",key:"",variant:"",auto_hide_duration:6000},};return _this;} Snackbar_container.prototype.addToQueue=function(content,variant,secondary_button_content,secondary_button_action,auto_hide_duration){if(this.queue.length>5) this.queue=this.queue.slice(-4);this.queue.push({content:content,variant:variant,secondary_button_content:secondary_button_content,secondary_button_action:secondary_button_action,auto_hide_duration:auto_hide_duration,key:new Date().getTime(),});};Snackbar_container.prototype.processQueue=function(){var _this=this;if(this.waiting) return;if(this.queue.length>0){this.waiting=1;clearTimeout(this.process_timeout);if(this.state.open){this.setState({open:false,},function(){setTimeout(function(){_this._processQueue();},100);});return;} this._processQueue();}};Snackbar_container.prototype._processQueue=function(){var _this=this;this.setState({message_info:this.queue.shift(),open:true,});this.process_timeout=setTimeout(function(){if(!_this.setState) return;_this.waiting=0;_this.processQueue();},3000);};Snackbar_container.prototype.handleClose=function(event,reason){if(reason==='clickaway'){return;} this.waiting=0;this.setState({open:false});};Snackbar_container.prototype.handleExited=function(){this.waiting=0;this.processQueue();};Snackbar_container.prototype.componentDidMount=function(){var _this=this;var queue=this.props.state_manager.getRunStateProperty("snackbar_queue");if(queue&&queue.length>0){queue.forEach(function(i){_this.addToQueue(i.content,i.variant,i.secondary_button_content,i.secondary_button_action,i.auto_hide_duration);});this.processQueue();this.props.state_manager.setRunState("snackbar_queue",[]);} on(this.props.state_manager,'update-run-state',function(data){if(data.property==="snackbar_queue"){if(data.value&&data.value.length>0){data.value.forEach(function(i){_this.addToQueue(i.content,i.variant,i.secondary_button_content,i.secondary_button_action,i.auto_hide_duration);});_this.processQueue();_this.props.state_manager.setRunState("snackbar_queue",[]);}}});};Snackbar_container.prototype.render=function(){var _this=this;var _a=this.props,classes=_a.classes,theme=_a.theme;var _b=this.state.message_info,content=_b.content,key=_b.key,variant=_b.variant,secondary_button_content=_b.secondary_button_content,secondary_button_action=_b.secondary_button_action,auto_hide_duration=_b.auto_hide_duration;var secondary_button;if(secondary_button_content&&secondary_button_content!==""){secondary_button=React.createElement(material_ui_components_1.Button,{key:"undo",color:"default",style:{color:'#fff'},size:"small",onClick:function(){return secondary_button_action(_this);}},secondary_button_content);} else{secondary_button=React.createElement("span",null);} return(React.createElement(material_ui_components_1.Snackbar,{key:key,anchorOrigin:{vertical:'bottom',horizontal:'left',},open:this.state.open,autoHideDuration:auto_hide_duration||6000,onClose:this.handleClose.bind(this),onExited:this.handleExited.bind(this),ContentProps:{'aria-describedby':'message-id','className':classes[variant]},message:React.createElement("span",{id:"message-id"},content),action:[secondary_button,React.createElement(material_ui_components_1.IconButton,{style:{},key:"close","aria-label":"Close",color:"inherit",className:classes.close,onClick:this.handleClose.bind(this)},React.createElement("i",{className:"fa fa-times"})),]}));};Snackbar_container=__decorate([with_state_manager_1.default],Snackbar_container);return Snackbar_container;}(React.Component));exports.default=material_ui_components_1.withStyles(styles)(Snackbar_container);});