"use client"; import { useMemo } from "react"; import useSWR from "swr"; import { Check, ImageIcon, 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 { data } = useSWR<{ agentWorkflowBrandModelConfig?: AgentWorkflowBrandModelConfig }>( "/api/site-settings", fetcher ); const normalizedBrand = brand.trim(); 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"; return (
品牌模特选择
根据第一步选择的品牌,展示管理员预先上传的模特图。选中后会自动带入右侧“模特图”槽位。
{!normalizedBrand ? (
先回到第一步选择品牌,第二步才会按品牌展示可选模特图。
) : images.length > 0 ? (
品牌:{normalizedBrand} 共 {images.length} 张模特图 {selectedBrandModel ? ( 已选 1 张 ) : null}
{images.map((image) => { const selected = selectedBrandModel?.brandName === normalizedBrand && selectedBrandModel?.id === image.id; return ( ); })}
) : (
品牌“{normalizedBrand}”暂未配置模特图库,请到系统设置上传对应模特图。
)}
); }