import './bootstrap';

import Alpine from 'alpinejs';

window.Alpine = Alpine;

document.addEventListener('alpine:init', () => {
    Alpine.store('__confirm', {
        open: false,
        message: '',
        formId: null,
        openConfirm(message, formId) {
            this.message = message;
            this.formId = formId;
            this.open = true;
        },
        close() {
            this.open = false;
            this.message = '';
            this.formId = null;
        },
        confirm() {
            if (this.formId) {
                const form = document.getElementById(this.formId);
                if (form) {
                    form.submit();
                }
            }
            this.close();
        },
    });
});

Alpine.start();
