import 'package:flutter/material.dart';

class MapInfoCard extends StatelessWidget {
  final Widget title;
  final Widget child;
  final VoidCallback? onClose;

  const MapInfoCard({
    super.key,
    required this.title,
    required this.child,
    this.onClose,
  });

  @override
  Widget build(BuildContext context) {
    final colorScheme = Theme.of(context).colorScheme;
    final screenWidth = MediaQuery.sizeOf(context).width;

    return Material(
      elevation: 6,
      color: colorScheme.surface.withOpacity(0.64),
      borderRadius: BorderRadius.circular(18),
      child: Container(
        width: screenWidth - 60,
        padding: const EdgeInsets.fromLTRB(6, 2, 6, 2),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(18),
          border: Border.all(
            color: colorScheme.outlineVariant.withOpacity(0.7),
          ),
        ),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            Row(
              children: [
                Expanded(child: title),
                if (onClose != null)
                  IconButton(
                    visualDensity: VisualDensity.compact,
                    tooltip: 'Kártya bezárása',
                    icon: const Icon(Icons.close, size: 18),
                    onPressed: onClose,
                  ),
              ],
            ),
            const SizedBox(height: 1),
            child,
          ],
        ),
      ),
    );
  }
}
