"use client"; import { useMemo } from "react"; import useSWR from "swr"; import { Check, ImageIcon, Loader2, UserRound } from "lucide-react"; import { Button } from "@/components/ui/button"; import { cn, fetcher } from "@/lib/utils"; import { normalizeAgentWorkflowBrandModelConfig } from "@/lib/agents/workflow-brand-model-config"; import type { AgentWorkflowBrandModelConfig, AgentWorkflowSelectedBrandModel, } from "@/types/agent"; interface AgentWorkflowBrandModelPickerProps { brand: string; selectedBrandModel?: AgentWorkflowSelectedBrandModel | null; onSelectBrandModel: (value: AgentWorkflowSelectedBrandModel | null) => void; theme?: "light" | "dark"; } export function AgentWorkflowBrandModelPicker({ brand, selectedBrandModel = null, onSelectBrandModel, theme = "light", }: AgentWorkflowBrandModelPickerProps) { const normalizedBrand = brand.trim(); const brandModelSettingsKey = normalizedBrand ? `/api/site-settings?scope=agent-brand-model&brand=${encodeURIComponent( normalizedBrand )}` : null; const { data, error } = useSWR<{ agentWorkflowBrandModelConfig?: AgentWorkflowBrandModelConfig; }>(brandModelSettingsKey, fetcher, { errorRetryCount: 1, revalidateOnFocus: false, }); const config = useMemo( () => normalizeAgentWorkflowBrandModelConfig(data?.agentWorkflowBrandModelConfig), [data?.agentWorkflowBrandModelConfig] ); const matchedEntry = useMemo( () => config.entries.find( (entry) => entry.brandName.toLowerCase() === normalizedBrand.toLowerCase() ) || null, [config.entries, normalizedBrand] ); const images = matchedEntry?.images || []; const isDark = theme === "dark"; const isLoading = Boolean(normalizedBrand) && !data && !error; const renderPlaceholderGrid = (message: string, iconMode: "loading" | "empty" = "empty") => (