'use client'; import React, { useState, useEffect } from 'react'; import { useRecordMode } from './RecordModeContext'; import { finder } from '@medv/finder'; import { Play, Square, MousePointer2, Scroll, Plus, Save, Trash2, Eye, Edit2, X, Check, Download, } from 'lucide-react'; import { RecordEvent } from '@/types/record-mode'; import { PlaybackCursor } from './PlaybackCursor'; export function RecordModeOverlay() { const { isActive, setIsActive, events, addEvent, updateEvent, removeEvent, isPlaying, playEvents, saveSession, clearEvents, } = useRecordMode(); const [pickingMode, setPickingMode] = useState<'click' | 'scroll' | null>(null); const [hoveredElement, setHoveredElement] = useState(null); const [editingEventId, setEditingEventId] = useState(null); // Edit form state const [editForm, setEditForm] = useState>({}); const [mounted, setMounted] = useState(false); useEffect(() => { setMounted(true); }, []); useEffect(() => { if (!mounted || !isActive) return; const handleMessage = (e: MessageEvent) => { if (e.data.type === 'ELEMENT_SELECTED') { const { selector, rect, tagName } = e.data; if (pickingMode === 'click') { addEvent({ type: 'click', selector, duration: 1000, zoom: 1, description: `Click on ${tagName}`, motionBlur: false, rect, }); } else if (pickingMode === 'scroll') { addEvent({ type: 'scroll', selector, duration: 1500, zoom: 1, description: `Scroll to ${tagName}`, motionBlur: false, rect, }); } setPickingMode(null); } else if (e.data.type === 'PICKING_CANCELLED') { setPickingMode(null); } }; window.addEventListener('message', handleMessage); if (pickingMode) { // Find the iframe and signal start picking const iframe = document.querySelector('iframe'); if (iframe?.contentWindow) { iframe.contentWindow.postMessage({ type: 'START_PICKING', mode: pickingMode }, '*'); } } else { // Signal stop picking const iframe = document.querySelector('iframe'); if (iframe?.contentWindow) { iframe.contentWindow.postMessage({ type: 'STOP_PICKING' }, '*'); } } return () => { window.removeEventListener('message', handleMessage); }; }, [isActive, pickingMode, addEvent]); const [showEvents, setShowEvents] = useState(false); if (!mounted) return null; if (!isActive) { // Failsafe: Never render host toggle in embedded mode if (typeof window !== 'undefined' && (window.self !== window.top || window.name === 'record-mode-iframe' || window.location.search.includes('embedded=true'))) { return null; } return ( ); } return (
{/* 1. Global Toolbar - Slim Industrial Bar */}
{/* Identity Tag */}
Event Builder Manual Mode
{/* Action Tools */}
{/* Sequence Controls */}
{/* 2. Event Timeline Popover */} {showEvents && (

Recording Track

{events.length} Actions Recorded

{events.length === 0 ? (

Timeline is empty

) : ( events.map((event, index) => (
{index + 1}
{event.type} {event.duration}ms

{event.selector || 'system:wait'}

)) )}
)} {/* Industrial Selector Highlighter - handled inside iframe via PickingHelper */} {/* Picking Tooltip */} {pickingMode && (
Assigning {pickingMode}
)}
); }