'use strict';

var vue = require('vue');
var store = require('../../../components/src/base/rectSelect/store.js');

const useRectSelect = (options) => {
  const rectSelectStore = store.useRectSelectStore();
  const startPoint = vue.ref({ x: 0, y: 0 });
  const mousedown = (e) => {
    const target = e.target;
    if (options?.notSelectClass && target.classList.contains(options?.notSelectClass)) {
      return false;
    }
    rectSelectStore.isShow = true;
    startPoint.value.x = e.clientX;
    startPoint.value.y = e.clientY;
    rectSelectStore.selectStyle = {
      width: 0,
      height: 0,
      top: `${startPoint.value.y}px`,
      left: `${startPoint.value.x}px`
    };
    return true;
  };
  const isElementInSelection = (element) => {
    const rect = element.getBoundingClientRect();
    const boxRect = rectSelectStore.rectSelectRef?.getBoundingClientRect();
    if (!boxRect) {
      return false;
    }
    return boxRect.left <= rect.right && boxRect.right >= rect.left && boxRect.top <= rect.bottom && boxRect.bottom >= rect.top;
  };
  const mousemove = (e) => {
    if (!rectSelectStore.isShow) {
      return false;
    }
    const currentX = e.clientX;
    const currentY = e.clientY;
    const width = Math.abs(currentX - startPoint.value.x);
    const height = Math.abs(currentY - startPoint.value.y);
    const newX = currentX < startPoint.value.x ? currentX : startPoint.value.x;
    const newY = currentY < startPoint.value.y ? currentY : startPoint.value.y;
    rectSelectStore.selectStyle.width = `${width}px`;
    rectSelectStore.selectStyle.height = `${height}px`;
    rectSelectStore.selectStyle.top = `${newY}px`;
    rectSelectStore.selectStyle.left = `${newX}px`;
    return true;
  };
  const mouseup = (e) => {
    rectSelectStore.isShow = false;
    rectSelectStore.selectStyle = {
      width: 0,
      height: 0,
      top: 0,
      left: 0
    };
    return true;
  };
  return {
    mousedown,
    mousemove,
    mouseup,
    isElementInSelection
  };
};

exports.useRectSelect = useRectSelect;
//# sourceMappingURL=index.js.map
