import { toast } from 'vue-sonner';
import { h } from 'vue';

export function showErrorToast(error) {
	if (!error) {
		toast.error('发生了未知错误');
		return;
	}
	
	let errorMessage = error.messages?.length 
		? error.messages.join('\n') 
		: (error.message || '发生了未知错误');
	toast.error(errorMessage);
}

export function getToastErrorMessage(error, fallbackMessage = '发生了错误') {
	if (!error) return fallbackMessage;
	
	try {
		const errorMessage = error.messages?.length
			? error.messages.join('<br>')
			: (error.message || fallbackMessage);
		
		return h('div', {
			innerHTML: errorMessage,
		});
	} catch (e) {
		return fallbackMessage;
	}
} 