import React, { useMemo } from "react"; import { ScrollView } from "react-native"; import type { DetailRendererProps } from "../types/renderer.types"; import { humanizeKey } from "./helpers/value"; import { ContentLinkAttributeSections } from "./shared/ContentLinkAttributeSections"; import { ContentValue } from "./shared/ContentValue"; import { Hero } from "./shared/Hero"; import { ImageGallery } from "./shared/ImageGallery"; import { SectionCard } from "./shared/SectionCard"; const RESERVED_KEYS = new Set(["code", "id", "slug", "sort_order", "link"]); /** * Generic detail renderer for modules and catalog items. * * Each attribute is rendered in its own separate SectionCard. * For therapeutics modules, the redundant Hero name card is hidden. */ export function GenericDetailRenderer({ content, data, moduleCode, templateCode, definitions, presentationAttributes, }: DetailRendererProps) { const isTherapeutic = Boolean( moduleCode?.toLowerCase().startsWith("m004") || templateCode?.toLowerCase().startsWith("m004") ); const definitionMap = useMemo( () => new Map( (definitions ?? []).map((d) => [d.code, d.label]), ), [definitions], ); return ( {Object.entries(data) .filter( ([key]) => !RESERVED_KEYS.has(key) && !(isTherapeutic && key.toLowerCase() === "name"), ) .map(([key, value]) => { const rawLabel = definitionMap.get(key) || key; const label = humanizeKey(rawLabel); return ( ); })} ); }