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 'package:smart_hotel_app/views/home/inspection/cubit/inspection_cubit.dart';
import 'package:smart_hotel_app/views/home/inspection/cubit/inspection_state.dart';
import 'package:smart_hotel_app/views/home/inspection/widget/filter_panel.dart';
import 'package:smart_hotel_app/views/home/inspection/widget/device_list.dart';

@RoutePage()
class InspectionDetailView extends StatelessWidget {
  const InspectionDetailView({super.key});

  @override
  Widget build(BuildContext context) {
    return BlocProvider(
      create: (_) => InspectionCubit(),
      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<InspectionCubit, InspectionState>(
            builder: (context, state) {
              final cubit = context.read<InspectionCubit>();
              return Column(
                children: [
                  FilterPanel(
                    selectedTab: state.selectedTab,
                    tabCounts: state.tabCounts,
                    onTabSelected: (tab) => cubit.selectTab(tab),
                    selectedRooms: state.selectedRooms,
                    onRoomToggle: (room) => cubit.toggleRoom(room),
                  ),
                  SizedBox(height: 20.h),
                  DeviceList(deviceList: state.deviceList),
                  SizedBox(height: 30.h),
                ],
              );
            },
          ),
        ),
      ),
    );
  }
}
