import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flux/core/blocs/session/session_cubit.dart'; import 'package:flux/features/master_data/staff/blocs/staff_cubit.dart'; import 'package:flux/features/operations/blocs/operations_cubit.dart'; import 'package:flux/features/operations/models/operation_model.dart'; import 'package:get_it/get_it.dart'; // IMPORTA IL TUO CUBIT DELLO STAFF // import 'package:flux/features/staff/blocs/staff_cubit.dart'; class StaffSection extends StatelessWidget { final OperationModel? currentOp; const StaffSection({super.key, required this.currentOp}); @override Widget build(BuildContext context) { final theme = Theme.of(context); final selectedStaffId = currentOp?.staffId ?? GetIt.I.get().state.currentStaffMember?.id; return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Padding( padding: const EdgeInsets.only(bottom: 12.0), child: Text( 'Operatore', style: theme.textTheme.titleLarge?.copyWith( fontWeight: FontWeight.bold, ), ), ), BlocBuilder( builder: (context, state) { // Dati finti per farti vedere la UI, piallali quando attacchi il BlocBuilder! final staffMembers = state.storeStaff; final currentLoggedStaffMember = GetIt.I .get() .state .currentStaffMember; return SingleChildScrollView( scrollDirection: Axis.horizontal, child: Row( children: staffMembers.map((staff) { final isSelected = staff.id == selectedStaffId; return GestureDetector( onTap: () { // Aggiorniamo la form con un solo tap! context.read().updateOperationFields( staffId: staff.id, staffDisplayName: staff.name, ); }, child: AnimatedContainer( duration: const Duration(milliseconds: 200), margin: const EdgeInsets.only(right: 12.0), padding: const EdgeInsets.symmetric( horizontal: 16.0, vertical: 10.0, ), decoration: BoxDecoration( color: isSelected ? theme.colorScheme.primary : theme.colorScheme.surface, borderRadius: BorderRadius.circular(30), border: Border.all( color: isSelected ? theme.colorScheme.primary : theme.dividerColor, width: 1.5, ), boxShadow: isSelected ? [ BoxShadow( color: theme.colorScheme.primary.withValues( alpha: 0.3, ), blurRadius: 8, offset: const Offset(0, 2), ), ] : null, ), child: Row( mainAxisSize: MainAxisSize.min, children: [ CircleAvatar( radius: 12, backgroundColor: isSelected ? Colors.white : theme.colorScheme.primaryContainer, child: Text( staff.name.substring(0, 1).toUpperCase(), style: TextStyle( fontSize: 12, fontWeight: FontWeight.bold, color: isSelected ? theme.colorScheme.primary : theme.colorScheme.onPrimaryContainer, ), ), ), const SizedBox(width: 8), Text( staff == currentLoggedStaffMember ? 'Tu (${staff.name})' : staff.name, style: TextStyle( fontWeight: isSelected ? FontWeight.bold : FontWeight.w500, color: isSelected ? Colors.white : theme.colorScheme.onSurface, ), ), ], ), ), ); }).toList(), ), ); }, ), ], ); } }