import React from "react";
import { Pressable, View, Text, TextInput } from "react-native";
import { ChevronLeft, Search, Bell, X } from "lucide-react-native";
import { useThemeColors } from "@/hooks/use-theme-colors";
export interface AppHeaderProps {
title: string;
subtitle?: string;
showBack?: boolean;
onBack?: () => void;
showSearch?: boolean;
searchPlaceholder?: string;
searchValue?: string;
onSearchChange?: (text: string) => void;
unreadNotificationsCount?: number;
onNotificationsPress?: () => void;
avatarUrl?: string;
avatarFallback?: string;
onAvatarPress?: () => void;
rightAction?: React.ReactNode;
}
export function AppHeader({
title,
subtitle,
showBack = false,
onBack,
showSearch = false,
searchPlaceholder = "Search...",
searchValue = "",
onSearchChange,
unreadNotificationsCount = 0,
onNotificationsPress,
avatarFallback = "JD",
onAvatarPress,
rightAction,
}: AppHeaderProps) {
const palette = useThemeColors();
return (
<View className="bg-background border-b border-border/80 sp-px-4 sp-py-3">
{/* Top Bar: Brand, Title, Actions */}
<View className="flex-row items-center justify-between">
<View className="flex-row items-center sp-gap-3 flex-1 mr-2">
{showBack && (
<Pressable
onPress={onBack}
accessibilityRole="button"
accessibilityLabel="Go back"
className="surface h-9 w-9 rounded-control items-center justify-center active:bg-muted active:opacity-70"
>
<ChevronLeft size={20} color={palette.foreground} />
</Pressable>
)}
<View className="flex-1">
<Text className="type-lg weight-title text-foreground tracking-tight" numberOfLines={1}>
{title}
</Text>
{subtitle && (
<Text className="type-xs text-muted-foreground mt-0.5" numberOfLines={1}>
{subtitle}
</Text>
)}
</View>
</View>
{/* Right Action Icons & Avatar */}
<View className="flex-row items-center sp-gap-2">
{rightAction}
{onNotificationsPress && (
<Pressable
onPress={onNotificationsPress}
accessibilityRole="button"
accessibilityLabel="Notifications"
className="surface relative h-9 w-9 rounded-control items-center justify-center active:opacity-70"
>
<Bell size={18} color={palette["muted-foreground"]} />
{unreadNotificationsCount > 0 && (
<View className="absolute -top-1 -right-1 min-w-[18px] h-[18px] sp-px-1 rounded-full bg-destructive items-center justify-center border-2 border-border">
<Text className="type-2xs weight-title text-destructive-foreground leading-none">
{unreadNotificationsCount > 99 ? "99+" : unreadNotificationsCount}
</Text>
</View>
)}
</Pressable>
)}
{onAvatarPress && (
<Pressable
onPress={onAvatarPress}
accessibilityRole="button"
accessibilityLabel="User profile"
className="h-9 w-9 rounded-full bg-primary/20 border border-primary/40 items-center justify-center ml-1 active:opacity-70"
>
<Text className="type-xs weight-title text-primary font-mono">
{avatarFallback}
</Text>
</Pressable>
)}
</View>
</View>
{/* Integrated Search Bar */}
{showSearch && (
<View className="mt-3 flex-row items-center bg-card/90 border border-border rounded-control sp-px-3 min-h-control">
<Search size={16} color={palette["muted-foreground"]} />
<TextInput
value={searchValue}
onChangeText={onSearchChange}
placeholder={searchPlaceholder}
placeholderTextColor={palette["muted-foreground"]}
className="flex-1 ml-2.5 type-xs text-foreground"
autoCapitalize="none"
/>
{searchValue.length > 0 && onSearchChange && (
<Pressable
onPress={() => onSearchChange("")}
accessibilityRole="button"
accessibilityLabel="Clear search"
className="active:opacity-20"
>
<X size={14} color={palette["muted-foreground"]} />
</Pressable>
)}
</View>
)}
</View>
);
}