import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
import { useEffect, useState } from 'react';
export function DynamicLabel({ value, labelRenderer, fallbackLabel }) {
    const [label, setLabel] = useState(fallbackLabel || value);
    const [isLoading, setIsLoading] = useState(false);
    useEffect(() => {
        if (!labelRenderer) {
            setLabel(fallbackLabel || value);
            return;
        }
        const renderLabel = async () => {
            setIsLoading(true);
            try {
                const result = labelRenderer(value);
                if (result instanceof Promise) {
                    const resolvedLabel = await result;
                    setLabel(resolvedLabel);
                }
                else {
                    setLabel(result);
                }
            }
            catch (error) {
                console.error('Error rendering label:', error);
                setLabel(fallbackLabel || value);
            }
            finally {
                setIsLoading(false);
            }
        };
        renderLabel();
    }, [value, labelRenderer, fallbackLabel]);
    if (isLoading) {
        return _jsx("span", { className: "text-muted-foreground", children: "Loading..." });
    }
    return _jsx(_Fragment, { children: label });
}
//# sourceMappingURL=DynamicLabel.js.map