/**
 * Replay panel data provider.
 *
 * Wraps a `DeterministicReplayEngine` and exposes its state for the
 * diagnostics view as a snapshot-based panel. Subscribers are notified
 * whenever the engine state changes (load, step, seek, diff, reset).
 *
 * This panel is push-passive: it does not drive the engine itself.
 * The caller (or the /replay command handler) drives the engine.
 */
import { logger } from '../../../utils/logger.js';
import { summarizeError } from '../../../utils/error-display.js';
/**
 * ReplayPanel — diagnostics data provider for the deterministic replay view.
 *
 * Usage:
 * ```ts
 * const panel = new ReplayPanel(engine);
 * panel.subscribe(() => {
 *   const snap = panel.getSnapshot();
 *   render(snap);
 * });
 * ```
 */
export class ReplayPanel {
    _engine;
    _subscribers = new Set();
    _unsub = null;
    constructor(engine) {
        this._engine = engine;
        // Forward engine notifications to panel subscribers.
        this._unsub = engine.subscribe(() => this._notify());
    }
    /**
     * Get the current engine snapshot for rendering.
     */
    getSnapshot() {
        return this._engine.getSnapshot();
    }
    /**
     * Register a callback invoked whenever engine state changes.
     * @returns An unsubscribe function.
     */
    subscribe(callback) {
        this._subscribers.add(callback);
        return () => this._subscribers.delete(callback);
    }
    /**
     * Release all subscriptions and disconnect from the engine.
     */
    dispose() {
        this._unsub?.();
        this._unsub = null;
        this._subscribers.clear();
    }
    _notify() {
        for (const cb of this._subscribers) {
            try {
                cb();
            }
            catch (err) {
                logger.warn('[ReplayPanel] subscriber error', { error: summarizeError(err) });
            }
        }
    }
}
