import React from "react"; import { ScrollView, StyleSheet, Text, View } from "react-native"; import type { DetailRendererProps } from "../../types/renderer.types"; import { findAttributePresentationRule, isEmptyValue, presentationDisplayOrder, } from "../../utils/attribute-presentation"; import { asRecordArray, asString, asStringArray } from "../helpers/value"; import { BulletList } from "../shared/BulletList"; import { ChipList } from "../shared/ChipList"; import { ContentLinkAttributeSections } from "../shared/ContentLinkAttributeSections"; import { ContentValue } from "../shared/ContentValue"; import { Hero } from "../shared/Hero"; import { ImageGallery } from "../shared/ImageGallery"; import { ReferenceChipList } from "../shared/ReferenceChipList"; import { SectionCard } from "../shared/SectionCard"; const POINT_RELATIONSHIP_KEYS = [ "master_point", "coupled_point", "luo_point", "xi_cleft_point", "intersection_points", "paired_meridian", ] as const; interface RelationshipRowProps { label: string; value: unknown; chips?: boolean; } function RelationshipRow({ label, value, chips = false }: RelationshipRowProps) { if (isEmptyValue(value)) return null; return ( {label} {chips ? : } ); } export function EovDetailRenderer({ content, data, definitions, presentationAttributes, }: DetailRendererProps) { const definitionByKey = React.useMemo(() => { const map = new Map(); for (const definition of definitions) { map.set(definition.attribute_key, definition); map.set(definition.code, definition); } return map; }, [definitions]); const orderFor = React.useCallback( (key: string, fallbackIndex = 0) => { const rule = findAttributePresentationRule(key, presentationAttributes); const definition = definitionByKey.get(key); return presentationDisplayOrder(rule, definition?.sort_order, fallbackIndex); }, [definitionByKey, presentationAttributes], ); const relationshipRows = React.useMemo( () => [ { key: "master_point", label: "Master Point", value: data.master_point }, { key: "coupled_point", label: "Coupled Point", value: data.coupled_point }, { key: "luo_point", label: "Luo Point", value: data.luo_point }, { key: "xi_cleft_point", label: "Xi-Cleft Point", value: data.xi_cleft_point }, { key: "intersection_points", label: "Intersection Points", value: data.intersection_points, chips: true, }, { key: "paired_meridian", label: "Paired Meridian", value: data.paired_meridian }, ] .filter((row) => !isEmptyValue(row.value)) .sort((a, b) => orderFor(a.key) - orderFor(b.key)), [data, orderFor], ); const sections = React.useMemo(() => { const items: Array<{ key: string; order: number; render: () => React.ReactNode; }> = []; if (relationshipRows.length > 0) { items.push({ key: "point_relationships", order: Math.min(...relationshipRows.map((row) => orderFor(row.key))), render: () => ( {relationshipRows.map((row) => ( ))} ), }); } if (!isEmptyValue(data.areas_of_effect)) { items.push({ key: "areas_of_effect", order: orderFor("areas_of_effect", 100), render: () => ( ), }); } if (!isEmptyValue(data.functions)) { items.push({ key: "functions", order: orderFor("functions", 110), render: () => ( ), }); } if (!isEmptyValue(data.pathway)) { items.push({ key: "pathway", order: orderFor("pathway", 120), render: () => ( {asString(data.pathway)} ), }); } const clinicalManifestations = data.clinical_manifestation ?? data.clinical_manifestations; if (!isEmptyValue(clinicalManifestations)) { items.push({ key: "clinical_manifestation", order: orderFor("clinical_manifestation", orderFor("clinical_manifestations", 125)), render: () => ( ), }); } if (!isEmptyValue(data.connecting_channel)) { items.push({ key: "connecting_channel", order: orderFor("connecting_channel", 130), render: () => ( {asString(data.connecting_channel)} ), }); } if (!isEmptyValue(data.treatment)) { items.push({ key: "treatment", order: orderFor("treatment", 140), render: () => ( {asString(data.treatment)} ), }); } return items.sort((a, b) => a.order - b.order || a.key.localeCompare(b.key)); }, [data, orderFor, relationshipRows]); return ( {sections.map((section) => ( {section.render()} ))} ); } const styles = StyleSheet.create({ relationshipRow: { gap: 5, paddingBottom: 10, borderBottomWidth: StyleSheet.hairlineWidth, borderBottomColor: "#E8ECEF", }, relationshipLabel: { fontSize: 12, lineHeight: 17, fontWeight: "700", color: "#597064", textTransform: "uppercase", letterSpacing: 0.4, }, pathway: { fontSize: 16, lineHeight: 26, color: "#334155", }, });