import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; import 'package:ristoris/core/credit_score_color.dart'; import 'package:ristoris/database/database.dart'; 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( children: [ Expanded( 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.surfaceContainerHighest, 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, ), ), ], ), const SizedBox(height: 4), 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, ), ), ], ), ], ), ), Divider(height: 1, color: cs.outlineVariant), const SizedBox(height: 16), 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.add_shopping_cart_outlined, size: 18, ), label: const Text('Ordine'), ), ), ], ), ], ), ), ), ); } }