import 'package:flutter/material.dart';
import 'plus_button_widget.dart'; // Make sure to import your PlusButtonWidget

class SpaceCardWidget extends StatelessWidget {
  final int index;
  final Size screenSize;
  final Offset position;
  final bool isHovered;
  final Function(int index, bool isHovered) onHoverChanged;
  final Function(int index, Offset newPosition) onButtonTap;
  final Widget Function(int index) buildSpaceContainer;
  final ValueChanged<Offset> onPositionChanged;

  const SpaceCardWidget({
    super.key,
    required this.index,
    required this.onPositionChanged,
    required this.screenSize,
    required this.position,
    required this.isHovered,
    required this.onHoverChanged,
    required this.onButtonTap,
    required this.buildSpaceContainer,
  });

  @override
  Widget build(BuildContext context) {
    return MouseRegion(
      onEnter: (_) => onHoverChanged(index, true),
      onExit: (_) => onHoverChanged(index, false),
      child: SizedBox(
        width: 140, // Make sure this covers both card and plus button
        height: 90,
        child: Stack(
          clipBehavior: Clip.none,
          children: [
            // Main card
            Container(
              width: 140,
              height: 80,
              alignment: Alignment.center,
              color: Colors.transparent,
              child: buildSpaceContainer(index),
            ),
            // Plus button (NO inner Positioned!)
            if (isHovered)
              Align(
                alignment: Alignment.bottomCenter,
                child: PlusButtonWidget(
                  index: index,
                  direction: 'down',
                  offset: Offset.zero,
                  onButtonTap: onButtonTap,
                ),
              ),
          ],
        ),
      ),
    );
  }
}
