import*as t from"react";import{Toast as e}from"./toast.js";import{findToast as o,getToastPosition as i}from"./toast.utils.js";import{AnimatePresence as s}from"../../../../framer-motion/dist/es/components/AnimatePresence/index.js";import{objectKeys as r}from"../../../utils/dist/esm/object.js";function n(){return(n=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var o=arguments[e];for(var i in o)Object.prototype.hasOwnProperty.call(o,i)&&(t[i]=o[i])}return t}).apply(this,arguments)}function a(t,e,o){return e in t?Object.defineProperty(t,e,{value:o,enumerable:!0,configurable:!0,writable:!0}):t[e]=o,t}class l extends t.Component{constructor(t){var e;super(t),e=this,a(this,"state",{top:[],"top-left":[],"top-right":[],"bottom-left":[],bottom:[],"bottom-right":[]}),a(this,"notify",((t,e)=>{var o=this.createToast(t,e),{position:i,id:s}=o;return this.setState((t=>{var e=i.includes("top")?[o,...t[i]]:[...t[i],o];return n({},t,{[i]:e})})),s})),a(this,"updateToast",((t,e)=>{this.setState((i=>{var s=n({},i),{position:r,index:a}=o(s,t);return r&&-1!==a&&(s[r][a]=n({},s[r][a],e)),s}))})),a(this,"closeAll",(function(t){var{positions:o}=void 0===t?{}:t;e.setState((t=>(null!=o?o:["bottom","bottom-right","bottom-left","top","top-left","top-right"]).reduce(((e,o)=>(e[o]=t[o].map((t=>n({},t,{requestClose:!0}))),e)),{})))})),a(this,"createToast",((t,e)=>{var o,i;l.counter+=1;var s=null!=(o=e.id)?o:l.counter,r=null!=(i=e.position)?i:"top";return{id:s,message:t,position:r,duration:e.duration,onCloseComplete:e.onCloseComplete,onRequestRemove:()=>this.removeToast(String(s),r),status:e.status,requestClose:!1}})),a(this,"closeToast",(t=>{this.setState((e=>{var o=i(e,t);return o?n({},e,{[o]:e[o].map((e=>e.id==t?n({},e,{requestClose:!0}):e))}):e}))})),a(this,"removeToast",((t,e)=>{this.setState((o=>n({},o,{[e]:o[e].filter((e=>e.id!=t))})))})),a(this,"isVisible",(t=>{var{position:e}=o(this.state,t);return Boolean(e)})),a(this,"getStyle",(t=>({position:"fixed",zIndex:5500,pointerEvents:"none",display:"flex",flexDirection:"column",margin:"top"===t||"bottom"===t?"0 auto":void 0,top:t.includes("top")?"env(safe-area-inset-top, 0px)":void 0,bottom:t.includes("bottom")?"env(safe-area-inset-bottom, 0px)":void 0,right:t.includes("left")?void 0:"env(safe-area-inset-right, 0px)",left:t.includes("right")?void 0:"env(safe-area-inset-left, 0px)"})));var s={notify:this.notify,closeAll:this.closeAll,close:this.closeToast,update:this.updateToast,isActive:this.isVisible};t.notify(s)}render(){return r(this.state).map((o=>{var i=this.state[o];return t.createElement("ul",{key:o,id:"chakra-toast-manager-"+o,style:this.getStyle(o)},t.createElement(s,{initial:!1},i.map((o=>t.createElement(e,n({key:o.id},o))))))}))}}a(l,"counter",0);export{l as ToastManager};
//# sourceMappingURL=toast-manager.js.map
