package components import ( "github.com/starfleetcptn/gomft/internal/db" "time" "fmt" ) type NotificationsData struct { Notifications []db.UserNotification UnreadCount int64 // Pagination fields CurrentPage int TotalPages int TotalCount int PerPage int } // FormatNotificationTime formats a notification time in a user-friendly way func FormatNotificationTime(t time.Time) string { now := time.Now() diff := now.Sub(t) if diff < time.Minute { return "just now" } else if diff < time.Hour { minutes := int(diff.Minutes()) if minutes == 1 { return "1 minute ago" } return fmt.Sprintf("%d minutes ago", minutes) } else if diff < 24*time.Hour { hours := int(diff.Hours()) if hours == 1 { return "1 hour ago" } return fmt.Sprintf("%d hours ago", hours) } else if diff < 48*time.Hour { return "yesterday" } else { days := int(diff.Hours() / 24) if days < 7 { return fmt.Sprintf("%d days ago", days) } else { return t.Format("Jan 2") } } } // GetNotificationIcon returns the appropriate icon class based on notification type func GetNotificationIcon(notificationType db.NotificationType) string { switch notificationType { case db.NotificationJobStart: return "fas fa-play text-blue-600 dark:text-blue-300" case db.NotificationJobComplete: return "fas fa-check-circle text-green-600 dark:text-green-300" case db.NotificationJobFail: return "fas fa-exclamation-circle text-red-600 dark:text-red-300" case db.NotificationConfigUpdate: return "fas fa-cog text-blue-600 dark:text-blue-300" case db.NotificationSystemAlert: return "fas fa-bell text-yellow-600 dark:text-yellow-300" default: return "fas fa-info-circle text-blue-600 dark:text-blue-300" } } // GetNotificationBgColor returns the appropriate background color class based on notification type func GetNotificationBgColor(notificationType db.NotificationType) string { switch notificationType { case db.NotificationJobStart: return "bg-blue-100 dark:bg-blue-900" case db.NotificationJobComplete: return "bg-green-100 dark:bg-green-900" case db.NotificationJobFail: return "bg-red-100 dark:bg-red-900" case db.NotificationConfigUpdate: return "bg-blue-100 dark:bg-blue-900" case db.NotificationSystemAlert: return "bg-yellow-100 dark:bg-yellow-900" default: return "bg-blue-100 dark:bg-blue-900" } } // GetNotificationBadgeColor returns the appropriate badge color class based on notification type func GetNotificationBadgeColor(notificationType db.NotificationType) string { switch notificationType { case db.NotificationJobStart: return "bg-primary-700" case db.NotificationJobComplete: return "bg-green-600" case db.NotificationJobFail: return "bg-red-600" case db.NotificationConfigUpdate: return "bg-blue-500" case db.NotificationSystemAlert: return "bg-yellow-500" default: return "bg-primary-700" } } // GetNotificationBadgeIcon returns the appropriate badge icon class based on notification type func GetNotificationBadgeIcon(notificationType db.NotificationType) string { switch notificationType { case db.NotificationJobStart: return "fas fa-play" case db.NotificationJobComplete: return "fas fa-check" case db.NotificationJobFail: return "fas fa-times" case db.NotificationConfigUpdate: return "fas fa-wrench" case db.NotificationSystemAlert: return "fas fa-exclamation" default: return "fas fa-info" } } templ NotificationDropdown(data NotificationsData) {
Notifications
if len(data.Notifications) == 0 {

No notifications

} else { for _, notification := range data.Notifications {
//
// //
{ notification.Title }: { notification.Message }
{ FormatNotificationTime(notification.CreatedAt) }
} }
View all
Mark all read
} templ NotificationCount(count int64) { if count > 0 {
if count > 99 { 99+ } else { { fmt.Sprintf("%d", count) } }
} else { } }