// import 'package:flutter/material.dart';
// import '../../../../core/theme/app_theme.dart';
// import '../../../../core/constants/asset_paths.dart';

// class PlateVisualizer extends StatelessWidget {
//   final List<double> plateConfiguration;
//   final bool isTwoSided;
//   final String exerciseName;

//   const PlateVisualizer({
//     super.key,
//     required this.plateConfiguration,
//     required this.isTwoSided,
//     required this.exerciseName,
//   });

//   Color _getPlateColor(double weight) {
//     final colorValue = PlateColors.colors[weight];
//     return colorValue != null ? Color(colorValue) : Colors.grey;
//   }

//   Color _getTextColor(double weight) {
//     if (weight == 5.0) {
//       return Colors.black;
//     }
//     if (weight <= 2.5) {
//       return Colors.white70;
//     }
//     return Colors.white;
//   }

//   @override
//   Widget build(BuildContext context) {
//     if (plateConfiguration.isEmpty) {
//       return Card(
//         child: Padding(
//           padding: const EdgeInsets.all(32),
//           child: Column(
//             children: [
//               Icon(
//                 isTwoSided ? Icons.fitness_center : Icons.accessibility,
//                 size: 64,
//                 color: AppTheme.primaryColor.withValues(alpha: 0.5),
//               ),
//               const SizedBox(height: 16),
//               Text(
//                 isTwoSided ? 'Bar Only' : 'Bodyweight Only',
//                 style: Theme.of(context)
//                     .textTheme
//                     .titleLarge
//                     ?.copyWith(color: AppTheme.textSecondary),
//               ),
//             ],
//           ),
//         ),
//       );
//     }

//     return Card(
//       child: Padding(
//         padding: const EdgeInsets.all(16),
//         child: Column(
//           children: [
//             Text(
//               isTwoSided ? 'Load Per Side' : 'Load on Belt',
//               style: Theme.of(context).textTheme.titleMedium,
//             ),
//             const SizedBox(height: 16),
//             if (isTwoSided) _buildBarbellView() else _buildBeltView(),
//             const SizedBox(height: 16),
//             Text(
//               'Total: ${plateConfiguration.fold<double>(0, (sum, p) => sum + p).toStringAsFixed(1)} kg ${isTwoSided ? 'per side' : ''}',
//               style: Theme.of(context).textTheme.bodyMedium?.copyWith(
//                     color: AppTheme.primaryColor,
//                   ),
//             ),
//           ],
//         ),
//       ),
//     );
//   }

//   Widget _buildBarbellView() {
//     return SizedBox(
//       height: 120,
//       child: Row(
//         mainAxisAlignment: MainAxisAlignment.center,
//         crossAxisAlignment: CrossAxisAlignment.center,
//         children: [
//           Container(
//             width: 8,
//             height: 80,
//             color: Colors.grey[800],
//           ),
//           ...plateConfiguration.map((weight) {
//             final size = _getPlateSize(weight);
//             return Container(
//               width: 20,
//               height: size,
//               margin: const EdgeInsets.symmetric(horizontal: 2),
//               decoration: BoxDecoration(
//                 color: _getPlateColor(weight),
//                 border: Border.all(color: Colors.white24, width: 2),
//                 borderRadius: BorderRadius.circular(4),
//               ),
//             );
//           }).toList(),
//           Container(
//             width: 40,
//             height: 20,
//             decoration: BoxDecoration(
//               color: Colors.grey[700],
//               borderRadius: BorderRadius.circular(4),
//             ),
//             child: Center(
//               child: Container(
//                 width: 30,
//                 height: 10,
//                 decoration: BoxDecoration(
//                   color: Colors.grey[600],
//                   borderRadius: BorderRadius.circular(2),
//                 ),
//               ),
//             ),
//           ),
//         ],
//       ),
//     );
//   }

//   Widget _buildBeltView() {
//     return Wrap(
//       spacing: 8,
//       runSpacing: 8,
//       alignment: WrapAlignment.center,
//       children: plateConfiguration.map((weight) {
//         return Container(
//           width: _getPlateSize(weight) * 0.8,
//           height: _getPlateSize(weight) * 0.8,
//           decoration: BoxDecoration(
//             color: _getPlateColor(weight),
//             shape: BoxShape.circle,
//             border: Border.all(color: Colors.white24, width: 3),
//           ),
//           child: Center(
//             child: Text(
//               weight == weight.toInt()
//                   ? '${weight.toInt()}'
//                   : weight.toStringAsFixed(2),
//               style: const TextStyle(
//                 color: Colors.white,
//                 fontWeight: FontWeight.bold,
//                 fontSize: 14,
//               ),
//             ),
//           ),
//         );
//       }).toList(),
//     );
//   }

