import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:smart_hotel_app/views/home/index/cubit/home_index_state.dart';
import 'package:smart_hotel_app/routes/app_router.gr.dart';

class EquipmentListBlock extends StatelessWidget {
  final List<EquipmentItem> equipmentList;

  const EquipmentListBlock({
    super.key,
    required this.equipmentList,
  });

  Widget _buildEquipmentItem(EquipmentItem item) {
    return Container(
      padding: EdgeInsets.symmetric(vertical: 16.h),
      decoration: BoxDecoration(
        border: Border(
          bottom: BorderSide(
            color: const Color.fromRGBO(235, 235, 235, 1.0),
            width: 1.w,
          ),
        ),
      ),
      child: Row(
        children: [
          Container(
            width: 64.w,
            height: 66.h,
            decoration: BoxDecoration(
              color: const Color.fromRGBO(235, 244, 255, 1.0),
              borderRadius: BorderRadius.circular(12.r),
              border: Border.all(
                color: const Color.fromRGBO(66, 165, 245, 1.0),
                width: 2.w,
                style: BorderStyle.solid,
              ),
            ),
            child: Icon(
              item.icon,
              color: const Color.fromRGBO(66, 165, 245, 1.0),
              size: 32.sp,
            ),
          ),
          SizedBox(width: 16.w),
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Transform.translate(
                  offset: Offset(0, 2.h),
                  child: Text(
                    item.title,
                    style: TextStyle(
                      fontSize: 28.sp,
                      fontWeight: FontWeight.bold,
                      color: Colors.black,
                    ),
                  ),
                ),
                SizedBox(height: 4.h),
                Text(
                  item.subtitle,
                  style: TextStyle(
                    fontSize: 24.sp,
                    color: const Color.fromRGBO(100, 116, 139, 1.0),
                  ),
                ),
              ],
            ),
          ),
          Text(
            item.status,
            style: TextStyle(
              fontSize: 24.sp,
              fontWeight: FontWeight.bold,
              color: item.statusColor,
            ),
          ),
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      width: double.infinity,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisSize: MainAxisSize.min,
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Text(
                '设备巡检',
                style: TextStyle(
                  fontSize: 28.sp,
                  fontWeight: FontWeight.bold,
                  color: Colors.black,
                ),
              ),
              GestureDetector(
                onTap: () {
                  context.pushRoute(const InspectionDetailRoute());
                },
                child: Row(
                  children: [
                    Text(
                      '查看全部',
                      style: TextStyle(
                        fontSize: 24.sp,
                        color: const Color.fromRGBO(66, 165, 245, 1.0),
                      ),
                    ),
                    Icon(
                      Icons.chevron_right,
                      color: const Color.fromRGBO(66, 165, 245, 1.0),
                      size: 24.sp,
                    ),
                  ],
                ),
              ),
            ],
          ),
          SizedBox(height: 12.h),
          Container(
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.circular(20.r),
            ),
            padding: EdgeInsets.symmetric(horizontal: 20.w),
            child: Column(
              children: equipmentList.take(5).map((item) => _buildEquipmentItem(item)).toList(),
            ),
          ),
        ],
      ),
    );
  }
}