"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.KanbanDraggableCardItem = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _react = _interopRequireWildcard(require("react"));
var _mobxReactLite = require("mobx-react-lite");
var _core = require("@wix/wix-style-react-incubator/dnd-kit/core");
var _mobx = require("mobx");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/KanbanDragAndDropDndKit/KanbanDraggableCardItem.tsx";
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
function _KanbanDraggableCardItem(props) {
  const {
    children: CardComponent,
    id,
    cardProps,
    state
  } = props;
  const dragHandleRef = (0, _react.useRef)(null);
  const cardRef = (0, _react.useRef)(null);
  const [cardHeight, setCardHeight] = (0, _react.useState)(undefined);

  // Measure card height after render
  (0, _react.useLayoutEffect)(() => {
    if (cardRef.current) {
      const height = cardRef.current.offsetHeight;
      setCardHeight(height);
    }
  }, [cardProps]);

  // Use useDraggable instead of useSortable since we only support cross-stage movement
  const {
    attributes,
    listeners,
    setNodeRef,
    transform,
    isDragging,
    setActivatorNodeRef
  } = (0, _core.useDraggable)({
    id
  });
  const ariaDescribedBy = `draggable-kanban-card-description-${id}`;
  const stateDragAndDrop = state.dragAndDropState;
  const dragHandleProps = {
    ...attributes,
    ...listeners,
    ref: e => {
      setActivatorNodeRef(e);
      dragHandleRef.current = e;
    },
    'aria-describedby': ariaDescribedBy,
    onClick: e => e.stopPropagation(),
    ...(process.env.NODE_ENV === 'test' && {
      onPointerDown: (0, _mobx.action)(() => {
        stateDragAndDrop.handleDragStart({
          active: {
            id
          }
        });
      })
    }),
    style: {
      pointerEvents: 'auto'
    }
  };
  const dragStyle = {
    // Apply transform for drag feedback
    transform: transform ? `translate3d(${transform.x}px, ${transform.y}px, 0)` : undefined,
    // Hide the original card when dragging, letting the drag system handle the visual feedback
    visibility: isDragging ? 'hidden' : 'visible',
    // Allow pointer events to pass through to parent droppable when not dragging
    pointerEvents: isDragging ? 'auto' : 'none',
    // Ensure dragged card appears above all other elements including stages
    zIndex: isDragging ? 1000 : 'auto',
    position: 'relative'
  };
  const containerStyle = {
    position: 'relative'
  };
  return /*#__PURE__*/_react.default.createElement("div", {
    style: containerStyle,
    "data-hook": "kanban-card-item-events",
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 85,
      columnNumber: 5
    }
  }, isDragging && /*#__PURE__*/_react.default.createElement("div", {
    style: {
      position: 'absolute',
      top: 0,
      left: 0,
      height: cardHeight ? `${cardHeight}px` : '129px',
      // Use measured height or fallback
      width: '246px',
      backgroundColor: '#D6E6FE',
      borderRadius: '8px',
      pointerEvents: 'none',
      zIndex: 1,
      marginLeft: '12px'
    },
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 88,
      columnNumber: 9
    }
  }), /*#__PURE__*/_react.default.createElement("div", {
    ref: node => {
      setNodeRef(node);
      cardRef.current = node;
    },
    style: dragStyle,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 107,
      columnNumber: 7
    }
  }, /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({}, dragHandleProps, {
    "data-hook": `kanban-card-drag-item-${id}`,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 114,
      columnNumber: 9
    }
  }), /*#__PURE__*/_react.default.createElement(CardComponent, (0, _extends2.default)({}, cardProps, {
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 115,
      columnNumber: 11
    }
  })))));
}
const KanbanDraggableCardItem = exports.KanbanDraggableCardItem = (0, _mobxReactLite.observer)(_KanbanDraggableCardItem);
//# sourceMappingURL=KanbanDraggableCardItem.js.map