import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:go_router/go_router.dart'; import 'package:intl/intl.dart'; import 'package:ristoris/ui/pages/customers/tabs/destinations_tab.dart'; import 'package:ristoris/ui/pages/customers/tabs/info_tab.dart'; import 'package:ristoris/ui/pages/customers/tabs/orders_tab.dart'; import 'package:ristoris/ui/pages/customers/tabs/payments_tab.dart'; import '../../../database/database.dart'; import '../../../providers/auth_provider.dart'; import '../../../providers/database_provider.dart'; import '../../../providers/customer_provider.dart'; import '../../../database/tables/clienti.dart'; import '../../../database/tables/filiali.dart'; import '../../../database/tables/scadenze.dart'; import '../../../core/responsive.dart'; class CustomerDetailPage extends ConsumerWidget { final int id; const CustomerDetailPage({super.key, required this.id}); @override Widget build(BuildContext context, WidgetRef ref) { final clientiDao = ref.read(clientiDaoProvider); final clienteAsync = clientiDao.getById(id); final theme = Theme.of(context); return DefaultTabController( length: 4, child: Scaffold( appBar: AppBar( title: FutureBuilder( future: clienteAsync, builder: (_, snap) => Text(snap.data?.ragioneSociale ?? 'Cliente'), ), bottom: const TabBar( tabs: [ Tab(text: 'Info', icon: Icon(Icons.info_outline)), Tab(text: 'Ordini', icon: Icon(Icons.receipt_long_outlined)), Tab(text: 'Destinazioni', icon: Icon(Icons.location_on_outlined)), Tab( text: 'Scadenze', icon: Icon(Icons.account_balance_wallet_outlined), ), ], ), ), body: SafeArea( child: FutureBuilder( future: clienteAsync, builder: (_, snap) { final cliente = snap.data; if (cliente == null) { return const Center(child: CircularProgressIndicator()); } return TabBarView( children: [ InfoTab(cliente: cliente, theme: theme), OrdersTab(idCliente: id, theme: theme), DestinationsTab(idCliente: id, theme: theme), PaymentsTab( idCliente: id ?? 0, theme: theme, ), ], ); }, ), ), ), ); } }