import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; import 'package:ristoris/database/database.dart'; Color? _creditScoreBg(String? colorName) { switch (colorName?.toUpperCase()) { case 'VERDE': return const Color(0xFF008000); case 'VERDE CHIARO': return const Color(0xFF90EE90); case 'VERDE SCURO': return const Color(0xFF006400); case 'GIALLO': return const Color(0xFFFFA500); case 'GRIGIO': return const Color(0xFF808080); case 'ROSSO VIVO': return const Color(0xFFA80000); case 'ROSSO SCURO': return const Color(0xFF8B0000); case 'ROSSO': return const Color(0xFFFF0000); default: return null; } } class CustomerCard extends StatelessWidget { final Cliente cliente; const CustomerCard({super.key, required this.cliente}); @override Widget build(BuildContext context) { final theme = Theme.of(context); final cs = theme.colorScheme; return Card( elevation: 0, color: Colors.white, clipBehavior: Clip.antiAlias, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(12), side: BorderSide(color: cs.outlineVariant), ), child: InkWell( onTap: () => context.push('/dashboard/customers/${cliente.idCliente}'), child: Padding( padding: const EdgeInsets.all(16), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ Expanded( child: Text( cliente.ragioneSociale ?? '', style: theme.textTheme.bodyMedium?.copyWith( color: cs.primary, ), maxLines: 2, overflow: TextOverflow.ellipsis, ), ), if ((cliente.codCliente ?? '').isNotEmpty) ...[ const SizedBox(width: 8), Container( padding: const EdgeInsets.symmetric( horizontal: 8, vertical: 4, ), decoration: BoxDecoration( color: _creditScoreBg(cliente.creditScoreColor) ?? cs.surfaceVariant, borderRadius: BorderRadius.circular(4), ), child: Text( cliente.codCliente ?? '', style: TextStyle( fontSize: 12, height: 16 / 12, fontWeight: FontWeight.w500, color: _creditScoreBg(cliente.creditScoreColor) != null ? Colors.white : cs.onSurfaceVariant, ), ), ), ], ], ), const SizedBox(height: 4), Text( cliente.email ?? '', style: theme.textTheme.bodyMedium?.copyWith( color: cs.onSurfaceVariant, ), maxLines: 1, overflow: TextOverflow.ellipsis, ), const SizedBox(height: 16), Row( children: [ Icon(Icons.phone, size: 20, color: cs.onSurfaceVariant), const SizedBox(width: 8), Expanded( child: Text( cliente.telefono ?? '', style: theme.textTheme.bodyMedium?.copyWith( color: cs.onSurfaceVariant, ), maxLines: 1, overflow: TextOverflow.ellipsis, ), ), ], ), Row( children: [ Icon(Icons.business, size: 20, color: cs.onSurfaceVariant), const SizedBox(width: 8), Expanded( child: Text( cliente.indirizzo ?? '', style: theme.textTheme.bodyMedium?.copyWith( color: cs.onSurfaceVariant, ), maxLines: 1, overflow: TextOverflow.ellipsis, ), ), ], ), const SizedBox(height: 8), Row( children: [ Icon(Icons.location_on, size: 20, color: cs.onSurfaceVariant), const SizedBox(width: 8), Expanded( child: Text( [ if ((cliente.citta ?? '').isNotEmpty) cliente.citta, if ((cliente.provincia ?? '').isNotEmpty) cliente.provincia, ].join(', '), style: theme.textTheme.bodyMedium?.copyWith( color: cs.onSurfaceVariant, ), maxLines: 1, overflow: TextOverflow.ellipsis, ), ), ], ), const SizedBox(height: 16), Divider(height: 1, color: cs.outlineVariant), const SizedBox(height: 12), Row( children: [ Expanded( child: OutlinedButton.icon( onPressed: () { context.go('/dashboard/customers/${cliente.idCliente}'); }, icon: const Icon(Icons.info_outline, size: 18), label: const Text('Dettagli'), style: OutlinedButton.styleFrom( foregroundColor: cs.secondary, side: BorderSide( color: cs.secondary.withValues(alpha: 0.3), ), ), ), ), const SizedBox(width: 8), Expanded( child: FilledButton.icon( onPressed: () => context.go( '/dashboard/orders/new?cliente=${cliente.idCliente}', ), icon: const Icon(Icons.shopping_cart, size: 18), label: const Text('Nuovo ordine'), ), ), ], ), ], ), ), ), ); } }