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: 20.w, vertical: 20.h),
        margin: EdgeInsets.only(bottom: 16.h),
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(24.r),
        ),
        child: Row(
          children: [
            Container(
              width: 112.w,
              height: 90.h,
              alignment: Alignment.center,
              decoration: BoxDecoration(
                color: const Color.fromRGBO(229, 241, 255, 1),
                borderRadius: BorderRadius.circular(24.r),
              ),
              child: Image.asset(
                item.icon,
                width: 48.w,
                height: 48.h,
              ),
            ),
            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: 56.sp,
              ),
          ],
        ),
      ),
    );
  }

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

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