"use client"; import React from "react"; import { Check, ChevronsUpDown } from "lucide-react"; import { isValidBranchParam } from "@/lib/frontend/params"; import { cn } from "@/lib/utils"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Skeleton } from "@/components/ui/skeleton"; import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover"; import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, } from "@/components/ui/command"; function normalizeTypedBranch(value) { if (typeof value !== "string") return null; const s = value.trim().toUpperCase(); return s ? s : null; } export default function SearchSingleBranchCombobox({ branch, branchesStatus, availableBranches, onSingleBranchChange, isSubmitting, }) { const [open, setOpen] = React.useState(false); const [manual, setManual] = React.useState(""); const listReady = branchesStatus === "ready"; const listLoading = branchesStatus === "loading"; const listError = branchesStatus === "error"; const branchOptions = Array.isArray(availableBranches) ? availableBranches : []; const typed = normalizeTypedBranch(manual); const canApply = Boolean(typed && isValidBranchParam(typed)); return (
{listReady ? ( Keine Treffer. {branchOptions.map((b) => { const id = String(b); const isActive = id === branch; return ( { if (typeof onSingleBranchChange !== "function") return; const next = normalizeTypedBranch(value); if (!next || !isValidBranchParam(next)) return; if (next !== branch) onSingleBranchChange(next); setOpen(false); }} > {id} ); })} ) : listLoading ? (
{Array.from({ length: 6 }).map((_, i) => (
))}
) : (

Niederlassungen konnten nicht geladen werden. Sie können NLxx manuell eingeben.

setManual(e.target.value)} onKeyDown={(e) => { if (e.key !== "Enter") return; if (!canApply) return; e.preventDefault(); if (typeof onSingleBranchChange !== "function") return; onSingleBranchChange(typed); setManual(""); setOpen(false); }} placeholder="z. B. NL17" disabled={isSubmitting} />
)}
); }