import FilePlugin, { DEFAULT_STORE_NAME } from '../../utils/file/file';
import { FILE_DROP_NAME } from '../directive-names';
export var MFileDropDirective = {
    bind: function (el, binding, vnode, oldVnode) {
        var $file = vnode.context.$file;
        var onDragEnterOver = function (e) {
            el.classList.add('m--is-drag-over');
            e.stopPropagation();
            e.preventDefault();
        };
        var onDragLeave = function (e) {
            el.classList.remove('m--is-drag-over');
            e.stopPropagation();
            e.preventDefault();
        };
        var onDrop = function (e) {
            el.classList.remove('m--is-drag-over');
            e.preventDefault();
            $file.add(e.dataTransfer.files, binding.value ? binding.value : DEFAULT_STORE_NAME);
        };
        var cleanup = function () {
            el.removeEventListener('dragenter', onDragEnterOver);
            el.removeEventListener('dragover', onDragEnterOver);
            el.removeEventListener('dragleave', onDragLeave);
            el.removeEventListener('drop', onDrop);
        };
        el.addEventListener('dragenter', onDragEnterOver);
        el.addEventListener('dragover', onDragEnterOver);
        el.addEventListener('dragleave', onDragLeave);
        el.addEventListener('drop', onDrop);
        el.cleanupMFileDropDirective = cleanup;
    },
    unbind: function (el, binding, vnode, oldVnode) {
        el.cleanupMFileDropDirective();
        var $file = vnode.context.$file;
        if (!binding.modifiers['keep-store']) {
            $file.destroy(binding.value ? binding.value : DEFAULT_STORE_NAME);
        }
    }
};
var FileDropPlugin = {
    install: function (v, options) {
        v.use(FilePlugin);
        v.directive(FILE_DROP_NAME, MFileDropDirective);
    }
};
export default FileDropPlugin;
//# sourceMappingURL=file-drop.js.map