"use client"; import React from "react"; import { Clock3, Search } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover"; import { Command, CommandGroup, CommandItem, CommandList, } from "@/components/ui/command"; function getScopeSummary(entry) { if (entry?.scope === "all") return "Alle Niederlassungen"; if (entry?.scope === "multi") { const count = Array.isArray(entry?.branches) ? entry.branches.length : 0; return count > 0 ? `Mehrere Niederlassungen (${count})` : "Mehrere Niederlassungen"; } return `Niederlassung ${entry?.routeBranch || ""}`.trim(); } function getDateSummary(entry) { const from = typeof entry?.from === "string" ? entry.from.trim() : ""; const to = typeof entry?.to === "string" ? entry.to.trim() : ""; if (from && to) return `${from} bis ${to}`; if (from) return `ab ${from}`; if (to) return `bis ${to}`; return ""; } function getEntryMetaSummary(entry) { const parts = [getScopeSummary(entry)]; const dateSummary = getDateSummary(entry); if (dateSummary) parts.push(dateSummary); return parts.join(" • "); } export default function SearchQueryBox({ qDraft, onQDraftChange, onSubmit, currentQuery, isSubmitting, canSearch, recentSearches, onSelectRecentSearch, onClearRecentSearches, }) { const [open, setOpen] = React.useState(false); const historyItems = Array.isArray(recentSearches) ? recentSearches : []; const hasHistory = historyItems.length > 0; const canClearHistory = hasHistory && typeof onClearRecentSearches === "function"; React.useEffect(() => { if (hasHistory) return; setOpen(false); }, [hasHistory]); const handleInputFocus = React.useCallback(() => { const trimmedDraft = typeof qDraft === "string" ? qDraft.trim() : ""; if (trimmedDraft) return; if (!hasHistory) return; setOpen(true); }, [qDraft, hasHistory]); return ( // Important for flex layouts: // - w-full ensures the box fills its container width. // - min-w-0 allows the input row to shrink without overflow.
{entry.q}
{getEntryMetaSummary(entry)}