import{p as t,H as s,c as o,h as i,a as e}from"./index.js";import{v as a}from"./p-BKP-F1qP.js";import{C as c}from"./p-U40vKHrs.js";import{p as r}from"./p-CQvUntGY.js";import{g as n}from"./p-DKo9A5gq.js";import{c as h}from"./p-vN03FcXN.js";import{A as l,a as d,i as m}from"./p-CXgom82_.js";import{d as b}from"./p-CWqMiVYH.js";import{d as f}from"./p-BJnSrRNH.js";const p=r(c,["PRIMARY","NEUTRAL","ERROR","SUCCESS","WARNING"]);var u;(function(t){t["BOLD"]="bold";t["SUBTLE"]="subtle"})(u||(u={}));const v={root:"gov-toast",hidden:"gov-toast--hidden",content:"gov-toast__content",icon:"gov-toast__icon",close:"gov-toast__close",timer:"gov-toast__timer"};const g=t(class t extends s{constructor(){super();this.__registerHost();this.govClose=o(this,"gov-close");this.color="primary";this.gravity="top";this.position="right";this.type="bold";this.time=0;this.inheritedAttributes={};this.h=n(this.host);this.toastId=h("GovToast")}validateColor(t){a(p,t,v.root)}componentDidLoad(){this.attributeObserver=new l(this.host,((t,s)=>{this.onAriaAttributeChange(t,s)}));this.attributeObserver.startObserving(d)}componentWillLoad(){this.validateColor(this.color);this.runTimer();this.inheritedAttributes=m(this.host)}disconnectedCallback(){var t;clearTimeout(this.timeout);(t=this.attributeObserver)===null||t===void 0?void 0:t.stopObserving()}onAriaAttributeChange(t,s){this.host.removeAttribute(t);this.inheritedAttributes=Object.assign(Object.assign({},this.inheritedAttributes),{[t]:s})}runTimer(){if(this.isTimer){this.timeout=setTimeout((()=>{this.host.classList.add(v.hidden);setTimeout((()=>{this.destroy().catch();this.govClose.emit(this.toastId)}),600)}),this.time)}}render(){return i(e,{key:"623b9b85e6b10894429d50c4624bac71808d29ad",class:this.h.classes(v.root),"data-toast-id":this.toastId,gravity:this.gravity,position:this.position,color:this.color,type:this.type,style:{"--toast-duration":this.time+"ms"}},this.h.hasSlot("icon")&&i("span",{key:"ae58b921c0aff0f678176c24d4cf69d05fb6cdab",class:v.icon},i("slot",{key:"40d58461b3e16abd1d4cd627057e986548ac63c1",name:"icon"})),i("div",Object.assign({key:"b003f0521f3fb5095b94280e2cf252b2a26ccaed",class:v.content},this.inheritedAttributes,{"aria-live":"polite",role:"status"}),i("slot",{key:"4743ada7cc1d31d6ca07871228d3fadc3576982f"})),i("gov-button",{key:"0d4e9bae29391f47389abbc2ada9ca9edaa13b97",size:"s","aria-label":this.accessibleCloseLabel,color:this.isBold?this.color:"neutral",type:"base","on-gov-click":this.onCloseHandler.bind(this),class:v.close},this.closeLabel?this.closeLabel:i("gov-icon",{name:"x-lg",type:"components"})),i("div",{key:"a8cb56376d11503abe586598f330476a45f59c8e",class:v.timer}))}onCloseHandler(){this.govClose.emit(this.toastId);this.destroy().catch()}get isBold(){return this.type==="bold"}get isTimer(){return Number.isInteger(this.time)&&this.time>0}async destroy(){clearTimeout(this.timeout);const t=document.querySelector(`[data-toast-id="${this.toastId}"]`);if(t){t.classList.add(v.hidden);if(typeof t.remove==="function"){t.remove()}}}get host(){return this}static get watchers(){return{color:["validateColor"]}}},[4,"gov-toast",{color:[1],gravity:[1],position:[1],type:[1],time:[2],closeLabel:[1,"close-label"],accessibleCloseLabel:[1,"accessible-close-label"],inheritedAttributes:[32],destroy:[64]},undefined,{color:["validateColor"]}]);function y(){if(typeof customElements==="undefined"){return}const t=["gov-toast","gov-button","gov-icon"];t.forEach((t=>{switch(t){case"gov-toast":if(!customElements.get(t)){customElements.define(t,g)}break;case"gov-button":if(!customElements.get(t)){b()}break;case"gov-icon":if(!customElements.get(t)){f()}break}}))}y();const C=g;const j=y;export{C as GovToast,j as defineCustomElement};
//# sourceMappingURL=gov-toast.js.map