"use client"; import { TextInput } from "@/components/ui/TextInput/TextInput"; import { Button } from "@/components/ui/button"; import { ArrowDown, ArrowUp, Plus, Trash2 } from "lucide-react"; import type { ListScreenDefinition, ListOptionDefinition, SelectionType, BottomActionButtonDefinition } from "@/lib/funnel/types"; import type { BuilderScreen } from "@/lib/admin/builder/types"; interface ListScreenConfigProps { screen: BuilderScreen & { template: "list" }; onUpdate: (updates: Partial) => void; } function mutateOptions( options: ListOptionDefinition[], index: number, mutation: (option: ListOptionDefinition) => ListOptionDefinition ): ListOptionDefinition[] { return options.map((option, currentIndex) => (currentIndex === index ? mutation(option) : option)); } export function ListScreenConfig({ screen, onUpdate }: ListScreenConfigProps) { const listScreen = screen as ListScreenDefinition & { position: { x: number; y: number } }; const handleSelectionTypeChange = (selectionType: SelectionType) => { onUpdate({ list: { ...listScreen.list, selectionType, }, }); }; const handleAutoAdvanceChange = (checked: boolean) => { onUpdate({ list: { ...listScreen.list, autoAdvance: checked || undefined, }, }); }; const handleOptionChange = ( index: number, field: keyof ListOptionDefinition, value: string | boolean | undefined ) => { const nextOptions = mutateOptions(listScreen.list.options, index, (option) => ({ ...option, [field]: value, })); onUpdate({ list: { ...listScreen.list, options: nextOptions, }, }); }; const handleMoveOption = (index: number, direction: -1 | 1) => { const nextOptions = [...listScreen.list.options]; const targetIndex = index + direction; if (targetIndex < 0 || targetIndex >= nextOptions.length) { return; } const [current] = nextOptions.splice(index, 1); nextOptions.splice(targetIndex, 0, current); onUpdate({ list: { ...listScreen.list, options: nextOptions, }, }); }; const handleAddOption = () => { const nextOptions = [ ...listScreen.list.options, { id: `option-${Date.now()}`, label: "Новый вариант", }, ]; onUpdate({ list: { ...listScreen.list, options: nextOptions, }, }); }; const handleRemoveOption = (index: number) => { const nextOptions = listScreen.list.options.filter((_, currentIndex) => currentIndex !== index); onUpdate({ list: { ...listScreen.list, options: nextOptions, }, }); }; const handleListButtonChange = (value: BottomActionButtonDefinition | undefined) => { onUpdate({ list: { ...listScreen.list, bottomActionButton: value, }, }); }; return (

Варианты выбора

Настройка вариантов

{listScreen.list.options.map((option, index) => (
Вариант {index + 1}
))}
{listScreen.list.options.length === 0 && (
Добавьте хотя бы один вариант, чтобы экран работал корректно.
)}

Кнопка внутри списка

{listScreen.list.bottomActionButton && (
)}

Для одиночного выбора пустая кнопка включает авто-переход. Для множественного выбора кнопка отображается всегда.

); }