{"version":3,"file":"index.js","names":["c","_c","getTranslation","formatFilesize","React","Button","useDocumentDrawer","Pill","ThumbnailComponent","useConfig","useTranslation","baseClass","RelationshipContent","props","$","id","allowEdit","allowRemove","alt","byteSize","className","collectionSlug","displayPreview","filename","mimeType","onRemove","reloadDoc","showCollectionSlug","t0","src","thumbnailSrc","updatedAt","withMeta","t1","x","y","undefined","config","i18n","collectionConfig","collections","find","collection","slug","t2","t3","DocumentDrawer","t4","openDrawer","t5","t6","doc","onSave","generateMetaText","mimeType_0","size","sections","push","join","metaText","previewAllowed","upload","t7","filter","Boolean","_jsxs","children","_jsx","fileSrc","imageCacheTag","cacheTags","labels","singular","href","target","buttonStyle","icon","iconStyle","onClick"],"sources":["../../../../src/fields/Upload/RelationshipContent/index.tsx"],"sourcesContent":["'use client'\n\nimport type { TypeWithID } from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport { formatFilesize } from 'payload/shared'\nimport React from 'react'\n\nimport type { ReloadDoc } from '../types.js'\n\nimport { Button } from '../../../elements/Button/index.js'\nimport { useDocumentDrawer } from '../../../elements/DocumentDrawer/index.js'\nimport { Pill } from '../../../elements/Pill/index.js'\nimport { ThumbnailComponent } from '../../../elements/Thumbnail/index.js'\nimport './index.scss'\nimport { useConfig } from '../../../providers/Config/index.js'\nimport { useTranslation } from '../../../providers/Translation/index.js'\n\nconst baseClass = 'upload-relationship-details'\n\ntype Props = {\n readonly allowEdit?: boolean\n readonly allowRemove?: boolean\n readonly alt: string\n readonly byteSize: number\n readonly className?: string\n readonly collectionSlug: string\n readonly displayPreview?: boolean\n readonly filename: string\n readonly id?: number | string\n readonly mimeType: string\n readonly onRemove: () => void\n readonly reloadDoc: ReloadDoc\n readonly showCollectionSlug?: boolean\n readonly src: string\n readonly thumbnailSrc: string\n readonly updatedAt?: string\n readonly withMeta?: boolean\n readonly x?: number\n readonly y?: number\n}\nexport function RelationshipContent(props: Props) {\n const {\n id,\n allowEdit,\n allowRemove,\n alt,\n byteSize,\n className,\n collectionSlug,\n displayPreview,\n filename,\n mimeType,\n onRemove,\n reloadDoc,\n showCollectionSlug = false,\n src,\n thumbnailSrc,\n updatedAt,\n withMeta = true,\n x,\n y,\n } = props\n\n const { config } = useConfig()\n const { i18n } = useTranslation()\n const collectionConfig =\n 'collections' in config\n ? config.collections.find((collection) => collection.slug === collectionSlug)\n : undefined\n\n const [DocumentDrawer, _, { openDrawer }] = useDocumentDrawer({\n id: id ?? undefined,\n collectionSlug,\n })\n\n const onSave = React.useCallback(\n async ({ doc }: { doc: TypeWithID }) => reloadDoc(doc.id, collectionSlug),\n [reloadDoc, collectionSlug],\n )\n\n function generateMetaText(mimeType: string, size: number): string {\n const sections: string[] = []\n if (size) {\n sections.push(formatFilesize(size))\n }\n\n if (x && y) {\n sections.push(`${x}x${y}`)\n }\n\n if (mimeType) {\n sections.push(mimeType)\n }\n\n return sections.join(' — ')\n }\n\n const metaText = withMeta ? generateMetaText(mimeType, byteSize) : ''\n const previewAllowed = displayPreview ?? collectionConfig?.upload?.displayPreview ?? true\n\n return (\n
\n {src ? (\n \n {filename}\n \n ) : (\n filename\n )}\n
\n {withMeta ?{metaText}
: null}\n