import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

import 'package:petitbac/cubit/game_cubit.dart';
import 'package:petitbac/models/game.dart';
import 'package:petitbac/utils/color_extensions.dart';

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

  @override
  Widget build(BuildContext context) {
    const Color backgroundColor = Colors.green;
    const double borderWidth = 8.0;

    return BlocBuilder<GameCubit, GameState>(
      builder: (BuildContext context, GameState gameState) {
        final Game currentGame = gameState.currentGame;

        final Color borderColor = backgroundColor.darken();

        return Container(
          margin: const EdgeInsets.all(borderWidth),
          padding: const EdgeInsets.all(borderWidth),
          decoration: BoxDecoration(
            color: backgroundColor,
            borderRadius: BorderRadius.circular(borderWidth),
            border: Border.all(
              color: borderColor,
              width: borderWidth,
            ),
          ),
          child: TextButton(
            onPressed: () {
              final GameCubit gameCubit = BlocProvider.of<GameCubit>(context);
              gameCubit.pickNewCategory();
            },
            child: Text(
              currentGame.category.text,
              textAlign: TextAlign.center,
              style: const TextStyle(
                fontSize: 30,
                fontWeight: FontWeight.w600,
                color: Colors.black,
              ),
            ),
          ),
        );
      },
    );
  }
}