import React from 'react'; import { View, Text, ScrollView } from 'react-native'; import { useTranslation } from 'react-i18next'; import { useTheme } from '~/features/theme/ThemeProvider'; import Button from '~/components/atoms/Button'; interface ToolbarAction { icon: string; label: string; onPress: () => void; color?: string; variant?: 'primary' | 'secondary' | 'danger'; } interface ToolbarProps { // Position options position: 'top' | 'bottom'; // Layout options layout?: 'row' | 'column'; // Content options title?: string; primaryActions?: ToolbarAction[]; secondaryActions?: ToolbarAction[]; additionalActions?: ToolbarAction[]; // For selection toolbar specific selectedCount?: number; // For edit toolbar specific onSave?: () => void; onCancel?: () => void; // Style options scrollable?: boolean; className?: string; backgroundColor?: string; disableAbsolutePosition?: boolean; } /** * A unified toolbar component that can be used for various purposes like * editing, selection, or other actions. It can be positioned at the top or bottom * of the screen and can have different layouts. */ const Toolbar = ({ position = 'top', layout = 'row', title, primaryActions = [], secondaryActions = [], additionalActions = [], selectedCount, onSave, onCancel, scrollable = false, className = '', backgroundColor, disableAbsolutePosition = false, }: ToolbarProps): React.ReactElement => { const { isDark } = useTheme(); const { t } = useTranslation(); // Dynamic classes based on theme const containerBgClass = isDark ? 'bg-gray-800' : 'bg-gray-200'; const textColorClass = isDark ? 'text-white' : 'text-black'; // Use custom background color if provided const finalBackgroundColor = backgroundColor || (isDark ? '#1F1F1F' : '#E5E5EA'); // Position classes const positionClass = position === 'top' ? 'top-0 left-0 right-0 z-50' : 'bottom-0 left-0 right-0 z-50'; // Layout classes const layoutClass = layout === 'row' ? 'flex-row justify-between' : 'flex-col justify-center'; // Prepare actions const allActions = [ ...(onCancel ? [{ icon: 'close-outline', label: t('common.cancel', 'Cancel'), onPress: onCancel, variant: 'secondary' as const, }] : []), ...primaryActions, ...additionalActions, ...(onSave ? [{ icon: 'checkmark-outline', label: t('common.save', 'Save'), onPress: onSave, variant: 'primary' as const, }] : []), ...secondaryActions, ]; // Render the content const renderContent = () => { // If we have a selection count, show title, actions, and count if (selectedCount !== undefined) { return ( <> {selectedCount === 1 ? t('memo.process_selected_singular', 'Ausgewähltes {{count}} Memo verarbeiten:', { count: selectedCount }) : t('memo.process_selected_plural', 'Ausgewählte {{count}} Memos verarbeiten:', { count: selectedCount }) } {renderActions()} ); } // If we have a title, show it if (title) { return ( <> {title} {renderActions()} ); } // Otherwise just show the actions return renderActions(); }; // Render the actions const renderActions = () => { if (scrollable) { return ( {allActions.map((action, index) => renderAction(action, index))} ); } if (layout === 'row') { return ( <> {/* Left side */} {onCancel && (