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

import '../../../core/app_export.dart';
import '../../../theme/app_theme.dart';

class NotificationBadgeWidget extends StatelessWidget {
  final int count;
  final Widget child;

  const NotificationBadgeWidget({
    super.key,
    required this.count,
    required this.child,
  });

  @override
  Widget build(BuildContext context) {
    return Stack(
      clipBehavior: Clip.none,
      children: [
        child,
        if (count > 0)
          Positioned(
            right: -1.w,
            top: -0.5.h,
            child: Container(
              padding: EdgeInsets.symmetric(
                horizontal: count > 9 ? 1.5.w : 1.w,
                vertical: 0.5.h,
              ),
              decoration: BoxDecoration(
                color: AppTheme.lightTheme.colorScheme.error,
                borderRadius: BorderRadius.circular(10),
                border: Border.all(
                  color: AppTheme.lightTheme.colorScheme.surface,
                  width: 2,
                ),
              ),
              constraints: BoxConstraints(
                minWidth: 5.w,
                minHeight: 2.5.h,
              ),
              child: Text(
                count > 99 ? '99+' : count.toString(),
                style: AppTheme.lightTheme.textTheme.labelSmall?.copyWith(
                  color: AppTheme.lightTheme.colorScheme.onError,
                  fontWeight: FontWeight.w600,
                  fontSize: 10.sp,
                ),
                textAlign: TextAlign.center,
              ),
            ),
          ),
      ],
    );
  }
}
