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

import 'package:worker/core/theme/colors.dart';

/// Floating action button for chat support access.
///
/// Positioned at bottom-right of the screen with accent cyan color.
/// Opens chat support when tapped.
///
/// Example usage:
/// ```dart
/// Scaffold(
///   floatingActionButton: ChatFloatingButton(
///     onPressed: () => Navigator.pushNamed(context, '/chat'),
///   ),
/// )
/// ```
class ChatFloatingButton extends StatelessWidget {
  /// Callback when the button is pressed
  final VoidCallback onPressed;

  /// Optional badge count for unread messages
  final int? unreadCount;

  /// Size of the FAB. Defaults to 56.
  final double size;

  const ChatFloatingButton({
    super.key,
    required this.onPressed,
    this.unreadCount,
    this.size = 56,
  });

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      width: size,
      height: size,
      child: Stack(
        children: [
          FloatingActionButton(
            onPressed: onPressed,
            backgroundColor: AppColors.accentCyan,
            elevation: 6,
            child: const FaIcon(
              FontAwesomeIcons.message,
              color: Colors.white,
              size: 22,
            ),
          ),
          if (unreadCount != null && unreadCount! > 0)
            Positioned(
              right: 0,
              top: 0,
              child: Container(
                padding: const EdgeInsets.all(4),
                decoration: BoxDecoration(
                  color: AppColors.danger,
                  shape: BoxShape.circle,
                  border: Border.all(color: Colors.white, width: 2),
                ),
                constraints: const BoxConstraints(minWidth: 20, minHeight: 20),
                child: Center(
                  child: Text(
                    unreadCount! > 99 ? '99+' : unreadCount.toString(),
                    style: const TextStyle(
                      color: Colors.white,
                      fontSize: 10,
                      fontWeight: FontWeight.bold,
                    ),
                    textAlign: TextAlign.center,
                  ),
                ),
              ),
            ),
        ],
      ),
    );
  }
}
