import 'package:flutter/material.dart';

import 'package:pshared/models/recipient/filter.dart';


class RecipientFilterButton extends StatelessWidget {
  final String text;
  final RecipientFilter filter;
  final RecipientFilter selected;
  final ValueChanged<RecipientFilter> onTap;

  const RecipientFilterButton({
    super.key,
    required this.text,
    required this.filter,
    required this.selected,
    required this.onTap,
  });

  @override
  Widget build(BuildContext context) {
    final isSelected = selected == filter;
    final theme = Theme.of(context).colorScheme;

    return ElevatedButton(
      onPressed: () => onTap(filter),
      style: ButtonStyle(
        backgroundColor: WidgetStateProperty.all(Colors.transparent),
        overlayColor: WidgetStateProperty.all(Colors.transparent),
        shadowColor: WidgetStateProperty.all(Colors.transparent),
        elevation: WidgetStateProperty.all(0),
      ),
      child: IntrinsicWidth(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            Text(
              text,
              style: TextStyle(
                fontSize: 20,
                color: isSelected
                    ? theme.onPrimaryContainer
                    : theme.onPrimaryContainer.withAlpha(60),
              ),
            ),
            SizedBox(
              height: 2,
              child: DecoratedBox(
                decoration: BoxDecoration(
                  color: isSelected
                      ? theme.primary
                      : theme.onPrimaryContainer.withAlpha(60),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
