"use client"; import { useState } from "react"; import { ChevronDown, ChevronRight } from "lucide-react"; import { TextInput } from "@/components/ui/TextInput/TextInput"; import { ImageUpload } from "@/components/admin/builder/forms/ImageUpload"; import { VariablesConfig } from "./VariablesConfig"; import { useBuilderState } from "@/lib/admin/builder/context"; import type { InfoScreenDefinition } from "@/lib/funnel/types"; import type { BuilderScreen } from "@/lib/admin/builder/types"; interface InfoScreenConfigProps { screen: BuilderScreen & { template: "info" }; onUpdate: (updates: Partial) => void; } function CollapsibleSection({ title, children, defaultExpanded = false, }: { title: string; children: React.ReactNode; defaultExpanded?: boolean; }) { const storageKey = `info-section-${title.toLowerCase().replace(/\s+/g, '-')}`; const [isExpanded, setIsExpanded] = useState(() => { if (typeof window === 'undefined') return defaultExpanded; const stored = sessionStorage.getItem(storageKey); return stored !== null ? JSON.parse(stored) : defaultExpanded; }); const handleToggle = () => { const newExpanded = !isExpanded; setIsExpanded(newExpanded); if (typeof window !== 'undefined') { sessionStorage.setItem(storageKey, JSON.stringify(newExpanded)); } }; return (
{isExpanded &&
{children}
}
); } export function InfoScreenConfig({ screen, onUpdate }: InfoScreenConfigProps) { const infoScreen = screen as InfoScreenDefinition; const state = useBuilderState(); // Получаем доступные экраны для настройки условий переменных const availableScreens = state.screens; const handleIconChange = >( field: T, value: NonNullable[T] | undefined ) => { const baseIcon = infoScreen.icon ?? { type: "emoji", value: "✨", size: "lg" }; if (field === "value") { if (!value) { onUpdate({ icon: undefined }); } else { onUpdate({ icon: { ...baseIcon, value } }); } return; } // При изменении типа иконки сбрасываем значение if (field === "type") { const defaultValue = value === "emoji" ? "✨" : ""; onUpdate({ icon: { ...baseIcon, type: value as "emoji" | "image", value: defaultValue } }); return; } onUpdate({ icon: { ...baseIcon, [field]: value } }); }; return (
{/* Иконка */}
{infoScreen.icon?.type === "image" ? (
Изображение иконки handleIconChange("value", url)} onImageRemove={() => handleIconChange("value", undefined)} funnelId={screen.id} />
) : ( )}
{/* Переменные */} onUpdate({ variables })} availableScreens={availableScreens} />
); }