import { invariant as a } from "../../../@react-dnd/invariant/dist/index.es.js";
import { getSourceClientOffset as f, getDifferenceFromInitialOffset as u } from "../utils/coords.es.js";
import { areDirty as c } from "../utils/dirtiness.es.js";
import { matchesType as o } from "../utils/matchesType.es.js";
class O {
  subscribeToStateChange(t, e = {}) {
    const { handlerIds: s } = e;
    a(typeof t == "function", "listener must be a function."), a(typeof s > "u" || Array.isArray(s), "handlerIds, when specified, must be an array of strings.");
    let r = this.store.getState().stateId;
    const g = () => {
      const i = this.store.getState(), n = i.stateId;
      try {
        n === r || n === r + 1 && !c(i.dirtyHandlerIds, s) || t();
      } finally {
        r = n;
      }
    };
    return this.store.subscribe(g);
  }
  subscribeToOffsetChange(t) {
    a(typeof t == "function", "listener must be a function.");
    let e = this.store.getState().dragOffset;
    const s = () => {
      const r = this.store.getState().dragOffset;
      r !== e && (e = r, t());
    };
    return this.store.subscribe(s);
  }
  canDragSource(t) {
    if (!t)
      return !1;
    const e = this.registry.getSource(t);
    return a(e, `Expected to find a valid source. sourceId=${t}`), this.isDragging() ? !1 : e.canDrag(this, t);
  }
  canDropOnTarget(t) {
    if (!t)
      return !1;
    const e = this.registry.getTarget(t);
    if (a(e, `Expected to find a valid target. targetId=${t}`), !this.isDragging() || this.didDrop())
      return !1;
    const s = this.registry.getTargetType(t), r = this.getItemType();
    return o(s, r) && e.canDrop(this, t);
  }
  isDragging() {
    return Boolean(this.getItemType());
  }
  isDraggingSource(t) {
    if (!t)
      return !1;
    const e = this.registry.getSource(t, !0);
    if (a(e, `Expected to find a valid source. sourceId=${t}`), !this.isDragging() || !this.isSourcePublic())
      return !1;
    const s = this.registry.getSourceType(t), r = this.getItemType();
    return s !== r ? !1 : e.isDragging(this, t);
  }
  isOverTarget(t, e = {
    shallow: !1
  }) {
    if (!t)
      return !1;
    const { shallow: s } = e;
    if (!this.isDragging())
      return !1;
    const r = this.registry.getTargetType(t), g = this.getItemType();
    if (g && !o(r, g))
      return !1;
    const i = this.getTargetIds();
    if (!i.length)
      return !1;
    const n = i.indexOf(t);
    return s ? n === i.length - 1 : n > -1;
  }
  getItemType() {
    return this.store.getState().dragOperation.itemType;
  }
  getItem() {
    return this.store.getState().dragOperation.item;
  }
  getSourceId() {
    return this.store.getState().dragOperation.sourceId;
  }
  getTargetIds() {
    return this.store.getState().dragOperation.targetIds;
  }
  getDropResult() {
    return this.store.getState().dragOperation.dropResult;
  }
  didDrop() {
    return this.store.getState().dragOperation.didDrop;
  }
  isSourcePublic() {
    return Boolean(this.store.getState().dragOperation.isSourcePublic);
  }
  getInitialClientOffset() {
    return this.store.getState().dragOffset.initialClientOffset;
  }
  getInitialSourceClientOffset() {
    return this.store.getState().dragOffset.initialSourceClientOffset;
  }
  getClientOffset() {
    return this.store.getState().dragOffset.clientOffset;
  }
  getSourceClientOffset() {
    return f(this.store.getState().dragOffset);
  }
  getDifferenceFromInitialOffset() {
    return u(this.store.getState().dragOffset);
  }
  constructor(t, e) {
    this.store = t, this.registry = e;
  }
}
export {
  O as DragDropMonitorImpl
};
//# sourceMappingURL=DragDropMonitorImpl.es.js.map
