import React from 'react'
import { View, StyleSheet } from 'react-native'
import { useDeletingIds } from '../../hooks'
import {
DenormalizedAttachmentResource,
DenormalizedMessageAttachmentResource,
} from '../../types/resources/denormalized_attachment_resource'
import { AudioAttachment } from './attachments/audio_attachment'
import { ExpandedLink } from './attachments/expanded_link'
import { GenericFileAttachment } from './attachments/generic_file_attachment'
import { GiphyAttachment } from './attachments/giphy_attachment'
import { ImageAttachment, type MetaProps } from './attachments/image_attachment'
import { VideoAttachment } from './attachments/video_attachment'
export function MessageAttachments(props: {
attachments: DenormalizedAttachmentResource[]
metaProps: MetaProps
onMessageAttachmentLongPress: (attachment: DenormalizedMessageAttachmentResource) => void
onMessageLongPress: () => void
}) {
const styles = useStyles()
const { attachments, metaProps, onMessageAttachmentLongPress, onMessageLongPress } = props
const deletingAttachmentIds = useDeletingIds('deleteAttachment')
if (!attachments || attachments.length === 0) return null
const imageAttachments = attachments.filter(
attachment =>
attachment.type === 'MessageAttachment' &&
attachment.attributes?.contentType?.startsWith('image/')
) as DenormalizedMessageAttachmentResource[]
const showImageAttachmentGroup = imageAttachments.length > 0
return (
{showImageAttachmentGroup &&
imageAttachments.map((image, index) => (
))}
{attachments.map((attachment, index) => {
switch (attachment.type) {
case 'MessageAttachment':
return (
)
case 'giphy':
return (
)
case 'ExpandedLink':
return (
)
default:
return null
}
})}
)
}
function MessageAttachment({
attachment,
onMessageAttachmentLongPress,
isDeleting,
}: {
attachment: DenormalizedMessageAttachmentResource
onMessageAttachmentLongPress: (attachment: DenormalizedMessageAttachmentResource) => void
isDeleting: boolean
}) {
const { attributes } = attachment
const contentType = attributes?.contentType
const basicType = contentType ? contentType.split('/')[0] : ''
switch (basicType) {
case 'video':
return (
)
case 'audio':
return (
)
case 'application':
return (
)
default:
return null
}
}
const useStyles = () => {
return StyleSheet.create({
attachmentsContainer: {
gap: 2,
padding: 2,
},
})
}