// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://@sbaseurl@/jsapi/jsapi/esri/copyright.txt and http://www.arcgis.com/apps/webappbuilder/copyright.txt for details.

//>>built
define("dojo/aspect dojo/dom-class dojo/dom-construct dojo/dom-geometry dojo/on ../../../dijit/utils/MouseUtil ../../../dijit/tooltips/TooltipUtil".split(" "),function(t,g,A,B,n,u,v){function p(a){return a&&a.isDraggable}function C(a){r=!0;h=null;var c=v.createTooltip(null,null,{htmlFragment:D(a)}),b=n(d.domNode,"mousemove, touchmove, dojotouchmove",function(l){u.fixTouchEvent(l);(l=d.row(l))&&l.data&&w(l.data,a)}),f=n(document.body,"mouseup, touchend",function(){!h||h==a||"before"===m&&d.store.data[h.index-
1]==a||"after"===m&&x(h)==a||!k.onDnDHappened||k.onDnDHappened({objectDropped:a,objectOver:h,position:m});y()}),q=n(document.body,"keyup",function(l){27==l.keyCode&&y()}),y=function(){v.removeTooltip(c);b.remove();f.remove();q.remove();w(null,null);h=null;r=!1}}function D(a){if(k.dndBoxRenderer)return k.dndBoxRenderer(a);a=A.create("div",{innerHTML:a.label||"DnD Box in action!","class":"esriMapsAnalystXSelectableTreeDnDBoxRoot"});a.style.cursor="move";return a}function w(a,c){e&&(g.remove(e,"esriMapsAnalystXSelectableTreeDnDRowHighlightedAllowedBefore"),
g.remove(e,"esriMapsAnalystXSelectableTreeDnDRowHighlightedAllowedAfter"),g.remove(e,"esriMapsAnalystXSelectableTreeDnDRowHighlightedForbiddenBefore"),g.remove(e,"esriMapsAnalystXSelectableTreeDnDRowHighlightedForbiddenAfter"),m=e=null);if(a&&(c=d.row(a))&&c.element){e=c.element;c=p(a);var b=B.position(e);m=b=b.y+b.h/2>u.getCursorPosition().clientY?"before":"after";(c=a.isHost?c?"before"==b||!(d._expanded&&d._expanded[a.id]):"before"==b?p(d.store.data[a.index-1]):!(d._expanded&&d._expanded[a.id])&&
p(x(a)):"after"==b&&!(!a.isHost&&a.hostElement.children[a.index+1]))&&"before"===b?g.add(e,"esriMapsAnalystXSelectableTreeDnDRowHighlightedAllowedBefore"):c&&"after"===b?g.add(e,"esriMapsAnalystXSelectableTreeDnDRowHighlightedAllowedAfter"):c||"before"!==b?c||"after"!==b||g.add(e,"esriMapsAnalystXSelectableTreeDnDRowHighlightedForbiddenAfter"):g.add(e,"esriMapsAnalystXSelectableTreeDnDRowHighlightedForbiddenBefore");h=c?a.isHost?a:a.hostElement:null}}function x(a){return a.isHost?d.store.data[a.index+
1]:d.store.data[a.hostElement.index+1]}function z(a){k=a;t.after(k,"init",function(){d=k.grid;var c=[];t.after(d,"destroy",function(){c.forEach(function(b){b.remove()})});c.push(n(d.domNode,"mousedown, touchstart, dojotouchover",function(b){r||(b=d.row(b))&&b.data&&p(b.data)&&C(b.data)}))});return k}var d,k,h,e,m,r=!1;z.prepareTreeData=function(a){var c=0,b=0;a.forEach(function(f){f.index=c++;f.isHost=!0;f.isDraggable=void 0===f.isDraggable?!0:f.isDraggable;f.children&&f.children.forEach(function(q){q.index=
b++;q.hostElement=f})})};return z});