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/abnormal_list/cubit/abnormal_list_cubit.dart';
import 'package:smart_hotel_app/views/home/abnormal_list/cubit/abnormal_list_state.dart';
import 'package:smart_hotel_app/views/home/abnormal_list/widget/alarm_list_item.dart';
import 'package:smart_hotel_app/views/home/abnormal_list/widget/filter_tab_block.dart';

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

  @override
  Widget build(BuildContext context) {
    return BlocProvider(
      create: (_) => AbnormalListCubit(),
      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: BlocBuilder<AbnormalListCubit, AbnormalListState>(
          builder: (context, state) {
            final cubit = context.read<AbnormalListCubit>();
            return SingleChildScrollView(
              padding: EdgeInsets.symmetric(horizontal: 28.w),
              child: Column(
                children: [
                  FilterTabBlock(
                    currentFilter: state.currentFilter,
                    onFilterChanged: cubit.setFilter,
                  ),
                  SizedBox(height: 10.h),
                  ...state.filteredList.map((item) {
                    return AlarmListItem(
                      item: item,
                      onTap: cubit.onAlarmItemTap,
                    );
                  }).toList(),
                  SizedBox(height: 30.h),
                ],
              ),
            );
          },
        ),
      ),
    );
  }
}
