content: import 'package:flutter/material.dart';
  import 'package:flutter_screenutil/flutter_screenutil.dart';
  import '../../../../models/brief_ai_tools/character_chat/character_card.dart';
  import '../../_chat_components/_small_tool_widgets.dart';
  
  class CharacterCardItem extends StatelessWidget {
    final CharacterCard character;
    final VoidCallback onTap;
    final VoidCallback onEdit;
    final VoidCallback onDelete;
  
    const CharacterCardItem({
      super.key,
      required this.character,
      required this.onTap,
      required this.onEdit,
      required this.onDelete,
    });
  
    @override
    Widget build(BuildContext context) {
      return Card(
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(12.sp),
        ),
        child: GestureDetector(
          onTap: onTap,
          onLongPress: () => _showContextMenu(context),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: [
              // 角色头像
              avatarArea(),
  
              SizedBox(height: 4.sp),
  
              // 角色信息
              infoArea(context),
            ],
          ),
        ),
      );
    }
  
    Widget avatarArea() {
      return Expanded(
        flex: 2,
        child: ClipRRect(
          borderRadius: BorderRadius.only(
            topLeft: Radius.circular(12.sp),
            topRight: Radius.circular(12.sp),
          ),
          child: buildAvatarClipOval(character.avatar, clipBehavior: Clip.none),
        ),
      );
    }
  
    Widget infoArea(BuildContext context) {
      return Expanded(
        flex: 1,
        child: Padding(
          padding: EdgeInsets.symmetric(horizontal: 8.sp, vertical: 8.sp),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              // 角色名称和系统标签
              Row(
                children: [
                  Expanded(
                    child: Text(
                      character.name,
                      style: TextStyle(
                        fontSize: 16.sp,
                        fontWeight: FontWeight.bold,
                      ),
                      maxLines: 1,
                      overflow: TextOverflow.ellipsis,
                    ),
                  ),
                  if (character.isSystem)
                    Container(
                      padding: EdgeInsets.all(2.sp),
                      decoration: BoxDecoration(
                        color: Colors.blue.withValues(alpha: 0.2),
                        borderRadius: BorderRadius.circular(4.sp),
                      ),
                      child: Text(
                        '系统',
                        style: TextStyle(fontSize: 10.sp, color: Colors.blue),
                      ),
                    ),
                ],
              ),
  
              // 角色描述
              Expanded(
                child: Text(
                  character.description,
                  style: TextStyle(fontSize: 12.sp, color: Colors.grey[600]),
                  maxLines: 2,
                  overflow: TextOverflow.ellipsis,
                ),
              ),
            ],
          ),
        ),
      );
    }
  
    void _showContextMenu(BuildContext context) {
      final RenderBox button = context.findRenderObject() as RenderBox;
      final RenderBox overlay =
          Overlay.of(context).context.findRenderObject() as RenderBox;
      final RelativeRect position = RelativeRect.fromRect(
        Rect.fromPoints(
          button.localToGlobal(Offset.zero, ancestor: overlay),
          button.localToGlobal(button.size.bottomRight(Offset.zero),
              ancestor: overlay),
        ),
        Offset.zero & overlay.size,
      );
  
      showMenu(
        context: context,
        position: position,
        items: [
          PopupMenuItem(
            onTap: onEdit,
            child: Row(
              children: [
                Icon(Icons.edit, color: Theme.of(context).primaryColor),
                SizedBox(width: 8.sp),
                Text('编辑角色'),
              ],
            ),
          ),
          if (!character.isSystem)
            PopupMenuItem(
              onTap: onDelete,
              child: Row(
                children: [
                  Icon(Icons.delete, color: Colors.red),
                  SizedBox(width: 8.sp),
                  Text('删除角色'),
                ],
              ),
            ),
        ],
      );
    }
  }
  