/**
 * FieldTooltip component for displaying help tooltips on field labels
 *
 * Supports both simple string format and full TooltipConfig format.
 * Uses HoverCard with dynamic import and native title attribute fallback.
 */
'use client';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import React from 'react';
import { HiQuestionMarkCircle } from 'react-icons/hi';
import { use_logger } from '../../../logger/context.js';
/**
 * Normalize tooltip value to TooltipConfig format
 */
function normalize_tooltip(tooltip) {
    if (typeof tooltip === 'string') {
        return {
            enabled: true,
            content: tooltip,
        };
    }
    return tooltip;
}
/**
 * FieldTooltip component
 *
 * Renders a question mark icon that displays tooltip content on hover.
 * Uses HoverCard when available, falls back to native title attribute.
 */
export function FieldTooltip({ tooltip, icon_class_name }) {
    const logger = use_logger();
    const normalized = normalize_tooltip(tooltip);
    // Don't render if tooltip is disabled or has no content
    if (!normalized.enabled || !normalized.content) {
        return null;
    }
    const [HoverCardComponents, setHoverCardComponents] = React.useState(null);
    React.useEffect(() => {
        const loadComponents = async () => {
            try {
                const hoverCardModule = await import('hazo_ui').catch(() => null);
                if (hoverCardModule) {
                    setHoverCardComponents({
                        HoverCard: hoverCardModule.HoverCard,
                        HoverCardTrigger: hoverCardModule.HoverCardTrigger,
                        HoverCardContent: hoverCardModule.HoverCardContent,
                    });
                }
            }
            catch (error) {
                logger.warn('[FieldTooltip] Error loading HoverCard', {
                    error: error instanceof Error ? error.message : String(error),
                });
            }
        };
        loadComponents();
    }, [logger]);
    // Fallback to native title attribute if HoverCard is not available
    if (!HoverCardComponents) {
        return (_jsx("span", { title: normalized.content, className: "inline-flex items-center", children: _jsx(HiQuestionMarkCircle, { className: icon_class_name || 'h-4 w-4 text-muted-foreground flex-shrink-0' }) }));
    }
    const { HoverCard, HoverCardTrigger, HoverCardContent } = HoverCardComponents;
    return (_jsxs(HoverCard, { children: [_jsx(HoverCardTrigger, { asChild: true, children: _jsx("button", { type: "button", className: "inline-flex items-center", children: _jsx(HiQuestionMarkCircle, { className: icon_class_name || 'h-4 w-4 text-muted-foreground hover:text-foreground flex-shrink-0' }) }) }), _jsxs(HoverCardContent, { className: "w-64", children: [normalized.title && _jsx("h4", { className: "font-medium text-sm mb-1", children: normalized.title }), _jsx("p", { className: "text-sm text-muted-foreground", children: normalized.content })] })] }));
}
//# sourceMappingURL=field_tooltip.js.map