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

/// A circular icon button used in the header section.
///
/// Supports an optional badge for notification counts and an active state
/// for toggled actions.
class HeaderIconButton extends StatelessWidget {

  /// Creates a [HeaderIconButton].
  const HeaderIconButton({
    required this.icon,
    this.badgeText,
    this.isActive = false,
    required this.onTap,
    super.key,
  });
  /// The icon to display.
  final IconData icon;

  /// Optional badge text (e.g., notification count).
  final String? badgeText;

  /// Whether this button is in an active/selected state.
  final bool isActive;

  /// Callback invoked when the button is tapped.
  final VoidCallback onTap;

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: onTap,
      child: Stack(
        clipBehavior: Clip.none,
        children: <Widget>[
          Container(
            width: UiConstants.space8,
            height: UiConstants.space8,
            decoration: BoxDecoration(
              color: isActive ? UiColors.primary : UiColors.white,
              borderRadius: UiConstants.radiusMd,
              boxShadow: <BoxShadow>[
                BoxShadow(
                  color: UiColors.black.withValues(alpha: 0.05),
                  blurRadius: 2,
                ),
              ],
            ),
            child: Icon(
              icon,
              color: isActive ? UiColors.white : UiColors.iconSecondary,
              size: UiConstants.iconSm,
            ),
          ),
          if (badgeText != null)
            Positioned(
              top: -UiConstants.space1,
              right: -UiConstants.space1,
              child: Container(
                padding: const EdgeInsets.all(UiConstants.space1),
                decoration: const BoxDecoration(
                  color: UiColors.iconError,
                  shape: BoxShape.circle,
                ),
                constraints: const BoxConstraints(
                  minWidth: UiConstants.space4,
                  minHeight: UiConstants.space4,
                ),
                child: Center(
                  child: Text(
                    badgeText!,
                    style: UiTypography.footnote2b.copyWith(
                      color: UiColors.white,
                      fontSize: 8,
                    ),
                  ),
                ),
              ),
            ),
        ],
      ),
    );
  }
}
