import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../../providers.dart';
import '../../game/config.dart';

class CharacterStatsWidget extends StatelessWidget {
  const CharacterStatsWidget({super.key});

  @override
  Widget build(BuildContext context) {
    return Consumer<BattleProvider>(
      builder: (context, battleProvider, child) {
        final player = battleProvider.player;
        return Card(
          margin: const EdgeInsets.all(16.0),
          child: Padding(
            padding: const EdgeInsets.all(16.0),
            child: Column(
              children: [
                Text(
                  player.name,
                  style: Theme.of(context).textTheme.headlineSmall,
                ),
                const SizedBox(height: 8),
                Text("Stage: ${battleProvider.stage}"),
                const Divider(),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: [
                    _buildStatItem(
                      AppStrings.hp,
                      "${player.hp}/${player.totalMaxHp}",
                      color: ThemeConfig.statHpColor,
                    ),
                    _buildStatItem(
                      AppStrings.atk,
                      "${player.totalAtk}",
                      // color: ThemeConfig.statAtkColor,
                    ),
                    _buildStatItem(
                      AppStrings.def,
                      "${player.totalDefense}",
                      // color: ThemeConfig.statDefColor,
                    ),
                    // _buildStatItem(AppStrings.armor, "${player.armor}"),
                    _buildStatItem(
                      AppStrings.luck,
                      "${player.totalLuck}",
                      // color: ThemeConfig.statLuckColor,
                    ),
                    _buildStatItem(
                      "Dodge", // TODO: Add to AppStrings
                      "${player.totalDodge}%",
                      // color: ThemeConfig.statLuckColor,
                    ),
                    _buildStatItem(
                      AppStrings.gold,
                      "${player.gold} G",
                      color: ThemeConfig.statGoldColor,
                    ),
                  ],
                ),
              ],
            ),
          ),
        );
      },
    );
  }

  Widget _buildStatItem(String label, String value, {Color? color}) {
    return Column(
      children: [
        Text(
          label,
          style: const TextStyle(
            color: ThemeConfig.textColorGrey,
            fontSize: 12,
          ),
        ),
        Text(
          value,
          style: TextStyle(
            fontWeight: ThemeConfig.fontWeightBold,
            fontSize: 16,
            color: color,
          ),
        ),
      ],
    );
  }
}
