import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:smart_hotel_app/views/report/device/cubit/device_list_state.dart';

class DeviceFilterTab extends StatelessWidget {
  final DeviceTypeEnum selectedType;
  final Function(DeviceTypeEnum) onSelect;

  const DeviceFilterTab({
    super.key,
    required this.selectedType,
    required this.onSelect,
  });

  @override
  Widget build(BuildContext context) {
    final tabs = [
      {'type': DeviceTypeEnum.all, 'label': '全部'},
      {'type': DeviceTypeEnum.smartBreaker, 'label': '空开'},
      {'type': DeviceTypeEnum.guestControl, 'label': '客控'},
      {'type': DeviceTypeEnum.network, 'label': '网络'},
    ];

    return Container(
      width: double.infinity,
      padding: EdgeInsets.all(20.w),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(24.r),
        color: Colors.white,
      ),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: tabs.map((tab) {
          final isSelected = selectedType == tab['type'];
          return GestureDetector(
            onTap: () => onSelect(tab['type'] as DeviceTypeEnum),
            child: Container(
              padding: EdgeInsets.symmetric(horizontal: 24.w, vertical: 12.h),
              decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(16.r),
                color: isSelected
                    ? const Color.fromRGBO(59, 130, 246, 1)
                    : const Color.fromRGBO(243, 244, 246, 1),
              ),
              child: Text(
                tab['label'] as String,
                style: TextStyle(
                  fontSize: 24.sp,
                  color: isSelected ? Colors.white : const Color.fromRGBO(107, 114, 128, 1),
                  fontWeight: isSelected ? FontWeight.bold : FontWeight.normal,
                ),
              ),
            ),
          );
        }).toList(),
      ),
    );
  }
}
