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/report/room/cubit/room_report_cubit.dart';
import 'package:smart_hotel_app/views/report/room/cubit/room_report_state.dart';
import 'package:smart_hotel_app/views/report/room/widget/floor_selector.dart';
import 'package:smart_hotel_app/views/report/room/widget/room_grid.dart';
import 'package:smart_hotel_app/views/report/room/widget/status_stats.dart';
import 'package:smart_hotel_app/views/report/room/widget/room_detail_card.dart';

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

  @override
  Widget build(BuildContext context) {
    return BlocProvider(
      create: (_) => RoomReportCubit(),
      child: BlocBuilder<RoomReportCubit, RoomReportState>(
        builder: (context, state) {
          return Scaffold(
            backgroundColor: const Color.fromRGBO(242, 243, 245, 1),
            appBar: AppBar(
              backgroundColor: Colors.white,
              elevation: 0,
              leading: IconButton(
                icon: const Icon(Icons.arrow_back, color: Colors.black),
                onPressed: () {
                  context.popRoute();
                },
              ),
              title: Text(
                '客房详情',
                style: TextStyle(
                  color: Colors.black,
                  fontSize: 32.sp,
                  fontWeight: FontWeight.bold,
                ),
              ),
              centerTitle: true,
            ),
            body: SingleChildScrollView(
              child: Column(
                children: [
                  Padding(
                    padding: EdgeInsets.symmetric(horizontal: 28.w),
                    child: Column(
                      children: [
                        SizedBox(height: 10.h),
                        if (state.floors.isNotEmpty)
                          Container(
                            decoration: BoxDecoration(
                              color: Colors.white,
                              borderRadius: BorderRadius.vertical(top: Radius.circular(24.r)),
                            ),
                            child: FloorSelector(
                              floorNames: state.floors.map((f) => f.floorName).toList(),
                              selectedIndex: state.selectedFloorIndex,
                            ),
                          ),
                        if (state.floors.isNotEmpty && state.selectedFloorIndex < state.floors.length)
                          Container(
                            decoration: BoxDecoration(
                              color: Colors.white,
                              borderRadius: BorderRadius.vertical(bottom: Radius.circular(24.r)),
                            ),
                            padding: EdgeInsets.only(bottom: 28.w),
                            child: RoomGrid(rooms: state.floors[state.selectedFloorIndex].rooms),
                          ),
                        SizedBox(height: 10.h),
                        if (state.statusStats.isNotEmpty)
                          StatusStats(stats: state.statusStats),
                        SizedBox(height: 10.h),
                        ...state.detailRooms.map((room) {
                          return Padding(
                            padding: EdgeInsets.only(bottom: 10.h),
                            child: RoomDetailCard(room: room),
                          );
                        }).toList(),
                        SizedBox(height: 10.h),
                      ],
                    ),
                  ),
                ],
              ),
            ),
          );
        },
      ),
    );
  }
}