Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | import { useState } from 'react'
import { FileText, Globe, Upload, Link } from 'lucide-react'
import FileDropzone from './FileDropzone'
import UrlInput from './UrlInput'
export default function SourceSelector({
sourceType,
onSourceTypeChange,
file,
onFileSelect,
url,
onUrlChange,
onFileSubmit,
onUrlSubmit,
fileLoading = false,
urlLoading = false,
fileUrl,
onFileUrlChange,
onFileUrlSubmit
}) {
// Sous-mode pour l'onglet Fichier: 'upload' ou 'url'
const [fileMode, setFileMode] = useState('upload')
return (
<div className="space-y-4">
{/* Source Type Tabs */}
<div className="flex border-b border-gray-200">
<button
type="button"
onClick={() => onSourceTypeChange('file')}
className={`flex items-center px-4 py-3 text-sm font-medium border-b-2 transition-colors ${
sourceType === 'file' || sourceType === 'fileUrl'
? 'border-purple-500 text-purple-600'
: 'border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300'
}`}
>
<FileText className="w-4 h-4 mr-2" />
Fichier
</button>
<button
type="button"
onClick={() => onSourceTypeChange('url')}
className={`flex items-center px-4 py-3 text-sm font-medium border-b-2 transition-colors ${
sourceType === 'url'
? 'border-purple-500 text-purple-600'
: 'border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300'
}`}
>
<Globe className="w-4 h-4 mr-2" />
URL Web
</button>
</div>
{/* Source Input */}
<div className="pt-4">
{sourceType === 'file' || sourceType === 'fileUrl' ? (
<div className="space-y-4">
{/* File Mode Selection */}
<div className="flex gap-2 mb-4">
<button
type="button"
onClick={() => {
setFileMode('upload')
onSourceTypeChange('file')
}}
className={`flex-1 p-3 rounded-lg border-2 transition-all flex items-center justify-center gap-2 ${
fileMode === 'upload'
? 'border-purple-500 bg-purple-50 text-purple-700'
: 'border-gray-200 hover:border-gray-300 text-gray-600'
}`}
>
<Upload className="w-4 h-4" />
<span className="text-sm font-medium">Uploader</span>
</button>
<button
type="button"
onClick={() => {
setFileMode('url')
// Notifier le parent que c'est un URL de fichier
onSourceTypeChange('fileUrl')
}}
className={`flex-1 p-3 rounded-lg border-2 transition-all flex items-center justify-center gap-2 ${
fileMode === 'url'
? 'border-purple-500 bg-purple-50 text-purple-700'
: 'border-gray-200 hover:border-gray-300 text-gray-600'
}`}
>
<Link className="w-4 h-4" />
<span className="text-sm font-medium">URL fichier</span>
</button>
</div>
{/* File Mode Content */}
{fileMode === 'upload' ? (
<FileDropzone
onFileSelect={onFileSelect}
disabled={fileLoading}
/>
) : (
<div className="space-y-3">
<UrlInput
value={fileUrl || ''}
onChange={onFileUrlChange}
onSubmit={onFileUrlSubmit}
disabled={fileLoading}
loading={fileLoading}
placeholder="https://example.com/document.pdf"
buttonText="Extraire PDF"
icon="file"
/>
<p className="text-xs text-gray-500">
Formats supportés : PDF, DOCX, images. Le fichier sera téléchargé puis analysé.
</p>
</div>
)}
</div>
) : (
<UrlInput
value={url}
onChange={onUrlChange}
onSubmit={onUrlSubmit}
disabled={urlLoading}
loading={urlLoading}
placeholder="https://example.com"
buttonText="Extraire"
/>
)}
</div>
</div>
)
}
|