import { Modal } from '@arco-design/web-vue' import type { VNodeChild } from 'vue' // Frozen API (Phase 005). Mirrors the Naive `useDialog` option names used in // this repo (positiveText/onPositiveClick/...) and maps them onto Arco Modal. // Extend this adapter instead of importing Arco's Modal directly in views. export interface AppDialogOptions { title?: string content?: string | (() => VNodeChild) positiveText?: string negativeText?: string // Naive semantics: resolving false (or rejecting) keeps the dialog open // and shows no success close; anything else closes it. onPositiveClick?: () => unknown | Promise onNegativeClick?: () => unknown | Promise onClose?: () => void closable?: boolean } function normalize(options: AppDialogOptions) { return { title: options.title, // RenderContent = string | (() => VNodeChild) — pass functions through; // Arco invokes them itself. content: options.content ?? '', okText: options.positiveText, cancelText: options.negativeText, // Map naive's "resolve false / reject → keep open" onto Arco's onBeforeOk // (async result false keeps the modal open; it also drives ok-button // loading while pending, matching naive). onBeforeOk: options.onPositiveClick ? async (): Promise => { try { const result = await options.onPositiveClick!() return result !== false } catch { return false } } : undefined, // Arco's onBeforeCancel is sync-only; a returned promise (naive async // style with no explicit false) counts as "proceed". onBeforeCancel: options.onNegativeClick ? (): boolean => options.onNegativeClick!() !== false : undefined, onClose: options.onClose, closable: options.closable, } } export function useDialog() { return { confirm: (options: AppDialogOptions) => Modal.confirm(normalize(options)), info: (options: AppDialogOptions) => Modal.info(normalize(options)), success: (options: AppDialogOptions) => Modal.success(normalize(options)), error: (options: AppDialogOptions) => Modal.error(normalize(options)), warning: (options: AppDialogOptions) => Modal.warning(normalize(options)), } } export type AppDialog = ReturnType