import 'package:fis_theme/theme.dart';
import 'package:fis_ui/index.dart';
import 'package:flutter/material.dart';

class FHoverTextTab extends FStatefulWidget {
  final String text;
  final VoidCallback onPressed;
  final bool isSelected;
  const FHoverTextTab({
    required this.text,
    required this.onPressed,
    this.isSelected = false,
  });

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

class _FHoverTextTabState extends FState<FHoverTextTab> {
  bool isHovering = false;
  bool _isSelected = false;
  Color get _defaultTextColor => Color.fromRGBO(113, 123, 133, 1);
  Color get _selectedColor => FTheme.ins.colorScheme.primary;
  @override
  void initState() {
    _isSelected = widget.isSelected;
    super.initState();
  }

  @override
  void didUpdateWidget(FHoverTextTab oldWidget) {
    if (oldWidget.isSelected != widget.isSelected) {
      setState(() {
        _isSelected = widget.isSelected;
      });
    }
    super.didUpdateWidget(oldWidget);
  }

  @override
  FWidget build(BuildContext context) {
    return FInkWell(
      onTap: () {
        widget.onPressed.call();
        // setState(() {
        //   _isSelected = !_isSelected;
        // });
      },
      onHover: (value) {
        setState(() {
          isHovering = value;
        });
      },
      child: Container(
        margin: EdgeInsets.symmetric(horizontal: 15),
        decoration: BoxDecoration(
          border: Border(
            bottom: BorderSide(
              color: (isHovering || _isSelected)
                  ? _selectedColor
                  : Colors.transparent,
              width: 2.0,
            ),
          ),
        ),
        child: Padding(
          padding: EdgeInsets.symmetric(vertical: 5.0),
          child: Text(
            widget.text,
            style: TextStyle(
              color: (isHovering || _isSelected)
                  ? _selectedColor
                  : _defaultTextColor,
              fontSize: 16.0,
              fontWeight: FontWeight.bold,
              decoration: TextDecoration.none,
            ),
            textAlign: TextAlign.center,
          ),
        ),
      ),
    );
  }
}
