import { isEmpty, isFunction } from '@legendapp/state';
import { reactive } from '@legendapp/state/react';
import { createElement, forwardRef } from 'react';
const bindables = new Set(['input', 'textarea', 'select']);
const bindInfo = { value: { handler: 'onChange', getValue: (e) => e.target.value, defaultValue: '' } };
const bindInfoInput = Object.assign({ checked: { handler: 'onChange', getValue: (e) => e.target.checked } }, bindInfo);
export const Legend = new Proxy({}, {
    get(target, p) {
        if (!target[p]) {
            // Create a wrapper around createElement with the string so we can proxy it
            // eslint-disable-next-line react/display-name
            const render = forwardRef((props, ref) => {
                const propsOut = { ...props };
                if (ref && (isFunction(ref) || !isEmpty(ref))) {
                    propsOut.ref = ref;
                }
                return createElement(p, propsOut);
            });
            target[p] = reactive(render, bindables.has(p) ? (p === 'input' ? bindInfoInput : bindInfo) : undefined);
        }
        return target[p];
    },
});
//# sourceMappingURL=react-components.jsx.map