'use client' import type { FC } from 'react' import type { DocumentItem } from '@/models/datasets' import { RiArrowDownSLine } from '@remixicon/react' import { useBoolean } from 'ahooks' import * as React from 'react' import { useCallback } from 'react' import { useTranslation } from 'react-i18next' import Loading from '@/app/components/base/loading' import { PortalToFollowElem, PortalToFollowElemContent, PortalToFollowElemTrigger, } from '@/app/components/base/portal-to-follow-elem' import { cn } from '@/utils/classnames' import FileIcon from '../document-file-icon' import DocumentList from './document-list' type Props = { className?: string value?: DocumentItem files: DocumentItem[] onChange: (value: DocumentItem) => void } const PreviewDocumentPicker: FC = ({ className, value, files, onChange, }) => { const { t } = useTranslation() const name = value?.name || '' const extension = value?.extension 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('preprocessDocument', { ns: 'dataset', num: files.length })}
} {files?.length > 0 ? ( ) : (
)}
) } export default React.memo(PreviewDocumentPicker)