diff --git a/src/features/content/renderers/details/YuanLuoDetailRenderer.tsx b/src/features/content/renderers/details/YuanLuoDetailRenderer.tsx new file mode 100644 index 0000000..4f30416 --- /dev/null +++ b/src/features/content/renderers/details/YuanLuoDetailRenderer.tsx @@ -0,0 +1,248 @@ +import React, { useMemo } from "react"; +import { ScrollView, StyleSheet, Text, View } from "react-native"; +import { useRouter } from "expo-router"; +import { moderateScale, verticalScale } from "react-native-size-matters"; + +import { Colors } from "@/theme"; +import { useSettingsStore } from "@/store/settings.store"; +import type { DetailRendererProps } from "../../types/renderer.types"; +import { + asNumber, + asRecordArray, + asString, + asStringArray, +} from "../helpers/value"; +import { BulletList } from "../shared/BulletList"; +import { ContentLinkAttributeSections } from "../shared/ContentLinkAttributeSections"; +import { Hero } from "../shared/Hero"; +import { OverviewCard } from "../shared/OverviewCard"; +import { Images } from "./categoryParts"; +import { + buildCategoryOverviewParagraphs, + extractPointRefLabel, + navigateToPointRef, + PointCategoryAccordionCard, + pointCategoryStyles, + PointLinkChip, + type PointsCatalogMap, + usePointsCatalogMap, +} from "./pointCategoryShared"; + +interface PairingItemProps { + key?: React.Key; + pairing: Record; + index: number; + defaultExpanded: boolean; + moduleCode: string; + pointsCatalogMap: PointsCatalogMap; +} + +function PairingAccordionCard({ + pairing, + index, + defaultExpanded, + moduleCode, + pointsCatalogMap, +}: PairingItemProps) { + const router = useRouter(); + + const num = asNumber(pairing.number) ?? index + 1; + const meridianPair = asString(pairing.meridian_pair).trim(); + const hostLabel = extractPointRefLabel(pairing.host); + const guestLabel = extractPointRefLabel(pairing.guest); + const patterns = asRecordArray(pairing.patterns); + + const title = meridianPair + ? `${num}. ${meridianPair}` + : `Pairing ${num}`; + const pairBadge = + hostLabel && guestLabel + ? `${hostLabel} + ${guestLabel}` + : hostLabel || guestLabel; + + return ( + + {patterns.map((pattern, patternIdx) => { + const patternCode = asString(pattern.pattern_code).trim(); + const patternName = asString(pattern.pattern_name).trim(); + const needleTechnique = asString(pattern.needle_technique).trim(); + const actions = asStringArray(pattern.actions); + const indications = asStringArray(pattern.indications); + + const heading = patternCode && patternName + ? `${patternCode}. ${patternName}` + : patternName || `Pattern ${patternIdx + 1}`; + + return ( + 0 && styles.patternDivider, + ]} + > + {heading} + + {needleTechnique ? ( + + + NEEDLE TECHNIQUE + + {needleTechnique} + + ) : null} + + {actions.length > 0 ? ( + + ACTIONS + + + ) : null} + + {indications.length > 0 ? ( + + INDICATIONS + + + ) : null} + + ); + })} + + {hostLabel || guestLabel ? ( + + {hostLabel ? ( + + navigateToPointRef( + router, + pairing.host, + moduleCode, + pointsCatalogMap, + ) + } + /> + ) : null} + {guestLabel ? ( + + navigateToPointRef( + router, + pairing.guest, + moduleCode, + pointsCatalogMap, + ) + } + /> + ) : null} + + ) : null} + + ); +} + +/** Renders Yuan–Luo (Host–Guest) category overview and meridian pairing pattern accordions. */ +export function YuanLuoDetailRenderer({ + moduleCode = "m0001", + content, + data, + definitions, + presentationAttributes, +}: DetailRendererProps) { + const accordionDefaultExpanded = useSettingsStore( + (state) => state.accordionDefaultExpanded, + ); + const pointsCatalogMap = usePointsCatalogMap(moduleCode); + + const rawTitle = + asString(data.title) || asString(data.name) || content.title || "Yuan–Luo Points"; + const alias = asString(data.alias).trim() || undefined; + const overviewParagraphs = useMemo( + () => buildCategoryOverviewParagraphs(data), + [data], + ); + const pairings = asRecordArray(data.pairings); + + return ( + + + + + + {overviewParagraphs.length > 0 ? ( + + ) : null} + + {pairings.length > 0 ? ( + + {pairings.map((pairing, index) => ( + + ))} + + ) : null} + + + + ); +} + +const styles = StyleSheet.create({ + patternBlock: { + gap: verticalScale(10), + }, + patternDivider: { + paddingTop: verticalScale(12), + borderTopWidth: 1, + borderTopColor: "#E2E8F0", + }, + patternTitle: { + fontSize: moderateScale(15), + lineHeight: moderateScale(21), + fontWeight: "700", + color: Colors.primaryDark, + }, + techniqueBox: { + backgroundColor: "#F8FAFC", + borderRadius: moderateScale(10), + borderWidth: 1, + borderColor: "#E2E8F0", + paddingHorizontal: moderateScale(12), + paddingVertical: verticalScale(8), + gap: verticalScale(3), + }, + techniqueText: { + fontSize: moderateScale(14), + lineHeight: moderateScale(20), + fontWeight: "600", + color: "#1E293B", + }, + listGroup: { + gap: verticalScale(6), + }, +}); +