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

class HaloChip extends StatelessWidget {
  const HaloChip({
    super.key,
    required this.label,
    required this.selected,
    required this.onTap,
    this.icon,
  });

  final String label;
  final bool selected;
  final VoidCallback? onTap;
  final Widget? icon;

  @override
  Widget build(BuildContext context) {
    final disabled = onTap == null;
    final bgColor = selected
        ? HaloTokens.brand
        : disabled
            ? HaloTokens.brandSofter
            : HaloTokens.surface;
    final fgColor = selected
        ? Colors.white
        : disabled
            ? HaloTokens.inkMuted
            : HaloTokens.ink;
    final borderColor = selected ? HaloTokens.brand : HaloTokens.border;

    return Material(
      color: bgColor,
      borderRadius: HaloRadius.pill,
      child: InkWell(
        onTap: onTap,
        borderRadius: HaloRadius.pill,
        child: AnimatedContainer(
          duration: HaloMotion.fast,
          curve: HaloMotion.ease,
          padding: const EdgeInsets.symmetric(
            horizontal: HaloSpacing.s16,
            vertical: HaloSpacing.s8,
          ),
          decoration: BoxDecoration(
            border: Border.all(color: borderColor),
            borderRadius: HaloRadius.pill,
          ),
          child: Row(
            mainAxisSize: MainAxisSize.min,
            children: [
              if (icon != null) ...[
                IconTheme(
                  data: IconThemeData(size: 16, color: fgColor),
                  child: icon!,
                ),
                const SizedBox(width: HaloSpacing.s8),
              ],
              Text(
                label,
                style: TextStyle(
                  fontFamily: HaloTokens.fontBody,
                  fontSize: 14,
                  fontWeight: FontWeight.w500,
                  color: fgColor,
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
