import { Controller } from "@hotwired/stimulus"; export default class extends Controller { static values = { closeAfter: { type: Number, default: 4000 }, autoClose: { type: Boolean, default: true }, }; static classes = ["show", "hide"]; static targets = ["content"]; connect() { setTimeout(() => { this.show(); }, 50); if (this.hasContentTarget) { const longText = this.contentTarget.innerHTML.length > 50; const closeAfterSeconds = longText ? 8000 : this.closeAfterValue; if (this.autoCloseValue) { setTimeout(() => { this.close(); }, closeAfterSeconds); } } } close() { this.hide(); } show() { this.element.classList.add(...this.showClasses); } hide() { this.element.classList.add(...this.hideClasses); } }