import 'package:flutter/material.dart';
import 'package:flyinsono/global.dart';
import 'package:flyinsono/lab/color/lab_colors.dart';

class LogoItem extends StatefulWidget {
  const LogoItem({
    super.key,
    required this.isActive,
    required this.onTap,
  });

  final bool isActive;
  final VoidCallback onTap;

  @override
  State<LogoItem> createState() => _LogoItemState();
}

class _LogoItemState extends State<LogoItem> {
  bool _isHover = false;
  EdgeInsetsGeometry get innerPadding =>
      const EdgeInsets.only(left: 10, right: 10);

  @override
  Widget build(BuildContext context) {
    Color backgroundColor =
        widget.isActive ? LabColors.base300 : LabColors.tabBarButtonColor;
    Color iconColor = widget.isActive ? LabColors.text800 : LabColors.text300;
    if (_isHover) {
      backgroundColor =
          widget.isActive ? LabColors.base300 : LabColors.hoverButtonColor;
    }
    return Padding(
      padding: const EdgeInsets.only(left: 5, right: 5, top: 5),
      child: MouseRegion(
        onEnter: (event) => setState(() => _isHover = true),
        onExit: (event) => setState(() => _isHover = false),
        cursor: SystemMouseCursors.click,
        child: GestureDetector(
          onTap: widget.onTap,
          child: Container(
            height: double.infinity,
            padding: innerPadding,
            decoration: BoxDecoration(
              color: backgroundColor,
              borderRadius: BorderRadius.only(
                topLeft: Radius.circular(3),
                topRight: Radius.circular(3),
              ),
            ),
            child: Container(
              padding: const EdgeInsets.symmetric(vertical: 2),
              child: ColorFiltered(
                colorFilter: ColorFilter.mode(iconColor, BlendMode.srcIn),
                child: InkWell(
                  child: Image.asset(
                    "assets/images/logo_icon.png",
                    filterQuality: FilterQuality.high,
                    isAntiAlias: true,
                    fit: BoxFit.contain,
                  ),
                  onTap: widget.onTap,
                ),
              ),
            ),
          ),
        ),
      ),
    );
  }
}
