import {prefix,camelCase} from './Validate2'
export default function bind(key,ctx,model){
    if(!ctx){
        ctx = this
    }
    if(!model && ctx.model){
        model = ctx.model
    }
    if(!model){
        return {}
    }
    if(!ctx.bindSet)
        ctx.bindSet = new Set()
    ctx.bindSet.add(key)
    return {
        onChange:model.inDisplay ? undefined:function(value){
            model[key] = value
        }.bind(ctx),
        value:model[key],
        formBlur:ctx.formBlur,
        inDisplay:model.inDisplay,
        displayChanged:model.inDisplay && model.displayChanged(key),
        help:model.__errors__ && model.__errors__[camelCase(prefix,key)]
    }
}