import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:kaer_with_panels/app/widgets/kr_local_image.dart';

// 1. 将 MenuItem 数据模型也移到这里，并设为公开
class MenuItem {
  final String iconName;
  final String title;
  final String? route; // 路由地址
  final VoidCallback? onTap; // 或者是一个点击回调

  const MenuItem({
    required this.iconName,
    required this.title,
    this.route,
    this.onTap,
  }) : assert(route != null || onTap != null,
            'Either route or onTap must be provided.');
// 使用 assert 强制要求 route 和 onTap 至少提供一个
}

// 2. MenuListItem 组件现在是这个文件的核心
class MenuListItem extends StatelessWidget {
  const MenuListItem({
    super.key,
    required this.item,
  });

  final MenuItem item;

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        // 优先处理 onTap 回调
        if (item.onTap != null) {
          item.onTap!();
        }
        // 如果没有 onTap，再处理 route 跳转
        else if (item.route != null) {
          Get.toNamed(item.route!);
        }
      },
      child: Container(
        height: 50,
        padding: EdgeInsets.fromLTRB(20.w, 7, 18.w, 7),
        decoration: BoxDecoration(
          color: Theme.of(context).primaryColor, // 使用主题的主色作为背景
          borderRadius: BorderRadius.circular(1000.r), // 添加圆角
        ),
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            KrLocalImage(
              imageName: item.iconName,
              imageType: ImageType.svg,
            ),
            SizedBox(width: 8.w),
            Expanded(
              child: Text(
                item.title,
                style: TextStyle(
                  color: Colors.black,
                  fontSize: 16.sp,
                  fontWeight: FontWeight.w600,
                ),
              ),
            ),
            KrLocalImage(
              imageName: 'arrow-right-icon',
              imageType: ImageType.svg,
              color: Colors.black,
            ),
          ],
        ),
      ),
    );
  }
}
