import 'package:flutter/material.dart'; import '../../../core/constants.dart'; import '../models/request_history_entry.dart'; class RequestStatusLabel { final String label; final Color background; final Color foreground; const RequestStatusLabel(this.label, this.background, this.foreground); } RequestStatusLabel labelFor(RequestHistoryEntry entry) { if (entry.isPending) { return RequestStatusLabel( 'Menunggu respon', Colors.amber.shade100, Colors.amber.shade900, ); } switch (entry.response) { case RequestResponse.accepted: return RequestStatusLabel( 'Diterima', Colors.green.shade100, Colors.green.shade900, ); case RequestResponse.declined: return RequestStatusLabel( 'Ditolak', Colors.grey.shade300, Colors.grey.shade800, ); case RequestResponse.missed: return RequestStatusLabel( 'Terlewat', Colors.grey.shade300, Colors.grey.shade800, ); case RequestResponse.ignored: if (entry.sessionStatus == SessionStatus.cancelled) { return RequestStatusLabel( 'Dibatalkan', Colors.grey.shade300, Colors.grey.shade800, ); } return RequestStatusLabel( 'Kedaluwarsa', Colors.grey.shade300, Colors.grey.shade800, ); case null: // Non-pending null (session moved past pending_acceptance without a logged response) return RequestStatusLabel( 'Kedaluwarsa', Colors.grey.shade300, Colors.grey.shade800, ); } } String formatRelative(DateTime when) { final now = DateTime.now(); final diff = now.difference(when); if (diff.inSeconds < 60) return 'Baru saja'; if (diff.inMinutes < 60) return '${diff.inMinutes} menit lalu'; if (diff.inHours < 24) return '${diff.inHours} jam lalu'; if (diff.inDays < 2) return 'Kemarin'; return '${diff.inDays} hari lalu'; } String _two(int n) => n.toString().padLeft(2, '0'); String formatAbsolute(DateTime when) { return '${when.day}/${when.month}/${when.year} ${_two(when.hour)}:${_two(when.minute)}'; }