var ANJUNA_DRAG_CLASS = 'anj-dragging';
var DragController = /** @class */ (function () {
    function DragController(element, data) {
        var _this = this;
        this.element = element;
        this.data = data;
        this.dragStartListener = function (e) { return _this.onDragStart(e); };
        this.dragEndListener = function (e) { return _this.onDragEnd(e); };
    }
    DragController.prototype.connect = function () {
        this.element.setAttribute('draggable', 'true');
        this.element.addEventListener('dragstart', this.dragStartListener);
        this.element.addEventListener('dragend', this.dragEndListener);
        return this;
    };
    DragController.prototype.disconnect = function () {
        this.element.removeAttribute('draggable');
        this.element.removeEventListener('dragstart', this.dragStartListener);
        this.element.removeEventListener('dragend', this.dragEndListener);
        return undefined;
    };
    DragController.prototype.onDragStart = function (event) {
        this.element.classList.add(ANJUNA_DRAG_CLASS);
        if (event.dataTransfer) {
            event.dataTransfer.effectAllowed = 'move';
            if (this.data) {
                event.dataTransfer.setData('data', JSON.stringify(this.getData()));
            }
        }
    };
    DragController.prototype.onDragEnd = function (event) {
        event.preventDefault();
        this.element.classList.remove(ANJUNA_DRAG_CLASS);
    };
    DragController.prototype.getData = function () {
        return typeof this.data === 'function' ? this.data() : this.data;
    };
    return DragController;
}());
var ANJUNA_DROP_CLASS = 'anj-dragover';
var DropController = /** @class */ (function () {
    function DropController(element) {
        var _this = this;
        this.element = element;
        this.dragEnterListener = function () { return _this.onDragEnter(); };
        this.dragLeaveListener = function () { return _this.onDragLeave(); };
        this.dragOverListener = function (e) { return _this.onDragOver(e); };
        this.dropListener = function (e) { return _this.onDrop(e); };
    }
    DropController.prototype.connect = function () {
        this.element.addEventListener('dragenter', this.dragEnterListener);
        this.element.addEventListener('dragleave', this.dragLeaveListener);
        this.element.addEventListener('dragover', this.dragOverListener);
        this.element.addEventListener('drop', this.dropListener);
        return this;
    };
    DropController.prototype.disconnect = function () {
        this.element.removeEventListener('dragenter', this.dragEnterListener);
        this.element.removeEventListener('dragleave', this.dragLeaveListener);
        this.element.removeEventListener('dragover', this.dragOverListener);
        this.element.removeEventListener('drop', this.dropListener);
        return undefined;
    };
    DropController.prototype.onDragEnter = function () {
        this.element.classList.add(ANJUNA_DROP_CLASS);
    };
    DropController.prototype.onDragLeave = function () {
        this.element.classList.remove(ANJUNA_DROP_CLASS);
    };
    DropController.prototype.onDragOver = function (event) {
        if (event.preventDefault) {
            event.preventDefault();
        }
        this.checkStyle();
        event.dataTransfer.dropEffect = 'move';
        return false;
    };
    DropController.prototype.onDrop = function (event) {
        if (event.stopPropagation) {
            event.stopPropagation(); // Stops some browsers from redirecting.
        }
        this.element.classList.remove(ANJUNA_DROP_CLASS);
        if (event.dataTransfer && event.dataTransfer.getData && event.dataTransfer.getData('data')) {
            var detail = JSON.parse(event.dataTransfer.getData('data'));
            var anjEvent = new CustomEvent('anjDrop', { detail: detail, bubbles: true });
            this.element.dispatchEvent(anjEvent);
        }
        return false;
    };
    DropController.prototype.checkStyle = function () {
        if (!this.element.classList.contains(ANJUNA_DROP_CLASS)) {
            this.element.classList.add(ANJUNA_DROP_CLASS);
        }
    };
    return DropController;
}());
export { ANJUNA_DRAG_CLASS as A, DragController as D, ANJUNA_DROP_CLASS as a, DropController as b };
