import { useState } from 'react'; export default function ProfileProofPicker({ documents, value, onChange, disabled = false, }: { documents: { id: string; file_name: string }[]; value: string[]; onChange: (ids: string[]) => void; disabled?: boolean; }) { const [query, setQuery] = useState(''); const [showAll, setShowAll] = useState(false); const [limit, setLimit] = useState(10); const normalize = (text: string) => text .normalize('NFD') .replace(/\p{Diacritic}/gu, '') .toLocaleLowerCase(); const matches = documents.filter((document) => normalize(document.file_name).includes(normalize(query)), ); const toggle = (id: string) => onChange( value.includes(id) ? value.filter((item) => item !== id) : [...value, id], ); return (
Escolher comprovativos

Escolha os seus documentos que sustentam este pedido. A lista contém ficheiros próprios com análise antimalware concluída; não confirma a sua adequação como comprovativo.

{value.length} comprovativos escolhidos

{value.map((id) => (
{documents.find((document) => document.id === id) ?.file_name ?? 'Ficheiro seleccionado indisponível nesta consulta'}
))} {(query || showAll) && (

{matches.length} ficheiros encontrados · a mostrar até{' '} {Math.min(limit, matches.length)}

{matches.slice(0, limit).map((document) => ( ))} {matches.length > limit && ( )}
)}
); }