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/routes/app_router.gr.dart';
import 'package:smart_hotel_app/views/home/abnormal/cubit/abnormal_cubit.dart';
import 'package:smart_hotel_app/views/home/abnormal/cubit/abnormal_state.dart';
import 'package:smart_hotel_app/views/home/abnormal/widget/alarm_info_block.dart';
import 'package:smart_hotel_app/views/home/abnormal/widget/temperature_block.dart';
import 'package:smart_hotel_app/views/home/abnormal/widget/temperature_char_block.dart';

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

  @override
  Widget build(BuildContext context) {
    return BlocProvider(
      create: (_) => AbnormalCubit(),
      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<AbnormalCubit, AbnormalState>(
            builder: (context, state) {
              final cubit = context.read<AbnormalCubit>();
              return Column(
                children: [
                  TemperatureBlock(alarmInfo: state.alarmInfo),
                  SizedBox(height: 10.h),
                  TemperatureCharBlock(alarmInfo: state.alarmInfo),
                  SizedBox(height: 10.h),
                  AlarmInfoBlock(alarmInfo: state.alarmInfo),
                  SizedBox(height: 10.h),
                  _buildBottomButtons(context, cubit),
                  SizedBox(height: 30.h),
                ],
              );
            },
          ),
        ),
      ),
    );
  }

  Widget _buildBottomButtons(BuildContext context, AbnormalCubit cubit) {
    return Container(
      width: double.infinity,
      padding: EdgeInsets.symmetric(vertical: 15.h),
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          Container(
            width: double.infinity,
            height: 88.h,
            decoration: BoxDecoration(
              color: const Color.fromRGBO(73, 149, 234, 1),
              borderRadius: BorderRadius.circular(16.r),
            ),
            child: TextButton(
              onPressed: () => cubit.handleConfirm(),
              child: Text(
                '确认处理',
                style: TextStyle(
                  fontSize: 28.sp,
                  color: const Color.fromRGBO(237, 245, 255, 1),
                ),
              ),
            ),
          ),
          SizedBox(height: 20.h),
          Container(
            width: double.infinity,
            height: 88.h,
            decoration: BoxDecoration(
              color: const Color.fromRGBO(100, 116, 139, 0.2),
              borderRadius: BorderRadius.circular(16.r),
            ),
            child: TextButton(
              onPressed: () {
                context.pushRoute(const DeviceDetailRoute());
              },
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text(
                    '设备控制',
                    style: TextStyle(
                      fontSize: 28.sp,
                      color: const Color.fromRGBO(100, 116, 139, 1),
                    ),
                  ),
                  SizedBox(width: 8.w),
                  Image.asset(
                    "lib/assets/icon/right.png",
                    width: 24.w,
                    height: 21.h,
                  ),
                ],
              ),
            ),
          ),
        ],
      ),
    );
  }
}