"use client" import { useState, useEffect } from "react" import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" import { Badge } from "@/components/ui/badge" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" import { Checkbox } from "@/components/ui/checkbox" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select" import { Textarea } from "@/components/ui/textarea" import { Search, FileText, Folder, Tag, Clock, Eye, Download, Share2, Star, ChevronUp, Zap, Target, BookOpen, ImageIcon, FileSpreadsheet, FileVideo, Archive, MoreHorizontal, X, SortAsc, SortDesc, } from "lucide-react" export default function SearchPage() { const [searchQuery, setSearchQuery] = useState("") const [advancedSearch, setAdvancedSearch] = useState(false) const [searchResults, setSearchResults] = useState([]) const [isSearching, setIsSearching] = useState(false) const [searchStats, setSearchStats] = useState({ total: 0, documents: 0, folders: 0, searchTime: 0, }) // Advanced search filters const [filters, setFilters] = useState({ fileType: "all", dateRange: "all", author: "all", folder: "all", tags: "", content: "", exactPhrase: "", excludeWords: "", minSize: "", maxSize: "", }) const [sortBy, setSortBy] = useState("relevance") const [sortOrder, setSortOrder] = useState<"asc" | "desc">("desc") const [selectedResults, setSelectedResults] = useState([]) useEffect(() => { // Simuler une recherche automatique si il y a une query if (searchQuery.trim()) { performSearch() } else { setSearchResults([]) setSearchStats({ total: 0, documents: 0, folders: 0, searchTime: 0 }) } }, [searchQuery, filters, sortBy, sortOrder]) const performSearch = async () => { setIsSearching(true) const startTime = Date.now() // Simuler un délai de recherche await new Promise((resolve) => setTimeout(resolve, 500)) // Données de démonstration pour les résultats de recherche const mockResults = [ { id: 1, type: "document", name: "Contrat_Client_ABC.pdf", path: "/Contrats/Clients/", content: "Contrat de prestation de services avec le client ABC Corporation...", size: "2.4 MB", modified: new Date("2024-01-15T10:30:00"), author: "Marie Dubois", tags: ["contrat", "client", "juridique"], relevance: 95, highlights: ["Contrat", "client ABC", "prestation de services"], fileType: "PDF", thumbnail: "/placeholder.svg?height=60&width=60&text=PDF", }, { id: 2, type: "folder", name: "Projets Alpha", path: "/Projets/", content: "Dossier contenant tous les documents du projet Alpha", documentsCount: 23, modified: new Date("2024-01-14T16:45:00"), author: "Jean Martin", tags: ["projet", "alpha", "développement"], relevance: 88, highlights: ["Projet Alpha", "développement"], }, { id: 3, type: "document", name: "Rapport_Mensuel_Nov.docx", path: "/Rapports/2024/", content: "Rapport mensuel de novembre avec analyse des performances...", size: "1.8 MB", modified: new Date("2024-01-13T08:45:00"), author: "Sophie Laurent", tags: ["rapport", "mensuel", "analyse"], relevance: 82, highlights: ["Rapport mensuel", "novembre", "performances"], fileType: "DOCX", thumbnail: "/placeholder.svg?height=60&width=60&text=DOCX", }, { id: 4, type: "document", name: "Budget_2024.xlsx", path: "/Finance/Budgets/", content: "Budget prévisionnel pour l'année 2024 avec détail par département...", size: "892 KB", modified: new Date("2024-01-12T14:20:00"), author: "Marie Dubois", tags: ["budget", "2024", "finance"], relevance: 76, highlights: ["Budget", "2024", "prévisionnel"], fileType: "XLSX", thumbnail: "/placeholder.svg?height=60&width=60&text=XLSX", }, { id: 5, type: "document", name: "Présentation_Projet.pptx", path: "/Projets/Alpha/", content: "Présentation du projet Alpha pour le comité de direction...", size: "5.2 MB", modified: new Date("2024-01-11T07:15:00"), author: "Jean Martin", tags: ["présentation", "projet", "alpha"], relevance: 71, highlights: ["Présentation", "projet Alpha", "comité"], fileType: "PPTX", thumbnail: "/placeholder.svg?height=60&width=60&text=PPTX", }, { id: 6, type: "document", name: "Formation_Équipe.mp4", path: "/Formation/Vidéos/", content: "Vidéo de formation pour l'équipe sur les nouvelles procédures...", size: "45.2 MB", modified: new Date("2024-01-10T11:30:00"), author: "Pierre Durand", tags: ["formation", "vidéo", "équipe"], relevance: 65, highlights: ["Formation", "équipe", "procédures"], fileType: "MP4", thumbnail: "/placeholder.svg?height=60&width=60&text=MP4", }, ] // Filtrer les résultats selon les critères let filteredResults = mockResults.filter((result) => { if ( !result.name.toLowerCase().includes(searchQuery.toLowerCase()) && !result.content.toLowerCase().includes(searchQuery.toLowerCase()) ) { return false } if ( filters.fileType !== "all" && result.type === "document" && result.fileType?.toLowerCase() !== filters.fileType.toLowerCase() ) { return false } if (filters.author !== "all" && result.author !== filters.author) { return false } return true }) // Trier les résultats filteredResults = filteredResults.sort((a, b) => { let aValue, bValue switch (sortBy) { case "name": aValue = a.name.toLowerCase() bValue = b.name.toLowerCase() break case "date": aValue = a.modified.getTime() bValue = b.modified.getTime() break case "author": aValue = a.author.toLowerCase() bValue = b.author.toLowerCase() break case "relevance": default: aValue = a.relevance bValue = b.relevance break } if (sortOrder === "asc") { return aValue > bValue ? 1 : -1 } else { return aValue < bValue ? 1 : -1 } }) const endTime = Date.now() const searchTime = (endTime - startTime) / 1000 setSearchResults(filteredResults) setSearchStats({ total: filteredResults.length, documents: filteredResults.filter((r) => r.type === "document").length, folders: filteredResults.filter((r) => r.type === "folder").length, searchTime, }) setIsSearching(false) } const getFileIcon = (type: string) => { switch (type?.toLowerCase()) { case "pdf": return case "docx": case "doc": return case "xlsx": case "xls": return case "pptx": case "ppt": return case "png": case "jpg": case "jpeg": return case "mp4": case "avi": return case "zip": case "rar": return default: return } } const formatDate = (date: Date) => { const now = new Date() const diffInHours = (now.getTime() - date.getTime()) / (1000 * 60 * 60) if (diffInHours < 1) { return "Il y a quelques minutes" } else if (diffInHours < 24) { return `Il y a ${Math.floor(diffInHours)} heure${Math.floor(diffInHours) > 1 ? "s" : ""}` } else if (diffInHours < 48) { return "Hier" } else { return date.toLocaleDateString("fr-FR") } } const highlightText = (text: string, highlights: string[]) => { let highlightedText = text highlights.forEach((highlight) => { const regex = new RegExp(`(${highlight})`, "gi") highlightedText = highlightedText.replace(regex, "$1") }) return highlightedText } const toggleResultSelection = (resultId: number) => { setSelectedResults((prev) => (prev.includes(resultId) ? prev.filter((id) => id !== resultId) : [...prev, resultId])) } const clearFilters = () => { setFilters({ fileType: "all", dateRange: "all", author: "all", folder: "all", tags: "", content: "", exactPhrase: "", excludeWords: "", minSize: "", maxSize: "", }) } return (
{/* Header */}

Recherche

Trouvez rapidement vos documents et dossiers

{/* Search Bar */}
setSearchQuery(e.target.value)} className="pl-10 text-lg h-12" /> {searchQuery && ( )}
{/* Quick Filters */}
{/* Advanced Search */} {advancedSearch && ( Recherche avancée
setFilters({ ...filters, exactPhrase: e.target.value })} />
setFilters({ ...filters, excludeWords: e.target.value })} />
setFilters({ ...filters, tags: e.target.value })} />