'use client' import { useState } from 'react' import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@/components/ui/card' import { Button } from '@/components/ui/button' import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select' import { Label } from '@/components/ui/label' /** A field that can be mapped to a column in the uploaded file. */ export interface RegisterColumnSpec { key: K label: string required: boolean } interface RegisterColumnMappingStepProps { headers: string[] previewRows: string[][] specs: RegisterColumnSpec[] initial: Record onConfirm: (mapping: Record) => void onBack: () => void } export default function RegisterColumnMappingStep({ headers, previewRows, specs, initial, onConfirm, onBack, }: RegisterColumnMappingStepProps) { const [mapping, setMapping] = useState>(initial) const columnOptions = headers.map((h, i) => ({ value: String(i), label: `${i + 1}: ${h || '(tom)'}`, })) const canContinue = specs .filter((s) => s.required) .every((s) => mapping[s.key] !== null && mapping[s.key]! >= 0) return ( Kolumnmappning Vi kunde inte automatiskt identifiera alla kolumner. Ange vilka kolumner i din fil som motsvarar respektive fält. Lämna tomt för fält som inte finns.
{specs.map((spec) => (
))}
{previewRows.length > 0 && (
{headers.map((h, i) => ( ))} {previewRows.slice(0, 5).map((row, ri) => ( {row.map((cell, ci) => ( ))} ))}
{h || `Kolumn ${i + 1}`}
{cell}
)}
) }