import 'package:flutter/material.dart';
import '../../utils/constants.dart';

/// 应用卡片组件
class AppCard extends StatelessWidget {
  final Widget? title;
  final List<Widget>? actions;
  final Widget child;
  final EdgeInsets? padding;
  final EdgeInsets? margin;
  final bool hoverable;
  final VoidCallback? onTap;

  const AppCard({
    Key? key,
    this.title,
    this.actions,
    required this.child,
    this.padding,
    this.margin,
    this.hoverable = false,
    this.onTap,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    Widget card = Card(
      elevation: 2,
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
      margin: margin ?? const EdgeInsets.all(0),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisSize: MainAxisSize.min,
        children: [
          if (title != null || actions != null)
            Padding(
              padding: EdgeInsets.fromLTRB(
                AppSpacing.md,
                AppSpacing.md,
                AppSpacing.sm,
                title != null ? AppSpacing.sm : AppSpacing.md,
              ),
              child: Row(
                children: [
                  if (title != null) Expanded(child: title!),
                  if (actions != null) ...actions!,
                ],
              ),
            ),
          Padding(
            padding:
                padding ?? EdgeInsets.all(title != null ? 0 : AppSpacing.md),
            child: child,
          ),
        ],
      ),
    );

    if (onTap != null) {
      card = InkWell(
        onTap: onTap,
        borderRadius: BorderRadius.circular(8),
        child: card,
      );
    }

    if (hoverable) {
      card = MouseRegion(
        cursor:
            onTap != null ? SystemMouseCursors.click : SystemMouseCursors.basic,
        child: card,
      );
    }

    return card;
  }
}
