import { useCallback, useState } from "react"; import { useTranslation } from "react-i18next"; import { LuInfo, LuX } from "react-icons/lu"; import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover"; import { Button } from "@/components/ui/button"; import { cn } from "@/lib/utils"; export type SaveAllPreviewItem = { scope: "global" | "camera"; cameraName?: string; profileName?: string; fieldPath: string; value: unknown; }; type SaveAllPreviewPopoverProps = { items: SaveAllPreviewItem[]; className?: string; align?: "start" | "center" | "end"; side?: "top" | "bottom" | "left" | "right"; }; export default function SaveAllPreviewPopover({ items, className, align = "end", side = "bottom", }: SaveAllPreviewPopoverProps) { const { t } = useTranslation(["views/settings", "common"]); const [open, setOpen] = useState(false); const resetLabel = t("saveAllPreview.value.reset", { ns: "views/settings", }); const formatValue = useCallback( (value: unknown) => { if (value === "") return resetLabel; if (typeof value === "string") return value; try { return JSON.stringify(value, null, 2); } catch { return String(value); } }, [resetLabel], ); return ( event.preventDefault()} >
{t("saveAllPreview.title", { ns: "views/settings" })}
{items.length === 0 ? (
{t("saveAllPreview.empty", { ns: "views/settings" })}
) : (
{items.map((item) => { const scopeLabel = item.scope === "global" ? t("saveAllPreview.scope.global", { ns: "views/settings", }) : t("saveAllPreview.scope.camera", { ns: "views/settings", cameraName: item.cameraName, }); return (
{t("saveAllPreview.scope.label", { ns: "views/settings", })} {scopeLabel} {item.profileName && ( <> {t("saveAllPreview.profile.label", { ns: "views/settings", })} {item.profileName} )} {t("saveAllPreview.field.label", { ns: "views/settings", })} {item.fieldPath} {t("saveAllPreview.value.label", { ns: "views/settings", })} {formatValue(item.value)}
); })}
)}
); }