"use client"; import { useI18n } from "@/translations/provider"; import { useMarriageProfileQuery } from "@/hooks/marriage/use-profile-main"; import { NavigationButton, type NavigationButtonProps, } from "./navigation-button"; import { hasSupportAccess } from "./support-access"; type PageHeaderProps = { className?: string; /** Props for the left button. Defaults to icon="back". */ leftButton?: NavigationButtonProps; /** Props for the right button. Defaults to icon="support" with support label. */ rightButton?: NavigationButtonProps; /** * When false, skip the profile query entirely. Useful on pages where the * right button has an explicit onClick and no icon resolution is needed * (e.g. Intro's "support" icon that opens a report sheet). * Defaults to true. */ enableProfileQuery?: boolean; profile?: any; }; export function PageHeader({ className, leftButton, rightButton, enableProfileQuery = true, profile: profileProp, }: PageHeaderProps) { const { dictionary: t } = useI18n(); // Only fetch profile when needed for icon resolution (subscription/support // visibility depends on profile data). Pages that pass an explicit onClick // for the right button can set enableProfileQuery=false to avoid an // unnecessary API call (e.g. anonymous Intro). const iconFromProp = rightButton?.icon; const isCustomRightButton = !!rightButton?.onClick || (iconFromProp !== undefined && iconFromProp !== "subscription" && iconFromProp !== "support"); const needsProfile = enableProfileQuery && !rightButton?.onClick && !profileProp; const { data: queriedProfile } = useMarriageProfileQuery({ enabled: needsProfile, }); const profile = profileProp !== undefined ? profileProp : queriedProfile; const isMale = profile?.gender === "male"; const { icon: rightButtonIcon, ...rightButtonRest } = rightButton || {}; return (
{leftButton?.className?.includes("hidden") ? (
) : ( )}

{t["Habib Marriage"]}

{isCustomRightButton ? ( ) : isMale ? (
) : ( )}
); } export default PageHeader;