'use client' import { useState, useCallback } from 'react' import { useTranslations } from 'next-intl' import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card' import { Progress } from '@/components/ui/progress' import { Upload, FileText, AlertCircle, HelpCircle } from 'lucide-react' interface SkattekontoFileUploadStepProps { onFileSelect: (file: File) => void isLoading: boolean error: string | null errorTitle?: string | null } const ACCEPTED_EXTENSIONS = ['.csv', '.txt', '.skv'] export default function SkattekontoFileUploadStep({ onFileSelect, isLoading, error, errorTitle, }: SkattekontoFileUploadStepProps) { const t = useTranslations('import') const [isDragging, setIsDragging] = useState(false) const acceptFile = useCallback( (file: File | undefined) => { if (!file) return const name = file.name.toLowerCase() if (ACCEPTED_EXTENSIONS.some((ext) => name.endsWith(ext))) { onFileSelect(file) } }, [onFileSelect], ) const handleDrop = useCallback( (e: React.DragEvent) => { e.preventDefault() setIsDragging(false) acceptFile(e.dataTransfer.files[0]) }, [acceptFile], ) return (
{t('skattekonto_upload_title')} {t('skattekonto_upload_description')}
{ e.preventDefault() setIsDragging(true) }} onDragLeave={(e) => { e.preventDefault() setIsDragging(false) }} onDrop={handleDrop} onClick={() => document.getElementById('skattekonto-file-input')?.click()} onKeyDown={(e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault() document.getElementById('skattekonto-file-input')?.click() } }} > acceptFile(e.target.files?.[0])} disabled={isLoading} /> {isLoading ? (

{t('skattekonto_analyzing')}

) : (

{t('skattekonto_drop_here')}

{t('skattekonto_tap_select')}

{t('skattekonto_file_types')}

)}
{error && (

{errorTitle || t('skattekonto_error_title')}

{error}

)}
{t('skattekonto_howto_title')}

Skatteverket

{t('skattekonto_howto_steps')}

{t('skattekonto_howto_note')}

) }