import { h } from 'vue';

declare interface ActiveDialog extends DialogProps {
    deferred?: Deferred<Result>;
    onConfirm?: () => void;
    onCancel?: () => void;
    slots?: Record<string, typeof h>;
}

declare class Deferred<T> {
    promise: Promise<T>;
    reject: (value: T | PromiseLike<T>) => void;
    resolve: (value: T | PromiseLike<T>) => void;
    constructor();
}

declare interface DialogProps {
    /**
     * Shows or hides the dialog.
     * Usage: v-model:open="isOpen"
     */
    open?: boolean;
    /**
     * Whether the confirmation button is enabled or not.
     */
    disabled?: boolean;
    /**
     * Is this a dangerous action? Will turn the confirmation button red.
     */
    dangerZone?: boolean;
    /**
     * Header text.
     */
    header?: string;
    /**
     * Description text.
     */
    description?: string;
    /**
     * Cancel button text.
     */
    cancelText?: string;
    /**
     * Confirm button text.
     */
    confirmText?: string;
    /**
     * Callback function when the confirm button is clicked.
     */
    onConfirm?: (event: Event) => Promise<void> | void;
    /**
     * Treats it like an Alert Dialog, with only the confirmation button showing.
     *
     * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Window/alert}
     */
    alert?: boolean;
    /**
     * Adds a top accent border and icon next to the header.
     * This behaves similarly to the Alert component in respect to the levels, icons, and colors
     * passing `error` will treat the dialog the same as `dangerZone`
     */
    status?: StatusSeverity;
}

declare interface Result {
    isConfirmed?: boolean;
    isCanceled?: boolean;
}

declare enum StatusSeverities {
    Error = "error",
    Warning = "warning",
    Info = "info",
    Success = "success"
}

declare type StatusSeverity = `${StatusSeverities}`;

declare function useDialog(): {
    active: {
        readonly deferred?: {
            readonly promise: Promise<{
                readonly isConfirmed?: boolean | undefined;
                readonly isCanceled?: boolean | undefined;
            }>;
            readonly reject: (value: Result | PromiseLike<Result>) => void;
            readonly resolve: (value: Result | PromiseLike<Result>) => void;
        } | undefined;
        readonly onConfirm?: (() => void) | undefined;
        readonly onCancel?: (() => void) | undefined;
        readonly slots?: {
            readonly [x: string]: typeof h;
        } | undefined;
        readonly open?: boolean | undefined;
        readonly disabled?: boolean | undefined;
        readonly dangerZone?: boolean | undefined;
        readonly header?: string | undefined;
        readonly description?: string | undefined;
        readonly cancelText?: string | undefined;
        readonly confirmText?: string | undefined;
        readonly alert?: boolean | undefined;
        readonly status?: StatusSeverity | undefined;
    } | undefined;
    open: (dialog: Omit<ActiveDialog, "deferred">) => Promise<Result> | undefined;
    close: () => void;
};
export default useDialog;

export { }
