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: [
          Text(
            '巡检历史 (${historyList.length})',
            style: TextStyle(
              fontSize: 26.sp,
              fontWeight: FontWeight.bold,
              color: const Color.fromRGBO(10, 13, 20, 1.0),
            ),
          ),
          SizedBox(height: 20.h),
          ...historyList.map((item) => _buildHistoryItem(item)).toList(),
        ],
      ),
    );
  }

  Widget _buildHistoryItem(InspectionHistoryItem item) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Row(
              children: [
                Container(
                  width: 60.w,
                  height: 60.h,
                  decoration: BoxDecoration(
                    color: const Color.fromRGBO(242, 243, 245, 1.0),
                    borderRadius: BorderRadius.circular(8.r),
                  ),
                  child: Icon(
                    Icons.person,
                    color: const Color.fromRGBO(100, 116, 139, 1.0),
                    size: 32.sp,
                  ),
                ),
                SizedBox(width: 12.w),
                Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      item.inspectorName,
                      style: TextStyle(
                        fontSize: 26.sp,
                        fontWeight: FontWeight.bold,
                        color: const Color.fromRGBO(10, 13, 20, 1.0),
                      ),
                    ),
                    SizedBox(height: 4.h),
                    Row(
                      children: [
                        Icon(
                          Icons.access_time,
                          color: const Color.fromRGBO(100, 116, 139, 1.0),
                          size: 20.sp,
                        ),
                        SizedBox(width: 4.w),
                        Text(
                          item.inspectionTime,
                          style: TextStyle(
                            fontSize: 22.sp,
                            color: const Color.fromRGBO(100, 116, 139, 1.0),
                          ),
                        ),
                      ],
                    ),
                  ],
                ),
              ],
            ),
            Container(
              padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 6.h),
              decoration: BoxDecoration(
                color: const Color.fromRGBO(225, 245, 238, 1.0),
                borderRadius: BorderRadius.circular(10.r),
              ),
              child: Row(
                children: [
                  Icon(
                    Icons.check,
                    color: const Color.fromRGBO(26, 188, 156, 1.0),
                    size: 20.sp,
                  ),
                  SizedBox(width: 4.w),
                  Text(
                    item.result,
                    style: TextStyle(
                      fontSize: 22.sp,
                      color: const Color.fromRGBO(26, 188, 156, 1.0),
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                ],
              ),
            ),
          ],
        ),
        SizedBox(height: 16.h),
        Container(
          width: double.infinity,
          padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 12.h),
          decoration: BoxDecoration(
            color: const Color.fromRGBO(242, 243, 245, 1.0),
            borderRadius: BorderRadius.circular(12.r),
          ),
          child: Text(
            item.remark,
            style: TextStyle(
              fontSize: 22.sp,
              color: const Color.fromRGBO(100, 116, 139, 1.0),
            ),
          ),
        ),
        SizedBox(height: 20.h),
      ],
    );
  }
}
