import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';

class TabMenuButton extends StatelessWidget {
  final String? label;
  final String? icon;
  final VoidCallback onPress;
  final bool isSelected;

  const TabMenuButton({
    super.key,
    this.label,
    this.icon,
    required this.onPress,
    this.isSelected = false,
  });

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        if (icon != null && icon!.isNotEmpty)
          IconButton(
            icon: SvgPicture.asset(
              icon!,
              width: 28,
              height: 28,
              colorFilter: ColorFilter.mode(
                isSelected
                    ? const Color.fromARGB(255, 106, 24, 207)
                    : Colors.white,
                BlendMode.srcIn,
              ),
            ),
            onPressed: onPress, // Semua aksi klik hanya lewat satu function
          ),
        GestureDetector(
          onTap: onPress, // Menggunakan satu event handler saja
          child: Container(
            width: 120,
            padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 16),
            decoration: BoxDecoration(
              color:
                  isSelected
                      ? const Color.fromARGB(
                        255,
                        199,
                        204,
                        212,
                      ).withOpacity(0.3)
                      : Colors.transparent,
              borderRadius: BorderRadius.circular(20),
            ),
            child: Center(
              child: Text(
                label ?? '',
                style: TextStyle(
                  fontSize: 16,
                  fontWeight: FontWeight.bold,
                  color:
                      isSelected
                          ? const Color.fromARGB(255, 0, 0, 0)
                          : const Color.fromARGB(255, 0, 0, 0),
                ),
              ),
            ),
          ),
        ),
      ],
    );
  }
}
