import 'package:flutter/material.dart';
import '../../providers/battle_provider.dart';
import 'character_status_card.dart';
import 'shake_widget.dart';
import 'battle_animation_widget.dart';

class BattleArena extends StatelessWidget {
  final BattleProvider battleProvider;
  final GlobalKey playerKey;
  final GlobalKey enemyKey;
  final GlobalKey<BattleAnimationWidgetState> playerAnimKey;
  final GlobalKey<BattleAnimationWidgetState> enemyAnimKey;
  final GlobalKey<ShakeWidgetState> shakeKey;
  final GlobalKey stackKey;
  final bool isPlayerAttacking;
  final bool isEnemyAttacking;
  final String? playerOverrideImage;
  final String? enemyOverrideImage;

  const BattleArena({
    super.key,
    required this.battleProvider,
    required this.playerKey,
    required this.enemyKey,
    required this.playerAnimKey,
    required this.enemyAnimKey,
    required this.shakeKey,
    required this.stackKey,
    required this.isPlayerAttacking,
    required this.isEnemyAttacking,
    this.playerOverrideImage,
    this.enemyOverrideImage,
  });

  @override
  Widget build(BuildContext context) {
    return ShakeWidget(
      key: shakeKey,
      child: Stack(
        key: stackKey,
        children: [
          // 1. Background Image
          Container(
            decoration: const BoxDecoration(
              image: DecorationImage(
                image: AssetImage('assets/images/background/tier_1.jpg'),
                fit: BoxFit.cover,
              ),
            ),
          ),
          // 1.1 Opacity Layer
          Container(color: Colors.black.withValues(alpha: 0.7)),

          // 2. Character Area
          Padding(
            padding: const EdgeInsets.all(16.0),
            child: Stack(
              children: [
                // Player (Bottom Left)
                Positioned(
                  bottom: 80,
                  left: 16,
                  child: CharacterStatusCard(
                    character: battleProvider.player,
                    isPlayer: true,
                    isTurn: battleProvider.isPlayerTurn,
                    key: playerKey,
                    animationKey: playerAnimKey,
                    hideStats: isPlayerAttacking,
                    overrideImage: playerOverrideImage,
                  ),
                ),
                // Enemy (Top Right)
                Positioned(
                  top: 16,
                  right: 16,
                  child: CharacterStatusCard(
                    character: battleProvider.enemy,
                    isPlayer: false,
                    isTurn: !battleProvider.isPlayerTurn,
                    key: enemyKey,
                    animationKey: enemyAnimKey,
                    hideStats: isEnemyAttacking,
                    overrideImage: enemyOverrideImage,
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
