import{animate as t,fadeIn as s,fadeOut as i,none as e}from"@lit-labs/motion";import{LitElement as o,html as a,css as n}from"lit";import{repeat as r}from"lit/directives/repeat.js";import"./cc-toast.js";const m=[{transform:"translateY(-100%)"}],l=[{transform:"translateY(100%)"}],c=[{transform:"translateX(-100%)"}],u=[{transform:"translateX(100%)"}],h={in:s,out:i},p={top:{in:m,out:e},"top-left":{in:m,out:c},"top-right":{in:m,out:u},bottom:{in:l,out:e},"bottom-left":{in:l,out:c},"bottom-right":{in:l,out:u}};class d extends o{static get properties(){return{animation:{type:String},maxToasts:{type:Number,attribute:"max-toasts"},position:{type:String},toastDefaultOptions:{type:Object,attribute:"toast-default-options"},_toasts:{type:Array,state:!0}}}constructor(){super(),this.animation="fade",this.maxToasts=null,this.position="top-right",this.toastDefaultOptions=null,this._toasts=[],this._mediaQuery=window.matchMedia("(prefers-reduced-motion: reduce)")}show(t){if(0===this.maxToasts)return;if(null!=this.maxToasts&&!Number.isNaN(this.maxToasts)){const t=this._toasts.filter((t=>!t.dismissing));if(t.length>=this.maxToasts){const s=t[t.length-1];this._dismiss(s)}}const s=this._createToast(t);return this._toasts=[s,...this._toasts],()=>{this._dismiss(s)}}_createToast(t){return{...t,key:Math.random().toString(36).slice(2),options:{closeable:!1,showProgress:!1,timeout:5e3,...this.toastDefaultOptions,...t.options}}}_dismiss(t){this._toasts=this._toasts.filter((s=>s!==t))}_getInOutAnimations(){switch(this.animation){case"fade":return h;case"slide":return p[this.position];case"fade-and-slide":return{in:[{...(t=p[this.position]).in[0],opacity:0}],out:[{...t.out[0],opacity:0}]}}var t}_getAnimationDirective(){const s={duration:400,easing:"ease"};return null!=this._mediaQuery&&this._mediaQuery.matches?null:t({keyframeOptions:s,...this._getInOutAnimations()})}render(){const t=this.position.split("-").join(" ");return a`<div class="${t} toaster" aria-live=polite aria-atomic=true>${r(this._toasts,(t=>t.key),(t=>this._renderToast(t)))}</div>`}_renderToast(t){return a`<cc-toast intent=${t.intent} .heading=${t.title} .message=${t.message} .timeout=${t.options.timeout} ?closeable=${t.options.closeable} ?show-progress=${t.options.showProgress} ${this._getAnimationDirective()} @cc-toast:dismiss=${()=>this._dismiss(t)}></cc-toast>`}static get styles(){return[n`:host{display:block}.toaster{align-items:center;display:flex;flex-direction:column;gap:1em;pointer-events:none}.toaster.left{align-items:start}.toaster.right{align-items:end}.toaster.bottom{flex-direction:column-reverse}`]}}window.customElements.define("cc-toaster",d);export{d as CcToaster};
//# sourceMappingURL=cc-toaster.js.map
