"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"; import { Tooltip, TooltipContent, TooltipTrigger, } from "@/components/ui/tooltip"; function toBranchShort(value) { const normalized = String(value || "").trim().toUpperCase(); const match = /^NL(\d+)$/i.exec(normalized); if (!match) return null; const digits = match[1]; return digits.length === 1 ? `0${digits}` : digits; } function getMultiBranchSummary(branches) { const compact = (Array.isArray(branches) ? branches : []) .map((branch) => toBranchShort(branch)) .filter(Boolean); if (compact.length === 0) return null; return `NL: ${compact.join(",")}`; } function getScopeSummary(entry) { if (entry?.scope === "all") return "Alle Niederlassungen"; if (entry?.scope === "multi") { const compactBranches = getMultiBranchSummary(entry?.branches); if (compactBranches) return compactBranches; 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]); React.useEffect(() => { if (!isSubmitting) return; setOpen(false); }, [isSubmitting]); 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)}