import React from 'react'
import { Upload, Loader2, CheckCircle, AlertCircle } from 'lucide-react'

interface IngestPanelProps {
  onUpload: (file: File) => void
  isLoading: boolean
  success: string | null
  error: string | null
}

export const IngestPanel: React.FC<IngestPanelProps> = ({
  onUpload,
  isLoading,
  success,
  error,
}) => {
  const handleFileChange = (event: React.ChangeEvent<HTMLInputElement>) => {
    const file = event.target.files?.[0]
    if (file) {
      onUpload(file)
    }
  }

  return (
    <div className="p-4 space-y-4">
      <input
        type="file"
        accept=".pdf,.docx,.txt"
        onChange={handleFileChange}
        disabled={isLoading}
        className="hidden"
        id="file-upload"
        data-testid="file-input"
      />
      <label
        htmlFor="file-upload"
        className={`inline-flex items-center space-x-2 px-4 py-2 rounded cursor-pointer ${
          isLoading
            ? 'bg-gray-300 cursor-not-allowed'
            : 'bg-blue-500 hover:bg-blue-600 text-white'
        }`}
      >
        {isLoading ? (
          <>
            <Loader2 className="w-4 h-4 animate-spin" />
            <span>Uploading...</span>
          </>
        ) : (
          <>
            <Upload className="w-4 h-4" />
            <span>Upload Document</span>
          </>
        )}
      </label>

      {success && (
        <div className="flex items-center space-x-2 text-green-700">
          <CheckCircle className="w-5 h-5" />
          <span>Uploaded {success}</span>
        </div>
      )}

      {error && (
        <div className="flex items-center space-x-2 text-red-700">
          <AlertCircle className="w-5 h-5" />
          <span>{error}</span>
        </div>
      )}
    </div>
  )
}
