379 lines
12 KiB
TypeScript
379 lines
12 KiB
TypeScript
import React from "react";
|
|
import { Pressable, ScrollView, StyleSheet, Text, View } from "react-native";
|
|
import { Ionicons } from "@expo/vector-icons";
|
|
import { router } from "expo-router";
|
|
import { moderateScale, verticalScale } from "react-native-size-matters";
|
|
|
|
import { Colors } from "@/theme";
|
|
import type { DetailRendererProps } from "../../types/renderer.types";
|
|
import { ContentLinkAttributeSections } from "../shared/ContentLinkAttributeSections";
|
|
import { Hero } from "../shared/Hero";
|
|
import { asRecordArray, asString, asStringArray } from "../helpers/value";
|
|
|
|
function resolveSequenceTargetTemplate(
|
|
currentModule: string,
|
|
sectionTitle: string,
|
|
sectionRecord: Record<string, unknown>,
|
|
index: number,
|
|
): string {
|
|
// 1. Direct template_code in data section if present
|
|
const directTemplate =
|
|
asString(sectionRecord.template_code) ||
|
|
asString(
|
|
(sectionRecord.link as Record<string, unknown> | undefined)?.target
|
|
? ((sectionRecord.link as Record<string, unknown>).target as Record<string, unknown>).template_code
|
|
: undefined,
|
|
);
|
|
if (directTemplate) return directTemplate;
|
|
|
|
// 2. Resolve by semantic title keyword
|
|
const normalized = sectionTitle.toLowerCase();
|
|
if (normalized.includes("generating")) return `${currentModule}_ct0002`;
|
|
if (normalized.includes("overacting")) return `${currentModule}_ct0003`;
|
|
if (normalized.includes("insulting")) return `${currentModule}_ct0004`;
|
|
|
|
// 3. Fallback by ordinal index
|
|
return `${currentModule}_ct000${index + 2}`;
|
|
}
|
|
|
|
function extractParagraphs(value: unknown): string[] {
|
|
if (Array.isArray(value)) {
|
|
return value
|
|
.map((item) => asString(item).trim())
|
|
.filter((item) => item.length > 0);
|
|
}
|
|
const str = asString(value).trim();
|
|
return str.length > 0 ? [str] : [];
|
|
}
|
|
|
|
export function FiveElementsDetailRenderer({
|
|
moduleCode,
|
|
templateCode,
|
|
content,
|
|
data,
|
|
definitions,
|
|
presentationAttributes,
|
|
}: DetailRendererProps) {
|
|
const currentModule = moduleCode || "m0019";
|
|
const title =
|
|
asString(data.name) ||
|
|
asString(data.title) ||
|
|
content.title ||
|
|
"";
|
|
|
|
const code = asString(data.code) || templateCode || content.slug || "";
|
|
|
|
// Dynamic Overview resolution from data only (generic fallback hierarchy)
|
|
const overviewCandidates = [
|
|
extractParagraphs(data.overview),
|
|
extractParagraphs(data.content),
|
|
extractParagraphs(data.description),
|
|
extractParagraphs(content.summary),
|
|
];
|
|
const overviewParagraphs =
|
|
overviewCandidates.find((candidates) => candidates.length > 0) ?? [];
|
|
|
|
const rawSections = asRecordArray(data.sections);
|
|
|
|
// The Identification page is the parent/entry screen containing sequence links
|
|
const isIdentificationPage =
|
|
templateCode.toLowerCase() === `${currentModule.toLowerCase()}_ct0001` ||
|
|
code.toLowerCase().includes("identification") ||
|
|
title.toLowerCase().includes("identification");
|
|
|
|
// ----------------------------------------------------
|
|
// SCREEN 1: Identification Page with Dynamic Sequence Buttons
|
|
// ----------------------------------------------------
|
|
if (isIdentificationPage) {
|
|
return (
|
|
<ScrollView
|
|
contentContainerStyle={styles.container}
|
|
showsVerticalScrollIndicator={false}
|
|
>
|
|
<Hero title={title} />
|
|
|
|
{/* Overview Card (rendered only when overview/content exists in data) */}
|
|
{overviewParagraphs.length > 0 ? (
|
|
<View style={styles.overviewCard}>
|
|
<View style={styles.overviewHeader}>
|
|
<Ionicons name="information-circle" size={20} color={Colors.primary} />
|
|
<Text style={styles.overviewTitle}>Overview</Text>
|
|
</View>
|
|
{overviewParagraphs.map((para, idx) => (
|
|
<Text
|
|
key={idx}
|
|
style={[styles.overviewText, idx > 0 && styles.paragraphSpacing]}
|
|
>
|
|
{para}
|
|
</Text>
|
|
))}
|
|
</View>
|
|
) : null}
|
|
|
|
{/* Dynamic Sequences List from data.sections */}
|
|
{rawSections.length > 0 ? (
|
|
<View style={styles.sequencesContainer}>
|
|
<Text style={styles.sectionHeading}>Sequences</Text>
|
|
{rawSections.map((sec, idx) => {
|
|
const sectionTitle = asString(sec.title) || `Sequence ${idx + 1}`;
|
|
const sectionItems = asStringArray(sec.content);
|
|
const count = sectionItems.length;
|
|
const targetTemplate = resolveSequenceTargetTemplate(
|
|
currentModule,
|
|
sectionTitle,
|
|
sec,
|
|
idx,
|
|
);
|
|
|
|
return (
|
|
<Pressable
|
|
key={idx}
|
|
accessibilityRole="button"
|
|
accessibilityLabel={`Open ${sectionTitle}`}
|
|
onPress={() =>
|
|
router.push(
|
|
`/modules/${encodeURIComponent(currentModule)}/${encodeURIComponent(targetTemplate)}` as never,
|
|
)
|
|
}
|
|
style={({ pressed }) => [styles.sequenceRow, pressed && styles.pressed]}
|
|
>
|
|
<View style={styles.sequenceNumberWrapper}>
|
|
<Text style={styles.sequenceNumber}>{idx + 1}</Text>
|
|
</View>
|
|
|
|
<View style={styles.sequenceTextWrapper}>
|
|
<Text style={styles.sequenceTitle}>{sectionTitle}</Text>
|
|
</View>
|
|
|
|
{count > 0 ? (
|
|
<View style={styles.badgeWrapper}>
|
|
<Text style={styles.badgeText}>{count} patterns</Text>
|
|
</View>
|
|
) : null}
|
|
|
|
<Ionicons name="chevron-forward" size={20} color="#9CA3AF" />
|
|
</Pressable>
|
|
);
|
|
})}
|
|
</View>
|
|
) : null}
|
|
|
|
<ContentLinkAttributeSections
|
|
data={data}
|
|
definitions={definitions}
|
|
presentationAttributes={presentationAttributes}
|
|
/>
|
|
</ScrollView>
|
|
);
|
|
}
|
|
|
|
// ----------------------------------------------------
|
|
// SCREEN 2: Leaf Node Data Page (Specific Sequence Patterns)
|
|
// ----------------------------------------------------
|
|
return (
|
|
<ScrollView
|
|
contentContainerStyle={styles.container}
|
|
showsVerticalScrollIndicator={false}
|
|
>
|
|
<Hero title={title} />
|
|
|
|
{/* Overview Card (rendered only when overview/content exists in data) */}
|
|
{overviewParagraphs.length > 0 ? (
|
|
<View style={styles.overviewCard}>
|
|
<View style={styles.overviewHeader}>
|
|
<Ionicons name="information-circle" size={20} color={Colors.primary} />
|
|
<Text style={styles.overviewTitle}>Overview</Text>
|
|
</View>
|
|
{overviewParagraphs.map((para, idx) => (
|
|
<Text
|
|
key={idx}
|
|
style={[styles.overviewText, idx > 0 && styles.paragraphSpacing]}
|
|
>
|
|
{para}
|
|
</Text>
|
|
))}
|
|
</View>
|
|
) : null}
|
|
|
|
{/* Numbered Pattern Cards from data.sections */}
|
|
{rawSections.length > 0 ? (
|
|
<View style={styles.sectionsContainer}>
|
|
<Text style={styles.sectionHeading}>Patterns & Manifestations</Text>
|
|
{rawSections.map((sec, idx) => {
|
|
const sectionTitle = asString(sec.title) || `Pattern ${idx + 1}`;
|
|
const sectionContent = extractParagraphs(sec.content);
|
|
|
|
return (
|
|
<View key={idx} style={styles.patternCard}>
|
|
<View style={styles.patternHeader}>
|
|
<View style={styles.numberBadge}>
|
|
<Text style={styles.numberText}>{idx + 1}</Text>
|
|
</View>
|
|
<Text style={styles.patternTitle}>{sectionTitle}</Text>
|
|
</View>
|
|
|
|
{sectionContent.length > 0 ? (
|
|
<View style={styles.patternBody}>
|
|
{sectionContent.map((text, cIdx) => (
|
|
<Text key={cIdx} style={styles.contentText}>
|
|
{text}
|
|
</Text>
|
|
))}
|
|
</View>
|
|
) : null}
|
|
</View>
|
|
);
|
|
})}
|
|
</View>
|
|
) : null}
|
|
|
|
<ContentLinkAttributeSections
|
|
data={data}
|
|
definitions={definitions}
|
|
presentationAttributes={presentationAttributes}
|
|
/>
|
|
</ScrollView>
|
|
);
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
container: {
|
|
paddingHorizontal: moderateScale(16),
|
|
paddingTop: verticalScale(14),
|
|
paddingBottom: verticalScale(40),
|
|
gap: verticalScale(14),
|
|
},
|
|
overviewCard: {
|
|
backgroundColor: "#FFFFFF",
|
|
borderRadius: moderateScale(16),
|
|
borderWidth: 1,
|
|
borderColor: "#E2EAE5",
|
|
padding: moderateScale(16),
|
|
},
|
|
overviewHeader: {
|
|
flexDirection: "row",
|
|
alignItems: "center",
|
|
marginBottom: verticalScale(8),
|
|
gap: moderateScale(8),
|
|
},
|
|
overviewTitle: {
|
|
fontSize: moderateScale(16),
|
|
fontWeight: "700",
|
|
color: Colors.textPrimary,
|
|
},
|
|
overviewText: {
|
|
fontSize: moderateScale(13),
|
|
lineHeight: verticalScale(19),
|
|
color: Colors.textSecondary,
|
|
},
|
|
paragraphSpacing: {
|
|
marginTop: verticalScale(10),
|
|
},
|
|
sequencesContainer: {
|
|
gap: verticalScale(10),
|
|
},
|
|
sectionHeading: {
|
|
fontSize: moderateScale(15),
|
|
fontWeight: "700",
|
|
color: Colors.textPrimary,
|
|
marginLeft: moderateScale(4),
|
|
marginBottom: verticalScale(2),
|
|
},
|
|
sequenceRow: {
|
|
minHeight: moderateScale(60),
|
|
flexDirection: "row",
|
|
alignItems: "center",
|
|
padding: moderateScale(14),
|
|
backgroundColor: "#FFFFFF",
|
|
borderRadius: moderateScale(14),
|
|
borderWidth: 1,
|
|
borderColor: "#E2EAE5",
|
|
},
|
|
pressed: {
|
|
opacity: 0.72,
|
|
},
|
|
sequenceNumberWrapper: {
|
|
width: moderateScale(36),
|
|
height: moderateScale(36),
|
|
borderRadius: moderateScale(18),
|
|
justifyContent: "center",
|
|
alignItems: "center",
|
|
backgroundColor: "#E8F5E9",
|
|
},
|
|
sequenceNumber: {
|
|
fontSize: moderateScale(15),
|
|
fontWeight: "800",
|
|
color: Colors.primaryDark,
|
|
},
|
|
sequenceTextWrapper: {
|
|
flex: 1,
|
|
marginLeft: moderateScale(12),
|
|
marginRight: moderateScale(8),
|
|
},
|
|
sequenceTitle: {
|
|
fontSize: moderateScale(15),
|
|
fontWeight: "600",
|
|
color: Colors.textPrimary,
|
|
},
|
|
badgeWrapper: {
|
|
backgroundColor: "#F3F4F6",
|
|
paddingHorizontal: moderateScale(8),
|
|
paddingVertical: verticalScale(4),
|
|
borderRadius: moderateScale(8),
|
|
marginRight: moderateScale(6),
|
|
},
|
|
badgeText: {
|
|
fontSize: moderateScale(11),
|
|
fontWeight: "600",
|
|
color: Colors.textSecondary,
|
|
},
|
|
sectionsContainer: {
|
|
gap: verticalScale(12),
|
|
},
|
|
patternCard: {
|
|
backgroundColor: "#FFFFFF",
|
|
borderRadius: moderateScale(14),
|
|
borderWidth: 1,
|
|
borderColor: "#E5E7EB",
|
|
overflow: "hidden",
|
|
},
|
|
patternHeader: {
|
|
flexDirection: "row",
|
|
alignItems: "center",
|
|
paddingHorizontal: moderateScale(14),
|
|
paddingVertical: verticalScale(12),
|
|
backgroundColor: "#F9FAFB",
|
|
borderBottomWidth: 1,
|
|
borderBottomColor: "#EEF2F6",
|
|
gap: moderateScale(10),
|
|
},
|
|
numberBadge: {
|
|
width: moderateScale(28),
|
|
height: moderateScale(28),
|
|
borderRadius: moderateScale(14),
|
|
backgroundColor: "#E8F5E9",
|
|
justifyContent: "center",
|
|
alignItems: "center",
|
|
},
|
|
numberText: {
|
|
fontSize: moderateScale(14),
|
|
fontWeight: "800",
|
|
color: Colors.primaryDark,
|
|
},
|
|
patternTitle: {
|
|
flex: 1,
|
|
fontSize: moderateScale(14),
|
|
fontWeight: "700",
|
|
color: Colors.textPrimary,
|
|
},
|
|
patternBody: {
|
|
padding: moderateScale(14),
|
|
gap: verticalScale(10),
|
|
},
|
|
contentText: {
|
|
fontSize: moderateScale(13),
|
|
lineHeight: verticalScale(19),
|
|
color: Colors.textSecondary,
|
|
},
|
|
});
|