/**
 * with_field_audit — internal helper that wires the FieldAudit feature into
 * a form view when `enable_field_audit` is true.
 *
 * Returns:
 *  - `wrap(children)` — wraps the children in a FieldAuditProvider + a
 *    FormDataAuditor that watches the current `form_data`.
 *  - `merged_components` — the `field_action_components` value to feed into
 *    the form's context. Consumer-supplied slots win on collision so they
 *    can be combined with the audit overlay.
 *
 * When `enable_field_audit` is false this helper is a no-op: `wrap` returns
 * its children unchanged and `merged_components` is the original prop.
 */
'use client';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useMemo } from 'react';
import { FieldAuditProvider } from './context.js';
import { FormDataAuditor } from './auditor.js';
import { FieldAuditIcon } from './field_audit_icon.js';
import { FieldAuditPanel } from './field_audit_panel.js';
export function useFieldAuditWiring(options) {
    const { enable_field_audit, field_action_components, form_data, current_user, audit_debounce_ms, } = options;
    const merged_components = useMemo(() => {
        if (!enable_field_audit)
            return field_action_components;
        return {
            row_end: field_action_components?.row_end ?? FieldAuditIcon,
            row_below: field_action_components?.row_below ?? FieldAuditPanel,
        };
    }, [enable_field_audit, field_action_components]);
    const wrap = useMemo(() => {
        if (!enable_field_audit) {
            return (children) => children;
        }
        return (children) => (_jsxs(FieldAuditProvider, { children: [_jsx(FormDataAuditor, { form_data: form_data, current_user: current_user, debounce_ms: audit_debounce_ms }), children] }));
        // form_data identity must be allowed to refresh the watcher; current_user
        // typically stable.
    }, [enable_field_audit, form_data, current_user, audit_debounce_ms]);
    return { merged_components, wrap };
}
//# sourceMappingURL=with_field_audit.js.map