String formatLastOpenedFromString(String? raw) {
  if (raw == null || raw.isEmpty) return "—";

  DateTime? date;

  try {
    date = DateTime.parse(raw).toLocal();
  } catch (_) {
    return "—";
  }

  final now = DateTime.now();
  final diff = now.difference(date);

  if (diff.inMinutes < 1) {
    return "just now";
  } else if (diff.inMinutes < 60) {
    return "${diff.inMinutes} mins ago";
  } else if (diff.inHours < 24) {
    return "${diff.inHours} hrs ago";
  } else if (diff.inDays < 7) {
    return "${diff.inDays} days ago";
  } else {
    return "${date.day}/${date.month}/${date.year}";
  }
}
