import React from 'react'; import { Image } from 'react-native'; import type { MediaCardProps } from '../../../../types/media-card'; import { View } from '../../../layout/public'; import { withZoraThemeScope } from '../../../theme/adapters/inbound/withZoraThemeScope'; import { useZoraTheme } from '../../../theme/composition/useZoraTheme'; import { Heading } from '../../../typography/public'; import { Text } from '../../../typography/public'; import { Card } from '../../public'; /*** * Card layout with an optional media/header region and structured content slots. */ export const MediaCard = withZoraThemeScope(MediaCardInner); function resolveImageAspectRatio( imageAspectRatio: NonNullable, ) { if (!Number.isFinite(imageAspectRatio) || imageAspectRatio <= 0) { return 16 / 9; } return imageAspectRatio; } function MediaCardInner({ themeId: _themeId, mode: _mode, interactionPolicy, testID, imageSource, imageLabel, image, imageAspectRatio = 16 / 9, title, description, eyebrow, badges, actions, footer, children, tone = 'default', compact = false, onPress, }: MediaCardProps) { const { theme } = useZoraTheme(); const gap = compact ? 's' : 'm'; const isInteractive = Boolean(onPress) && !actions; const resolvedAspectRatio = resolveImageAspectRatio(imageAspectRatio); const renderImage = () => { if (image) { return ( {image} ); } if (!imageSource) { return null; } return ( ); }; const hasHeader = [eyebrow, title, description, badges, actions].some((item) => item != null); return ( {renderImage()} {hasHeader ? ( {eyebrow ? ( {eyebrow} ) : null} {title} {badges ? {badges} : null} {description ? ( {description} ) : null} {actions ? {actions} : null} ) : null} {children ? {children} : null} {footer ? {footer} : null} ); }