import React from 'react';
import { View, Pressable, Platform } from 'react-native';
import { useTheme } from '~/features/theme/ThemeProvider';
import Text from '~/components/atoms/Text';
import Icon from '~/components/atoms/Icon';
import colors from '~/tailwind.config.js';
import { useTranslation } from 'react-i18next';
import { getTheme } from '~/features/theme/constants';
// @expo/ui ContextMenu - use appropriate platform import
import { ContextMenu as ContextMenuiOS, Button as ButtoniOS, Host as HostiOS } from '@expo/ui/swift-ui';
import { ContextMenu as ContextMenuAndroid, Button as ButtonAndroid } from '@expo/ui/jetpack-compose';
// Select the correct components based on platform
const ContextMenu = Platform.OS === 'ios' ? ContextMenuiOS : ContextMenuAndroid;
const ExpoButton = Platform.OS === 'ios' ? ButtoniOS : ButtonAndroid;
const Host = Platform.OS === 'ios' ? HostiOS : View;
interface Blueprint {
id: string;
name: {
[key: string]: string;
};
color?: string;
}
interface PromptModel {
id: string;
prompt_text: {
[key: string]: string;
};
memory_title: {
[key: string]: string;
};
created_at: string;
updated_at: string;
blueprints?: Blueprint[];
is_public?: boolean;
}
interface PromptPreviewProps {
prompt: PromptModel;
onPress?: () => void;
onShare?: () => void;
onCopy?: () => void;
isLoading?: boolean;
isSelected?: boolean;
disableContextMenu?: boolean;
}
/**
* PromptPreviewSkeleton-Komponente
*
* Zeigt einen einfachen Skeleton-Loader für die PromptPreview-Komponente an.
*/
const PromptPreviewSkeleton: React.FC<{ isDark: boolean; themeVariant: string }> = ({ isDark, themeVariant }) => {
// Container-Style mit Hintergrundfarbe aus der Tailwind-Konfiguration
const getContainerStyle = () => {
// Direkter Zugriff auf die Farben aus der Tailwind-Konfiguration
const backgroundColor = isDark
? ((colors as any).theme?.extend?.colors?.dark)?.[themeVariant]?.contentBackground || '#1E1E1E'
: ((colors as any).theme?.extend?.colors)?.[themeVariant]?.contentBackground || '#FFFFFF';
return {
backgroundColor,
borderRadius: 12,
height: 140,
padding: 16,
marginLeft: 16,
marginRight: 16,
flexShrink: 0,
};
};
return ;
};
/**
* PromptPreview-Komponente
*
* Zeigt eine Vorschau eines Prompts mit Titel, Text und verknüpften Blueprints an.
*/
const PromptPreview: React.FC = ({
prompt,
onPress,
onShare,
onCopy,
isLoading = false,
isSelected = false,
disableContextMenu = false
}) => {
const { isDark, themeVariant, colorScheme, colors: themeColors } = useTheme();
const theme = getTheme(colorScheme, themeVariant);
const { i18n } = useTranslation();
const currentLanguage = i18n.language || 'en';
// Icon-Farbe basierend auf Theme (weiß im Dark Mode, dunkel im Light Mode)
const iconColor = '#AEAEB2'; // Light gray icon color for both light and dark mode
// Wenn das Laden aktiv ist, zeige den Skeleton-Loader an
if (isLoading) {
return ;
}
// Extrahiere den Titel und Text in der aktuellen Sprache
const title = prompt.memory_title?.[currentLanguage] || prompt.memory_title?.en || '';
const promptText = prompt.prompt_text?.[currentLanguage] || prompt.prompt_text?.en || '';
// Formatiere das Datum
const formattedDate = new Date(prompt.created_at).toLocaleDateString(currentLanguage, {
year: 'numeric',
month: 'short',
day: 'numeric',
});
// Container-Style mit Hintergrundfarbe aus der Tailwind-Konfiguration
const getContainerStyle = () => {
// Direkter Zugriff auf die Farben aus der Tailwind-Konfiguration
const backgroundColor = isDark
? ((colors as any).theme?.extend?.colors?.dark)?.[themeVariant]?.contentBackground || '#1E1E1E'
: ((colors as any).theme?.extend?.colors)?.[themeVariant]?.contentBackground || '#FFFFFF';
// Keep original background color regardless of selection
return {
backgroundColor,
borderRadius: 12,
padding: 16,
flexShrink: 0,
overflow: 'visible',
shadowColor: isDark ? 'rgba(0, 0, 0, 0.3)' : 'rgba(0, 0, 0, 0.1)',
shadowOffset: { width: 0, height: 2 },
shadowOpacity: 0.8,
shadowRadius: 2,
elevation: 2,
};
};
// Text-Style basierend auf dem Theme
const getTextStyle = (isTitle = false) => {
const textColor = isDark ? '#FFFFFF' : '#000000';
return {
color: textColor,
fontSize: isTitle ? 16 : 14,
fontWeight: isTitle ? 'bold' : 'normal' as 'bold' | 'normal',
marginBottom: isTitle ? 8 : 4,
};
};
// Menu items
const menuItems = [
{
key: 'copy',
title: 'Kopieren',
systemIcon: 'doc.on.doc',
onSelect: onCopy,
},
{
key: 'share',
title: 'Teilen',
systemIcon: 'square.and.arrow.up',
onSelect: onShare,
},
];
// Render-Funktion für die Blueprints-Liste
const renderBlueprints = () => {
if (!prompt.blueprints || prompt.blueprints.length === 0) {
return null;
}
return (
{prompt.blueprints.map((blueprint) =>
blueprint.name?.[currentLanguage] || blueprint.name?.en || ''
).join(', ')}
);
};
// Hauptinhalt der Komponente
const content = (
{/* Checkmark für ausgewählte Elemente */}
{isSelected && (
)}
{title}
{promptText}
{renderBlueprints()}
);
// Wenn Kontextmenü deaktiviert ist, verwende einfaches Pressable
if (disableContextMenu) {
return (
{content}
);
}
// Verwende @expo/ui ContextMenu
return (
{menuItems.map((item) => (
{item.title}
))}
{content}
);
};
export default PromptPreview;