import { FormControl } from '../../utils/form/form-control';
var INPUT_SELECTOR = 'input, textarea, [contenteditable=true]';
export var AbstractControlDirective = {
    bind: function (el, binding, vnode) {
        var control = binding.value;
        // We can't assign the element directly on recent Vue version.
        // https://github.com/vuejs/vue/issues/7788
        control.htmlElementAccessor = function () { return el.querySelector(INPUT_SELECTOR); };
        if (control instanceof FormControl) {
            Object.defineProperty(el, 'ControlDirectiveListeners', {
                value: {
                    focusListener: function () { return control.initEdition(); },
                    blurListener: function () { return control.endEdition(); }
                }
            });
            vnode.componentInstance.$on('focus', el['ControlDirectiveListeners'].focusListener);
            vnode.componentInstance.$on('blur', el['ControlDirectiveListeners'].blurListener);
        }
    },
    unbind: function (el, binding, vnode) {
        var control = binding.value;
        control.htmlElementAccessor = function () { return undefined; };
        if (control instanceof FormControl && el['ControlDirectiveListeners'] !== undefined) {
            vnode.componentInstance.$off('focus', el['ControlDirectiveListeners'].focusListener);
            vnode.componentInstance.$off('blur', el['ControlDirectiveListeners'].blurListener);
        }
    }
};
//# sourceMappingURL=control-directive.js.map