import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:slrpg_app/l10n/app_localizations.dart';

import '../../../../core/theme/app_theme.dart';
import '../../../../core/constants/asset_paths.dart';

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

  @override
  Widget build(BuildContext context) {
    final l10n = AppLocalizations.of(context)!;

    return Scaffold(
      appBar: AppBar(
        title: Text(l10n.codexTitle),
        leading: IconButton(
          icon: const Icon(Icons.arrow_back),
          onPressed: () => context.go('/hub'),
        ),
      ),
      body: ListView(
        padding: const EdgeInsets.all(16),
        children: [
          _LoreCard(
            name: l10n.enemyIronGolemName,
            title: l10n.enemyIronGolemTitle,
            description: l10n.enemyIronGolemDesc,
            assetPath: AssetPaths.enemyIronGolem,
            exercise: l10n.enemyIronGolemNemesis,
            color: Colors.redAccent,
          ),
          const SizedBox(height: 24),
          _LoreCard(
            name: l10n.enemyGravityDemonName,
            title: l10n.enemyGravityDemonTitle,
            description: l10n.enemyGravityDemonDesc,
            assetPath: AssetPaths.enemyGravityDemon,
            exercise: l10n.enemyGravityDemonNemesis,
            color: Colors.purpleAccent,
          ),
          const SizedBox(height: 24),
          _LoreCard(
            name: l10n.enemyPressurePhantomName,
            title: l10n.enemyPressurePhantomTitle,
            description: l10n.enemyPressurePhantomDesc,
            assetPath: AssetPaths.enemyPressurePhantom,
            exercise: l10n.enemyPressurePhantomNemesis,
            color: Colors.cyanAccent,
          ),
        ],
      ),
    );
  }
}

class _LoreCard extends StatelessWidget {
  final String name;
  final String title;
  final String description;
  final String assetPath;
  final String exercise;
  final Color color;

  const _LoreCard({
    required this.name,
    required this.title,
    required this.description,
    required this.assetPath,
    required this.exercise,
    required this.color,
  });

  @override
  Widget build(BuildContext context) {
    return Card(
      clipBehavior: Clip.antiAlias,
      child: Container(
        decoration: BoxDecoration(
          border: Border.all(color: color.withValues(alpha: 0.5), width: 1),
          borderRadius: BorderRadius.circular(16),
          gradient: LinearGradient(
            begin: Alignment.topLeft,
            end: Alignment.bottomRight,
            colors: [
              AppTheme.surfaceColor,
              color.withValues(alpha: 0.1),
            ],
          ),
        ),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            Container(
              height: 200,
              padding: const EdgeInsets.all(24),
              decoration: BoxDecoration(
                color: Colors.black26,
                image: DecorationImage(
                  image: AssetImage(AssetPaths.bgUndergroundGym),
                  fit: BoxFit.cover,
                  opacity: 0.3,
                ),
              ),
              child: Center(
                child: Image.asset(
                  assetPath,
                  fit: BoxFit.contain,
                  color: Colors.white.withValues(alpha: 0.9),
                  colorBlendMode: BlendMode.modulate,
                ),
              ),
            ),
            Padding(
              padding: const EdgeInsets.all(16),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(
                        name.toUpperCase(),
                        style:
                            Theme.of(context).textTheme.headlineSmall?.copyWith(
                                  color: color,
                                  fontWeight: FontWeight.bold,
                                  letterSpacing: 1.5,
                                ),
                      ),
                      Chip(
                        label: Text(exercise,
                            style: const TextStyle(
                                fontSize: 10, color: Colors.white)),
                        backgroundColor: Colors.black54,
                        padding: EdgeInsets.zero,
                        visualDensity: VisualDensity.compact,
                      ),
                    ],
                  ),
                  Text(
                    title,
                    style: TextStyle(
                      color: AppTheme.textSecondary,
                      fontStyle: FontStyle.italic,
                    ),
                  ),
                  const Divider(height: 24),
                  Text(
                    description,
                    style: Theme.of(context).textTheme.bodyMedium?.copyWith(
                          height: 1.5,
                          color: Colors.white70,
                        ),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}
