import * as arr from '../../utils/arr';

export default class DropEvent {
  constructor (dropStatus, dragEvent, type) {
    const { element, dropzone } = type === 'dragleave'
      ? dropStatus.prev
      : dropStatus.cur;

    this.type          = type;
    this.target        = element;
    this.currentTarget = element;
    this.dropzone      = dropzone;
    this.dragEvent     = dragEvent;
    this.relatedTarget = dragEvent.target;
    this.interaction   = dragEvent.interaction;
    this.draggable     = dragEvent.interactable;
    this.timeStamp     = dragEvent.timeStamp;

    this.propagationStopped = this.immediatePropagationStopped = false;
  }

  reject () {
    const { dropStatus } = this.interaction;

    if (
      (this.type !== 'dropactivate') && (
        !this.dropzone ||
        dropStatus.cur.dropzone !== this.dropzone ||
        dropStatus.cur.element !== this.target)) {
      return;
    }

    dropStatus.prev.dropzone = this.dropzone;
    dropStatus.prev.element = this.target;

    dropStatus.rejected = true;
    dropStatus.events.enter = null;

    this.stopImmediatePropagation();

    if (this.type === 'dropactivate') {
      const activeDrops = dropStatus.activeDrops;
      const index = arr.findIndex(activeDrops, ({ dropzone, element }) =>
        dropzone === this.dropzone && element === this.target);

      dropStatus.activeDrops = [
        ...activeDrops.slice(0, index),
        ...activeDrops.slice(index + 1),
      ];

      const deactivateEvent = new DropEvent(dropStatus, this.dragEvent, 'dropdeactivate');

      deactivateEvent.dropzone = this.dropzone;
      deactivateEvent.target = this.target;

      this.dropzone.fire(deactivateEvent);
    }
    else {
      this.dropzone.fire(new DropEvent(dropStatus, this.dragEvent, 'dragleave'));
    }
  }

  preventDefault () {}

  stopPropagation () {
    this.propagationStopped = true;
  }

  stopImmediatePropagation () {
    this.immediatePropagationStopped = this.propagationStopped = true;
  }
}

@@ -38,23 +38,8 @@
 ';%0A%0A
-export default 
 clas
@@ -52,16 +52,106 @@
 Event %7B%0A
+  /**%0A   * Class of events fired on dropzones during drags with acceptable targets.%0A   */%0A
   constr
@@ -726,16 +726,232 @@
 e;%0A  %7D%0A%0A
+  /**%0A   * If this is a %60dropactivate%60 event, the dropzone element will be%0A   * deactivated.%0A   *%0A   * If this is a %60dragmove%60 or %60dragenter%60, a %60dragleave%60 will be fired on the%0A   * dropzone element and more.%0A   */%0A
   reject
@@ -2289,8 +2289,35 @@
 ;%0A  %7D%0A%7D%0A
+%0Aexport default DropEvent;%0A

add jsdoc comments