import React from 'react';
import { TextInput, Alert, NativeSyntheticEvent, TextInputChangeEventData } from 'react-native';
import { Cfg } from './action';
import { Picker } from '@react-native-picker/picker';
import { cfg } from '../lib/cfg';

export function SelectRenderer({
    ...props
}: {
    [key: string]: any;
}) {
    
    const onPress = () => Alert.alert('pressed!');
    const { tnode } = props;
    const { domNode } = tnode;
    const { attribs } = domNode;

    const handleChange = (event: any) => {
        const config = Cfg.action as { [key: string]: (event: Function) => void };
        const custAction: ((event: Function) => void) | null =
            (attribs?.action && typeof config[attribs?.action] === 'function')
                ? config[attribs?.action]
                : null;
        if (custAction) {
            custAction(event); // Pass only the event
        }
    }
    return (
        <Picker
            selectedValue={cfg.input[attribs.name] ? cfg.input[attribs.name]:null}
            onValueChange={cfg.action[attribs.name] ? cfg.action[attribs.name] : null}>
            <Picker.Item label="Java" value="java" />
            <Picker.Item label="JavaScript" value="js" />
        </Picker>
    );
}