// ==========================================
// Debug Modal — State Tab
// ==========================================
// Displays current application state snapshot as formatted JSON.
//
// v0.37.18: Preact rebuild from debug.js _renderStateTab().

const html = window.html;
const { useMemo } = window.hooks;

function _esc(s) {
    if (!s) return '';
    return String(s).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
}

/**
 * @param {{ engine: { getStateSnapshot: () => object } }} props
 */
export function StateTab({ engine }) {
    const snap = useMemo(() => engine.getStateSnapshot(), [engine.entries.length]);

    return html`
        <div class="debug-state-tab">
            <div class="debug-content">
                <pre class="debug-pre debug-state-pre">${_esc(JSON.stringify(snap, null, 2))}</pre>
            </div>
        </div>`;
}
