import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import { c as usePlannerUIHandler } from './index-bbdfb97a.js';
import { useState } from 'react';
import DPACC from './index-92be0503.js';
import { Vector2 } from '@crystaldesign/web-planner-logic';
import { jsx, Fragment } from 'react/jsx-runtime';

function useDockingPointPositioning(_ref) {
  var _item$position$x, _item$position$y, _boundingState$width, _boundingState$height;
  var dpElement = _ref.dpElement,
    item = _ref.item;
  var plannerUIHandler = usePlannerUIHandler();
  var boundingState = dpElement === null || dpElement === void 0 ? void 0 : dpElement.getBoundingClientRect();
  var left = (_item$position$x = item === null || item === void 0 ? void 0 : item.position.x) !== null && _item$position$x !== void 0 ? _item$position$x : 0;
  var top = (_item$position$y = item === null || item === void 0 ? void 0 : item.position.y) !== null && _item$position$y !== void 0 ? _item$position$y : 0;
  if (boundingState && item) {
    var correctedPos = new Vector2(left, top);
    var viewConfig = plannerUIHandler.getViewConfig();
    var offsetVec = new Vector2(0, 0);
    if ((item === null || item === void 0 ? void 0 : item.type) == 'AVL' || (item === null || item === void 0 ? void 0 : item.type) == 'AVR') {
      switch (item.plannerMode) {
        case '2D':
          switch (viewConfig.posDPIcon2D) {
            case 'CORNER':
              //Standard
              //  offsetVec = new Vector2(-boundingState, -boundingState.height / 2);
              // if (item?.rotOfElement) offsetVec = Vector2.rotateOrigin(offsetVec, item?.rotOfElement);
              // correctedPos = new Vector2(left + offsetVec.x, top + offsetVec.y, "pixel");

              break;
            case 'SIDE_TOP':
              //Pfister
              if ((item === null || item === void 0 ? void 0 : item.type) == 'AVL') {
                offsetVec = new Vector2(-boundingState.width, 0);
                if (item !== null && item !== void 0 && item.rotOfElement) offsetVec = Vector2.rotateOrigin(offsetVec, item === null || item === void 0 ? void 0 : item.rotOfElement);
                correctedPos = new Vector2(left + offsetVec.x, top + offsetVec.y, 'pixel');
              }
              break;
          }
          break;
      }
    } else if ((item === null || item === void 0 ? void 0 : item.type) == 'AccDP' && (item === null || item === void 0 ? void 0 : item.plannerMode) == '3D') {
      correctedPos.y = 100 - correctedPos.y;
    } else if (item.type == 'BoxCopyLeft' || (item === null || item === void 0 ? void 0 : item.type) == 'BoxCopyRight' || (item === null || item === void 0 ? void 0 : item.type) == 'BoxCopyTop') ;
    left = correctedPos.x;
    top = correctedPos.y;
  }
  var rect = {
    width: (_boundingState$width = boundingState === null || boundingState === void 0 ? void 0 : boundingState.width) !== null && _boundingState$width !== void 0 ? _boundingState$width : 0,
    height: (_boundingState$height = boundingState === null || boundingState === void 0 ? void 0 : boundingState.height) !== null && _boundingState$height !== void 0 ? _boundingState$height : 0,
    top: top,
    left: left
  };
  return rect;
}

var ItemsDPAccContainer = function ItemsDPAccContainer(_ref) {
  var item = _ref.item,
    plannerUIProps = _ref.plannerUIProps;
  var _useState = useState(null),
    _useState2 = _slicedToArray(_useState, 2),
    dpAccElement = _useState2[0],
    setDpAccElement = _useState2[1];
  var dpAccRect = useDockingPointPositioning({
    item: item,
    dpElement: dpAccElement
  });
  return /*#__PURE__*/jsx(Fragment, {
    children: item && /*#__PURE__*/jsx(DPACC, {
      item: item,
      rect: dpAccRect,
      onElement: setDpAccElement,
      plannerUIProps: plannerUIProps
    }, item === null || item === void 0 ? void 0 : item.key)
  });
};

var index = /*#__PURE__*/Object.freeze({
  __proto__: null,
  'default': ItemsDPAccContainer
});

export { ItemsDPAccContainer as I, index as i, useDockingPointPositioning as u };
