import _objectWithoutProperties from"@babel/runtime/helpers/esm/objectWithoutProperties";import _defineProperty from"@babel/runtime/helpers/esm/defineProperty";import _extends from"@babel/runtime/helpers/esm/extends";import*as React from"react";import PropTypes from"prop-types";import clsx from"clsx";import withStyles from"../styles/withStyles";import{duration}from"../styles/transitions";import ClickAwayListener from"../ClickAwayListener";import useEventCallback from"../utils/useEventCallback";import capitalize from"../utils/capitalize";import createChainedFunction from"../utils/createChainedFunction";import Grow from"../Grow";import SnackbarContent from"../SnackbarContent";export var styles=function(e){var n={top:8},t={bottom:8},o={justifyContent:"flex-end"},r={justifyContent:"flex-start"},i={top:24},s={bottom:24},a={right:24},p={left:24},c={left:"50%",right:"auto",transform:"translateX(-50%)"};return{root:{zIndex:e.zIndex.snackbar,position:"fixed",display:"flex",left:8,right:8,justifyContent:"center",alignItems:"center"},anchorOriginTopCenter:_extends({},n,_defineProperty({},e.breakpoints.up("sm"),_extends({},i,{},c))),anchorOriginBottomCenter:_extends({},t,_defineProperty({},e.breakpoints.up("sm"),_extends({},s,{},c))),anchorOriginTopRight:_extends({},n,{},o,_defineProperty({},e.breakpoints.up("sm"),_extends({left:"auto"},i,{},a))),anchorOriginBottomRight:_extends({},t,{},o,_defineProperty({},e.breakpoints.up("sm"),_extends({left:"auto"},s,{},a))),anchorOriginTopLeft:_extends({},n,{},r,_defineProperty({},e.breakpoints.up("sm"),_extends({right:"auto"},i,{},p))),anchorOriginBottomLeft:_extends({},t,{},r,_defineProperty({},e.breakpoints.up("sm"),_extends({right:"auto"},s,{},p)))}};var Snackbar=React.forwardRef(function(e,n){var t=e.action,o=e.anchorOrigin,r=(o=void 0===o?{vertical:"bottom",horizontal:"center"}:o).vertical,i=o.horizontal,s=e.autoHideDuration,a=void 0===s?null:s,p=e.children,c=e.classes,u=e.className,l=e.ClickAwayListenerProps,d=e.ContentProps,m=e.disableWindowBlurListener,f=void 0!==m&&m,y=e.message,P=e.onClose,b=e.onEnter,T=e.onEntered,E=e.onEntering,x=e.onExit,h=e.onExited,g=e.onExiting,C=e.onMouseEnter,v=e.onMouseLeave,k=e.open,w=e.resumeHideDuration,_=e.TransitionComponent,L=void 0===_?Grow:_,R=e.transitionDuration,O=void 0===R?{enter:duration.enteringScreen,exit:duration.leavingScreen}:R,S=e.TransitionProps,j=_objectWithoutProperties(e,["action","anchorOrigin","autoHideDuration","children","classes","className","ClickAwayListenerProps","ContentProps","disableWindowBlurListener","message","onClose","onEnter","onEntered","onEntering","onExit","onExited","onExiting","onMouseEnter","onMouseLeave","open","resumeHideDuration","TransitionComponent","transitionDuration","TransitionProps"]),D=React.useRef(),z=React.useState(!0),M=z[0],A=z[1],B=useEventCallback(function(){P&&P.apply(void 0,arguments)}),H=useEventCallback(function(e){P&&null!=e&&(clearTimeout(D.current),D.current=setTimeout(function(){B(null,"timeout")},e))});React.useEffect(function(){return k&&H(a),function(){clearTimeout(D.current)}},[k,a,H]);var N=function(){clearTimeout(D.current)},W=React.useCallback(function(){null!=a&&H(null!=w?w:.5*a)},[a,w,H]);return React.useEffect(function(){if(!f&&k)return window.addEventListener("focus",W),window.addEventListener("blur",N),function(){window.removeEventListener("focus",W),window.removeEventListener("blur",N)}},[f,W,k]),!k&&M?null:React.createElement(ClickAwayListener,_extends({onClickAway:function(e){P&&P(e,"clickaway")}},l),React.createElement("div",_extends({className:clsx(c.root,c["anchorOrigin".concat(capitalize(r)).concat(capitalize(i))],u),onMouseEnter:function(e){C&&C(e),N()},onMouseLeave:function(e){v&&v(e),W()},ref:n},j),React.createElement(L,_extends({appear:!0,in:k,onEnter:createChainedFunction(function(){A(!1)},b),onEntered:T,onEntering:E,onExit:x,onExited:createChainedFunction(function(){A(!0)},h),onExiting:g,timeout:O,direction:"top"===r?"down":"up"},S),p||React.createElement(SnackbarContent,_extends({message:y,action:t},d)))))});"production"!==process.env.NODE_ENV&&(Snackbar.propTypes={action:PropTypes.node,anchorOrigin:PropTypes.shape({horizontal:PropTypes.oneOf(["left","center","right"]).isRequired,vertical:PropTypes.oneOf(["top","bottom"]).isRequired}),autoHideDuration:PropTypes.number,children:PropTypes.element,classes:PropTypes.object.isRequired,className:PropTypes.string,ClickAwayListenerProps:PropTypes.object,ContentProps:PropTypes.object,disableWindowBlurListener:PropTypes.bool,key:PropTypes.any,message:PropTypes.node,onClose:PropTypes.func,onEnter:PropTypes.func,onEntered:PropTypes.func,onEntering:PropTypes.func,onExit:PropTypes.func,onExited:PropTypes.func,onExiting:PropTypes.func,onMouseEnter:PropTypes.func,onMouseLeave:PropTypes.func,open:PropTypes.bool,resumeHideDuration:PropTypes.number,TransitionComponent:PropTypes.elementType,transitionDuration:PropTypes.oneOfType([PropTypes.number,PropTypes.shape({enter:PropTypes.number,exit:PropTypes.number})]),TransitionProps:PropTypes.object});export default withStyles(styles,{flip:!1,name:"MuiSnackbar"})(Snackbar);