import React, { memo, useState } from 'react' import { Pressable, StyleSheet, Text, View, type StyleProp, type ViewStyle } from 'react-native' import { ChevronDown, ChevronRight, Files } from 'lucide-react-native' import { strings } from '../locales/i18n' import { useTheme } from './theme-context' import { DshFileTypeIcon, classifyDshFileType, getDshCategoryTheme } from './dsh-icons' export interface PresentedFileItem { path: string name?: string description?: string binary?: boolean action?: 'created' | 'edited' | 'deleted' | 'presented' size?: number | string } export interface PresentedFileCardProps { file: PresentedFileItem onFilePress?: (path: string) => void style?: StyleProp } export const PresentedFileCard = memo(function PresentedFileCard({ file, onFilePress, style }: PresentedFileCardProps) { const { colors } = useTheme() const category = classifyDshFileType(file.path) const theme = getDshCategoryTheme(category) const filename = file.name || file.path.split(/[/\\]/u).pop() || file.path const actionLabel = file.action === 'created' ? 'Created' : file.action === 'deleted' ? 'Deleted' : file.action === 'edited' ? 'Edited' : '' const isImageOrBinary = file.binary || ['png', 'jpg', 'jpeg', 'webp', 'gif', 'svg'].includes(filename.split('.').pop()?.toLowerCase() || '') let metaText = file.description || (isImageOrBinary ? 'binary' : theme.label) if (file.size) { metaText = typeof file.size === 'number' ? `${(file.size / 1024).toFixed(1)} KB` : file.size } return ( onFilePress?.(file.path)} style={({ pressed }) => [ styles.card, { backgroundColor: colors.surface, borderColor: colors.border, opacity: pressed ? 0.75 : 1, }, style, ]} > {actionLabel ? `${actionLabel} ` : ''}{filename} {metaText} ) }) const styles = StyleSheet.create({ card: { flexDirection: 'row', alignItems: 'center', height: 58, paddingHorizontal: 10, borderRadius: 12, borderWidth: StyleSheet.hairlineWidth, marginVertical: 4, alignSelf: 'stretch', }, tile: { width: 40, height: 40, borderRadius: 10, borderWidth: StyleSheet.hairlineWidth, alignItems: 'center', justifyContent: 'center', marginRight: 10, }, info: { flex: 1, justifyContent: 'center', marginRight: 8, }, title: { fontSize: 13, fontWeight: '500', lineHeight: 18, }, filename: { fontWeight: '600', }, subtitle: { fontSize: 11, lineHeight: 15, marginTop: 2, }, }) /** File references and real tool edits remain available without repeating a card stack in every reply. */ export const PresentedFileGroup = memo(function PresentedFileGroup({ files, onFilePress }: { files: PresentedFileItem[] onFilePress?: (path: string) => void }) { const [expanded, setExpanded] = useState(false) const { colors } = useTheme() if (files.length === 0) return null const label = `${strings.sessionActivity.relatedFiles} · ${files.length}` return setExpanded(value => !value)} style={({ pressed }) => ({ minHeight: 44, flexDirection: 'row', alignItems: 'center', gap: 8, paddingHorizontal: 6, borderRadius: 8, backgroundColor: pressed ? colors.surfaceStrong : 'transparent', })}> {label} {expanded ? : } {expanded && files.map(file => )} })