import React, { type ReactNode } from "react";
import { Platform, Pressable, StyleSheet, Text, View } from "react-native";
import { Ionicons } from "@expo/vector-icons";
import { router } from "expo-router";
import { moderateScale } from "react-native-size-matters";
import { Colors } from "@/theme";
export interface ContentPageHeaderProps {
title: string;
subtitle?: string;
right?: ReactNode;
fallbackRoute?: string;
onTitlePress?: () => void;
titleAccessibilityLabel?: string;
onBack?: () => void;
}
export function ContentPageHeader({
title,
subtitle,
right,
fallbackRoute = "/modules",
onTitlePress,
titleAccessibilityLabel,
onBack,
}: ContentPageHeaderProps) {
const handleBack = () => {
if (onBack) {
onBack();
return;
}
if (router.canGoBack()) {
router.back();
return;
}
router.replace(fallbackRoute as never);
};
const titleContent = (
{title}
{subtitle ? (
{subtitle}
) : null}
);
return (
[
styles.iconButton,
pressed && styles.pressed,
]}
>
{onTitlePress ? (
[
styles.titleButton,
pressed && styles.pressed,
]}
>
{titleContent}
) : (
{titleContent}
)}
{right}
);
}
const styles = StyleSheet.create({
header: {
minHeight: 64,
flexDirection: "row",
alignItems: "center",
justifyContent: "space-between",
paddingHorizontal: moderateScale(16),
paddingTop: Platform.OS === "web" ? 14 : moderateScale(8),
paddingBottom: moderateScale(8),
borderBottomWidth: 1,
borderBottomColor: "#ECECEC",
backgroundColor: "#FFFFFF",
},
sideSlot: {
width: 82,
height: 40,
alignItems: "flex-start",
justifyContent: "center",
},
rightSlot: {
flexDirection: "row",
alignItems: "center",
justifyContent: "flex-end",
},
iconButton: {
width: 40,
height: 40,
borderRadius: 20,
alignItems: "center",
justifyContent: "center",
},
pressed: {
opacity: 0.65,
},
titleButton: {
flex: 1,
minHeight: 40,
marginHorizontal: moderateScale(12),
alignItems: "center",
justifyContent: "center",
},
titleContent: {
width: "100%",
alignItems: "center",
justifyContent: "center",
gap: 1,
},
title: {
width: "100%",
textAlign: "center",
fontSize: moderateScale(18),
fontWeight: "700",
color: Colors.textPrimary,
},
subtitle: {
width: "100%",
textAlign: "center",
fontSize: moderateScale(12),
lineHeight: moderateScale(16),
fontWeight: "500",
color: Colors.textSecondary,
},
});