"use client" import { useRef, useState } from "react" import { Dialog, DialogContent, DialogHeader, DialogTitle, } from "@/components/ui/dialog" import { Button } from "@/components/ui/button" import { Info } from "lucide-react" import { useContactsStore } from "@/lib/contacts/contacts-store" import { parseContactFile } from "@/lib/contacts/import-parsers" interface ImportDialogProps { open: boolean onOpenChange: (open: boolean) => void } export function ImportDialog({ open, onOpenChange }: ImportDialogProps) { const fileRef = useRef(null) const addContacts = useContactsStore((s) => s.addContacts) const [pendingFile, setPendingFile] = useState(null) const [previewCount, setPreviewCount] = useState(0) const [error, setError] = useState(null) const [importing, setImporting] = useState(false) function resetState() { setPendingFile(null) setPreviewCount(0) setError(null) setImporting(false) if (fileRef.current) fileRef.current.value = "" } function handleOpenChange(next: boolean) { if (!next) resetState() onOpenChange(next) } function handleFileSelect() { fileRef.current?.click() } async function handleFileChange(e: React.ChangeEvent) { const file = e.target.files?.[0] if (!file) return setError(null) setPendingFile(file) try { const parsed = await parseContactFile(file) setPreviewCount(parsed.length) if (parsed.length === 0) { setError("Aucun contact trouvé dans ce fichier.") } } catch { setError("Impossible de lire ce fichier.") setPreviewCount(0) } } async function handleImport() { if (!pendingFile || previewCount === 0) return setImporting(true) setError(null) try { const parsed = await parseContactFile(pendingFile) const count = addContacts(parsed) if (count === 0) { setError("Aucun contact importé.") return } handleOpenChange(false) } catch { setError("L'import a échoué. Vérifiez le format du fichier.") } finally { setImporting(false) } } return (
Importer des contacts

Pour commencer, sélectionnez un fichier.
Utilisez le format CSV ou vCard (.vcf).

{pendingFile && previewCount > 0 && (

{previewCount} contact{previewCount > 1 ? "s" : ""} prêt {previewCount > 1 ? "s" : ""} à importer depuis{" "} {pendingFile.name}

)} {error &&

{error}

}

Vous essayez de sauvegarder les contacts de votre mobile ?
Voici comment les synchroniser.

) }