//   double _getPlateSize(double weight) {
//     if (weight >= 20) return 120.0;
//     if (weight >= 10) return 100.0;
//     if (weight >= 5) return 80.0;
//     return 60.0;
//   }
// }

import 'package:flutter/material.dart';
import '../../../../core/theme/app_theme.dart';
import '../../../../core/constants/asset_paths.dart';

class PlateVisualizer extends StatelessWidget {
  final List<double> plateConfiguration;
  final bool isTwoSided;
  final String exerciseName;

  const PlateVisualizer({
    super.key,
    required this.plateConfiguration,
    required this.isTwoSided,
    required this.exerciseName,
  });

  Color _getPlateColor(double weight) {
    final colorValue = PlateColors.colors[weight];
    return colorValue != null ? Color(colorValue) : Colors.grey;
  }

  Color _getTextColor(double weight) {
    if (weight == 5.0) {
      return Colors.black;
    }
    if (weight <= 2.5) {
      return Colors.white70;
    }
    return Colors.white;
  }

  @override
  Widget build(BuildContext context) {
    if (plateConfiguration.isEmpty) {
      return Card(
        child: Padding(
          padding: const EdgeInsets.all(32),
          child: Column(
            children: [
              Icon(
                isTwoSided ? Icons.fitness_center : Icons.accessibility,
                size: 64,
                color: AppTheme.primaryColor.withValues(alpha: 0.5),
              ),
              const SizedBox(height: 16),
              Text(
                isTwoSided ? 'Bar Only' : 'Bodyweight Only',
                style: Theme.of(context)
                    .textTheme
                    .titleLarge
                    ?.copyWith(color: AppTheme.textSecondary),
              ),
            ],
          ),
        ),
      );
    }

    return Card(
      child: Padding(
        padding: const EdgeInsets.all(16),
        child: Column(
          children: [
            Text(
              isTwoSided ? 'Load Per Side' : 'Load on Belt',
              style: Theme.of(context).textTheme.titleMedium,
            ),
            const SizedBox(height: 16),
            if (isTwoSided) _buildBarbellView() else _buildBeltView(),
            const SizedBox(height: 16),
            Text(
              'Total: ${plateConfiguration.fold<double>(0, (sum, p) => sum + p).toStringAsFixed(2)} kg ${isTwoSided ? 'per side' : ''}',
              style: Theme.of(context).textTheme.bodyMedium?.copyWith(
                    color: AppTheme.primaryColor,
                  ),
            ),
          ],
        ),
      ),
    );
  }

  Widget _buildBarbellView() {
    return SizedBox(
      height: 120,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          Container(
            width: 8,
            height: 80,
            color: Colors.grey[800],
          ),
          ...plateConfiguration.map((weight) {
            final size = _getPlateSize(weight);
            return Container(
              width: 20,
              height: size,
              margin: const EdgeInsets.symmetric(horizontal: 2),
              decoration: BoxDecoration(
                color: _getPlateColor(weight),
                border: Border.all(color: Colors.white24, width: 2),
                borderRadius: BorderRadius.circular(4),
              ),
            );
          }).toList(),
          Container(
            width: 40,
            height: 20,
            decoration: BoxDecoration(
              color: Colors.grey[700],
              borderRadius: BorderRadius.circular(4),
            ),
            child: Center(
              child: Container(
                width: 30,
                height: 10,
                decoration: BoxDecoration(
                  color: Colors.grey[600],
                  borderRadius: BorderRadius.circular(2),
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }

  Widget _buildBeltView() {
    return Wrap(
      spacing: 8,
      runSpacing: 8,
      alignment: WrapAlignment.center,
      children: plateConfiguration.map((weight) {
        return Container(
          width: _getPlateSize(weight) * 0.8,
          height: _getPlateSize(weight) * 0.8,
          decoration: BoxDecoration(
            color: _getPlateColor(weight),
            shape: BoxShape.circle,
            border: Border.all(color: Colors.white24, width: 3),
          ),
          child: Center(
            child: Text(
              weight == weight.toInt()
                  ? '${weight.toInt()}'
                  : weight.toStringAsFixed(2),
              style: TextStyle(
                color: _getTextColor(weight),
                fontWeight: FontWeight.bold,
                fontSize: 14,
              ),
            ),
          ),
        );
      }).toList(),
    );
  }

  double _getPlateSize(double weight) {
    if (weight >= 20) return 120.0;
    if (weight >= 10) return 100.0;
    if (weight >= 5) return 80.0;
    return 60.0;
  }
}
