import React, { ReactNode, useCallback, useMemo } from 'react'; import { Title, TitleProps, Breadcrumbs, Anchor, Box, Text, ThemeIcon, Flex, Divider, ActionIcon, Tooltip, } from '@mantine/core'; import { useLocalStorage } from '@mantine/hooks'; import { Link } from 'react-router-dom'; import { ChevronRight, LucideIcon, Maximize2, Minimize2 } from 'lucide-react'; // <-- Update Import Icon import { PageActions, PageActionsProps } from '../../../../components'; // --------------------------------------------------------------------------- // Types // --------------------------------------------------------------------------- export interface BreadcrumbItem { label: string; href?: string; type: 'text' | 'link'; } export interface ModulePageHeaderProps { title?: ReactNode; titleProps?: Omit; miniTitleProps?: Omit; description?: React.ReactNode; icon?: LucideIcon; badges?: React.ReactNode; showBadges?: boolean; breadcrumbs?: BreadcrumbItem[]; showPageHeader?: boolean; disableMinimize?: boolean; moduleKey: string; actions?: PageActionsProps['actions']; customButtonProps?: PageActionsProps['customButtonProps']; } // --------------------------------------------------------------------------- // Shared transition style applied to all animated wrappers // --------------------------------------------------------------------------- const TRANSITION_STYLE: React.CSSProperties = { transition: 'all 0.25s cubic-bezier(0.4, 0, 0.2, 1)', }; // --------------------------------------------------------------------------- // Sub-components // --------------------------------------------------------------------------- interface BreadcrumbBarProps { breadcrumbs: BreadcrumbItem[]; } function BreadcrumbBar({ breadcrumbs }: BreadcrumbBarProps) { return ( } > {breadcrumbs.map((item, index) => { const isText = item.type === 'text'; const isLast = index === breadcrumbs.length - 1; const sharedProps = { c: !isLast ? ('dimmed' as const) : undefined, size: 'xs' as const, fw: 500, style: { color: isLast ? 'var(--mantine-color-text)' : undefined, transition: 'color 0.2s ease', letterSpacing: '0.2px', }, }; return !isText ? ( {item.label} ) : ( {item.label} ); })} ); } // --------------------------------------------------------------------------- // HeaderToggle // --------------------------------------------------------------------------- interface HeaderToggleProps { isMinimized: boolean; onToggle: () => void; } function HeaderToggle({ isMinimized, onToggle }: HeaderToggleProps) { // const ToggleIcon = isMinimized ? ChevronDown : ChevronUp; const ToggleIcon = isMinimized ? Maximize2 : Minimize2; const label = isMinimized ? 'Expand header' : 'Collapse header'; return ( ); } // --------------------------------------------------------------------------- // Main component // --------------------------------------------------------------------------- export function ModulePageHeader(_props: ModulePageHeaderProps) { const { title, titleProps, miniTitleProps, description, icon: Icon, badges, showBadges = true, breadcrumbs, actions, customButtonProps, showPageHeader = true, disableMinimize = false, moduleKey, } = _props; const [isMinimized, setIsMinimized] = useLocalStorage({ key: `page-header-minimized__${btoa(moduleKey)}`, defaultValue: false, getInitialValueInEffect: false, }); if (!showPageHeader) { return null; } const showToggle = !disableMinimize; const handleToggle = useCallback(() => setIsMinimized((v) => !v), [setIsMinimized]); const compactButtonProps = useMemo( () => (action: any) => { if (customButtonProps) return customButtonProps(action); return { size: 'xs' as const }; }, [customButtonProps], ); // ------------------------------------------------------------------------- // Compact / Toolbar mode // ------------------------------------------------------------------------- if (isMinimized) { return ( {/* Left cluster: title + badges */} {title && ( {title} )} {showBadges && badges && {badges}} {/* Right: actions + inline toggle (separated by divider) */} {actions && } {showToggle && ( <> {actions && actions.length > 0 && ( )} )} ); } // ------------------------------------------------------------------------- // Expanded / Full mode // ------------------------------------------------------------------------- const hasBreadcrumbs = breadcrumbs && breadcrumbs.length > 0; return ( {/* 1. Top Navigation Row: Breadcrumbs & Toggle */} {((breadcrumbs && breadcrumbs.length) || showToggle) && ( {hasBreadcrumbs && } {showToggle && ( )} )} {/* 2. Main Header Row – 3-column layout */} {Icon && ( )} {(title || badges || description) && ( {title && ( {title} )} {showBadges && badges && {badges}} {description && ( {description} )} )} {actions && } ); }