import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:smart_hotel_app/routes/app_router.gr.dart';
import 'package:smart_hotel_app/views/profile/index/cubit/profile_state.dart';

class ProfileMenuBlock extends StatelessWidget {
  final List<MenuItem> menuList;
  final VoidCallback? onLogout;

  const ProfileMenuBlock({super.key, required this.menuList, this.onLogout});

  Widget _buildMenuItem(BuildContext context, MenuItem item) {
    return GestureDetector(
      onTap: () {
        if (item.onTap != null) {
          item.onTap!();
        } else {
          _handleMenuTap(context, item.title);
        }
      },
      child: Container(
        width: double.infinity,
        padding: EdgeInsets.symmetric(horizontal: 24.w, vertical: 28.h),
        margin: EdgeInsets.only(bottom: 16.h),
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(24.r),
        ),
        child: Row(
          children: [
            Container(
              width: 68.w,
              height: 68.h,
              decoration: BoxDecoration(
                color: const Color.fromRGBO(229, 241, 255, 1),
                borderRadius: BorderRadius.circular(28.r),
              ),
              child: Icon(
                item.icon,
                color: const Color.fromRGBO(66, 165, 245, 1.0),
                size: 40.sp,
              ),
            ),
            SizedBox(width: 24.w),
            Expanded(
              child: Text(
                item.title,
                style: TextStyle(
                  fontSize: 28.sp,
                  fontWeight: FontWeight.w500,
                  color: const Color.fromRGBO(100, 116, 139, 1.0),
                ),
              ),
            ),
            if (item.title == '告警信息' || item.title == '设备列表')
              Icon(Icons.chevron_right,
                color: const Color.fromRGBO(100, 116, 139, 1.0),
                size: 32.sp,
              ),
            
          ],
        ),
      ),
    );
  }

  void _handleMenuTap(BuildContext context, String title) {
    switch (title) {
      case '设备列表':
        context.pushRoute(const InspectionDetailRoute());
        break;
      case '告警信息':
        context.pushRoute(const AbnormalListRoute());
        break;
      case '退出登录':
        onLogout?.call();
        break;
      default:
        break;
    }
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      width: double.infinity,
      child: Column(
        children: [
          ...menuList.map((item) => _buildMenuItem(context, item)).toList(),
        ],
      ),
    );
  }
}