import{r as t,c as s,h as i,H as o,g as a}from"./p-ClISz4NF.js";import{v as e}from"./p-NOJjz9dT.js";import{C as c}from"./p-U40vKHrs.js";import{p as r}from"./p-CQvUntGY.js";import{g as h}from"./p-CoD1xawt.js";import{c as n}from"./p-vN03FcXN.js";import{A as d,a as l}from"./p-Bz_RzYFb.js";import{i as m}from"./p-CzXeijOj.js";import"./p-CgDnDrq5.js";const b=r(c,["PRIMARY","NEUTRAL","ERROR","SUCCESS","WARNING"]);var p;(function(t){t["BOLD"]="bold";t["SUBTLE"]="subtle"})(p||(p={}));const f={root:"gov-toast",hidden:"gov-toast--hidden",content:"gov-toast__content",icon:"gov-toast__icon",close:"gov-toast__close",timer:"gov-toast__timer"};const v=class{constructor(i){t(this,i);this.govClose=s(this,"gov-close");this.color="primary";this.gravity="top";this.position="right";this.type="bold";this.time=0;this.inheritedAttributes={};this.h=h(this.host);this.toastId=n("GovToast")}validateColor(t){e(b,t,f.root)}componentDidLoad(){this.attributeObserver=new d(this.host,((t,s)=>{this.onAriaAttributeChange(t,s)}));this.attributeObserver.startObserving(l)}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(f.hidden);setTimeout((()=>{this.destroy().catch();this.govClose.emit(this.toastId)}),600)}),this.time)}}render(){return i(o,{key:"623b9b85e6b10894429d50c4624bac71808d29ad",class:this.h.classes(f.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:f.icon},i("slot",{key:"40d58461b3e16abd1d4cd627057e986548ac63c1",name:"icon"})),i("div",Object.assign({key:"b003f0521f3fb5095b94280e2cf252b2a26ccaed",class:f.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:f.close},this.closeLabel?this.closeLabel:i("gov-icon",{name:"x-lg",type:"components"})),i("div",{key:"a8cb56376d11503abe586598f330476a45f59c8e",class:f.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(f.hidden);if(typeof t.remove==="function"){t.remove()}}}get host(){return a(this)}static get watchers(){return{color:["validateColor"]}}};export{v as gov_toast};
//# sourceMappingURL=p-7387370c.entry.js.map