import { isEmpty, isFunction } from '@legendapp/state';
import { reactive } from '@legendapp/state/react';
import { createElement, forwardRef } from 'react';
import { ActivityIndicator, Button, FlatList, Image, Pressable, ScrollView, SectionList, Switch, Text, TextInput, TouchableWithoutFeedback, View, } from 'react-native';
const bindables = {
    TextInput: {
        handler: 'onChange',
        getValue: (e) => e.nativeEvent.text,
        defaultValue: '',
    },
    Switch: { handler: 'onValueChange', getValue: (e) => e, defaultValue: false },
};
const Components = {
    ActivityIndicator: ActivityIndicator,
    Button: Button,
    FlatList: FlatList,
    Image: Image,
    Pressable: Pressable,
    ScrollView: ScrollView,
    SectionList: SectionList,
    Switch: Switch,
    Text: Text,
    TextInput: TextInput,
    TouchableWithoutFeedback: TouchableWithoutFeedback,
    View: View,
};
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(Components[p], propsOut);
            });
            target[p] = reactive(render, bindables[p] &&
                {
                    value: bindables[p],
                });
        }
        return target[p];
    },
});
//# sourceMappingURL=rn-components.jsx.map