import type { ReactNode } from "react"; import { Text, View } from "react-native"; import Markdown from "react-native-markdown-display"; import { StyleSheet, useUnistyles } from "react-native-unistyles"; import { createMarkdownStyles } from "@/styles/markdown-styles"; import { getMarkdownListMarker } from "@/utils/markdown-list"; function createPlanMarkdownRules() { return { text: ( node: any, _children: ReactNode[], _parent: any, styles: any, inheritedStyles: any = {}, ) => ( {node.content} ), textgroup: ( node: any, children: ReactNode[], _parent: any, styles: any, inheritedStyles: any = {}, ) => ( {children} ), code_block: ( node: any, _children: ReactNode[], _parent: any, styles: any, inheritedStyles: any = {}, ) => ( {node.content} ), fence: ( node: any, _children: ReactNode[], _parent: any, styles: any, inheritedStyles: any = {}, ) => ( {node.content} ), code_inline: ( node: any, _children: ReactNode[], _parent: any, styles: any, inheritedStyles: any = {}, ) => ( {node.content} ), bullet_list: (node: any, children: ReactNode[], _parent: any, styles: any) => ( {children} ), ordered_list: (node: any, children: ReactNode[], _parent: any, styles: any) => ( {children} ), list_item: (node: any, children: ReactNode[], parent: any, styles: any) => { const { isOrdered, marker } = getMarkdownListMarker(node, parent); const iconStyle = isOrdered ? styles.ordered_list_icon : styles.bullet_list_icon; const contentStyle = isOrdered ? styles.ordered_list_content : styles.bullet_list_content; return ( {marker} {children} ); }, paragraph: (node: any, children: ReactNode[], parent: any, styles: any) => { const isLastChild = parent[0]?.children?.at(-1)?.key === node.key; return ( {children} ); }, }; } export function PlanCard({ title = "Plan", description, text, footer, disableOuterSpacing = false, }: { title?: string; description?: string; text: string; footer?: ReactNode; disableOuterSpacing?: boolean; }) { const { theme } = useUnistyles(); const markdownStyles = createMarkdownStyles(theme); const markdownRules = createPlanMarkdownRules(); return ( {title} {description ? ( {description} ) : null} {text} {footer ? {footer} : null} ); } const styles = StyleSheet.create((theme) => ({ container: { marginVertical: theme.spacing[3], padding: theme.spacing[3], borderRadius: theme.spacing[2], borderWidth: 1, gap: theme.spacing[2], }, containerCompact: { marginVertical: 0, }, title: { fontSize: theme.fontSize.base, lineHeight: 22, }, description: { fontSize: theme.fontSize.sm, lineHeight: 20, }, footer: { gap: theme.spacing[2], }, }));