import 'package:fis_ui/index.dart';
import 'package:fis_ui/interface/interactive_container.dart';
import 'package:flutter/material.dart';

class FHoverBorderButton extends FStatefulWidget
    implements FInteractiveContainer {
  final double width;
  final IconData icon;
  final void Function()? onTap;
  final BoxDecoration? boxDecoration;
  FHoverBorderButton({
    this.width = 25,
    required this.icon,
    this.onTap,
    this.boxDecoration,
  });

  @override
  String get pageName => 'FHoverBorderButton';

  @override
  _HoverBorderButtonState createState() => _HoverBorderButtonState();
}

class _HoverBorderButtonState extends FState<FHoverBorderButton> {
  bool _isHovering = false;
  Color _hoverColor = Color(0xff1b1b1b);

  @override
  FWidget build(BuildContext context) {
    return FMouseRegion(
      onEnter: (_) => setState(() => _isHovering = true),
      onExit: (_) => setState(() => _isHovering = false),
      child: FGestureDetector(
        name: 'FHoverBorderButton',
        businessParent: widget,
        onTap: widget.onTap,
        child: FContainer(
          margin: EdgeInsets.symmetric(horizontal: 3),
          width: widget.width,
          height: double.infinity,
          alignment: Alignment.center,
          decoration: _isHovering
              ? BoxDecoration(
                  color: _hoverColor,
                  borderRadius: BorderRadius.all(Radius.circular(8)),
                  boxShadow: [
                    BoxShadow(
                      color: Color(0xff000000).withOpacity(0.35), // 更深的阴影颜色
                      offset: Offset(4, 4), // 横向偏移4个像素，纵向偏移4个像素
                      blurRadius: 10, // 模糊半径
                    ),
                    BoxShadow(
                      color: Color.fromARGB(255, 21, 25, 27)
                          .withOpacity(0.6), // 更深的内阴影颜色
                      offset: Offset(-3, -3), // 横向偏移-3个像素，纵向偏移-3个像素（内阴影）
                      blurRadius: 6, // 模糊半径
                    ),
                  ],
                )
              : widget.boxDecoration,
          child: FIcon(
            widget.icon,
            size: 25,
            color: Colors.white,
          ),
        ),
      ),
    );
  }
}
