import React, { useMemo } from "react"; import { ScrollView } from "react-native"; import type { DetailRendererProps } from "../types/renderer.types"; import { humanizeKey } from "./helpers/value"; 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", "food_name", "foodname", "content_count", "content_label", "food_items", ]); /** * 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, }: 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], ); const heroTitle = humanizeKey( content.title || (typeof data.food_name === "string" ? data.food_name : "") || "Untitled content", ); return ( {Object.entries(data) .filter( ([key]) => !RESERVED_KEYS.has(key.toLowerCase()) && !(isTherapeutic && key.toLowerCase() === "name"), ) .map(([key, value]) => { const rawLabel = definitionMap.get(key) || key; const label = humanizeKey(rawLabel); return ( ); })} ); }