/**
 * IhelpIcon — Shared dynamic loader for hazo_ihelp inline help icons.
 *
 * Lazily imports hazo_ihelp (optional peer dependency) and renders
 * an IhelpIcon next to labels. Module-level cache ensures the import
 * only runs once across the entire app.
 *
 * Consumers can bypass dynamic import by calling register_ihelp_icon()
 * or by passing ihelp_icon prop on HazoCollabFormView / HazoDataForm.
 */
'use client';
import React from 'react';
import { optional_import } from '../../utils/optional_import.js';
// Module-level cache: prevents multiple dynamic imports
let _ihelp_load_state = 'pending';
let _ihelp_icon_render = null;
/** Register an externally provided IhelpIcon component, bypassing dynamic import. */
export function register_ihelp_icon(Icon) {
    _ihelp_icon_render = (p) => React.createElement(Icon, { context_key: p.context_key, size: p.size ?? 14, className: 'flex-shrink-0' });
    _ihelp_load_state = 'loaded';
}
export function IhelpIcon({ context_key, size = 14 }) {
    const [, force_update] = React.useState(0);
    React.useEffect(() => {
        if (_ihelp_load_state !== 'pending')
            return;
        _ihelp_load_state = 'loaded'; // prevent concurrent loads
        optional_import('hazo_ihelp').then((mod) => {
            if (mod?.IhelpIcon) {
                register_ihelp_icon(mod.IhelpIcon);
                force_update(n => n + 1);
            }
            else {
                _ihelp_load_state = 'failed';
            }
        }).catch(() => { _ihelp_load_state = 'failed'; });
    }, []);
    if (!_ihelp_icon_render)
        return null;
    return _ihelp_icon_render({ context_key, size });
}
//# sourceMappingURL=ihelp_icon.js.map