"use strict";

import { Controller } from "@hotwired/stimulus";
import { leave } from "el-transition";

export default class extends Controller {
  static values = {
    dismissAfter: Number,
  };

  connect() {
    if (this.hasDismissAfterValue && this.dismissAfterValue > 0) {
      setTimeout(() => {
        this.dismiss();
      }, this.dismissAfterValue * 1000);
    }
  }

  dismiss() {
    Promise.all([leave(this.element)]).then(() => {
      this.element.remove();
    });
  }
}
