import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useState } from "react";
import { Button } from "../../button";
import { Input } from "../../input";
import { Popover, PopoverContent, PopoverTrigger } from "../../popover";
export const TextCombobox = ({ filterType, filterValue, setFilterValue, }) => {
    const [open, setOpen] = useState(false);
    const [inputValue, setInputValue] = useState(filterValue);
    const handleKeyDown = (event) => {
        if (event.key === "Enter") {
            setFilterValue(inputValue);
            setOpen(false);
        }
    };
    return (_jsxs(Popover, { _open: open, onOpenChange: (open) => {
            setOpen(open);
            if (!open && inputValue !== filterValue) {
                setInputValue(filterValue);
            }
        }, children: [_jsx(PopoverTrigger, { className: "rounded-none p-1 h-8 bg-muted hover:bg-muted/50 text-muted hover:text-primary shrink-0 transition", children: _jsx("div", { className: "flex gap-1.5 items-center", children: filterValue || "Enter text..." }) }), _jsx(PopoverContent, { className: "w-[300px] p-3", children: _jsxs("div", { className: "flex flex-col gap-1", children: [_jsx("div", { className: "flex items-center p-1.5 text-xs text-muted", children: _jsx("span", { children: filterType }) }), _jsx(Input, { autoFocus: true, type: "text", size: "sm", value: inputValue, onChange: setInputValue, onKeyDown: handleKeyDown, placeholder: "Enter text..." }), _jsx("div", { className: "mt-2 p-2 border-t", children: _jsxs("div", { className: "flex gap-2 justify-end", children: [_jsx(Button, { variant: "ghost", size: "sm", onClick: () => {
                                            setInputValue(filterValue);
                                            setOpen(false);
                                        }, children: "Cancel" }), _jsx(Button, { size: "sm", onClick: () => {
                                            setFilterValue(inputValue);
                                            setOpen(false);
                                        }, children: "Apply" })] }) })] }) })] }));
};
//# sourceMappingURL=TextCombobox.js.map