import styles from './styles.module.css'
import {useContext, useEffect, useState} from "react";
import Context, {ContextInterface} from "../command/context";

export interface ArgumentInterface {
    name: string,
    description: string|null,
    default: any,
    isArray: boolean,
    isRequired: boolean,
}

export default function Argument(argument: ArgumentInterface) {
    let {argumentList, setArgumentList} = useContext<ContextInterface>(Context)
    let [value, setValue] = useState('')

    useEffect(() => {
        let temp = {
            ...argumentList,
        }
        temp[argument.name] = value
        setArgumentList(temp)
    }, [value])

    let onInput = (event: any) => {
        setValue(event.target.value)
    }
    return (
        <span>
            <input onInput={onInput} placeholder={argument.name} value={value} type="text"/>&nbsp;
        </span>
    )
}
