'use client'; import { Listbox } from '@headlessui/react'; import type { IconSize, SortBy, SortDirection, ViewMode } from '@/types/documents'; import { IconsViewIcon, ListViewIcon, GalleryViewIcon, SearchIcon, HamburgerIcon, } from './finderIcons'; import { ChevronUpDownIcon } from '@/components/icons/Icons'; import { SearchField, SharedListboxButton, SharedListboxOption, SharedListboxOptions, Toolbar, ToolbarButton, ToolbarGroup, ToolbarSegment } from '@/components/ui'; import type { ReactNode } from 'react'; interface FinderToolbarProps { viewMode: ViewMode; onViewModeChange: (mode: ViewMode) => void; iconSize: IconSize; onIconSizeChange: (size: IconSize) => void; sortBy: SortBy; sortDirection: SortDirection; onSortByChange: (s: SortBy) => void; onSortDirectionToggle: () => void; query: string; onQueryChange: (q: string) => void; onToggleSidebar: () => void; isSidebarOpen: boolean; showSortControls?: boolean; /** App-level content rendered at the far left (brand/logo). */ leftSlot?: ReactNode; /** App-level content rendered at the far right (settings, user menu). */ rightSlot?: ReactNode; } const VIEW_BUTTONS: Array<{ value: ViewMode; label: string; Icon: typeof IconsViewIcon }> = [ { value: 'icons', label: 'Icons', Icon: IconsViewIcon }, { value: 'list', label: 'List', Icon: ListViewIcon }, { value: 'gallery', label: 'Gallery', Icon: GalleryViewIcon }, ]; const SORT_OPTIONS: Array<{ value: SortBy; label: string; asc: string; desc: string }> = [ { value: 'name', label: 'Name', asc: 'A → Z', desc: 'Z → A' }, { value: 'type', label: 'Kind', asc: 'A → Z', desc: 'Z → A' }, { value: 'date', label: 'Modified', asc: 'Oldest', desc: 'Newest' }, { value: 'size', label: 'Size', asc: 'Smallest', desc: 'Largest' }, ]; const ICON_SIZES: Array<{ value: IconSize; label: string }> = [ { value: 'sm', label: 'S' }, { value: 'md', label: 'M' }, { value: 'lg', label: 'L' }, { value: 'xl', label: 'XL' }, ]; export function FinderToolbar({ viewMode, onViewModeChange, iconSize, onIconSizeChange, sortBy, sortDirection, onSortByChange, onSortDirectionToggle, query, onQueryChange, onToggleSidebar, isSidebarOpen, showSortControls = true, leftSlot, rightSlot, }: FinderToolbarProps) { const currentSort = SORT_OPTIONS.find((o) => o.value === sortBy) ?? SORT_OPTIONS[0]; const directionLabel = sortDirection === 'asc' ? currentSort.asc : currentSort.desc; return ( {leftSlot && (
{leftSlot}
)} {VIEW_BUTTONS.map(({ value, label, Icon }) => { const active = viewMode === value; const isIconsToggle = value === 'icons'; return (
onViewModeChange(value)} active={active} aria-pressed={active} aria-label={`${label} view`} title={`${label} view`} className="w-7" > {isIconsToggle && viewMode === 'icons' && (
{ICON_SIZES.map(({ value: sizeValue, label: sizeLabel }) => { const sizeActive = iconSize === sizeValue; return ( onIconSizeChange(sizeValue)} active={sizeActive} aria-pressed={sizeActive} aria-label={`Icon size ${sizeLabel}`} className="min-w-[26px] px-1.5 font-semibold tracking-wide" > {sizeLabel} ); })}
)}
); })}
{showSortControls && (
{directionLabel} {currentSort.label} {SORT_OPTIONS.map((opt) => ( {opt.label} ))}
)}
onQueryChange(e.target.value)} placeholder="Search" className="hidden w-[160px] md:w-[200px] sm:flex" icon={} /> {rightSlot && (
{rightSlot}
)} ); }