import 'package:badges/badges.dart' as badges;
import 'package:flutter/material.dart';
import 'package:flutter_custom_toolbox/flutter_toolbox.dart';

import 'package:sudoku/config/default_global_settings.dart';
import 'package:sudoku/cubit/game_cubit.dart';
import 'package:sudoku/models/game/game.dart';

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

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

        return StyledButton(
          color: Colors.purple,
          child: badges.Badge(
            showBadge: currentGame.givenTipsCount == 0 ? false : true,
            badgeStyle: badges.BadgeStyle(
              badgeColor: currentGame.givenTipsCount < 10
                  ? Colors.green
                  : currentGame.givenTipsCount < 20
                      ? Colors.orange
                      : Colors.red,
            ),
            badgeContent: Text(
              currentGame.givenTipsCount == 0 ? '' : currentGame.givenTipsCount.toString(),
              style: const TextStyle(color: Colors.white),
            ),
            child: Container(
              padding: EdgeInsets.all(10 *
                  currentGame.buttonTipsCountdown /
                  DefaultGlobalSettings.defaultTipCountDownValueInSeconds),
              child: const Image(
                image: AssetImage('assets/ui/button_help.png'),
                fit: BoxFit.fill,
              ),
            ),
          ),
          onPressed: () {
            currentGame.canGiveTip
                ? currentGame.showTip(BlocProvider.of<GameCubit>(context))
                : null;
          },
        );
      },
    );
  }
}