import { h, ref, render, nextTick } from 'vue' import AppDialog from '../Components/AppDialog.vue' // Глобальная очередь диалогов export const dialogQueue = ref([]) let idCounter = 0 // Вызывается при клике на кнопку / Esc / клик по маске export function closeDialog(id, confirmed = false) { const dialog = dialogQueue.value.find(d => d.id === id) if (dialog && dialog.show) { dialog.show = false // Запускает leave-анимацию dialog.resolve(confirmed) // Резолвим промис сразу для лучшего UX } } // Вызывается после завершения leave-анимации export function cleanupDialog(id) { dialogQueue.value = dialogQueue.value.filter(d => d.id !== id) } export function useAppDialog({title, content, positiveProps, negativeProps, positiveText = 'Подтвердить', negativeText = 'Отмена', maskClosable = false, onConfirm } = {}) { return new Promise((resolve) => { const id = idCounter++ // 1. Добавляем скрытым, чтобы сработала enter-анимация dialogQueue.value.push({ id, show: false, title, content, loading: false, onConfirm, positiveText, negativeText, positiveProps, negativeProps, maskClosable, resolve }) // 2. Переключаем в visible на следующем тике nextTick(() => { const dialog = dialogQueue.value.find(d => d.id === id) if (dialog) dialog.show = true }) }) }