"use client"; import { AiConfigCodeBlock } from "@app/components/ai-client-config/AiConfigCodeBlock"; import { OptionSelect, type OptionSelectOption } from "@app/components/OptionSelect"; import type { AiConfigBlock, AiConfigRelation } from "@app/lib/aiClientConfig"; import { useTranslations } from "next-intl"; import { useEffect, useMemo, useState } from "react"; type AiConfigBlocksProps = { blocks: AiConfigBlock[]; relation: AiConfigRelation; }; export function AiConfigBlocks({ blocks, relation }: AiConfigBlocksProps) { const t = useTranslations(); const showPicker = relation === "options" && blocks.length > 1; const [selectedId, setSelectedId] = useState(blocks[0]?.id ?? ""); const methodOptions: OptionSelectOption[] = useMemo( () => blocks.map((block) => ({ value: block.id, label: block.label })), [blocks] ); useEffect(() => { if (!blocks.some((block) => block.id === selectedId)) { setSelectedId(blocks[0]?.id ?? ""); } }, [blocks, selectedId]); if (blocks.length === 0) { return null; } if (showPicker) { const selected = blocks.find((block) => block.id === selectedId) ?? blocks[0]; return (
); } const numberSteps = relation === "steps" && blocks.length > 1; return (
{blocks.map((block, index) => ( ))}
); }