'use client'; import { useState } from 'react'; import { TaskPriority } from '@/lib/types'; import { Button } from '@/components/ui/Button'; import { Input } from '@/components/ui/Input'; import { useTasksContext } from '@/contexts/TasksContext'; export interface KanbanFilters { search?: string; tags?: string[]; priorities?: TaskPriority[]; showCompleted?: boolean; compactView?: boolean; swimlanesByTags?: boolean; } interface KanbanFiltersProps { filters: KanbanFilters; onFiltersChange: (filters: KanbanFilters) => void; } export function KanbanFilters({ filters, onFiltersChange }: KanbanFiltersProps) { const { tags: availableTags } = useTasksContext(); const [isExpanded, setIsExpanded] = useState(false); const handleSearchChange = (search: string) => { onFiltersChange({ ...filters, search: search || undefined }); }; const handleTagToggle = (tagName: string) => { const currentTags = filters.tags || []; const newTags = currentTags.includes(tagName) ? currentTags.filter(t => t !== tagName) : [...currentTags, tagName]; onFiltersChange({ ...filters, tags: newTags.length > 0 ? newTags : undefined }); }; const handlePriorityToggle = (priority: TaskPriority) => { const currentPriorities = filters.priorities || []; const newPriorities = currentPriorities.includes(priority) ? currentPriorities.filter(p => p !== priority) : [...currentPriorities, priority]; onFiltersChange({ ...filters, priorities: newPriorities.length > 0 ? newPriorities : undefined }); }; const handleCompactViewToggle = () => { onFiltersChange({ ...filters, compactView: !filters.compactView }); }; const handleSwimlanesToggle = () => { onFiltersChange({ ...filters, swimlanesByTags: !filters.swimlanesByTags }); }; const handleClearFilters = () => { onFiltersChange({}); }; const hasActiveFilters = filters.search || filters.tags?.length || filters.priorities?.length; const priorityOptions: { value: TaskPriority; label: string; color: string }[] = [ { value: 'urgent', label: 'Urgent', color: 'bg-red-500' }, { value: 'high', label: 'Haute', color: 'bg-orange-500' }, { value: 'medium', label: 'Moyenne', color: 'bg-yellow-500' }, { value: 'low', label: 'Basse', color: 'bg-blue-500' } ]; return (
{/* Header avec recherche et bouton expand */}
handleSearchChange(e.target.value)} placeholder="Rechercher des tâches..." className="bg-slate-800/50 border-slate-600" />
{/* Bouton swimlanes par tags */} {/* Bouton vue compacte */} {hasActiveFilters && ( )}
{/* Filtres étendus */} {isExpanded && (
{/* Filtres par priorité */}
{priorityOptions.map((priority) => ( ))}
{/* Filtres par tags */} {availableTags.length > 0 && (
{availableTags.map((tag) => ( ))}
)} {/* Résumé des filtres actifs */} {hasActiveFilters && (
Filtres actifs
{filters.search && (
Recherche: “{filters.search}”
)} {filters.priorities?.length && (
Priorités: {filters.priorities.join(', ')}
)} {filters.tags?.length && (
Tags: {filters.tags.join(', ')}
)}
)}
)}
); }