import { createPlugin as ee } from "../core/index.mjs";
import { bH as te, ar as ie, at as ne, as as se, au as re, Z as I, bG as Y, b_ as le, aw as N, ax as V, cu as oe, _ as A, aV as q, $ as S, a0 as m, bX as F, bZ as k, I as R, w as M, a7 as ae, q as he, aA as z, d as _, aR as ce, n as E, F as G, bI as O, aP as x, b2 as de, aO as ge, b6 as B, aG as ue, aE as pe, aH as fe, aI as ve, a as Ee, b9 as me, bf as Se, av as De, bc as we, b3 as ye, bd as Te, b5 as be, aF as Re, bb as Me } from "../core/internal-common.mjs";
O.touchMouseIgnoreWait = 500;
let H = 0, C = 0, X = !1;
class Z {
  constructor(e) {
    this.subjectEl = null, this.selector = "", this.handleSelector = "", this.shouldIgnoreMove = !1, this.shouldWatchScroll = !0, this.isDragging = !1, this.isTouchDragging = !1, this.wasTouchScroll = !1, this.handleMouseDown = (t) => {
      if (!this.shouldIgnoreMouse() && Ce(t) && this.tryStart(t)) {
        let i = this.createEventFromMouse(t, !0);
        this.emitter.trigger("pointerdown", i), this.initScrollWatch(i), this.shouldIgnoreMove || document.addEventListener("mousemove", this.handleMouseMove), document.addEventListener("mouseup", this.handleMouseUp);
      }
    }, this.handleMouseMove = (t) => {
      let i = this.createEventFromMouse(t);
      this.recordCoords(i), this.emitter.trigger("pointermove", i);
    }, this.handleMouseUp = (t) => {
      document.removeEventListener("mousemove", this.handleMouseMove), document.removeEventListener("mouseup", this.handleMouseUp), this.emitter.trigger("pointerup", this.createEventFromMouse(t)), this.cleanup();
    }, this.handleTouchStart = (t) => {
      if (this.tryStart(t)) {
        this.isTouchDragging = !0;
        let i = this.createEventFromTouch(t, !0);
        this.emitter.trigger("pointerdown", i), this.initScrollWatch(i);
        let n = t.target;
        this.shouldIgnoreMove || n.addEventListener("touchmove", this.handleTouchMove), n.addEventListener("touchend", this.handleTouchEnd), n.addEventListener("touchcancel", this.handleTouchEnd), window.addEventListener("scroll", this.handleTouchScroll, !0);
      }
    }, this.handleTouchMove = (t) => {
      let i = this.createEventFromTouch(t);
      this.recordCoords(i), this.emitter.trigger("pointermove", i);
    }, this.handleTouchEnd = (t) => {
      if (this.isDragging) {
        let i = t.target;
        i.removeEventListener("touchmove", this.handleTouchMove), i.removeEventListener("touchend", this.handleTouchEnd), i.removeEventListener("touchcancel", this.handleTouchEnd), window.removeEventListener("scroll", this.handleTouchScroll, !0), this.emitter.trigger("pointerup", this.createEventFromTouch(t)), this.cleanup(), this.isTouchDragging = !1, Ie();
      }
    }, this.handleTouchScroll = () => {
      this.wasTouchScroll = !0;
    }, this.handleScroll = (t) => {
      if (!this.shouldIgnoreMove) {
        let i = window.pageXOffset - this.prevScrollX + this.prevPageX, n = window.pageYOffset - this.prevScrollY + this.prevPageY;
        this.emitter.trigger("pointermove", {
          origEvent: t,
          isTouch: this.isTouchDragging,
          subjectEl: this.subjectEl,
          pageX: i,
          pageY: n,
          deltaX: i - this.origPageX,
          deltaY: n - this.origPageY
        });
      }
    }, this.containerEl = e, this.emitter = new G(), e.addEventListener("mousedown", this.handleMouseDown), e.addEventListener("touchstart", this.handleTouchStart, { passive: !0 }), Pe();
  }
  destroy() {
    this.containerEl.removeEventListener("mousedown", this.handleMouseDown), this.containerEl.removeEventListener("touchstart", this.handleTouchStart, { passive: !0 }), je();
  }
  tryStart(e) {
    let t = this.querySubjectEl(e), i = e.target;
    return t && (!this.handleSelector || S(i, this.handleSelector)) ? (this.subjectEl = t, this.isDragging = !0, this.wasTouchScroll = !1, !0) : !1;
  }
  cleanup() {
    X = !1, this.isDragging = !1, this.subjectEl = null, this.destroyScrollWatch();
  }
  querySubjectEl(e) {
    return this.selector ? S(e.target, this.selector) : this.containerEl;
  }
  shouldIgnoreMouse() {
    return H || this.isTouchDragging;
  }
  // can be called by user of this class, to cancel touch-based scrolling for the current drag
  cancelTouchScroll() {
    this.isDragging && (X = !0);
  }
  // Scrolling that simulates pointermoves
  // ----------------------------------------------------------------------------------------------------
  initScrollWatch(e) {
    this.shouldWatchScroll && (this.recordCoords(e), window.addEventListener("scroll", this.handleScroll, !0));
  }
  recordCoords(e) {
    this.shouldWatchScroll && (this.prevPageX = e.pageX, this.prevPageY = e.pageY, this.prevScrollX = window.pageXOffset, this.prevScrollY = window.pageYOffset);
  }
  destroyScrollWatch() {
    this.shouldWatchScroll && window.removeEventListener("scroll", this.handleScroll, !0);
  }
  // Event Normalization
  // ----------------------------------------------------------------------------------------------------
  createEventFromMouse(e, t) {
    let i = 0, n = 0;
    return t ? (this.origPageX = e.pageX, this.origPageY = e.pageY) : (i = e.pageX - this.origPageX, n = e.pageY - this.origPageY), {
      origEvent: e,
      isTouch: !1,
      subjectEl: this.subjectEl,
      pageX: e.pageX,
      pageY: e.pageY,
      deltaX: i,
      deltaY: n
    };
  }
  createEventFromTouch(e, t) {
    let i = e.touches, n, l, s = 0, r = 0;
    return i && i.length ? (n = i[0].pageX, l = i[0].pageY) : (n = e.pageX, l = e.pageY), t ? (this.origPageX = n, this.origPageY = l) : (s = n - this.origPageX, r = l - this.origPageY), {
      origEvent: e,
      isTouch: !0,
      subjectEl: this.subjectEl,
      pageX: n,
      pageY: l,
      deltaX: s,
      deltaY: r
    };
  }
}
function Ce(h) {
  return h.button === 0 && !h.ctrlKey;
}
function Ie() {
  H += 1, setTimeout(() => {
    H -= 1;
  }, O.touchMouseIgnoreWait);
}
function Pe() {
  C += 1, C === 1 && window.addEventListener("touchmove", Q, { passive: !1 });
}
function je() {
  C -= 1, C || window.removeEventListener("touchmove", Q, { passive: !1 });
}
function Q(h) {
  X && h.preventDefault();
}
class Le {
  constructor() {
    this.isVisible = !1, this.sourceEl = null, this.mirrorEl = null, this.sourceElRect = null, this.parentNode = document.body, this.zIndex = 9999, this.revertDuration = 0;
  }
  start(e, t, i) {
    this.sourceEl = e, this.sourceElRect = this.sourceEl.getBoundingClientRect(), this.origScreenX = t - window.pageXOffset, this.origScreenY = i - window.pageYOffset, this.deltaX = 0, this.deltaY = 0, this.updateElPosition();
  }
  handleMove(e, t) {
    this.deltaX = e - window.pageXOffset - this.origScreenX, this.deltaY = t - window.pageYOffset - this.origScreenY, this.updateElPosition();
  }
  // can be called before start
  setIsVisible(e) {
    e ? this.isVisible || (this.mirrorEl && (this.mirrorEl.style.display = ""), this.isVisible = e, this.updateElPosition()) : this.isVisible && (this.mirrorEl && (this.mirrorEl.style.display = "none"), this.isVisible = e);
  }
  // always async
  stop(e, t) {
    let i = () => {
      this.cleanup(), t();
    };
    e && this.mirrorEl && this.isVisible && this.revertDuration && // if 0, transition won't work
    (this.deltaX || this.deltaY) ? this.doRevertAnimation(i, this.revertDuration) : setTimeout(i, 0);
  }
  doRevertAnimation(e, t) {
    let i = this.mirrorEl, n = this.sourceEl.getBoundingClientRect();
    i.style.transition = "top " + t + "ms,left " + t + "ms", x(i, {
      left: n.left,
      top: n.top
    }), de(i, () => {
      i.style.transition = "", e();
    });
  }
  cleanup() {
    this.mirrorEl && (ge(this.mirrorEl), this.mirrorEl = null), this.sourceEl = null;
  }
  updateElPosition() {
    this.sourceEl && this.isVisible && x(this.getMirrorEl(), {
      left: this.sourceElRect.left + this.deltaX,
      top: this.sourceElRect.top + this.deltaY
    });
  }
  getMirrorEl() {
    let e = this.sourceElRect, t = this.mirrorEl;
    return t || (t = this.mirrorEl = this.sourceEl.cloneNode(!0), t.style.userSelect = "none", t.style.webkitUserSelect = "none", t.classList.add("fc-event-dragging"), x(t, {
      position: "fixed",
      zIndex: this.zIndex,
      visibility: "",
      boxSizing: "border-box",
      width: e.right - e.left,
      height: e.bottom - e.top,
      right: "auto",
      bottom: "auto",
      margin: 0
    }), this.parentNode.appendChild(t)), t;
  }
}
class $ extends Me {
  constructor(e, t) {
    super(), this.handleScroll = () => {
      this.scrollTop = this.scrollController.getScrollTop(), this.scrollLeft = this.scrollController.getScrollLeft(), this.handleScrollChange();
    }, this.scrollController = e, this.doesListening = t, this.scrollTop = this.origScrollTop = e.getScrollTop(), this.scrollLeft = this.origScrollLeft = e.getScrollLeft(), this.scrollWidth = e.getScrollWidth(), this.scrollHeight = e.getScrollHeight(), this.clientWidth = e.getClientWidth(), this.clientHeight = e.getClientHeight(), this.clientRect = this.computeClientRect(), this.doesListening && this.getEventTarget().addEventListener("scroll", this.handleScroll);
  }
  destroy() {
    this.doesListening && this.getEventTarget().removeEventListener("scroll", this.handleScroll);
  }
  getScrollTop() {
    return this.scrollTop;
  }
  getScrollLeft() {
    return this.scrollLeft;
  }
  setScrollTop(e) {
    this.scrollController.setScrollTop(e), this.doesListening || (this.scrollTop = Math.max(Math.min(e, this.getMaxScrollTop()), 0), this.handleScrollChange());
  }
  setScrollLeft(e) {
    this.scrollController.setScrollLeft(e), this.doesListening || (this.scrollLeft = Math.max(Math.min(e, this.getMaxScrollLeft()), 0), this.handleScrollChange());
  }
  getClientWidth() {
    return this.clientWidth;
  }
  getClientHeight() {
    return this.clientHeight;
  }
  getScrollWidth() {
    return this.scrollWidth;
  }
  getScrollHeight() {
    return this.scrollHeight;
  }
  handleScrollChange() {
  }
}
class K extends $ {
  constructor(e, t) {
    super(new we(e), t);
  }
  getEventTarget() {
    return this.scrollController.el;
  }
  computeClientRect() {
    return ye(this.scrollController.el);
  }
}
class xe extends $ {
  constructor(e) {
    super(new Te(), e);
  }
  getEventTarget() {
    return window;
  }
  computeClientRect() {
    return {
      left: this.scrollLeft,
      right: this.scrollLeft + this.clientWidth,
      top: this.scrollTop,
      bottom: this.scrollTop + this.clientHeight
    };
  }
  // the window is the only scroll object that changes it's rectangle relative
  // to the document's topleft as it scrolls
  handleScrollChange() {
    this.clientRect = this.computeClientRect();
  }
}
const W = typeof performance == "function" ? performance.now : Date.now;
class Ae {
  constructor() {
    this.isEnabled = !0, this.scrollQuery = [window, ".fc-scroller"], this.edgeThreshold = 50, this.maxVelocity = 300, this.pointerScreenX = null, this.pointerScreenY = null, this.isAnimating = !1, this.scrollCaches = null, this.everMovedUp = !1, this.everMovedDown = !1, this.everMovedLeft = !1, this.everMovedRight = !1, this.animate = () => {
      if (this.isAnimating) {
        let e = this.computeBestEdge(this.pointerScreenX + window.pageXOffset, this.pointerScreenY + window.pageYOffset);
        if (e) {
          let t = W();
          this.handleSide(e, (t - this.msSinceRequest) / 1e3), this.requestAnimation(t);
        } else
          this.isAnimating = !1;
      }
    };
  }
  start(e, t, i) {
    this.isEnabled && (this.scrollCaches = this.buildCaches(i), this.pointerScreenX = null, this.pointerScreenY = null, this.everMovedUp = !1, this.everMovedDown = !1, this.everMovedLeft = !1, this.everMovedRight = !1, this.handleMove(e, t));
  }
  handleMove(e, t) {
    if (this.isEnabled) {
      let i = e - window.pageXOffset, n = t - window.pageYOffset, l = this.pointerScreenY === null ? 0 : n - this.pointerScreenY, s = this.pointerScreenX === null ? 0 : i - this.pointerScreenX;
      l < 0 ? this.everMovedUp = !0 : l > 0 && (this.everMovedDown = !0), s < 0 ? this.everMovedLeft = !0 : s > 0 && (this.everMovedRight = !0), this.pointerScreenX = i, this.pointerScreenY = n, this.isAnimating || (this.isAnimating = !0, this.requestAnimation(W()));
    }
  }
  stop() {
    if (this.isEnabled) {
      this.isAnimating = !1;
      for (let e of this.scrollCaches)
        e.destroy();
      this.scrollCaches = null;
    }
  }
  requestAnimation(e) {
    this.msSinceRequest = e, requestAnimationFrame(this.animate);
  }
  handleSide(e, t) {
    let { scrollCache: i } = e, { edgeThreshold: n } = this, l = n - e.distance, s = (
      // the closer to the edge, the faster we scroll
      l * l / (n * n) * // quadratic
      this.maxVelocity * t
    ), r = 1;
    switch (e.name) {
      case "left":
        r = -1;
      case "right":
        i.setScrollLeft(i.getScrollLeft() + s * r);
        break;
      case "top":
        r = -1;
      case "bottom":
        i.setScrollTop(i.getScrollTop() + s * r);
        break;
    }
  }
  // left/top are relative to document topleft
  computeBestEdge(e, t) {
    let { edgeThreshold: i } = this, n = null, l = this.scrollCaches || [];
    for (let s of l) {
      let r = s.clientRect, o = e - r.left, a = r.right - e, d = t - r.top, c = r.bottom - t;
      o >= 0 && a >= 0 && d >= 0 && c >= 0 && (d <= i && this.everMovedUp && s.canScrollUp() && (!n || n.distance > d) && (n = { scrollCache: s, name: "top", distance: d }), c <= i && this.everMovedDown && s.canScrollDown() && (!n || n.distance > c) && (n = { scrollCache: s, name: "bottom", distance: c }), o <= i && this.everMovedLeft && s.canScrollLeft() && (!n || n.distance > o) && (n = { scrollCache: s, name: "left", distance: o }), a <= i && this.everMovedRight && s.canScrollRight() && (!n || n.distance > a) && (n = { scrollCache: s, name: "right", distance: a }));
    }
    return n;
  }
  buildCaches(e) {
    return this.queryScrollEls(e).map((t) => t === window ? new xe(!1) : new K(t, !1));
  }
  queryScrollEls(e) {
    let t = [];
    for (let i of this.scrollQuery)
      typeof i == "object" ? t.push(i) : t.push(...Array.prototype.slice.call(e.getRootNode().querySelectorAll(i)));
    return t;
  }
}
class w extends te {
  constructor(e, t) {
    super(e), this.containerEl = e, this.delay = null, this.minDistance = 0, this.touchScrollAllowed = !0, this.mirrorNeedsRevert = !1, this.isInteracting = !1, this.isDragging = !1, this.isDelayEnded = !1, this.isDistanceSurpassed = !1, this.delayTimeoutId = null, this.onPointerDown = (n) => {
      this.isDragging || (this.isInteracting = !0, this.isDelayEnded = !1, this.isDistanceSurpassed = !1, ie(document.body), ne(document.body), n.isTouch || n.origEvent.preventDefault(), this.emitter.trigger("pointerdown", n), this.isInteracting && // not destroyed via pointerdown handler
      !this.pointer.shouldIgnoreMove && (this.mirror.setIsVisible(!1), this.mirror.start(n.subjectEl, n.pageX, n.pageY), this.startDelay(n), this.minDistance || this.handleDistanceSurpassed(n)));
    }, this.onPointerMove = (n) => {
      if (this.isInteracting) {
        if (this.emitter.trigger("pointermove", n), !this.isDistanceSurpassed) {
          let l = this.minDistance, s, { deltaX: r, deltaY: o } = n;
          s = r * r + o * o, s >= l * l && this.handleDistanceSurpassed(n);
        }
        this.isDragging && (n.origEvent.type !== "scroll" && (this.mirror.handleMove(n.pageX, n.pageY), this.autoScroller.handleMove(n.pageX, n.pageY)), this.emitter.trigger("dragmove", n));
      }
    }, this.onPointerUp = (n) => {
      this.isInteracting && (this.isInteracting = !1, se(document.body), re(document.body), this.emitter.trigger("pointerup", n), this.isDragging && (this.autoScroller.stop(), this.tryStopDrag(n)), this.delayTimeoutId && (clearTimeout(this.delayTimeoutId), this.delayTimeoutId = null));
    };
    let i = this.pointer = new Z(e);
    i.emitter.on("pointerdown", this.onPointerDown), i.emitter.on("pointermove", this.onPointerMove), i.emitter.on("pointerup", this.onPointerUp), t && (i.selector = t), this.mirror = new Le(), this.autoScroller = new Ae();
  }
  destroy() {
    this.pointer.destroy(), this.onPointerUp({});
  }
  startDelay(e) {
    typeof this.delay == "number" ? this.delayTimeoutId = setTimeout(() => {
      this.delayTimeoutId = null, this.handleDelayEnd(e);
    }, this.delay) : this.handleDelayEnd(e);
  }
  handleDelayEnd(e) {
    this.isDelayEnded = !0, this.tryStartDrag(e);
  }
  handleDistanceSurpassed(e) {
    this.isDistanceSurpassed = !0, this.tryStartDrag(e);
  }
  tryStartDrag(e) {
    this.isDelayEnded && this.isDistanceSurpassed && (!this.pointer.wasTouchScroll || this.touchScrollAllowed) && (this.isDragging = !0, this.mirrorNeedsRevert = !1, this.autoScroller.start(e.pageX, e.pageY, this.containerEl), this.emitter.trigger("dragstart", e), this.touchScrollAllowed === !1 && this.pointer.cancelTouchScroll());
  }
  tryStopDrag(e) {
    this.mirror.stop(this.mirrorNeedsRevert, this.stopDrag.bind(this, e));
  }
  stopDrag(e) {
    this.isDragging = !1, this.emitter.trigger("dragend", e);
  }
  // fill in the implementations...
  setIgnoreMove(e) {
    this.pointer.shouldIgnoreMove = e;
  }
  setMirrorIsVisible(e) {
    this.mirror.setIsVisible(e);
  }
  setMirrorNeedsRevert(e) {
    this.mirrorNeedsRevert = e;
  }
  setAutoScrollEnabled(e) {
    this.autoScroller.isEnabled = e;
  }
}
class He {
  constructor(e) {
    this.origRect = B(e), this.scrollCaches = be(e).map((t) => new K(t, !0));
  }
  destroy() {
    for (let e of this.scrollCaches)
      e.destroy();
  }
  computeLeft() {
    let e = this.origRect.left;
    for (let t of this.scrollCaches)
      e += t.origScrollLeft - t.getScrollLeft();
    return e;
  }
  computeTop() {
    let e = this.origRect.top;
    for (let t of this.scrollCaches)
      e += t.origScrollTop - t.getScrollTop();
    return e;
  }
  isWithinClipping(e, t) {
    let i = { left: e, top: t };
    for (let n of this.scrollCaches)
      if (!Xe(n.getEventTarget()) && !Re(i, n.clientRect))
        return !1;
    return !0;
  }
}
function Xe(h) {
  let e = h.tagName;
  return e === "HTML" || e === "BODY";
}
class P {
  constructor(e, t) {
    this.useSubjectCenter = !1, this.requireInitial = !0, this.initialHit = null, this.movingHit = null, this.finalHit = null, this.handlePointerDown = (i) => {
      let { dragging: n } = this;
      this.initialHit = null, this.movingHit = null, this.finalHit = null, this.prepareHits(), this.processFirstCoord(i), this.initialHit || !this.requireInitial ? (n.setIgnoreMove(!1), this.emitter.trigger("pointerdown", i)) : n.setIgnoreMove(!0);
    }, this.handleDragStart = (i) => {
      this.emitter.trigger("dragstart", i), this.handleMove(i, !0);
    }, this.handleDragMove = (i) => {
      this.emitter.trigger("dragmove", i), this.handleMove(i);
    }, this.handlePointerUp = (i) => {
      this.releaseHits(), this.emitter.trigger("pointerup", i);
    }, this.handleDragEnd = (i) => {
      this.movingHit && this.emitter.trigger("hitupdate", null, !0, i), this.finalHit = this.movingHit, this.movingHit = null, this.emitter.trigger("dragend", i);
    }, this.droppableStore = t, e.emitter.on("pointerdown", this.handlePointerDown), e.emitter.on("dragstart", this.handleDragStart), e.emitter.on("dragmove", this.handleDragMove), e.emitter.on("pointerup", this.handlePointerUp), e.emitter.on("dragend", this.handleDragEnd), this.dragging = e, this.emitter = new G();
  }
  // sets initialHit
  // sets coordAdjust
  processFirstCoord(e) {
    let t = { left: e.pageX, top: e.pageY }, i = t, n = e.subjectEl, l;
    n instanceof HTMLElement && (l = B(n), i = ue(i, l));
    let s = this.initialHit = this.queryHitForOffset(i.left, i.top);
    if (s) {
      if (this.useSubjectCenter && l) {
        let r = pe(l, s.rect);
        r && (i = fe(r));
      }
      this.coordAdjust = ve(i, t);
    } else
      this.coordAdjust = { left: 0, top: 0 };
  }
  handleMove(e, t) {
    let i = this.queryHitForOffset(e.pageX + this.coordAdjust.left, e.pageY + this.coordAdjust.top);
    (t || !j(this.movingHit, i)) && (this.movingHit = i, this.emitter.trigger("hitupdate", i, !1, e));
  }
  prepareHits() {
    this.offsetTrackers = Ee(this.droppableStore, (e) => (e.component.prepareHits(), new He(e.el)));
  }
  releaseHits() {
    let { offsetTrackers: e } = this;
    for (let t in e)
      e[t].destroy();
    this.offsetTrackers = {};
  }
  queryHitForOffset(e, t) {
    let { droppableStore: i, offsetTrackers: n } = this, l = null;
    for (let s in i) {
      let r = i[s].component, o = n[s];
      if (o && // wasn't destroyed mid-drag
      o.isWithinClipping(e, t)) {
        let a = o.computeLeft(), d = o.computeTop(), c = e - a, g = t - d, { origRect: p } = o, v = p.right - p.left, u = p.bottom - p.top;
        if (
          // must be within the element's bounds
          c >= 0 && c < v && g >= 0 && g < u
        ) {
          let f = r.queryHit(c, g, v, u);
          f && // make sure the hit is within activeRange, meaning it's not a dead cell
          me(f.dateProfile.activeRange, f.dateSpan.range) && (!l || f.layer > l.layer) && (f.componentId = s, f.context = r.context, f.rect.left += a, f.rect.right += a, f.rect.top += d, f.rect.bottom += d, l = f);
        }
      }
    }
    return l;
  }
}
function j(h, e) {
  return !h && !e ? !0 : !!h != !!e ? !1 : Se(h.dateSpan, e.dateSpan);
}
function J(h, e) {
  let t = {};
  for (let i of e.pluginHooks.datePointTransforms)
    Object.assign(t, i(h, e));
  return Object.assign(t, Ye(h, e.dateEnv)), t;
}
function Ye(h, e) {
  return {
    date: e.toDate(h.range.start),
    dateStr: e.formatIso(h.range.start, { omitTime: h.allDay }),
    allDay: h.allDay
  };
}
class Ne extends I {
  constructor(e) {
    super(e), this.handlePointerDown = (i) => {
      let { dragging: n } = this, l = i.origEvent.target;
      n.setIgnoreMove(!this.component.isValidDateDownEl(l));
    }, this.handleDragEnd = (i) => {
      let { component: n } = this, { pointer: l } = this.dragging;
      if (!l.wasTouchScroll) {
        let { initialHit: s, finalHit: r } = this.hitDragging;
        if (s && r && j(s, r)) {
          let { context: o } = n, a = Object.assign(Object.assign({}, J(s.dateSpan, o)), { dayEl: s.dayEl, jsEvent: i.origEvent, view: o.viewApi || o.calendarApi.view });
          o.emitter.trigger("dateClick", a);
        }
      }
    }, this.dragging = new w(e.el), this.dragging.autoScroller.isEnabled = !1;
    let t = this.hitDragging = new P(this.dragging, Y(e));
    t.emitter.on("pointerdown", this.handlePointerDown), t.emitter.on("dragend", this.handleDragEnd);
  }
  destroy() {
    this.dragging.destroy();
  }
}
class Ve extends I {
  constructor(e) {
    super(e), this.dragSelection = null, this.handlePointerDown = (s) => {
      let { component: r, dragging: o } = this, { options: a } = r.context, d = a.selectable && r.isValidDateDownEl(s.origEvent.target);
      o.setIgnoreMove(!d), o.delay = s.isTouch ? Oe(r) : null;
    }, this.handleDragStart = (s) => {
      this.component.context.calendarApi.unselect(s);
    }, this.handleHitUpdate = (s, r) => {
      let { context: o } = this.component, a = null, d = !1;
      if (s) {
        let c = this.hitDragging.initialHit;
        s.componentId === c.componentId && this.isHitComboAllowed && !this.isHitComboAllowed(c, s) || (a = Ue(c, s, o.pluginHooks.dateSelectionTransformers)), (!a || !le(a, s.dateProfile, o)) && (d = !0, a = null);
      }
      a ? o.dispatch({ type: "SELECT_DATES", selection: a }) : r || o.dispatch({ type: "UNSELECT_DATES" }), d ? V() : N(), r || (this.dragSelection = a);
    }, this.handlePointerUp = (s) => {
      this.dragSelection && (oe(this.dragSelection, s, this.component.context), this.dragSelection = null);
    };
    let { component: t } = e, { options: i } = t.context, n = this.dragging = new w(e.el);
    n.touchScrollAllowed = !1, n.minDistance = i.selectMinDistance || 0, n.autoScroller.isEnabled = i.dragScroll;
    let l = this.hitDragging = new P(this.dragging, Y(e));
    l.emitter.on("pointerdown", this.handlePointerDown), l.emitter.on("dragstart", this.handleDragStart), l.emitter.on("hitupdate", this.handleHitUpdate), l.emitter.on("pointerup", this.handlePointerUp);
  }
  destroy() {
    this.dragging.destroy();
  }
}
function Oe(h) {
  let { options: e } = h.context, t = e.selectLongPressDelay;
  return t == null && (t = e.longPressDelay), t;
}
function Ue(h, e, t) {
  let i = h.dateSpan, n = e.dateSpan, l = [
    i.range.start,
    i.range.end,
    n.range.start,
    n.range.end
  ];
  l.sort(De);
  let s = {};
  for (let r of t) {
    let o = r(h, e);
    if (o === !1)
      return null;
    o && Object.assign(s, o);
  }
  return s.range = { start: l[0], end: l[3] }, s.allDay = i.allDay, s;
}
class y extends I {
  constructor(e) {
    super(e), this.subjectEl = null, this.subjectSeg = null, this.isDragging = !1, this.eventRange = null, this.relevantEvents = null, this.receivingContext = null, this.validMutation = null, this.mutatedRelevantEvents = null, this.handlePointerDown = (s) => {
      let r = s.origEvent.target, { component: o, dragging: a } = this, { mirror: d } = a, { options: c } = o.context, g = o.context;
      this.subjectEl = s.subjectEl;
      let p = this.subjectSeg = A(s.subjectEl), u = (this.eventRange = p.eventRange).instance.instanceId;
      this.relevantEvents = q(g.getCurrentData().eventStore, u), a.minDistance = s.isTouch ? 0 : c.eventDragMinDistance, a.delay = // only do a touch delay if touch and this event hasn't been selected yet
      s.isTouch && u !== o.props.eventSelection ? We(o) : null, c.fixedMirrorParent ? d.parentNode = c.fixedMirrorParent : d.parentNode = S(r, ".fc"), d.revertDuration = c.dragRevertDuration;
      let f = o.isValidSegDownEl(r) && !S(r, ".fc-event-resizer");
      a.setIgnoreMove(!f), this.isDragging = f && s.subjectEl.classList.contains("fc-event-draggable");
    }, this.handleDragStart = (s) => {
      let r = this.component.context, o = this.eventRange, a = o.instance.instanceId;
      s.isTouch ? a !== this.component.props.eventSelection && r.dispatch({ type: "SELECT_EVENT", eventInstanceId: a }) : r.dispatch({ type: "UNSELECT_EVENT" }), this.isDragging && (r.calendarApi.unselect(s), r.emitter.trigger("eventDragStart", {
        el: this.subjectEl,
        event: new m(r, o.def, o.instance),
        jsEvent: s.origEvent,
        view: r.viewApi
      }));
    }, this.handleHitUpdate = (s, r) => {
      if (!this.isDragging)
        return;
      let o = this.relevantEvents, a = this.hitDragging.initialHit, d = this.component.context, c = null, g = null, p = null, v = !1, u = {
        affectedEvents: o,
        mutatedEvents: R(),
        isEvent: !0
      };
      if (s) {
        c = s.context;
        let f = c.options;
        d === c || f.editable && f.droppable ? (g = _e(a, s, c.getCurrentData().pluginHooks.eventDragMutationMassagers), g && (p = F(o, c.getCurrentData().eventUiBases, g, c), u.mutatedEvents = p, k(u, s.dateProfile, c) || (v = !0, g = null, p = null, u.mutatedEvents = R()))) : c = null;
      }
      this.displayDrag(c, u), v ? V() : N(), r || (d === c && // TODO: write test for this
      j(a, s) && (g = null), this.dragging.setMirrorNeedsRevert(!g), this.dragging.setMirrorIsVisible(!s || !this.subjectEl.getRootNode().querySelector(".fc-event-mirror")), this.receivingContext = c, this.validMutation = g, this.mutatedRelevantEvents = p);
    }, this.handlePointerUp = () => {
      this.isDragging || this.cleanup();
    }, this.handleDragEnd = (s) => {
      if (this.isDragging) {
        let r = this.component.context, o = r.viewApi, { receivingContext: a, validMutation: d } = this, c = this.eventRange.def, g = this.eventRange.instance, p = new m(r, c, g), v = this.relevantEvents, u = this.mutatedRelevantEvents, { finalHit: f } = this.hitDragging;
        if (this.clearDrag(), r.emitter.trigger("eventDragStop", {
          el: this.subjectEl,
          event: p,
          jsEvent: s.origEvent,
          view: o
        }), d) {
          if (a === r) {
            let T = new m(r, u.defs[c.defId], g ? u.instances[g.instanceId] : null);
            r.dispatch({
              type: "MERGE_EVENTS",
              eventStore: u
            });
            let b = {
              oldEvent: p,
              event: T,
              relatedEvents: M(u, r, g),
              revert() {
                r.dispatch({
                  type: "MERGE_EVENTS",
                  eventStore: v
                  // the pre-change data
                });
              }
            }, D = {};
            for (let L of r.getCurrentData().pluginHooks.eventDropTransformers)
              Object.assign(D, L(d, r));
            r.emitter.trigger("eventDrop", Object.assign(Object.assign(Object.assign({}, b), D), { el: s.subjectEl, delta: d.datesDelta, jsEvent: s.origEvent, view: o })), r.emitter.trigger("eventChange", b);
          } else if (a) {
            let T = {
              event: p,
              relatedEvents: M(v, r, g),
              revert() {
                r.dispatch({
                  type: "MERGE_EVENTS",
                  eventStore: v
                });
              }
            };
            r.emitter.trigger("eventLeave", Object.assign(Object.assign({}, T), { draggedEl: s.subjectEl, view: o })), r.dispatch({
              type: "REMOVE_EVENTS",
              eventStore: v
            }), r.emitter.trigger("eventRemove", T);
            let b = u.defs[c.defId], D = u.instances[g.instanceId], L = new m(a, b, D);
            a.dispatch({
              type: "MERGE_EVENTS",
              eventStore: u
            });
            let U = {
              event: L,
              relatedEvents: M(u, a, D),
              revert() {
                a.dispatch({
                  type: "REMOVE_EVENTS",
                  eventStore: u
                });
              }
            };
            a.emitter.trigger("eventAdd", U), s.isTouch && a.dispatch({
              type: "SELECT_EVENT",
              eventInstanceId: g.instanceId
            }), a.emitter.trigger("drop", Object.assign(Object.assign({}, J(f.dateSpan, a)), { draggedEl: s.subjectEl, jsEvent: s.origEvent, view: f.context.viewApi })), a.emitter.trigger("eventReceive", Object.assign(Object.assign({}, U), { draggedEl: s.subjectEl, view: f.context.viewApi }));
          }
        } else
          r.emitter.trigger("_noEventDrop");
      }
      this.cleanup();
    };
    let { component: t } = this, { options: i } = t.context, n = this.dragging = new w(e.el);
    n.pointer.selector = y.SELECTOR, n.touchScrollAllowed = !1, n.autoScroller.isEnabled = i.dragScroll;
    let l = this.hitDragging = new P(this.dragging, ae);
    l.useSubjectCenter = e.useEventCenter, l.emitter.on("pointerdown", this.handlePointerDown), l.emitter.on("dragstart", this.handleDragStart), l.emitter.on("hitupdate", this.handleHitUpdate), l.emitter.on("pointerup", this.handlePointerUp), l.emitter.on("dragend", this.handleDragEnd);
  }
  destroy() {
    this.dragging.destroy();
  }
  // render a drag state on the next receivingCalendar
  displayDrag(e, t) {
    let i = this.component.context, n = this.receivingContext;
    n && n !== e && (n === i ? n.dispatch({
      type: "SET_EVENT_DRAG",
      state: {
        affectedEvents: t.affectedEvents,
        mutatedEvents: R(),
        isEvent: !0
      }
    }) : n.dispatch({ type: "UNSET_EVENT_DRAG" })), e && e.dispatch({ type: "SET_EVENT_DRAG", state: t });
  }
  clearDrag() {
    let e = this.component.context, { receivingContext: t } = this;
    t && t.dispatch({ type: "UNSET_EVENT_DRAG" }), e !== t && e.dispatch({ type: "UNSET_EVENT_DRAG" });
  }
  cleanup() {
    this.subjectSeg = null, this.isDragging = !1, this.eventRange = null, this.relevantEvents = null, this.receivingContext = null, this.validMutation = null, this.mutatedRelevantEvents = null;
  }
}
y.SELECTOR = ".fc-event-draggable, .fc-event-resizable";
function _e(h, e, t) {
  let i = h.dateSpan, n = e.dateSpan, l = i.range.start, s = n.range.start, r = {};
  i.allDay !== n.allDay && (r.allDay = n.allDay, r.hasEnd = e.context.options.allDayMaintainDuration, n.allDay && (l = he(l)));
  let o = z(l, s, h.context.dateEnv, h.componentId === e.componentId ? h.largeUnit : null);
  o.milliseconds && (r.allDay = !1);
  let a = {
    datesDelta: o,
    standardProps: r
  };
  for (let d of t)
    d(a, h, e);
  return a;
}
function We(h) {
  let { options: e } = h.context, t = e.eventLongPressDelay;
  return t == null && (t = e.longPressDelay), t;
}
class qe extends I {
  constructor(e) {
    super(e), this.draggingSegEl = null, this.draggingSeg = null, this.eventRange = null, this.relevantEvents = null, this.validMutation = null, this.mutatedRelevantEvents = null, this.handlePointerDown = (l) => {
      let { component: s } = this, r = this.querySegEl(l), o = A(r), a = this.eventRange = o.eventRange;
      this.dragging.minDistance = s.context.options.eventDragMinDistance, this.dragging.setIgnoreMove(!this.component.isValidSegDownEl(l.origEvent.target) || l.isTouch && this.component.props.eventSelection !== a.instance.instanceId);
    }, this.handleDragStart = (l) => {
      let { context: s } = this.component, r = this.eventRange;
      this.relevantEvents = q(s.getCurrentData().eventStore, this.eventRange.instance.instanceId);
      let o = this.querySegEl(l);
      this.draggingSegEl = o, this.draggingSeg = A(o), s.calendarApi.unselect(), s.emitter.trigger("eventResizeStart", {
        el: o,
        event: new m(s, r.def, r.instance),
        jsEvent: l.origEvent,
        view: s.viewApi
      });
    }, this.handleHitUpdate = (l, s, r) => {
      let { context: o } = this.component, a = this.relevantEvents, d = this.hitDragging.initialHit, c = this.eventRange.instance, g = null, p = null, v = !1, u = {
        affectedEvents: a,
        mutatedEvents: R(),
        isEvent: !0
      };
      l && (l.componentId === d.componentId && this.isHitComboAllowed && !this.isHitComboAllowed(d, l) || (g = Fe(d, l, r.subjectEl.classList.contains("fc-event-resizer-start"), c.range))), g && (p = F(a, o.getCurrentData().eventUiBases, g, o), u.mutatedEvents = p, k(u, l.dateProfile, o) || (v = !0, g = null, p = null, u.mutatedEvents = null)), p ? o.dispatch({
        type: "SET_EVENT_RESIZE",
        state: u
      }) : o.dispatch({ type: "UNSET_EVENT_RESIZE" }), v ? V() : N(), s || (g && j(d, l) && (g = null), this.validMutation = g, this.mutatedRelevantEvents = p);
    }, this.handleDragEnd = (l) => {
      let { context: s } = this.component, r = this.eventRange.def, o = this.eventRange.instance, a = new m(s, r, o), d = this.relevantEvents, c = this.mutatedRelevantEvents;
      if (s.emitter.trigger("eventResizeStop", {
        el: this.draggingSegEl,
        event: a,
        jsEvent: l.origEvent,
        view: s.viewApi
      }), this.validMutation) {
        let g = new m(s, c.defs[r.defId], o ? c.instances[o.instanceId] : null);
        s.dispatch({
          type: "MERGE_EVENTS",
          eventStore: c
        });
        let p = {
          oldEvent: a,
          event: g,
          relatedEvents: M(c, s, o),
          revert() {
            s.dispatch({
              type: "MERGE_EVENTS",
              eventStore: d
              // the pre-change events
            });
          }
        };
        s.emitter.trigger("eventResize", Object.assign(Object.assign({}, p), { el: this.draggingSegEl, startDelta: this.validMutation.startDelta || _(0), endDelta: this.validMutation.endDelta || _(0), jsEvent: l.origEvent, view: s.viewApi })), s.emitter.trigger("eventChange", p);
      } else
        s.emitter.trigger("_noEventResize");
      this.draggingSeg = null, this.relevantEvents = null, this.validMutation = null;
    };
    let { component: t } = e, i = this.dragging = new w(e.el);
    i.pointer.selector = ".fc-event-resizer", i.touchScrollAllowed = !1, i.autoScroller.isEnabled = t.context.options.dragScroll;
    let n = this.hitDragging = new P(this.dragging, Y(e));
    n.emitter.on("pointerdown", this.handlePointerDown), n.emitter.on("dragstart", this.handleDragStart), n.emitter.on("hitupdate", this.handleHitUpdate), n.emitter.on("dragend", this.handleDragEnd);
  }
  destroy() {
    this.dragging.destroy();
  }
  querySegEl(e) {
    return S(e.subjectEl, ".fc-event");
  }
}
function Fe(h, e, t, i) {
  let n = h.context.dateEnv, l = h.dateSpan.range.start, s = e.dateSpan.range.start, r = z(l, s, n, h.largeUnit);
  if (t) {
    if (n.add(i.start, r) < i.end)
      return { startDelta: r };
  } else if (n.add(i.end, r) > i.start)
    return { endDelta: r };
  return null;
}
class ke {
  constructor(e) {
    this.context = e, this.isRecentPointerDateSelect = !1, this.matchesCancel = !1, this.matchesEvent = !1, this.onSelect = (i) => {
      i.jsEvent && (this.isRecentPointerDateSelect = !0);
    }, this.onDocumentPointerDown = (i) => {
      let n = this.context.options.unselectCancel, l = ce(i.origEvent);
      this.matchesCancel = !!S(l, n), this.matchesEvent = !!S(l, y.SELECTOR);
    }, this.onDocumentPointerUp = (i) => {
      let { context: n } = this, { documentPointer: l } = this, s = n.getCurrentData();
      if (!l.wasTouchScroll) {
        if (s.dateSelection && // an existing date selection?
        !this.isRecentPointerDateSelect) {
          let r = n.options.unselectAuto;
          r && (!r || !this.matchesCancel) && n.calendarApi.unselect(i);
        }
        s.eventSelection && // an existing event selected?
        !this.matchesEvent && n.dispatch({ type: "UNSELECT_EVENT" });
      }
      this.isRecentPointerDateSelect = !1;
    };
    let t = this.documentPointer = new Z(document);
    t.shouldIgnoreMove = !0, t.shouldWatchScroll = !1, t.emitter.on("pointerdown", this.onDocumentPointerDown), t.emitter.on("pointerup", this.onDocumentPointerUp), e.emitter.on("select", this.onSelect);
  }
  destroy() {
    this.context.emitter.off("select", this.onSelect), this.documentPointer.destroy();
  }
}
const ze = {
  fixedMirrorParent: E
}, Ge = {
  dateClick: E,
  eventDragStart: E,
  eventDragStop: E,
  eventDrop: E,
  eventResizeStart: E,
  eventResizeStop: E,
  eventResize: E,
  drop: E,
  eventReceive: E,
  eventLeave: E
};
O.dataAttrPrefix = "";
var Qe = ee({
  name: "@fullcalendar/interaction",
  componentInteractions: [Ne, Ve, y, qe],
  calendarInteractions: [ke],
  elementDraggingImpl: w,
  optionRefiners: ze,
  listenerRefiners: Ge
});
export {
  Qe as default
};
