export const Message = {
    /**
     * 消息轻提示
     * @param text 消息内容
     */
    toast: (text: string, duration?: 'short' | 'long'): void => {
        if (text) {
            // #ifndef APP-PLUS
            uni.showToast({
                title: text,
                icon: 'none',
                duration: duration === 'short' ? 2000 : 3500,
            })
            // #endif

            // #ifdef APP-PLUS
            plus.nativeUI.toast(text, {
                duration: duration || 'short',
            })
            // #endif
        }
    },
    /**
     * 消息弹窗提示
     * @param message 消息内容
     * @param title 标题
     * @returns Promise<void>
     */
    alert: (message: string, title = '提示', confirmText = '确定'): Promise<void> => {
        return new Promise((resolve, reject) => {
            // #ifndef APP-PLUS
            uni.showModal({
                title: title,
                content: message,
                showCancel: false,
                confirmText: confirmText,
                success: () => resolve(),
                fail: (err) => reject(err),
            })
            // #endif

            // #ifdef APP-PLUS
            plus.nativeUI.alert(message, resolve, title, confirmText)
            // #endif
        })
    },
    /**
     * 消息确认提示
     * @param title 标题
     * @param message 提示内容
     * @param confirmText 确认按钮文字
     * @param showCancel 是否显示取消按钮
     * @returns Promise<boolean> 是否点击了确认按钮
     */
    confirm: (message: string, title = '提示', confirmText = '确定', showCancel = true): Promise<boolean> => {
        return new Promise((resolve, reject) => {
            // #ifndef APP-PLUS
            uni.showModal({
                title: title,
                content: message,
                showCancel: showCancel,
                confirmText: confirmText,
                success: (res) => resolve(res.confirm),
                fail: (err) => reject(err),
            })
            // #endif

            // #ifdef APP-PLUS
            plus.nativeUI.confirm(message, ({ index }) => resolve(index === 0), {
                title,
                buttons: ['确认', '取消'],
                verticalAlign: 'center',
            })
            // #endif
        })
    },
}
