import { DEFAULT_PANEL_CONFIG } from '../types.js';
export class ForensicsDataPanel {
    _config;
    _registry;
    _subscribers = new Set();
    _unsub = null;
    constructor(registry, config = DEFAULT_PANEL_CONFIG) {
        this._config = config;
        this._registry = registry;
        this._unsub = registry.subscribe(() => this._notify());
    }
    /**
     * Return all reports, newest first, capped at bufferLimit.
     */
    getAll() {
        const all = this._registry.getAll();
        return all.slice(0, this._config.bufferLimit);
    }
    /**
     * Return the most recent report.
     */
    latest() {
        return this._registry.latest();
    }
    /**
     * Return a report by ID.
     */
    getById(id) {
        return this._registry.getById(id);
    }
    /**
     * Subscribe to data changes. Returns an unsubscribe function.
     */
    subscribe(callback) {
        this._subscribers.add(callback);
        return () => { this._subscribers.delete(callback); };
    }
    /**
     * Dispose the data panel, unsubscribing from the registry.
     */
    dispose() {
        if (this._unsub) {
            this._unsub();
            this._unsub = null;
        }
        this._subscribers.clear();
    }
    _notify() {
        for (const cb of this._subscribers) {
            try {
                cb();
            }
            catch { /* non-fatal */ }
        }
    }
}
