import 'package:flutter/material.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';
import '../../core/i18n/app_localizations.dart';
import '../../core/theme/app_colors_extension.dart';

class ReportFilterBar extends StatelessWidget {
  final List<FilterItem> filters;
  final VoidCallback onApply;
  final VoidCallback onReset;

  const ReportFilterBar({
    super.key,
    required this.filters,
    required this.onApply,
    required this.onReset,
  });

  @override
  Widget build(BuildContext context) {
    final colors = Theme.of(context).extension<AppColorsExtension>()!;
    final l10n = AppLocalizations.of(context);
    return Container(
      padding: const EdgeInsets.all(12),
      decoration: BoxDecoration(
        color: colors.bgCard,
        borderRadius: BorderRadius.circular(10),
      ),
      child: Column(
        children: [
          Wrap(
            spacing: 8,
            runSpacing: 8,
            children: filters.map((f) {
              return GestureDetector(
                onTap: f.onTap,
                child: Container(
                  padding: const EdgeInsets.symmetric(
                    horizontal: 10,
                    vertical: 6,
                  ),
                  decoration: BoxDecoration(
                    border: Border.all(color: colors.timelineInactive),
                    borderRadius: BorderRadius.circular(6),
                  ),
                  child: Row(
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      Text(
                        f.label,
                        style: TextStyle(
                          fontSize: 11,
                          color: colors.textPrimary,
                        ),
                      ),
                      const SizedBox(width: 4),
                      Icon(
                        Icons.arrow_drop_down,
                        size: 16,
                        color: colors.textPlaceholder,
                      ),
                    ],
                  ),
                ),
              );
            }).toList(),
          ),
          const SizedBox(height: 10),
          Row(
            children: [
              Expanded(
                child: TDButton(
                  text: l10n.get('reset'),
                  type: TDButtonType.outline,
                  theme: TDButtonTheme.defaultTheme,
                  size: TDButtonSize.small,
                  onTap: onReset,
                ),
              ),
              const SizedBox(width: 8),
              Expanded(
                flex: 2,
                child: TDButton(
                  text: l10n.get('applyFilter'),
                  type: TDButtonType.fill,
                  theme: TDButtonTheme.primary,
                  size: TDButtonSize.small,
                  onTap: onApply,
                ),
              ),
            ],
          ),
        ],
      ),
    );
  }
}

class FilterItem {
  final String label;
  final String value;
  final VoidCallback onTap;
  const FilterItem({
    required this.label,
    required this.value,
    required this.onTap,
  });
}
