import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'; import { ArrowLeft, ClipboardCopy, ExternalLink, FileInput, Loader2, Plus, Trash2, GripVertical, } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Textarea } from '@/components/ui/textarea'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '@/components/ui/select'; import AppShell from '@/components/layout/AppShell'; import CtaFormPreview from '@/components/settings/CtaFormPreview'; import { apiFetch } from '@/lib/api'; import { buildCtaEmbedCodes } from '@/lib/ctaFormEmbed'; import { cn } from '@/lib/utils'; const FIELD_PRESETS = [ { key: 'name', label: 'Name', type: 'text', required: true, map_to: 'name' }, { key: 'email', label: 'Email', type: 'email', required: true, map_to: 'email' }, { key: 'company_name', label: 'Company Name', type: 'text', required: false, map_to: 'company_name', }, { key: 'title', label: 'Job Title', type: 'text', required: false, map_to: 'title' }, { key: 'phone', label: 'Phone', type: 'tel', required: false, map_to: 'phone' }, { key: 'message', label: 'Message', type: 'textarea', required: false, map_to: 'message' }, ]; const MAP_OPTIONS = [ { value: 'name', label: 'Full name' }, { value: 'email', label: 'Email' }, { value: 'company_name', label: 'Company' }, { value: 'title', label: 'Job title' }, { value: 'phone', label: 'Phone' }, { value: 'message', label: 'Message' }, { value: 'custom', label: 'Custom (in submission only)' }, ]; const AUTOSAVE_MS = 600; function emptyDraft() { return { name: 'New contact form', fields: FIELD_PRESETS.slice(0, 3).map((f) => ({ ...f })), }; } function draftFromForm(form) { return { name: form.name, fields: (form.fields || []).map((f) => ({ ...f })), }; } function draftSnapshot(draft) { return JSON.stringify({ name: (draft.name || '').trim(), fields: draft.fields || [], }); } function CopyBlock({ label, code }) { return (

{label}