import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import '../cubit/inspection_device_state.dart';

class InspectionHistoryCard extends StatelessWidget {
  final List<InspectionHistoryItem> historyList;

  const InspectionHistoryCard({
    super.key,
    required this.historyList,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.only(
          topLeft: Radius.circular(20.r),
          topRight: Radius.circular(20.r),
        ),
      ),
      padding: EdgeInsets.only(left: 20.w, right: 20.w, top: 16.h),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          ...historyList.map((item) => _buildHistoryItem(item)).toList(),
        ],
      ),
    );
  }

  Widget _buildHistoryItem(InspectionHistoryItem item) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Row(
              spacing: 12.w,
              children: [
                Container(
                  width: 80.w,
                  height: 64.h,
                  alignment: Alignment.center,
                  decoration: BoxDecoration(
                    color: const Color.fromRGBO(229, 241, 255, 1.0),
                    borderRadius: BorderRadius.circular(8.r),
                  ),
                  child: Container(
                    width: 44.w,
                    height: 44.h,
                    decoration: const BoxDecoration(
                      color: Color.fromRGBO(73, 149, 234, 1),
                      shape: BoxShape.circle,
                    ),
                    child: Icon(
                      Icons.person,
                      color: Colors.white,
                      size: 40.sp,
                    ),
                  ),
                ),
                Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  spacing: 4.h,
                  children: [
                    Text(
                      item.inspectorName.isNotEmpty ? item.inspectorName : '--',
                      style: TextStyle(
                        fontSize: 26.sp,
                        fontWeight: FontWeight.bold,
                        color: const Color.fromRGBO(10, 13, 20, 1.0),
                      ),
                    ),
                    Row(
                      children: [
                        Icon(
                          Icons.access_time,
                          color: const Color.fromRGBO(100, 116, 139, 1.0),
                          size: 24.sp,
                        ),
                        SizedBox(width: 4.w),
                        Text(
                          item.inspectionTime.isNotEmpty ? item.inspectionTime : '--',
                          style: TextStyle(
                            fontSize: 24.sp,
                            color: const Color.fromRGBO(100, 116, 139, 1.0),
                          ),
                        ),
                      ],
                    ),
                  ],
                ),
              ],
            ),
            Container(
              padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 2.h),
              decoration: BoxDecoration(
                color: const Color.fromRGBO(225, 245, 238, 1.0),
                borderRadius: BorderRadius.circular(40.r),
              ),
              child: Row(
                spacing: 4.w,
                children: [
                  Icon(
                    Icons.check,
                    color: const Color.fromRGBO(26, 188, 156, 1.0),
                    size: 24.sp,
                  ),
                  Text(
                    item.result == '0' ? '巡检中' :
                    item.result == '1' ? '不通过' :
                    item.result == '2' ? '通过' :
                    item.result == '3' ? '警告' : '',
                    style: TextStyle(
                      fontSize: 24.sp,
                      color: const Color.fromRGBO(26, 188, 156, 1.0),
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                ],
              ),
            ),
          ],
        ),
        SizedBox(height: 20.h),
        Container(
          width: double.infinity,
          padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 16.h),
          decoration: BoxDecoration(
            color: const Color.fromRGBO(242, 243, 245, 1.0),
            borderRadius: BorderRadius.circular(12.r),
          ),
          child: Text(
            item.remark,
            style: TextStyle(
              fontSize: 24.sp,
              color: const Color.fromRGBO(100, 116, 139, 1.0),
            ),
          ),
        ),
      ],
    );
  }
}
