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/index/cubit/home_index_cubit.dart';
import 'package:smart_hotel_app/views/home/index/cubit/home_index_state.dart';
import 'package:smart_hotel_app/views/home/index/widget/equipment_list_block.dart';
import 'package:smart_hotel_app/views/home/index/widget/task_head_block.dart';
import 'package:smart_hotel_app/views/home/index/widget/task_total_block.dart';
import 'package:smart_hotel_app/views/home/index/widget/temperature_block.dart';
import 'package:smart_hotel_app/views/home/index/widget/voltage_operate_block.dart';

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

  @override
  Widget build(BuildContext context) {
    return BlocProvider(
      create: (_) => HomeIndexCubit(),
      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<HomeIndexCubit, HomeIndexState>(
                  builder: (context, state) {
                    return Column(
                      children: [
                        const TaskHeadBlock(),
                        SizedBox(height: 20.h),
                        TaskTotalBlock(
                          highAlarmCount: state.highAlarmCount,
                          mediumAlarmCount: state.mediumAlarmCount,
                          onlineDeviceCount: state.onlineDeviceCount,
                        ),
                        SizedBox(height: 20.h),
                        TemperatureBlock(
                          temperatureAlarmTitle: state.temperatureAlarmTitle,
                          temperatureAlarmLocation: state.temperatureAlarmLocation,
                          currentTemperature: state.currentTemperature,
                          currentVoltage: state.currentVoltage,
                          currentCurrent: state.currentCurrent,
                          waitTime: state.waitTime,
                          alarmLevel: state.alarmLevel,
                        ),
                        SizedBox(height: 20.h),
                        VoltageOperateBlock(
                          voltageAlarmTitle: state.voltageAlarmTitle,
                          voltageAlarmLocation: state.voltageAlarmLocation,
                          voltageValue: state.voltageValue,
                          normalVoltage: state.normalVoltage,
                          voltageWaitTime: state.voltageWaitTime,
                          voltageAlarmLevel: state.voltageAlarmLevel,
                        ),
                        SizedBox(height: 20.h),
                        EquipmentListBlock(
                          equipmentList: state.equipmentList,
                        ),
                        SizedBox(height: 20.h),
                      ],
                    );
                  },
                ),
              ),
            ),
          );
        },
      ),
    );
  }
}