import { useState, type ReactNode } from "react"; import { useTranslation } from "react-i18next"; import { Bookmark, Check, Settings2 } from "lucide-react"; import { PopoverItem, PopoverSurface, useAnchoredPopover } from "./AnchoredPopover"; import { useSavedViews } from "./SavedViewsProvider"; // The saved-views quick-picker. The filter-panel header's icon (and the toolbar's view chip) use it as // their trigger: click → a popover list of the user's saved views (apply on click, the active one // checked) + a "Manage views…" entry that opens the Personal Views modal, where the editing lives. export default function SavedViewsPopover({ trigger, className, ariaLabel, placement = "bottom-start", }: { trigger: ReactNode; className?: string; ariaLabel?: string; placement?: "bottom-start" | "bottom-end"; }) { const { t } = useTranslation(); const { views, activeViewId, apply, openModal } = useSavedViews(); const [open, setOpen] = useState(false); const pop = useAnchoredPopover({ open, onOpenChange: setOpen, placement }); const label = ariaLabel ?? t("views.saved"); return ( <> {views.length === 0 ? (

{t("views.empty")}

) : (
{views.map((v) => ( { apply(v); setOpen(false); }} label={v.name} className={`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm transition ${ v.id === activeViewId ? "text-fg" : "text-muted" }`} > ))}
)}
{ openModal(); setOpen(false); }} label={t("views.manage")} className="flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm text-muted transition hover:text-fg" >
); }