import { __rest } from "tslib";
import { jsx as _jsx } from "react/jsx-runtime";
import clsx from 'clsx';
import { forwardRef } from 'react';
import useDnD from './useDnD';
import Box from '../Box';

/**
 * DraggableNode component can be used to make any node draggable within a drag-and-drop context.
 *
 * Demos:
 *
 * - [Drag & Drop (Oxygen UI)](https://wso2.github.io/oxygen-ui/react/?path=/docs/navigation-drag-and-drop--overview)
 *
 * API:
 *
 * - inherits [Box API](https://mui.com/material-ui/api/box/)
 *
 * @remarks
 * - ✨ This is a custom component that is not available in the Material-UI library.
 * - ✔️ Props of the [Box](https://mui.com/material-ui/api/box/) component are also available.
 * - ✅ `component` prop is supported.
 * - ✅ The `ref` is forwarded to the root element.
 *
 * @template C - The type of the component.
 * @param props - The props for the DraggableNode component.
 * @param ref - The ref to be forwarded to the Box component.
 * @returns The rendered DraggableNode component.
 */
const DraggableNode = forwardRef((_a, ref) => {
    var { className, children, node } = _a, rest = __rest(_a, ["className", "children", "node"]);
    const { setNode } = useDnD();
    const onDragStart = (event, draggingNode) => {
        setNode(draggingNode);
        const { dataTransfer } = event;
        dataTransfer.effectAllowed = 'move';
        dataTransfer.setData('application/json', JSON.stringify(draggingNode));
    };
    return (_jsx(Box, Object.assign({ ref: ref, draggable: true, onDragStart: (event) => onDragStart(event, node), className: clsx('OxygenDraggableNode-root', className) }, rest, { children: children })));
});
export default DraggableNode;
function addCSS(css){var head = document.getElementsByTagName('head')[0];var s = document.createElement('style');s.setAttribute('type', 'text/css');s.appendChild(document.createTextNode(css));head.appendChild(s);}
addCSS("/**\n * Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).\n *\n * WSO2 LLC. licenses this file to you under the Apache License,\n * Version 2.0 (the \"License\"); you may not use this file except\n * in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing,\n * software distributed under the License is distributed on an\n * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n * KIND, either express or implied. See the License for the\n * specific language governing permissions and limitations\n * under the License.\n */\n.OxygenDraggableNode-root:hover > div {\n  box-shadow: var(--oxygen-shadows-6);\n  cursor: move;\n}");