"use client"; import React from "react"; import { SEARCH_SCOPE } from "@/lib/frontend/search/urlState"; import SearchQueryBox from "@/components/search/form/SearchQueryBox"; import SearchScopeSelect from "@/components/search/form/SearchScopeSelect"; import SearchLimitSelect from "@/components/search/form/SearchLimitSelect"; import SearchSingleBranchCombobox from "@/components/search/form/SearchSingleBranchCombobox"; import SearchMultiBranchPicker from "@/components/search/form/SearchMultiBranchPicker"; import SearchDateRangePicker from "@/components/search/form/SearchDateRangePicker"; import SearchDateFilterChip from "@/components/search/form/SearchDateFilterChip"; import { Alert, AlertTitle, AlertDescription } from "@/components/ui/alert"; import { AlertCircleIcon } from "lucide-react"; export default function SearchForm({ branch, qDraft, onQDraftChange, onSubmit, currentQuery, isSubmitting, isAdminDev, scope, onScopeChange, onSingleBranchChange, availableBranches, branchesStatus, selectedBranches, onToggleBranch, onClearAllBranches, limit, onLimitChange, from, to, onDateRangeChange, validationError, }) { const canSearch = typeof qDraft === "string" && qDraft.trim().length > 0; // RHL-038 UI behavior: // - Single scope shows an extra combobox (branch picker). // - Multi/All does not. // - We animate the combobox container (max-width/max-height/opacity) so the // query block (input + search button) grows/shrinks smoothly. const showSingleBranchCombobox = Boolean( isAdminDev && scope === SEARCH_SCOPE.SINGLE ); const hasDateFilter = Boolean(from || to); return (
{ e.preventDefault(); if (!canSearch) return; onSubmit(); }} className="space-y-4" > {/* Layout goal: - Desktop: everything on one line (scope + optional single combobox | query | date range | limit) - Mobile: stack to avoid horizontal overflow */}
{/* Left block: scope + (animated) single-branch combobox */} {isAdminDev ? (
{/* Animated presence (no mount/unmount): - When hidden: max-w-0/max-h-0 + opacity-0 so it takes no space. - When shown: expands to a reasonable max size. This animation drives the smooth resize of the query input block. */}
) : null} {/* Middle block: query must take the most space */}
{/* Date range picker */}
{/* Right block: limit stays “content-sized” */}
{/* Validation feedback belongs near the inputs (not in results). */} {validationError ? ( {validationError.title} {validationError.description} ) : null} {/* Active date filter chip (quick clear) */} {hasDateFilter ? (
Aktive Filter: { if (typeof onDateRangeChange !== "function") return; onDateRangeChange({ from: null, to: null }); }} />
) : null} {/* Multi scope branch picker remains below */} {isAdminDev && scope === SEARCH_SCOPE.MULTI ? ( ) : null}
); }