wesal/frontend/lib/utils/invitation_utils.dart

115 lines
3.5 KiB
Dart

import 'package:flutter/material.dart';
class InvitationUtils {
static IconData getIconFromName(String iconName) {
switch (iconName) {
case 'sports_soccer':
return Icons.sports_soccer;
case 'restaurant':
return Icons.restaurant;
case 'games':
return Icons.games;
case 'menu_book':
return Icons.menu_book;
case 'group':
return Icons.group;
case 'flight':
return Icons.flight;
case 'music_note':
return Icons.music_note;
case 'movie':
return Icons.movie;
case 'coffee':
return Icons.coffee;
case 'local_dining':
return Icons.local_dining;
case 'sports':
return Icons.sports;
case 'school':
return Icons.school;
default:
return Icons.category;
}
}
static Color getColorFromHex(String hexColor) {
String cleanHex = hexColor.replaceAll('#', '');
if (cleanHex.length == 6) {
cleanHex = 'FF' + cleanHex;
}
return Color(int.parse(cleanHex, radix: 16));
}
static String getRelativeTime(DateTime dateTime) {
final now = DateTime.now();
final difference = now.difference(dateTime);
if (difference.inMinutes < 1) {
return 'just now';
} else if (difference.inMinutes < 60) {
return '${difference.inMinutes}m ago';
} else if (difference.inHours < 24) {
return '${difference.inHours}h ago';
} else if (difference.inDays == 1) {
return 'yesterday';
} else if (difference.inDays < 7) {
return '${difference.inDays}d ago';
} else {
return '${dateTime.day}/${dateTime.month}/${dateTime.year}';
}
}
static String getRelativeDateTime(DateTime dateTime) {
final now = DateTime.now();
final today = DateTime(now.year, now.month, now.day);
final tomorrow = today.add(Duration(days: 1));
final eventDate = DateTime(dateTime.year, dateTime.month, dateTime.day);
String timeString = _formatTime(dateTime);
if (eventDate == today) {
return 'today at $timeString';
} else if (eventDate == tomorrow) {
return 'tomorrow at $timeString';
} else if (eventDate.isAfter(today) && eventDate.isBefore(today.add(Duration(days: 7)))) {
List<String> weekdays = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
return '${weekdays[eventDate.weekday - 1]} at $timeString';
} else {
return '${eventDate.day}/${eventDate.month} at $timeString';
}
}
static String _formatTime(DateTime dateTime) {
int hour = dateTime.hour;
String period = hour >= 12 ? 'PM' : 'AM';
hour = hour > 12 ? hour - 12 : (hour == 0 ? 12 : hour);
String minute = dateTime.minute.toString().padLeft(2, '0');
return '$hour:$minute $period';
}
static String truncateDescription(String? description, {int maxLength = 80}) {
if (description == null || description.isEmpty) return '';
if (description.length <= maxLength) return description;
return '${description.substring(0, maxLength)}...';
}
static String getParticipantsStatus(int current, int max) {
int needed = max - current;
if (needed <= 2 && needed > 0) {
return '$needed more person${needed == 1 ? '' : 's'} needed';
} else {
return '$current/$max';
}
}
static Color getParticipantsStatusColor(int current, int max) {
int needed = max - current;
if (needed <= 2 && needed > 0) {
return Colors.orange;
} else if (current == max) {
return Colors.green;
} else {
return Colors.blue;
}
}
}