'use strict';

const linker = (component, handleInput) => {
    return key => {
        if (typeof key !== 'string')
            throw new Error('Only keys of type string are allowed');
        const capitalizedKey = key.charAt(0).toUpperCase() + key.slice(1);
        const value = component[key];
        return {
            key,
            value: Array.isArray(value) ? [...value] : value,
            label: component['label' + capitalizedKey],
            placeholder: component['placeholder' + capitalizedKey],
            onInput: handleInput.bind(component, key)
        };
    };
};

exports.linker = linker;
