import 'package:flutter/material.dart';
import '../tokens/unionflow_colors.dart';

/// Filtre de période pour le dashboard
enum PeriodFilter {
  today('Aujourd\'hui'),
  week('Cette semaine'),
  month('Ce mois'),
  quarter('Ce trimestre'),
  year('Cette année'),
  custom('Personnalisé');

  final String label;
  const PeriodFilter(this.label);
}

/// Widget de sélection de période
class UnionPeriodFilter extends StatelessWidget {
  final PeriodFilter selectedPeriod;
  final Function(PeriodFilter) onPeriodChanged;
  final bool showCustom;

  const UnionPeriodFilter({
    super.key,
    required this.selectedPeriod,
    required this.onPeriodChanged,
    this.showCustom = false,
  });

  @override
  Widget build(BuildContext context) {
    final periods = showCustom
        ? PeriodFilter.values
        : PeriodFilter.values.where((p) => p != PeriodFilter.custom).toList();

    return Container(
      padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
      decoration: BoxDecoration(
        color: UnionFlowColors.surface,
        borderRadius: BorderRadius.circular(16),
        boxShadow: UnionFlowColors.softShadow,
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          const Row(
            children: [
              Icon(
                Icons.calendar_today,
                size: 16,
                color: UnionFlowColors.unionGreen,
              ),
              SizedBox(width: 8),
              Text(
                'Période',
                style: TextStyle(
                  fontSize: 13,
                  fontWeight: FontWeight.w600,
                  color: UnionFlowColors.textPrimary,
                ),
              ),
            ],
          ),
          const SizedBox(height: 12),
          Wrap(
            spacing: 8,
            runSpacing: 8,
            children: periods.map((period) {
              final isSelected = selectedPeriod == period;
              return GestureDetector(
                onTap: () => onPeriodChanged(period),
                child: AnimatedContainer(
                  duration: const Duration(milliseconds: 200),
                  padding: const EdgeInsets.symmetric(
                    horizontal: 14,
                    vertical: 8,
                  ),
                  decoration: BoxDecoration(
                    gradient: isSelected
                        ? UnionFlowColors.primaryGradient
                        : null,
                    color: isSelected
                        ? null
                        : UnionFlowColors.surfaceVariant,
                    borderRadius: BorderRadius.circular(20),
                    border: Border.all(
                      color: isSelected
                          ? UnionFlowColors.unionGreen
                          : UnionFlowColors.border,
                      width: isSelected ? 1.5 : 1,
                    ),
                  ),
                  child: Text(
                    period.label,
                    style: TextStyle(
                      fontSize: 12,
                      fontWeight: isSelected ? FontWeight.w700 : FontWeight.w600,
                      color: isSelected
                          ? Colors.white
                          : UnionFlowColors.textSecondary,
                    ),
                  ),
                ),
              );
            }).toList(),
          ),
        ],
      ),
    );
  }
}
