/**
 * Shared hook that wraps ViewCallbacks into stable useCallback references.
 *
 * EditView creates ~12 useCallback wrappers that simply forward calls
 * to the `callbacks` object from context. This hook consolidates them.
 */
'use client';
import { useCallback } from 'react';
import { emit_form_intent } from '../../../audit/intent_emitter.js';
/**
 * Creates stable callback wrappers around ViewCallbacks from context.
 * Each callback is memoized with [callbacks] as the only dependency.
 */
export function use_view_callbacks({ callbacks, field_audit, form_id }) {
    const handle_field_change = useCallback((field_id, value) => {
        callbacks.on_field_change?.(field_id, value);
    }, [callbacks]);
    const handle_form_data_change = useCallback((data) => {
        callbacks.on_form_data_change?.(data);
    }, [callbacks]);
    const handle_metadata_change = useCallback((change) => {
        const { field_id, ...rest } = change;
        const context_change = {
            field_id,
            changes: rest,
        };
        callbacks.on_metadata_change?.(context_change);
    }, [callbacks]);
    const handle_data_ok_change = useCallback((field_id, value) => {
        callbacks.on_data_ok_change?.(field_id, value);
    }, [callbacks]);
    const handle_notes_change = useCallback((field_id, notes) => {
        callbacks.on_notes_change?.(field_id, notes);
    }, [callbacks]);
    const handle_visibility_change = useCallback((field_id, visibility) => {
        callbacks.on_visibility_change?.(field_id, visibility);
    }, [callbacks]);
    const handle_lock_change = useCallback((field_id, locked) => {
        callbacks.on_lock_change?.(field_id, locked);
    }, [callbacks]);
    const handle_delete = useCallback((field_id) => {
        callbacks.on_delete?.(field_id);
    }, [callbacks]);
    const handle_skip_change = useCallback((field_id, skipped) => {
        callbacks.on_skip_change?.(field_id, skipped);
    }, [callbacks]);
    const handle_add_field_config = useCallback((after_field_id, field_config) => {
        callbacks.on_add_field?.(after_field_id, field_config);
    }, [callbacks]);
    const handle_add_group_config = useCallback((position_id, group_config) => {
        callbacks.on_add_group_config?.(position_id, group_config);
    }, [callbacks]);
    const handle_edit_field_config = useCallback((field_id, current_config) => {
        callbacks.on_edit_field_config?.(field_id, current_config);
    }, [callbacks]);
    const handle_delete_field = useCallback((field_id) => {
        callbacks.on_delete_field?.(field_id);
    }, [callbacks]);
    const handle_files_change = useCallback((field_id, files) => {
        callbacks.on_field_files_change?.(field_id, files);
    }, [callbacks]);
    const handle_private_files_change = useCallback((field_id, files) => {
        callbacks.on_field_private_files_change?.(field_id, files);
    }, [callbacks]);
    const handle_revalidate = useCallback((field_id, validation_rule_ids) => {
        emit_form_intent('field_revalidated', { form_id, field_id }, field_audit).catch(() => { });
        callbacks.on_revalidate?.(field_id, validation_rule_ids);
    }, [callbacks, field_audit, form_id]);
    return {
        handle_field_change,
        handle_form_data_change,
        handle_metadata_change,
        handle_data_ok_change,
        handle_notes_change,
        handle_visibility_change,
        handle_lock_change,
        handle_delete,
        handle_skip_change,
        handle_add_field_config,
        handle_add_group_config,
        handle_edit_field_config,
        handle_delete_field,
        handle_files_change,
        handle_private_files_change,
        handle_revalidate,
    };
}
//# sourceMappingURL=use_view_callbacks.js.map