import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:go_router/go_router.dart'; import '../../models/profile.model.dart'; import '../../models/programmer_day_sheet.model.dart'; import '../../providers/profile_provider.dart'; import '../../providers/programmer_day_sheets_provider.dart'; import '../../theme/app_status_colors.dart'; import '../../utils/app_time.dart'; import '../../widgets/app_section_header.dart'; import '../../widgets/app_state_view.dart'; import '../../widgets/status_pill.dart'; import 'dashboard/programmer_dashboard.dart'; import 'report/accomplishment_report_dialog.dart'; /// Admin-only drill-down screen that shows [ProgrammerDashboard] for a /// specific user in read-only mode, plus their recent day sheets history. /// /// Route: /programmer-tasks/programmers/:userId class ProgrammerDrillDownScreen extends ConsumerWidget { const ProgrammerDrillDownScreen({ super.key, required this.userId, }); final String userId; @override Widget build(BuildContext context, WidgetRef ref) { final isStrictAdmin = ref.watch(isStrictAdminProvider); final profilesAsync = ref.watch(profilesProvider); if (!isStrictAdmin) { return Scaffold( appBar: AppBar(title: const Text('Programmer')), body: const AppEmptyView( icon: Icons.lock_outline, title: 'Admins only', ), ); } // Resolve the programmer's name for the AppBar title. final profiles = profilesAsync.valueOrNull ?? []; Profile? profile; for (final p in profiles) { if (p.id == userId) { profile = p; break; } } final name = profile?.fullName ?? 'Programmer'; return Scaffold( appBar: AppBar( title: Text(name), actions: [ OutlinedButton( onPressed: () => showAccomplishmentReportDialog( context, ref, programmerId: userId, ), child: const Text('Generate Accomplishment Report'), ), const SizedBox(width: 8), ], ), body: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ // Dashboard fills the upper portion of the screen. Expanded( child: ProgrammerDashboard(userId: userId, readOnly: true), ), const Divider(height: 1), // Recent day sheets section — fixed-height scrollable panel. _RecentDaySheetsPanel(userId: userId), ], ), ); } } // --------------------------------------------------------------------------- // Recent sheets panel // --------------------------------------------------------------------------- class _RecentDaySheetsPanel extends ConsumerWidget { const _RecentDaySheetsPanel({required this.userId}); final String userId; StatusKind _kindFor(String status) => switch (status) { DaySheetStatus.approved => StatusKind.success, DaySheetStatus.pending => StatusKind.info, DaySheetStatus.disapproved => StatusKind.warning, _ => StatusKind.neutral, }; @override Widget build(BuildContext context, WidgetRef ref) { final sheetsAsync = ref.watch(daySheetsForUserProvider(userId)); final allSheets = sheetsAsync.valueOrNull ?? const []; // Show the most-recent 10 sheets (provider already orders newest-first). final recent = allSheets.length > 10 ? allSheets.sublist(0, 10) : allSheets; final cs = Theme.of(context).colorScheme; final tt = Theme.of(context).textTheme; return ConstrainedBox( constraints: const BoxConstraints(maxHeight: 320), child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, mainAxisSize: MainAxisSize.min, children: [ Padding( padding: const EdgeInsets.fromLTRB(16, 12, 16, 0), child: AppSectionHeader('Recent day sheets'), ), if (recent.isEmpty) Padding( padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8), child: Text( 'No day sheets yet.', style: tt.bodySmall?.copyWith(color: cs.onSurfaceVariant), ), ) else Flexible( child: ListView.builder( padding: const EdgeInsets.only(bottom: 12), itemCount: recent.length, itemBuilder: (context, i) { final sheet = recent[i]; return InkWell( onTap: () => context.pushNamed( 'daySheetDetail', pathParameters: {'id': sheet.id}, ), child: Padding( padding: const EdgeInsets.symmetric( horizontal: 16, vertical: 8), child: Row( children: [ Expanded( child: Text( AppTime.formatDate(sheet.workDate), style: tt.bodyMedium, ), ), StatusPill.kind( _kindFor(sheet.status), label: DaySheetStatus.label(sheet.status), ), ], ), ), ); }, ), ), ], ), ); } }