'use client' import type { FC } from 'react' import React, { useCallback } from 'react' import { useBoolean } from 'ahooks' import { RiArrowDownSLine } from '@remixicon/react' import { useTranslation } from 'react-i18next' import FileIcon from '../document-file-icon' import DocumentList from './document-list' import { PortalToFollowElem, PortalToFollowElemContent, PortalToFollowElemTrigger, } from '@/app/components/base/portal-to-follow-elem' import cn from '@/utils/classnames' import Loading from '@/app/components/base/loading' import type { DocumentItem } from '@/models/datasets' type Props = { className?: string value: DocumentItem files: DocumentItem[] onChange: (value: DocumentItem) => void } const PreviewDocumentPicker: FC = ({ className, value, files, onChange, }) => { const { t } = useTranslation() const { name, extension } = value const [open, { set: setOpen, toggle: togglePopup, }] = useBoolean(false) const ArrowIcon = RiArrowDownSLine const handleChange = useCallback((item: DocumentItem) => { onChange(item) setOpen(false) }, [onChange, setOpen]) return (
{name || '--'}
{files?.length > 1 &&
{t('dataset.preprocessDocument', { num: files.length })}
} {files?.length > 0 ? ( ) : (
)}
) } export default React.memo(PreviewDocumentPicker)