import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:smart_hotel_app/views/home/abnormal_list/cubit/abnormal_list_state.dart';

class FilterTabBlock extends StatelessWidget {
  final AlarmStatus currentFilter;
  final Function(AlarmStatus) onFilterChanged;
  final int allCount;
  final int pendingCount;
  final int processedCount;
  final int falseAlarmCount;

  const FilterTabBlock({
    super.key,
    required this.currentFilter,
    required this.onFilterChanged,
    this.allCount = 0,
    this.pendingCount = 0,
    this.processedCount = 0,
    this.falseAlarmCount = 0,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      width: double.infinity,
      margin: EdgeInsets.only(top: 10.h),
      child: Row(
        children: [
          _buildTab('全部', AlarmStatus.all, allCount),
          SizedBox(width: 20.w),
          _buildTab('待处理', AlarmStatus.pending, pendingCount),
          SizedBox(width: 20.w),
          _buildTab('已处理', AlarmStatus.processed, processedCount),
          SizedBox(width: 20.w),
          _buildTab('误报', AlarmStatus.falseAlarm, falseAlarmCount),
        ],
      ),
    );
  }

  Widget _buildTab(String label, AlarmStatus status, int count) {
    final isSelected = currentFilter == status;
    return Expanded(
      child: GestureDetector(
        onTap: () => onFilterChanged(status),
        child: Container(
          height: 72.h,
          decoration: BoxDecoration(
            color: isSelected
                ? const Color.fromRGBO(73, 149, 234, 1)
                : const Color.fromRGBO(100, 116, 139, 0.1),
            borderRadius: BorderRadius.circular(16.r),
          ),
          alignment: Alignment.center,
          child: Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text(
                label,
                style: TextStyle(
                  fontSize: 26.sp,
                  color: isSelected
                      ? Colors.white
                      : const Color.fromRGBO(100, 116, 139, 1),
                ),
              ),
              if (count > 0) ...[
                SizedBox(width: 6.w),
                Text(
                  '$count',
                  style: TextStyle(
                    fontSize: 22.sp,
                    color: isSelected
                        ? Colors.white
                        : const Color.fromRGBO(100, 116, 139, 0.8),
                  ),
                ),
              ],
            ],
          ),
        ),
      ),
    );
  }
}