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/index/cubit/report_index_cubit.dart';
import 'package:smart_hotel_app/views/report/index/cubit/report_index_state.dart';
import 'package:smart_hotel_app/views/report/index/widget/device_online_rate.dart';
import 'package:smart_hotel_app/views/report/index/widget/quick_actions_block.dart';
import 'package:smart_hotel_app/views/report/index/widget/report_header_block.dart';
import 'package:smart_hotel_app/views/report/index/widget/report_metrics_block.dart';
import 'package:smart_hotel_app/views/report/index/widget/room_status_distribution.dart';
import 'package:smart_hotel_app/views/report/index/widget/weekly_power_chart.dart';

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

  @override
  Widget build(BuildContext context) {
    return BlocProvider(
      create: (_) => ReportIndexCubit(),
      child: BlocBuilder<ReportIndexCubit, ReportIndexState>(
        builder: (context, state) {
          return 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.only(left: 28.w, right: 28.w, top: ScreenUtil().statusBarHeight),
                    child: Column(
                      children: [
                        ReportHeaderBlock(
                            reportHeader: state.reportHeader),
                        SizedBox(height: 10.h),
                        ReportMetricsBlock(
                            reportMetrics: state.reportMetrics),
                        SizedBox(height: 10.h),
                        WeeklyPowerChart(
                            weeklyPowerUsage: state.weeklyPowerUsage),
                        SizedBox(height: 10.h),
                        RoomStatusDistribution(
                            roomStatusDistribution:
                                state.roomStatusDistribution),
                        SizedBox(height: 10.h),
                        DeviceOnlineRate(
                            deviceOnlineRate: state.deviceOnlineRate),
                        SizedBox(height: 10.h),
                        QuickActionsBlock(quickActions: state.quickActions),
                        SizedBox(height: 10.h),
                      ],
                    ),
                  ),
                ),
              );
            },
          );
        },
      ),
    );
  }
}