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/service/device/cubit/service_device_cubit.dart';
import 'package:smart_hotel_app/views/service/device/cubit/service_device_state.dart';
import 'package:smart_hotel_app/views/service/device/widget/mode_selection_block.dart';
import 'package:smart_hotel_app/views/service/device/widget/temperature_control_block.dart';
import 'package:smart_hotel_app/views/service/device/widget/wind_speed_block.dart';

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

  @override
  Widget build(BuildContext context) {
    return BlocProvider(
      create: (_) => ServiceDeviceCubit(),
      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),
          child: BlocBuilder<ServiceDeviceCubit, ServiceDeviceState>(
            builder: (context, state) {
              final cubit = context.read<ServiceDeviceCubit>();
              return Column(
                children: [
                  SizedBox(height: 20.h),
                  TemperatureControlBlock(
                    isOn: state.isOn,
                    targetTemperature: state.targetTemperature,
                    currentTemperature: state.currentTemperature,
                    minTemperature: state.minTemperature,
                    maxTemperature: state.maxTemperature,
                    onTogglePower: cubit.togglePower,
                    onIncreaseTemperature: cubit.increaseTemperature,
                    onDecreaseTemperature: cubit.decreaseTemperature,
                  ),
                  SizedBox(height: 20.h),
                  ModeSelectionBlock(
                    modeData: state.modeData,
                    onSelectMode: cubit.selectMode,
                  ),
                  SizedBox(height: 20.h),
                  WindSpeedBlock(
                    currentSpeed: state.currentSpeed,
                    speedOptions: state.speedOptions,
                    onSetWindSpeed: cubit.setWindSpeed,
                  ),
                  SizedBox(height: 20.h),
                ],
              );
            },
          ),
        ),
      ),
    );
  }
}