import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'cubit/inspection_history_cubit.dart';
import 'cubit/inspection_history_state.dart';
import 'widget/statistics_card.dart';
import 'widget/inspection_record_list.dart';

@RoutePage()
class InspectionHistoryView extends StatelessWidget {
  final String deviceId;

  const InspectionHistoryView({super.key, @pathParam required this.deviceId});

  @override
  Widget build(BuildContext context) {
    return BlocProvider(
      create: (_) => InspectionHistoryCubit(deviceId: deviceId),
      child: Scaffold(
        backgroundColor: const Color.fromRGBO(242, 243, 245, 1),
        appBar: AppBar(
          backgroundColor: Colors.white,
          elevation: 0,
          leading: IconButton(
            icon: const Icon(Icons.arrow_back_ios,
            color: Color.fromRGBO(100, 116, 139, 1)),
            onPressed: () {
              context.popRoute();
            },
          ),
          title: Text(
            '巡检记录',
            style: TextStyle(
              color: const Color.fromRGBO(10, 13, 20, 1),
              fontSize: 32.sp,
              fontWeight: FontWeight.w200,
            ),
          ),
          centerTitle: true,
        ),
        body: SingleChildScrollView(
          padding: EdgeInsets.symmetric(horizontal: 28.w, vertical: 20.h),
          child: BlocBuilder<InspectionHistoryCubit, InspectionHistoryState>(
            builder: (context, state) {
              return Column(
                children: [
                  StatisticsCard(
                    totalCount: state.totalCount,
                    passCount: state.passCount,
                    warningCount: state.warningCount,
                    failCount: state.failCount,
                  ),
                  SizedBox(height: 20.h),
                  InspectionRecordList(
                    records: state.records,
                  ),
                  SizedBox(height: 30.h),
                ],
              );
            },
          ),
        ),
      ),
    );
  }
}