import { useState } from "react";
import { ArrowRightLeft, Hexagon } from "lucide-react";
import { useTranslation } from "react-i18next";
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
import { HoverHint } from "@/components/ui/tooltip";
import { useLogoFallback } from "@/hooks/useLogoFallback";
import { providerBrand } from "@/lib/provider-brand";
import type { ResponseSource } from "@/lib/types";
import { cn } from "@/lib/utils";
export function FallbackResponseSources({
sources,
className,
badgeClassName,
}: {
sources?: ResponseSource[];
className?: string;
badgeClassName?: string;
}) {
const fallbacks = sources?.filter((source) => source.fallback === true) ?? [];
if (fallbacks.length === 0) return null;
return (
{fallbacks.map((source) => (
))}
);
}
/** A persisted invocation identity; deliberately independent of live settings. */
function ResponseSourceBadge({
source,
className,
}: {
source: ResponseSource;
className?: string;
}) {
const { t } = useTranslation();
const [open, setOpen] = useState(false);
const description = t("message.fallbackResponse", { preset: source.preset });
const brand = providerBrand(source.provider);
const { logoUrl, logoLoaded, onLogoLoad, onLogoError } = useLogoFallback(brand?.logoUrls);
const tile = brand?.logoLayout === "tile" && logoUrl === brand.logoUrl;
return (
event.preventDefault()}
className="max-w-[min(18rem,calc(100vw-2rem))] rounded-control px-3 py-2 text-xs leading-relaxed break-words">
{description}
);
}