import Component from '@ember/component';
import Droppable from 'ember-drag-drop/mixins/droppable';

export default Component.extend(Droppable, {
  classNameBindings: ['overrideClass'],
  overrideClass: 'draggable-object-target',
  isOver: false,

  handlePayload(payload, event) {
    let obj = this.get('coordinator').getObject(payload,{target: this});
    this.get('action')(obj, { target: this, event: event });
  },

  handleDrop(event) {
    let dataTransfer = event.dataTransfer;
    let payload = dataTransfer.getData("Text");
    if (payload === '') { return; }
    this.handlePayload(payload, event);
  },

  acceptDrop(event) {
    this.handleDrop(event);
    //Firefox is navigating to a url on drop sometimes, this prevents that from happening
    event.preventDefault();
  },

  handleDragOver(event) {
    if (!this.get('isOver')) {
      //only send once per hover event
      this.set('isOver', true);
      if(this.get('dragOverAction')) {
        this.get('dragOverAction')(event);
      }
    }
  },

  handleDragOut(event) {
    this.set('isOver', false);
    if(this.get('dragOutAction')) {
      this.get('dragOutAction')(event);
    }
  },

  click(e) {
    let onClick = this.get('onClick');
    if (onClick) {
      onClick(e);
    }
  },

  mouseDown(e) {
    let mouseDown = this.get('onMouseDown');
    if (mouseDown) {
      mouseDown(e);
    }
  },

  mouseEnter(e) {
    let mouseEnter = this.get('onMouseEnter');
    if (mouseEnter) {
      mouseEnter(e);
    }
  },

  actions: {
    acceptForDrop() {
      let hashId = this.get('coordinator.clickedId');
      this.handlePayload(hashId);
    }
  }
});

@@ -1372,25 +1372,31 @@
   %7D%0A  %7D,%0A%0A  
-m
+handleM
 ouseEnter(e)
@@ -1484,24 +1484,24 @@
 seEnter(e);%0A
-
     %7D%0A  %7D,%0A%0A
@@ -1496,24 +1496,301 @@
     %7D%0A  %7D,%0A%0A
+  didInsertElement() %7B%0A      this._super(...arguments);%0A      this.element.addEventListener('mouseenter', this.handleMouseEnter);%0A  %7D,%0A%0A  willDestroyElement() %7B%0A      this._super(...arguments);%0A      this.element.removeEventListener('mouseenter', this.handleMouseEnter);%0A  %7D,%0A%0A
   actions: %7B

fix ember mouseEnter deprecation