'use client'; import React, { useState } from 'react'; import { Button } from '@/components/ui/button'; import { Badge } from '@/components/ui/badge'; import { Logo } from '@/components/ui/logo'; import { ChevronDown, ChevronUp, Menu } from 'lucide-react'; export interface HeaderAction { id: string; label: string; icon?: React.ComponentType<{ className?: string }>; onClick: () => void; variant?: 'default' | 'outline' | 'ghost' | 'secondary'; size?: 'default' | 'sm' | 'lg' | 'icon'; disabled?: boolean; content?: React.ReactNode; dataTourId?: string; } export interface ViewTab { id: string; label: string; icon?: React.ComponentType<{ className?: string }>; } interface AppHeaderProps { title?: string; subtitle?: string; badge?: string; onLogoClick?: () => void; actions?: HeaderAction[]; mobileMenuContent?: React.ReactNode; desktopOnlyContent?: React.ReactNode; // Content shown only on desktop className?: string; leftText?: React.ReactNode; // Text to show next to logo on desktop, centered on mobile leftSubtext?: string; // Secondary line below leftText on mobile (e.g. active panel name) mobileVisibleActions?: string[]; // Action IDs to show outside dropdown on mobile viewTabs?: ViewTab[]; // View tabs for switching between sections activeViewTab?: string; // Currently active view tab onViewTabChange?: (tabId: string) => void; // Callback when view tab changes hideLogo?: boolean; // Hide the logo button (for use with sidebar) showMobileMenu?: boolean; // Show hamburger menu button on mobile (for sidebar) onMobileMenuClick?: () => void; // Callback when hamburger is clicked hideActionsOnMobile?: boolean; // Hide all actions on mobile (actions in sidebar instead) pageName?: string; // Page name to show in center on mobile (when showMobileMenu is true) } export function AppHeader({ title, subtitle, badge, onLogoClick, actions = [], mobileMenuContent, desktopOnlyContent, className = '', leftText, leftSubtext, mobileVisibleActions = [], viewTabs, activeViewTab, onViewTabChange, hideLogo = false, showMobileMenu = false, onMobileMenuClick, hideActionsOnMobile = false, pageName }: AppHeaderProps) { const [mobileMenuOpen, setMobileMenuOpen] = useState(false); // Split actions into mobile-visible and dropdown-only const mobileVisibleActionsSet = new Set(mobileVisibleActions); const visibleOnMobile = hideActionsOnMobile ? [] : actions.filter(a => mobileVisibleActionsSet.has(a.id)); const dropdownOnlyActions = hideActionsOnMobile ? [] : actions.filter(a => !mobileVisibleActionsSet.has(a.id)); return (
{/* Left side - Logo + pageName (mobile when showMobileMenu is true) */} {showMobileMenu && (
{pageName && {pageName}}
)} {/* Left side - Logo + text (desktop), empty (mobile with sidebar) */} {!hideLogo && !showMobileMenu && ( )} {/* Center - View tabs or leftText/title (desktop only now) */}
{viewTabs && viewTabs.length > 0 ? ( /* Show view tabs as pill toggle */
{viewTabs.map((tab, index) => ( ))}
) : title ? ( <> {title &&

{title}

} {badge && {badge}} ) : null}
{/* Desktop - Show subtitle only if no leftText and no center title */} {!leftText && !title && subtitle && (
{subtitle}
)} {/* Right side controls */}
{/* Desktop actions */}
{actions.map((action) => ( action.content ? (
{action.content}
) : ( ) ))} {desktopOnlyContent}
{/* Mobile visible actions */}
{visibleOnMobile.map((action) => ( action.content ? (
{action.content}
) : ( ) ))}
{/* Mobile menu toggle */} {(dropdownOnlyActions.length > 0 || mobileMenuContent) && ( )} {/* Mobile hamburger menu (on right side) */} {showMobileMenu && ( )}
{/* Mobile dropdown menu */} {mobileMenuOpen && (dropdownOnlyActions.length > 0 || mobileMenuContent) && (
{/* Show subtitle on mobile if no leftText and no center title */} {!leftText && !title && subtitle && (

{subtitle}

)} {/* Mobile dropdown-only actions */} {dropdownOnlyActions.length > 0 && (
{dropdownOnlyActions.map((action) => ( action.content ? (
{action.content}
) : ( ) ))}
)} {/* Custom mobile menu content */} {mobileMenuContent && (
{mobileMenuContent}
)}
)}
); }