import { inject, Injectable } from '@angular/core'; import Swal from 'sweetalert2'; @Injectable({ providedIn: 'root', }) export class UIService { showErrorAlert(message: string) { return Swal.fire({ title: message, icon: 'error', }); } showWarningAlert(title: string) { return Swal.fire(title, '', 'warning'); } showSuccessAlert(message: string) { return Swal.fire(message, '', 'success'); } showInfoAlert(message: string) { return Swal.fire({ title: message, confirmButtonText: 'Cerrar', }); } async showPromptAlert(text: string) { const { isConfirmed } = await Swal.fire({ icon: 'warning', text, showCancelButton: true, confirmButtonText: 'Si', cancelButtonText: 'No', }); return isConfirmed; } showToast(text: string) { return Swal.fire({ text, icon: 'success', toast: true, position: 'bottom', timer: 5000, showConfirmButton: false, }); } showNotificationToast(title: string, body?: string) { const maxLength = 100; const truncatedBody = body && body.length > maxLength ? body.substring(0, maxLength) + '...' : body; return Swal.fire({ title, text: truncatedBody, icon: 'info', toast: true, position: 'top-end', timer: 5000, timerProgressBar: true, showConfirmButton: false, }); } } export const injectUIService = () => inject(UIService);