import { Controller } from "@hotwired/stimulus";

export default class extends Controller {
    static targets = ["dialog", "form", "token"];

    open(event) {
        event.preventDefault();
        const button = event.currentTarget;

        // Récupère l'URL et le token depuis le bouton
        const url = button.dataset.url;
        const csrfToken = button.dataset.token;

        // Remplit le formulaire de la modale
        this.formTarget.action = url;
        this.tokenTarget.value = csrfToken;

        this.dialogTarget.classList.remove("hidden");
        this.dialogTarget.classList.add("flex");
    }

    close() {
        this.dialogTarget.classList.add("hidden");
        this.dialogTarget.classList.remove("flex");
    }
}
