import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:smart_hotel_app/views/service/index/cubit/service_index_cubit.dart';
import 'package:smart_hotel_app/views/service/index/cubit/service_index_state.dart';
import 'package:smart_hotel_app/views/service/index/widget/room_management_block.dart';
import 'package:smart_hotel_app/views/service/index/widget/service_head_block.dart';
import 'package:smart_hotel_app/views/service/index/widget/service_stats_block.dart';

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

  @override
  Widget build(BuildContext context) {
    return BlocProvider(
      create: (_) => ServiceIndexCubit(),
      child: LayoutBuilder(
        builder: (context, constraints) {
          return SingleChildScrollView(
            child: ConstrainedBox(
              constraints: BoxConstraints(
                minHeight: constraints.maxHeight,
              ),
              child: Container(
                width: double.infinity,
                color: const Color.fromRGBO(242, 243, 245, 1),
                padding: EdgeInsets.symmetric(horizontal: 28.w),
                child: BlocBuilder<ServiceIndexCubit, ServiceIndexState>(
                  builder: (context, state) {
                    return Column(
                      children: [
                        const ServiceHeadBlock(),
                        ServiceStatsBlock(
                          pendingCount: state.pendingCount,
                          occupiedCount: state.occupiedRooms,
                          vacantCount: state.vacantRooms,
                        ),
                        RoomManagementBlock(),
                      ],
                    );
                  },
                ),
              ),
            ),
          );
        },
      ),
    );
  }
}