import{createShadowRootWithCoreStyles}from"./utils/create-shadow-root-with-core-styles.js";export class DropTarget{constructor(e,t,s,a){e.addEventListener("dragenter",this._onDragEnter.bind(this),!0),e.addEventListener("dragover",this._onDragOver.bind(this),!0),this._element=e,this._transferTypes=t,this._messageText=s,this._handleDrop=a,this._enabled=!0,this._dragMaskElement=null}setEnabled(e){this._enabled=e}_onDragEnter(e){this._enabled&&this._hasMatchingType(e)&&e.consume(!0)}_hasMatchingType(e){const t=e;if(!t.dataTransfer)return!1;for(const s of this._transferTypes){if(Array.from(t.dataTransfer.items).find((e=>s.kind===e.kind&&Boolean(s.type.exec(e.type)))))return!0}return!1}_onDragOver(e){const t=e;if(!this._enabled||!this._hasMatchingType(t))return;if(t.dataTransfer&&(t.dataTransfer.dropEffect="copy"),t.consume(!0),this._dragMaskElement)return;this._dragMaskElement=this._element.createChild("div","");createShadowRootWithCoreStyles(this._dragMaskElement,{cssFile:"ui/dropTarget.css",enableLegacyPatching:!0,delegatesFocus:void 0}).createChild("div","drop-target-message").textContent=this._messageText,this._dragMaskElement.addEventListener("drop",this._onDrop.bind(this),!0),this._dragMaskElement.addEventListener("dragleave",this._onDragLeave.bind(this),!0)}_onDrop(e){const t=e;t.consume(!0),this._removeMask(),this._enabled&&t.dataTransfer&&this._handleDrop(t.dataTransfer)}_onDragLeave(e){e.consume(!0),this._removeMask()}_removeMask(){this._dragMaskElement&&(this._dragMaskElement.remove(),this._dragMaskElement=null)}}export const Type={URI:{kind:"string",type:/text\/uri-list/},Folder:{kind:"file",type:/$^/},File:{kind:"file",type:/.*/},WebFile:{kind:"file",type:/[\w]+/},ImageFile:{kind:"file",type:/image\/.*/}};